fix(identity): use System as the one root identity and record who created every task (#1851)
deploy / plan (push) Successful in 25s
deploy / gate (push) Successful in 7m57s
deploy / agent-image (push) Successful in 21s
deploy / dist-zip (push) Skipped
deploy / archied-image (push) Successful in 2m12s

Drop the bot_user-derived root identity and the empty-identity sentinel. System
polls forge connections and owns instance-level work; a polled task stores the
polling identity, task_queued and work_request_submitted carry task id, actor
and principal, and an empty task identity is refused. Migration 0072 moves
empty tasks.identity, the identity-grants root key and the old root's
connection permits to System so a re-poll dedups.
This commit is contained in:
sam committed 2026-11-10 20:01:16 +11:00
1 parent 04798b990a
commit e3ffefdc7d
36 files changed
+283 -189

No files matched your search

+38 -38
View File
@@ -200,7 +200,6 @@ type Daemon struct {
// every cycle so suspend/reactivate commands do not require a restart.
IdentityRepository identity.Repository
AgentAssignments org.AgentAssignments
RootIdentityID identity.IdentityID
// PackageAuthorities bounds the tools a package workflow's run is offered.
PackageAuthorities PackageAuthorities
@@ -267,14 +266,6 @@ func (d *Daemon) issueSources(ctx context.Context) []IssueSource {
return d.IssueSources(ctx)
}
// sourceTag is the identity a source's tasks carry: empty for the root.
func (d *Daemon) sourceTag(source IssueSource) string {
if source.Identity == d.RootIdentityID {
return ""
}
return string(source.Identity)
}
// emit publishes an observability event; safe on a nil bus.
func (d *Daemon) emit(ctx context.Context, e events.Event) {
if d.Bus != nil {
@@ -593,9 +584,9 @@ func (d *Daemon) dispatchBindings(ctx context.Context) {
if d.OrgPrincipals != nil {
principals = d.OrgPrincipals(ctx)
} else {
principal, err := d.Principals.PrincipalFor(ctx, d.RootIdentityID)
principal, err := d.Principals.PrincipalFor(ctx, identity.SystemID)
if err != nil {
d.Log.WarnContext(ctx, "binding dispatch: principal unavailable", "identity", d.RootIdentityID, "err", err)
d.Log.WarnContext(ctx, "binding dispatch: principal unavailable", "identity", identity.SystemID, "err", err)
return
}
principals = []access.Principal{principal}
@@ -734,8 +725,8 @@ func (d *Daemon) claimAndEnqueue(ctx context.Context, b binding.Binding, c store
if target.declared {
body = fmt.Sprintf("Started by binding %q from capture %q; the workflow's inputs travel with the task.", b.Name, c.ID)
}
taskIdentity := ""
if principal, ok := access.PrincipalFromContext(ctx); ok && (principal.IdentityID != d.RootIdentityID || principal.Org != org.DefaultOrgID) {
taskIdentity := string(identity.SystemID)
if principal, ok := access.PrincipalFromContext(ctx); ok {
taskIdentity = string(principal.IdentityID)
}
task, err := d.BindingTaskCreator.EnqueueBindingTask(ctx, target.owner, target.repo, title, body, b.Workflow, taskIdentity, b.ID, b.Version, c.ID, target.inputs)
@@ -1306,7 +1297,7 @@ func (d *Daemon) poll(ctx context.Context) error {
if source.Dispatch.Trigger != "" {
cfg.Dispatch, cfg.Label = source.Dispatch, source.Label
}
tag := d.sourceTag(source)
tag := string(source.Identity)
for _, repo := range source.Repos {
issues, complete := d.pollIssuesWithConfig(ctx, source.Forge, cfg, repo)
if complete {
@@ -1451,7 +1442,10 @@ func (d *Daemon) PublishTask(ctx context.Context, task workintake.TaskEnvelope)
if err := task.Kind.Validate(); err != nil {
return fmt.Errorf("publish task %s: %w", task.Ref(), err)
}
resolved, err := d.identityOrg(ctx, d.publisherIdentity(task.Identity))
if task.Identity == "" {
return fmt.Errorf("publish task %s: no identity", task.Ref())
}
resolved, err := d.identityOrg(ctx, identity.IdentityID(task.Identity))
if err != nil {
return fmt.Errorf("publish task %s: resolve org: %w", task.Ref(), err)
}
@@ -1470,7 +1464,7 @@ func (d *Daemon) PublishReaction(ctx context.Context, reaction workintake.Review
return fmt.Errorf("publish reaction %s: no task bus configured", reaction.Ref())
}
if reaction.Org == "" {
resolved, err := d.identityOrg(ctx, d.RootIdentityID)
resolved, err := d.identityOrg(ctx, identity.SystemID)
if err != nil {
return fmt.Errorf("publish reaction %s: resolve org: %w", reaction.Ref(), err)
}
@@ -1483,15 +1477,6 @@ func (d *Daemon) PublishReaction(ctx context.Context, reaction workintake.Review
return d.Tasks.PublishUnique(ctx, reaction.Subject(), reaction.IdempotencyKey(), payload)
}
// publisherIdentity is the identity a producer publishes as: the envelope's
// identity when it names one, otherwise the root identity.
func (d *Daemon) publisherIdentity(ref string) identity.IdentityID {
if ref == "" || identity.IdentityID(ref) == d.RootIdentityID || identity.StableID(ref) == d.RootIdentityID {
return d.RootIdentityID
}
return identity.IdentityID(ref)
}
// identityOrg resolves an identity's org. No PrincipalSource means the
// default org; a store error is returned.
func (d *Daemon) identityOrg(ctx context.Context, id identity.IdentityID) (org.OrgID, error) {
@@ -1505,7 +1490,7 @@ func (d *Daemon) identityOrg(ctx context.Context, id identity.IdentityID) (org.O
return principal.Org, nil
}
// acknowledge posts the pickup reaction and queued event
// acknowledge posts the pickup reaction
// using fg -- the forge client that owns repo (identity-scoped or root) --
// and the ack reaction from cfg, the dispatch config that owns this poll.
func (d *Daemon) acknowledge(ctx context.Context, fg forge.Forge, cfg config.Config, repo config.Repo, is forge.Issue) {
@@ -1515,10 +1500,22 @@ func (d *Daemon) acknowledge(ctx context.Context, fg forge.Forge, cfg config.Con
d.Log.WarnContext(ctx, "ack reaction failed", "issue", is.Number, "err", err)
}
}
d.emit(ctx, events.Event{
Kind: events.KindTaskQueued, Repo: repo.FullName(),
Issue: is.Number, Detail: is.Title,
})
}
// emitTaskQueued records the queued task under the identity that polled it,
// which is both the actor and the authority the task was created with.
func (d *Daemon) emitTaskQueued(ctx context.Context, task *workflow.Task) {
e := events.Event{
Kind: events.KindTaskQueued, TaskID: task.ID, Repo: task.Owner + "/" + task.Repo,
Issue: task.IssueNumber, Detail: task.Title, Attempt: task.Attempt,
ActorID: task.Identity, PrincipalID: task.Identity,
}
if d.IdentityRepository != nil {
if value, err := d.IdentityRepository.Get(ctx, identity.IdentityID(task.Identity)); err == nil {
e.ActorKind = string(value.Kind)
}
}
d.emit(ctx, e)
}
func (d *Daemon) acceptTaskPublisher(ctx context.Context, msg eventbus.Message, name string) bool {
@@ -1591,6 +1588,7 @@ func (d *Daemon) processNATSTask(ctx context.Context, msg eventbus.Message, hold
return
}
d.emitTaskQueued(ctx, task)
d.process(ctx, task, hold)
if err := msg.Ack(); err != nil {
d.Log.WarnContext(ctx, "ack failed", "err", err)
@@ -2632,10 +2630,13 @@ func (d *Daemon) captureAttemptConfig(ctx context.Context, task *workflow.Task,
}
// identityMayAct reports whether a task's identity may act, and the park
// class if not. Empty is the root identity. An unknown or inactive identity
// never falls back to the root forge.
// class if not. An empty, unknown or inactive identity never falls back to
// the System forge.
func (d *Daemon) identityMayAct(ctx context.Context, name string) (bool, string, taskstate.ParkClass) {
id := d.publisherIdentity(name)
if name == "" {
return false, "task has no identity", taskstate.ParkNeedsDecision
}
id := identity.IdentityID(name)
if d.IdentityRepository != nil {
value, err := d.IdentityRepository.Get(ctx, id)
if err != nil {
@@ -2646,15 +2647,14 @@ func (d *Daemon) identityMayAct(ctx context.Context, name string) (bool, string,
}
return true, "", ""
}
if name == "" || name == string(d.RootIdentityID) {
if name == string(identity.SystemID) {
return true, "", ""
}
return false, "identity " + name + " no longer resolves", taskstate.ParkTransient
}
// parkIfIdentityUnresolvable parks task when its non-empty identity cannot be
// acted on, reporting whether it did. An empty identity is the root
// single-identity path and never parks here.
// parkIfIdentityUnresolvable parks task when its identity cannot be acted on,
// reporting whether it did.
func (d *Daemon) parkIfIdentityUnresolvable(ctx context.Context, task *workflow.Task) bool {
ok, reason, class := d.identityMayAct(ctx, task.Identity)
if ok {
@@ -2711,7 +2711,7 @@ func (d *Daemon) treesFor(task *workflow.Task) *worktree.Manager {
}
func (d *Daemon) rootTask(task *workflow.Task) bool {
return task.Identity == "" || identity.IdentityID(task.Identity) == d.RootIdentityID
return identity.IdentityID(task.Identity) == identity.SystemID
}
// repoFor resolves a root task's repo config from Cfg.Repos.
+1 -1
View File
@@ -62,7 +62,7 @@ func TestPublishDiscoveredCap(t *testing.T) {
}
room := tt.cap
repo := config.Repo{Owner: "acme", Name: "widget"}
d.publishDiscovered(t.Context(), nil, config.Config{}, repo, issues, "", &room)
d.publishDiscovered(t.Context(), nil, config.Config{}, repo, issues, string(sys), &room)
if bus.published != tt.want {
t.Fatalf("published %d tasks, want %d", bus.published, tt.want)
}
+2 -1
View File
@@ -7,6 +7,7 @@ import (
"time"
"github.com/samcharles93/archie-core/internal/config"
"github.com/samcharles93/archie-core/internal/domain/identity"
"github.com/samcharles93/archie-core/internal/domain/workflow"
workflowtask "github.com/samcharles93/archie-core/internal/domain/workflow/task"
"github.com/samcharles93/archie-core/internal/infrastructure/egress"
@@ -68,7 +69,7 @@ func (d *Daemon) runKitTask(ctx context.Context, task *workflow.Task, repo confi
// config.Config d.configFor already resolves for every other identity
// override (Forge, Budgets, ...).
taskCfg := d.configFor(task)
credentialOrg, grantedServices := taskCfg.CredentialAccess("")
credentialOrg, grantedServices := taskCfg.CredentialAccess(string(identity.SystemID))
var record *egress.RecordOptions
if task.IsTestRun() {
record = &egress.RecordOptions{TaskID: task.ID, ModelHosts: modelHosts(d.Cfg.Get().Providers)}
+2 -2
View File
@@ -46,7 +46,7 @@ func TestOpenModelEgressCarriesOnlyReferencedProviders(t *testing.T) {
}),
ModelEgress: egressProxy,
}
task := &workflow.Task{ID: 7, WorkflowDefinitionYAML: "id: w\nsteps:\n - type: agent.run\n"}
task := &workflow.Task{ID: 7, Identity: string(sys), WorkflowDefinitionYAML: "id: w\nsteps:\n - type: agent.run\n"}
if _, _, err := d.openModelEgress(t.Context(), task, "run-credential"); err != nil {
t.Fatalf("open model egress: %v", err)
@@ -99,7 +99,7 @@ func TestRunViaAgentCarriesProviderCredentialVariable(t *testing.T) {
Tasks: bus,
Log: slog.New(slog.DiscardHandler),
}
task := &workflow.Task{ID: 7, Attempt: 1, Workflow: "implement", WorkflowDefinitionYAML: "id: w\nsteps:\n - type: agent.run\n"}
task := &workflow.Task{ID: 7, Identity: string(sys), Attempt: 1, Workflow: "implement", WorkflowDefinitionYAML: "id: w\nsteps:\n - type: agent.run\n"}
d.runViaAgent(t.Context(), task, config.Repo{}, config.AgentProfile{}, nil, "run-credential")
+88
View File
@@ -0,0 +1,88 @@
package daemon
import (
"context"
"log/slog"
"testing"
"github.com/samcharles93/archie-core/internal/config"
"github.com/samcharles93/archie-core/internal/domain/identity"
"github.com/samcharles93/archie-core/internal/domain/workintake"
"github.com/samcharles93/archie-core/internal/forge"
)
type labelledIssues struct {
forge.Forge
issues []forge.Issue
}
func (f labelledIssues) IssuesWithLabel(context.Context, string, string, string) ([]forge.Issue, error) {
return f.issues, nil
}
func (labelledIssues) React(context.Context, string, string, int, string) error { return nil }
type publishedKeys struct {
stubTasks
payloads [][]byte
keys []string
}
func (p *publishedKeys) PublishUnique(_ context.Context, _, key string, payload []byte) error {
p.keys = append(p.keys, key)
p.payloads = append(p.payloads, payload)
return nil
}
// migratedRootIdentity is what migration 0072 writes over the empty identity
// the root's tasks used to carry. The poller must publish under the same
// value, or a re-poll after the migration no longer dedups against the rows.
const migratedRootIdentity = "00000000-0000-5000-8000-000000000001"
// TestPolledTaskKeepsItsCreatingIdentity pins that a polled task is published
// under the identity that polled it, never empty, and that System's key is the
// one a migrated row carries.
func TestPolledTaskKeepsItsCreatingIdentity(t *testing.T) {
tests := []struct {
name string
source identity.IdentityID
want string
}{
{"System poll matches the migrated root", identity.SystemID, migratedRootIdentity},
{"named identity poll keeps its identity", "bot-7", "bot-7"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
bus := &publishedKeys{}
d := &Daemon{
Log: slog.New(slog.DiscardHandler), Store: taskLookup{}, Tasks: bus,
Cfg: config.NewHolder(config.Config{}),
IssueSources: func(context.Context) []IssueSource {
return []IssueSource{{
Identity: tt.source,
Forge: labelledIssues{issues: []forge.Issue{{Number: 12, Title: "t"}}},
Dispatch: config.Dispatch{Trigger: "label"}, Label: "archie",
Repos: []config.Repo{{Owner: "acme", Name: "widget"}},
}}
},
}
if err := d.poll(t.Context()); err != nil {
t.Fatal(err)
}
if len(bus.payloads) != 1 {
t.Fatalf("published %d tasks, want 1", len(bus.payloads))
}
envelope, err := workintake.DecodeTask(bus.payloads[0])
if err != nil {
t.Fatal(err)
}
if envelope.Identity != tt.want {
t.Fatalf("published identity %q, want %q", envelope.Identity, tt.want)
}
want := workintake.TaskEnvelope{Org: "org-sys", Identity: tt.want, Owner: "acme", Repo: "widget", Number: 12}.IdempotencyKey()
if bus.keys[0] != want {
t.Fatalf("idempotency key %q, want %q", bus.keys[0], want)
}
})
}
}
+2 -1
View File
@@ -5,6 +5,7 @@ import (
"fmt"
"github.com/samcharles93/archie-core/internal/config"
"github.com/samcharles93/archie-core/internal/domain/identity"
"github.com/samcharles93/archie-core/internal/domain/workflow"
workflowtask "github.com/samcharles93/archie-core/internal/domain/workflow/task"
"github.com/samcharles93/archie-core/internal/forge"
@@ -42,7 +43,7 @@ func (d *Daemon) Repository(ctx context.Context, task *workflow.Task, operation
if err != nil {
return RepositoryAccess{}, err
}
if _, err := d.databaseExecutionIdentity(ctx, &run, d.publisherIdentity(run.Identity)); err != nil {
if _, err := d.databaseExecutionIdentity(ctx, &run, identity.IdentityID(run.Identity)); err != nil {
return RepositoryAccess{}, err
}
return d.ResolveRepository(ctx, &run, operation)
+2 -1
View File
@@ -5,6 +5,7 @@ import (
"fmt"
"log/slog"
"github.com/samcharles93/archie-core/internal/domain/identity"
workflowtask "github.com/samcharles93/archie-core/internal/domain/workflow/task"
"github.com/samcharles93/archie-core/internal/domain/workintake"
"github.com/samcharles93/archie-core/internal/forge"
@@ -154,7 +155,7 @@ func (d *Daemon) scanPRReviews(ctx context.Context) error {
func (d *Daemon) scanOnePR(ctx context.Context, reader forge.PullRequestReviewReader, checker forge.WriteAccessChecker, t *workflowtask.Task) bool {
// Resolve the org; on failure skip this task for now.
if t.Org == "" {
resolved, err := d.identityOrg(ctx, d.publisherIdentity(t.Identity))
resolved, err := d.identityOrg(ctx, identity.IdentityID(t.Identity))
if err != nil {
d.Log.WarnContext(ctx, "review scan org resolve failed", "task", t.ID, "err", err)
return false
+5 -21
View File
@@ -20,7 +20,7 @@ import (
// a poller, or a calling workflow's declared identity) must be permitted run
// on the workflow, and so must the identity the run acts as. A workflow that
// declares no identity is refused: it neither inherits its starter's nor
// falls back to the root's. It runs before anything that depends on the
// falls back to System's. It runs before anything that depends on the
// identity, and reports whether processing may continue; a refusal parks the
// task.
func (d *Daemon) adoptWorkflowIdentity(ctx context.Context, task *workflow.Task) bool {
@@ -43,7 +43,7 @@ func (d *Daemon) adoptWorkflowIdentity(ctx context.Context, task *workflow.Task)
d.parkBlockedTask(ctx, task, "workflow "+task.Workflow+": "+err.Error(), pinParkClass(err), parkBlocker(err))
return false
}
if allowed, err := d.mayRunWorkflow(ctx, task, d.publisherIdentity(task.Identity)); !allowed {
if allowed, err := d.mayRunWorkflow(ctx, task, identity.IdentityID(task.Identity)); !allowed {
d.parkRefusedRun(ctx, task, "the identity that started it may not run workflow "+task.Workflow, err)
return false
}
@@ -58,32 +58,16 @@ func (d *Daemon) adoptWorkflowIdentity(ctx context.Context, task *workflow.Task)
}
// declaredIdentity resolves a workflow's declared identity to the ID it is
// authorized as and the name the task carries while it runs: a configured
// identity's name, or empty for the root identity of a single-identity
// install.
// authorized as and the name the task carries while it runs.
func (d *Daemon) declaredIdentity(ctx context.Context, task *workflow.Task, ref string) (identity.IdentityID, string, error) {
var id identity.IdentityID
var name string
if identity.IdentityID(ref) == d.RootIdentityID || identity.StableID(ref) == d.RootIdentityID {
id = d.RootIdentityID
} else {
id, name = identity.IdentityID(ref), ref
}
if d.IdentityRepository == nil {
if id == d.RootIdentityID {
return id, name, nil
}
return "", "", pinFailure{taskstate.ParkTransient, fmt.Errorf("identity authority unavailable for %s", ref)}
}
value, err := d.databaseExecutionIdentity(ctx, task, id)
value, err := d.databaseExecutionIdentity(ctx, task, identity.IdentityID(ref))
if err != nil {
return "", "", err
}
if name != "" {
name = string(value.ID)
}
return value.ID, name, nil
return value.ID, string(value.ID), nil
}
func (d *Daemon) databaseExecutionIdentity(ctx context.Context, task *workflow.Task, id identity.IdentityID) (identity.Identity, error) {
+15 -13
View File
@@ -37,12 +37,14 @@ func (principalOf) PrincipalFor(_ context.Context, id identity.IdentityID) (acce
return access.Principal{IdentityID: id, Org: org.DefaultOrgID}, nil
}
const sys = identity.SystemID
// agentDirectory knows each agent by name and by ID, all assigned to the
// system org.
type agentDirectory struct{ identity.Repository }
var directoryAgents = map[identity.IdentityID]identity.IdentityID{
"root": "root", "deployer": "id-deployer", "id-deployer": "id-deployer", "bot": "id-bot", "id-bot": "id-bot",
"deployer": "id-deployer", "id-deployer": "id-deployer", "bot": "id-bot", "id-bot": "id-bot",
}
func (agentDirectory) Get(_ context.Context, ref identity.IdentityID) (identity.Identity, error) {
@@ -113,14 +115,14 @@ func TestWorkflowIdentity(t *testing.T) {
wantDenied []identity.IdentityID
disabled bool
}{
{"allowed dispatch runs as the workflow's identity", deploy, "", runAllowed{"root": true, "id-deployer": true}, "id-deployer", false, "", nil, false},
{"refused invocation is parked", deploy, "", runAllowed{"id-deployer": true}, "", true, taskstate.ParkNeedsDecision, []identity.IdentityID{"root"}, false},
{"refused execution is parked", deploy, "", runAllowed{"root": true}, "", true, taskstate.ParkNeedsDecision, []identity.IdentityID{"id-deployer"}, false},
{"allowed dispatch runs as the workflow's identity", deploy, string(sys), runAllowed{sys: true, "id-deployer": true}, "id-deployer", false, "", nil, false},
{"refused invocation is parked", deploy, string(sys), runAllowed{"id-deployer": true}, "", true, taskstate.ParkNeedsDecision, []identity.IdentityID{sys}, false},
{"refused execution is parked", deploy, string(sys), runAllowed{sys: true}, "", true, taskstate.ParkNeedsDecision, []identity.IdentityID{"id-deployer"}, false},
{"a chain that cannot be read parks transient, not as a denial", deploy, "", unavailableChain{}, "", true, taskstate.ParkTransient, nil, false},
{"called workflow runs as its own identity, not its caller's", callee, "id-deployer", runAllowed{"id-deployer": true, "id-bot": true}, "id-bot", false, "", nil, false},
{"caller refused the called workflow is parked", callee, "id-deployer", runAllowed{"id-bot": true}, "", true, taskstate.ParkNeedsDecision, []identity.IdentityID{"id-deployer"}, false},
{"no declared identity is refused", "id: deploy\n", "id-bot", runAllowed{"root": true, "id-bot": true}, "", true, taskstate.ParkNeedsDecision, nil, false},
{"unconfigured identity is parked", "id: deploy\nidentity: ghost\n", "", runAllowed{"root": true}, "", true, taskstate.ParkNeedsDecision, nil, false},
{"no declared identity is refused", "id: deploy\n", "id-bot", runAllowed{sys: true, "id-bot": true}, "", true, taskstate.ParkNeedsDecision, nil, false},
{"unconfigured identity is parked", "id: deploy\nidentity: ghost\n", string(sys), runAllowed{sys: true}, "", true, taskstate.ParkNeedsDecision, nil, false},
{"disabled workflow is parked", deploy, "id-bot", runAllowed{"id-bot": true, "id-deployer": true}, "", true, taskstate.ParkNeedsDecision, nil, true},
}
for _, tt := range tests {
@@ -128,7 +130,7 @@ func TestWorkflowIdentity(t *testing.T) {
store := &identityStore{}
var denied denials
d := &Daemon{
Store: store, Log: slog.New(slog.DiscardHandler), RootIdentityID: "root",
Store: store, Log: slog.New(slog.DiscardHandler),
Access: tt.allowed, Principals: principalOf{}, Denials: &denied,
IdentityRepository: agentDirectory{}, AgentAssignments: agentDirectory{},
}
@@ -176,12 +178,12 @@ func TestWorkflowRunCarriesEventContext(t *testing.T) {
}{{"valid", true}, {"unsigned", false}, {"", false}} {
t.Run(tt.signature, func(t *testing.T) {
d := &Daemon{
Store: &identityStore{}, Log: slog.New(slog.DiscardHandler), RootIdentityID: "root",
Access: signedOnly{runAllowed{"root": true, "id-deployer": true}},
Store: &identityStore{}, Log: slog.New(slog.DiscardHandler),
Access: signedOnly{runAllowed{sys: true, "id-deployer": true}},
Principals: principalOf{}, IdentityRepository: agentDirectory{}, AgentAssignments: agentDirectory{},
}
task := &workflow.Task{
ID: 1, Workflow: "deploy", BindingSignature: tt.signature,
ID: 1, Identity: string(sys), Workflow: "deploy", BindingSignature: tt.signature,
WorkflowDefinitionYAML: deploy, WorkflowDefinitionDigest: workflow.DigestDefinition(deploy),
}
if got := d.adoptWorkflowIdentity(context.Background(), task); got != tt.want {
@@ -235,13 +237,13 @@ func TestDashboardExecutionIdentity(t *testing.T) {
store := &identityStore{}
cfg := config.Config{BotUser: "root-bot", GrantedCredentials: []string{"root-secret"}, Forge: config.Forge{Token: config.SecretRef{Engine: "env", Key: "ROOT"}}, Repos: []config.Repo{{Owner: "acme", Name: "app"}}}
d := &Daemon{
Store: store, Log: slog.New(slog.DiscardHandler), Cfg: config.NewHolder(cfg), RootIdentityID: "root",
Store: store, Log: slog.New(slog.DiscardHandler), Cfg: config.NewHolder(cfg),
IdentityRepository: repository, AgentAssignments: assignedAgents{{IdentityID: value.ID, OrgID: tt.assigned}},
Principals: workflowPrincipals{"root": "org-sys", "dashboard-agent": "org-sys"}, Access: runAllowed{"root": true, "dashboard-agent": true},
Principals: workflowPrincipals{sys: "org-sys", "dashboard-agent": "org-sys"}, Access: runAllowed{sys: true, "dashboard-agent": true},
}
definition := "id: deploy\nidentity: dashboard-agent\nrepository: none\n"
newTask := func() *workflow.Task {
return &workflow.Task{ID: 1, Workflow: "deploy", WorkflowDefinitionYAML: definition, WorkflowDefinitionDigest: workflow.DigestDefinition(definition)}
return &workflow.Task{ID: 1, Identity: string(sys), Workflow: "deploy", WorkflowDefinitionYAML: definition, WorkflowDefinitionDigest: workflow.DigestDefinition(definition)}
}
task := newTask()
ok := d.adoptWorkflowIdentity(context.Background(), task)
+1 -1
View File
@@ -25,7 +25,7 @@ func (d *Daemon) workflowContext(ctx context.Context, task *workflow.Task) (cont
}
return ctx, nil
}
principal, err := d.principalIn(ctx, d.publisherIdentity(task.Identity), owner)
principal, err := d.principalIn(ctx, identity.IdentityID(task.Identity), owner)
if err != nil {
return nil, pinFailure{taskstate.ParkTransient, fmt.Errorf("workflow principal: %w", err)}
}
+6 -6
View File
@@ -88,9 +88,9 @@ func TestDispatchOrgWorkflows(t *testing.T) {
{ID: "root", MappingID: "root", Matcher: binding.Matcher{Source: "root"}, OrgID: org.DefaultOrgID, Workflow: "deploy", Status: binding.StatusArmed, Owner: "owner", Repo: "repo"},
{ID: "acme", MappingID: "acme", Matcher: binding.Matcher{Source: "acme"}, OrgID: "acme", Workflow: "deploy", Status: binding.StatusArmed},
}}
d := &Daemon{Cfg: config.NewHolder(config.Config{}), Store: store, Log: slog.New(slog.DiscardHandler), Bindings: store, BindingDispatcher: store, BindingTaskCreator: store, Mappings: store, RootIdentityID: "root", OrgPrincipals: func(context.Context) []access.Principal {
return []access.Principal{{IdentityID: "root", Org: org.DefaultOrgID}, {IdentityID: "acme-bot", Org: "acme"}}
}, Principals: workflowPrincipals{"root": org.DefaultOrgID, "acme-bot": "acme"}, WorkflowDefinitions: orgDefinitions{
d := &Daemon{Cfg: config.NewHolder(config.Config{}), Store: store, Log: slog.New(slog.DiscardHandler), Bindings: store, BindingDispatcher: store, BindingTaskCreator: store, Mappings: store, OrgPrincipals: func(context.Context) []access.Principal {
return []access.Principal{{IdentityID: identity.SystemID, Org: org.DefaultOrgID}, {IdentityID: "acme-bot", Org: "acme"}}
}, Principals: workflowPrincipals{sys: org.DefaultOrgID, "acme-bot": "acme"}, WorkflowDefinitions: orgDefinitions{
org.DefaultOrgID: "id: deploy\nrepository: required\nsteps:\n - type: workflow.finish\n",
"acme": "id: deploy\nrepository: none\nsteps:\n - type: workflow.finish\n",
}}
@@ -99,7 +99,7 @@ func TestDispatchOrgWorkflows(t *testing.T) {
}
d.dispatchBindings(t.Context())
root := store.started[org.DefaultOrgID]
if root == nil || root.Repo != "repo" || root.Identity != "" {
if root == nil || root.Repo != "repo" || root.Identity != string(sys) {
t.Fatalf("root dispatch %#v", root)
}
acme := store.started["acme"]
@@ -146,11 +146,11 @@ func TestPinWorkflowInTaskOrg(t *testing.T) {
{"unresolved context cannot select another org", "", nil, "", true, "acme"},
} {
t.Run(tc.name, func(t *testing.T) {
d := &Daemon{Store: listsWorkspaces{&identityStore{}}, RootIdentityID: "bot", WorkflowDefinitions: orgDefinitions{org.DefaultOrgID: shared, "acme": custom}}
d := &Daemon{Store: listsWorkspaces{&identityStore{}}, WorkflowDefinitions: orgDefinitions{org.DefaultOrgID: shared, "acme": custom}}
if tc.principals != nil {
d.Principals = tc.principals
}
task := &workflow.Task{ID: 1, Org: tc.owner, Workflow: "deploy"}
task := &workflow.Task{ID: 1, Identity: "bot", Org: tc.owner, Workflow: "deploy"}
ctx := t.Context()
if tc.contextOrg != "" {
ctx = org.WithOrg(access.WithPrincipal(ctx, access.Principal{IdentityID: "foreign", Org: tc.contextOrg}), tc.contextOrg)