Support pushed CarrierNode credentials

This commit is contained in:
Gabriel20xx committed 2026-09-16 19:52:57 +02:00
1 parent 4b0566ea46
commit e4c1826d6a
3 files changed
+43 -5

No files matched your search

+16 -1
View File
@@ -39,6 +39,11 @@ type Info struct {
// discover files across every configured storage backend / fail over between replicas wire
// this through carriernodeclient.NewMulti(secret, store.CarrierNodeURLs) instead.
CarrierNodeURLs []string `json:"carrierNodeUrls"`
// CarrierNodeSecret is the credential CarrierNode expects in X-Internal-Auth.
// ProjectConfigurator includes it so consumers with independent databases can
// authenticate storage requests without falling back to their own SECRET.
CarrierNodeSecret string `json:"carrierNodeSecret,omitempty"`
}
// Store holds the most recently pushed Info, defaulting to whatever fallback NewStore was given
@@ -84,6 +89,9 @@ func (s *Store) CarrierNodeURL() string { return s.Get().CarrierNodeURL }
// store.CarrierNodeURLs() }).
func (s *Store) CarrierNodeURLs() []string { return s.Get().CarrierNodeURLs }
// CarrierNodeSecret is a convenience accessor for Get().CarrierNodeSecret.
func (s *Store) CarrierNodeSecret() string { return s.Get().CarrierNodeSecret }
// OnUpdate registers fn to be called (synchronously, so keep it fast) with the new Info after
// every Set - e.g. client.SetBaseURL for an authclient.Client that isn't already reading through
// Store on every call. Only one callback is kept; a second registration replaces the first, which
@@ -108,6 +116,9 @@ func (s *Store) Set(next Info) {
if url := strings.TrimRight(strings.TrimSpace(next.ProjectConfiguratorURL), "/"); url != "" {
s.info.ProjectConfiguratorURL = url
}
if secret := strings.TrimSpace(next.CarrierNodeSecret); secret != "" {
s.info.CarrierNodeSecret = secret
}
if len(next.CarrierNodeURLs) > 0 {
s.info.CarrierNodeURLs = next.CarrierNodeURLs
s.info.CarrierNodeURL = next.CarrierNodeURLs[0]
@@ -162,7 +173,11 @@ func Handler(secret string, store *Store) http.HandlerFunc {
return
}
store.Set(input)
writeJSON(w, http.StatusOK, map[string]any{"ok": true, "info": store.Get()})
// Do not echo the CarrierNode credential to the caller. The push is
// authenticated, but the credential is needed only by the recipient.
info := store.Get()
info.CarrierNodeSecret = ""
writeJSON(w, http.StatusOK, map[string]any{"ok": true, "info": info})
}
}