docs/prds/external-agent-harness.md (Credentials) and orgs-and-access.md: egress.Resolver had no production implementation, and no run carried a credential naming the org secrets its identity is granted, so a Kit's required credential@1 was refused at the proxy and no harness run authenticated (archie-core-egkf.11). Two things, as scoped (this does not attempt #1026's full run-credential consolidation replacing WorktreeGrantIssuer/StateStoreGrantIssuer -- that PRD item is real, separate, and still open; this is deliberately narrower): 1. A run credential naming granted secrets: config.CredentialBinding maps a Kit credential@1 service to a secret; config.Config/IdentityConfig gain Org and GrantedCredentials (a per-identity allowlist of service names, reusing the existing per-identity config-override pattern DiffCapLines already uses, not a new Cedar/Authorizer integration -- KindSecret policy objects exist in internal/domain/access but assembling a full Principal is #1026's job, not a two-line addition here). config.ContainerConfig. BoundCredentials computes the declared (Kit) ∩ granted (identity) ∩ org-matched intersection Sam's own rule requires: neither side widens the other, proven by a mutation-checked test flipping each of the three independently. 2. egress.GrantResolver: the production Resolver, holding only what a caller explicitly Grant-ed one run, replaced wholesale (not merged) on a repeated Grant, gone entirely on RevokeGrant. kitrun.Launcher.Launch computes the intersection per launch and resolves real values through the existing secret registry (SecretResolver), Grants it before the proxy session opens, and Release/error-path rollback (a new shared Launcher.release) always revokes it. Course-corrected mid-implementation (flagged by Sam): credential bindings first landed as a boot-time config.ContainerConfig.Credentials field captured once into Launcher.Bindings -- exactly the "parses but is not a resource" trap CLAUDE.md warns about, and inconsistent with agent-profiles (#1207) making a Kit profile apply without a restart. Rebuilt as its own live control-plane resource, CredentialBindingsKind ("credential-bindings"), following the agent-profiles/container-runtime-policies split precisely: config.ContainerConfig.Credentials is json:"-", [containers].credentials is only its seed, and kitrun.Launcher now holds *config.Holder (not a captured slice) and reads Containers.Credentials fresh on every Launch. Org/GrantedCredentials were already read fresh per dispatch (d.configFor inside runKitTask, never cached), so no equivalent fix was needed there. Deliberately not built: identities and grants as their own State Store resource (orgs-and-access.md's "Org owns ... identities and their grants"). Identities are entirely config.toml-defined today with no control-plane resource at all; moving GrantedCredentials alone into one would put half an identity in two places. That migration is identities' own scope, not credential bindings'.
79 lines
3.0 KiB
Go
79 lines
3.0 KiB
Go
package controlplane
|
|
|
|
import "github.com/samcharles93/archie-core/internal/config"
|
|
|
|
// CredentialBindingsKind is the control-plane resource mapping a Kit
|
|
// credential@1 service name to an org secret
|
|
// (docs/prds/external-agent-harness.md, Credentials; docs/prds/orgs-and-access.md).
|
|
// It exists so a binding applies without a restart, the same reason
|
|
// AgentProfileKind is its own resource: [containers].credentials in
|
|
// config.toml is only its seed, and kitrun.Launcher reads the live
|
|
// control-plane document on every launch, never a value captured at boot.
|
|
const CredentialBindingsKind = "credential-bindings"
|
|
|
|
// 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()
|
|
})
|
|
}
|