Archie runs its own agent loop only. Removes Kit resolution and launch, the harness runner and adapters, the setup terminal and sandbox view, harness secrets and OAuth capture (table dropped in migration 0075), the task-tools contract that only Kit containers reached, and the sandbox-kit-spec dependency. Agent profiles carry image and tools only. The egress proxy keeps the model-session path; the sandbox relay code stays for #1867.
80 lines
2.6 KiB
Go
80 lines
2.6 KiB
Go
package archied
|
|
|
|
import (
|
|
"context"
|
|
"slices"
|
|
|
|
"github.com/samcharles93/archie-core/internal/config"
|
|
"github.com/samcharles93/archie-core/internal/daemon"
|
|
"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 key
|
|
// 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.
|
|
type runCredentialResolver struct {
|
|
runs interface {
|
|
TaskForCredential(ctx context.Context, token string) (*workflow.Task, error)
|
|
}
|
|
// models answers a task's org's own providers. Nil grants only the
|
|
// instance providers.
|
|
models daemon.TaskModels
|
|
config *config.Holder
|
|
secrets interface {
|
|
Resolve(config.SecretRef) (string, error)
|
|
}
|
|
// credentials, when set, is told whether each bound secret resolved.
|
|
credentials *credentialWatch
|
|
}
|
|
|
|
func (r runCredentialResolver) Resolve(ctx context.Context, credential, service string) (string, error) {
|
|
task, err := r.runs.TaskForCredential(ctx, credential)
|
|
if err != nil {
|
|
return "", egress.ErrUnbound
|
|
}
|
|
cfg := r.config.Get()
|
|
_, granted := cfg.CredentialAccess(task.Identity)
|
|
org := task.OrgOrDefault()
|
|
// A configured model provider's key is granted to every run of the org:
|
|
// any agent stage needs model access.
|
|
if r.isModelProvider(ctx, cfg, task, service) {
|
|
granted = append(slices.Clone(granted), service)
|
|
}
|
|
return r.resolveBinding(ctx, org, granted, service)
|
|
}
|
|
|
|
// resolveBinding resolves service from the org's binding when the run is
|
|
// granted it.
|
|
func (r runCredentialResolver) resolveBinding(ctx context.Context, 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{}) || r.secrets == nil {
|
|
return "", egress.ErrUnbound
|
|
}
|
|
value, err := r.secrets.Resolve(binding.Secret)
|
|
r.credentials.observe(ctx, org, service, err != nil)
|
|
return value, err
|
|
}
|
|
|
|
// isModelProvider reports whether service is a provider the task's models
|
|
// run on: an instance provider, or one of its org's own.
|
|
func (r runCredentialResolver) isModelProvider(ctx context.Context, cfg config.Config, task *workflow.Task, service string) bool {
|
|
if _, ok := cfg.Providers[service]; ok {
|
|
return true
|
|
}
|
|
if r.models == nil {
|
|
return false
|
|
}
|
|
models, err := r.models.TaskModels(ctx, task.ID)
|
|
if err != nil {
|
|
return false
|
|
}
|
|
_, ok := models.Providers[service]
|
|
return ok
|
|
}
|