Files
archie/internal/infrastructure/controlplanestore/credential_bindings.go
T
sam db346b159d fix(webui): mark cookies Secure behind a TLS proxy; run gosec in the gate (#1919)
Cookies took Secure from r.TLS, which is nil behind a proxy that terminates
TLS, so sign-in cookies went out without it. Every dashboard cookie now goes
through one builder that reads the scheme the way the origin check does.

The worktree reset and the agent worker's chown walk use os.Root, so a
symlink swapped in mid-walk can't point them outside the worktree.

gosec runs in golangci-lint, tests included. G104, G115, G204 and G304 are
excluded in config; each remaining finding is fixed or suppressed at the site
with its reason.
2026-11-13 03:16:15 +11:00

74 lines
2.7 KiB
Go

package controlplanestore
import "github.com/samcharles93/archie-core/internal/config"
// CredentialBindingsKind is the resource mapping credential service names to
// org secrets. Applied live on each launch.
const CredentialBindingsKind = "credential-bindings" //nolint:gosec // G101: a resource kind, not a credential.
// credentialBinding is one config.CredentialBinding as the document writes
// it: explicit snake_case json tags, following channel_settings.go /
// container_settings.go's precedent, never the internal config struct
// (which has no json tags and would fall back to Go field names).
type credentialBinding struct {
Service string `json:"service"`
Org string `json:"org,omitempty"`
Secret credentialValue `json:"secret"`
}
// credentialValue is config.SecretRef as this document writes it.
type credentialValue struct {
Engine string `json:"engine,omitempty"`
Key string `json:"key,omitempty"`
}
func credentialBindingsDefinition() Definition {
return Definition{
Kind: CredentialBindingsKind,
Title: "Credential bindings",
ApplyMode: "live",
Document: []credentialBinding{},
Seed: seedCredentialBindings,
Validate: validateCredentialBindings,
}
}
func seedCredentialBindings(cfg config.Config) any {
return credentialBindingsDocument(cfg.Containers.Credentials)
}
func credentialBindingsDocument(bindings []config.CredentialBinding) []credentialBinding {
if bindings == nil {
return nil
}
out := make([]credentialBinding, len(bindings))
for i, b := range bindings {
out[i] = credentialBinding{Service: b.Service, Org: b.Org, Secret: credentialValue{Engine: b.Secret.Engine, Key: b.Secret.Key}}
}
return out
}
// credentialBindingsSettings reverses credentialBindingsDocument, for the
// layering in runtime_config.go and for validation against
// config.ContainerConfig.ValidateCredentialBindings.
func credentialBindingsSettings(bindings []credentialBinding) []config.CredentialBinding {
if bindings == nil {
return nil
}
out := make([]config.CredentialBinding, len(bindings))
for i, b := range bindings {
out[i] = config.CredentialBinding{Service: b.Service, Org: b.Org, Secret: config.SecretRef{Engine: b.Secret.Engine, Key: b.Secret.Key}}
}
return out
}
func validateCredentialBindings(input []byte) error {
// The rules live in the config package and are shared with the file
// document's own validation (config.ContainerConfig.ValidateCredentialBindings):
// which bindings are valid cannot differ between the file that seeds this
// resource and the resource that replaces it.
return validateAs(input, func(bindings []credentialBinding) error {
return config.ContainerConfig{Credentials: credentialBindingsSettings(bindings)}.ValidateCredentialBindings()
})
}