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.
75 lines
2.1 KiB
Go
75 lines
2.1 KiB
Go
package kitrun
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/docker/sandbox-kit-spec/v3/spec"
|
|
|
|
"github.com/samcharles93/archie-core/internal/config"
|
|
"github.com/samcharles93/archie-core/internal/infrastructure/egress"
|
|
)
|
|
|
|
// A setup session has no task and no identity grant, so it must bind only the
|
|
// org's own bindings for the Kit's declared services. Widening that
|
|
// intersection would let one org's terminal carry another org's credential,
|
|
// or a service the Kit never declared.
|
|
func TestOrgCredentialKinds(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
bindings := []config.CredentialBinding{
|
|
{Service: "github", Org: "acme", Secret: config.SecretRef{Engine: "builtin", Key: "gh"}},
|
|
{Service: "linear", Org: "acme"},
|
|
{Service: "github", Org: "other", Secret: config.SecretRef{Engine: "builtin", Key: "gh"}},
|
|
}
|
|
creds := []spec.CredentialCapability{{Service: "github"}, {Service: "linear"}, {Service: "unbound"}}
|
|
|
|
cases := []struct {
|
|
name string
|
|
org string
|
|
want map[string]egress.CredentialKind
|
|
services []string
|
|
}{
|
|
{
|
|
name: "binds the org's own declared services",
|
|
org: "acme",
|
|
want: map[string]egress.CredentialKind{
|
|
"github": egress.CredentialAPIKey,
|
|
"linear": egress.CredentialOAuth,
|
|
},
|
|
services: []string{"github", "linear"},
|
|
},
|
|
{
|
|
name: "another org's binding never resolves",
|
|
org: "other",
|
|
want: map[string]egress.CredentialKind{"github": egress.CredentialAPIKey},
|
|
services: []string{
|
|
"github",
|
|
},
|
|
},
|
|
{
|
|
name: "unknown org binds nothing",
|
|
org: "nobody",
|
|
want: map[string]egress.CredentialKind{},
|
|
services: []string{},
|
|
},
|
|
}
|
|
|
|
for _, tc := range cases {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
t.Parallel()
|
|
got, services := orgCredentialKinds(bindings, tc.org, creds)
|
|
if len(got) != len(tc.want) {
|
|
t.Fatalf("kinds = %v, want %v", got, tc.want)
|
|
}
|
|
for service, kind := range tc.want {
|
|
if got[service] != kind {
|
|
t.Errorf("kind[%s] = %q, want %q", service, got[service], kind)
|
|
}
|
|
}
|
|
if len(services) != len(tc.services) {
|
|
t.Fatalf("services = %v, want %v", services, tc.services)
|
|
}
|
|
})
|
|
}
|
|
}
|