The dashboard's setup terminal was a 503: it had a WebSocket route, an authorizer and an xterm.js surface, but nothing owned a container. The daemon owns containers, so the session contract lands there and the dashboard consumes it over a new gRPC contract. One session concept, two targets. A setup session is addressed by Kit profile and is ephemeral; a run session (archie-core-qi91) is addressed by task and attempt and is bounded by the task. This slice serves setup and answers Unimplemented for run. The contract, the authorisation, the lifetime and the egress phase are settled in docs/prds/external-agent-harness.md, "Session contract". The short version: the daemon serves harness.v1.HarnessService; the dashboard authorizes the operator as an update on the secret and then dials the daemon with the harness service token, required even on loopback because a session is a shell holding an org's credential; the setup container runs no worker, mounts no worktree, holds a keepalive, and carries an empty container environment. Install hooks run at the install phase and the session enters runtime before the shell, so a runtime-phase credential's token endpoint is the one the proxy intercepts. Capture is gated by the egress proxy on a granted service, and a setup session has no task, so the daemon registers a session grant: the session's proxy token resolves to the org's bindings for the Kit's declared services. The real token never enters the container: the token endpoint response is sentinelized and stored as the org's harness secret. Every teardown path releases the pool slot, revokes the egress session and the grant, removes the sandbox network, and removes the session's volumes. The listener requires HARNESS_TOKEN and stops with a 10s grace before Stop, so an open session cannot hold shutdown to the watchdog leash.
65 lines
2.2 KiB
Go
65 lines
2.2 KiB
Go
package archied
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/samcharles93/archie-core/internal/config"
|
|
"github.com/samcharles93/archie-core/internal/domain/workflow"
|
|
"github.com/samcharles93/archie-core/internal/infrastructure/egress"
|
|
)
|
|
|
|
// runCredentialResolver is the egress proxy's Resolver: it resolves a Kit
|
|
// credential for the run a run credential names, when the request is made,
|
|
// from the live grants and bindings. A revoked credential, a grant removed
|
|
// mid-run or a binding in another org stops resolving at once.
|
|
//
|
|
// A setup session's token names no task, so the resolver consults the session
|
|
// grants first: the session is bound for the org's bindings of the Kit's
|
|
// declared services, which is the intersection the operator's update-on-secret
|
|
// authorisation covers.
|
|
type runCredentialResolver struct {
|
|
runs interface {
|
|
TaskForCredential(ctx context.Context, token string) (*workflow.Task, error)
|
|
}
|
|
sessions interface {
|
|
GrantedFor(token string) (org string, services []string, ok bool)
|
|
}
|
|
config *config.Holder
|
|
secrets interface {
|
|
Resolve(config.SecretRef) (string, error)
|
|
}
|
|
}
|
|
|
|
func (r runCredentialResolver) Resolve(ctx context.Context, credential, service string) (string, error) {
|
|
if r.sessions != nil {
|
|
if org, services, ok := r.sessions.GrantedFor(credential); ok {
|
|
return r.resolveBinding(org, services, service)
|
|
}
|
|
}
|
|
task, err := r.runs.TaskForCredential(ctx, credential)
|
|
if err != nil {
|
|
return "", egress.ErrUnbound
|
|
}
|
|
cfg := r.config.Get()
|
|
org, granted := cfg.CredentialAccess(task.Identity)
|
|
return r.resolveBinding(org, granted, service)
|
|
}
|
|
|
|
// resolveBinding resolves service from the org's binding when the run or
|
|
// session is granted it. An OAuth binding resolves to the empty string: the
|
|
// proxy supplies the org's token set itself.
|
|
func (r runCredentialResolver) resolveBinding(org string, granted []string, service string) (string, error) {
|
|
cfg := r.config.Get()
|
|
binding, ok := cfg.Containers.BoundCredentials(org, granted, []string{service})[service]
|
|
if !ok {
|
|
return "", egress.ErrUnbound
|
|
}
|
|
if binding.Secret == (config.SecretRef{}) {
|
|
return "", nil
|
|
}
|
|
if r.secrets == nil {
|
|
return "", egress.ErrUnbound
|
|
}
|
|
return r.secrets.Resolve(binding.Secret)
|
|
}
|