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'.
60 lines
1.9 KiB
Go
60 lines
1.9 KiB
Go
package egress
|
|
|
|
import (
|
|
"context"
|
|
"sync"
|
|
)
|
|
|
|
// GrantResolver is the production Resolver: it holds, per active run, only
|
|
// the secrets a caller explicitly Grant-ed it -- the intersection a run
|
|
// credential carries (docs/prds/external-agent-harness.md, Credentials;
|
|
// docs/prds/orgs-and-access.md, "Agents: decided once, carried as a run
|
|
// credential"). It never derives a secret from anything else, so a service
|
|
// nobody granted, or granted to a different run, always answers ErrUnbound.
|
|
type GrantResolver struct {
|
|
mu sync.RWMutex
|
|
grants map[string]map[string]string
|
|
}
|
|
|
|
// NewGrantResolver returns an empty resolver: no run may resolve anything
|
|
// until Grant is called for it.
|
|
func NewGrantResolver() *GrantResolver {
|
|
return &GrantResolver{grants: map[string]map[string]string{}}
|
|
}
|
|
|
|
// Grant records exactly what one run may resolve, replacing whatever it held
|
|
// before -- a repeated Grant for the same run (a retry, or a narrower set)
|
|
// never merges with the last, since a service the caller dropped must not
|
|
// keep resolving from a stale entry.
|
|
func (g *GrantResolver) Grant(run string, secrets map[string]string) {
|
|
g.mu.Lock()
|
|
defer g.mu.Unlock()
|
|
g.grants[run] = secrets
|
|
}
|
|
|
|
// RevokeGrant ends a run: nothing it was granted resolves after this call.
|
|
func (g *GrantResolver) RevokeGrant(run string) {
|
|
g.mu.Lock()
|
|
defer g.mu.Unlock()
|
|
delete(g.grants, run)
|
|
}
|
|
|
|
// Resolve implements Resolver. A run with no Grant, or a service not among
|
|
// what it was granted, answers ErrUnbound -- the only error ambiguous enough
|
|
// for an optional credential to pass over (see Resolver's doc).
|
|
func (g *GrantResolver) Resolve(_ context.Context, run, service string) (string, error) {
|
|
g.mu.RLock()
|
|
defer g.mu.RUnlock()
|
|
secrets, ok := g.grants[run]
|
|
if !ok {
|
|
return "", ErrUnbound
|
|
}
|
|
v, ok := secrets[service]
|
|
if !ok {
|
|
return "", ErrUnbound
|
|
}
|
|
return v, nil
|
|
}
|
|
|
|
var _ Resolver = (*GrantResolver)(nil)
|