Files
archie/internal/daemon/workflow_org.go
T
sam e3ffefdc7d
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
fix(identity): use System as the one root identity and record who created every task (#1851)
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.
2026-11-10 20:01:16 +11:00

55 lines
2.2 KiB
Go

package daemon
import (
"context"
"fmt"
"github.com/samcharles93/archie-core/internal/domain/access"
"github.com/samcharles93/archie-core/internal/domain/identity"
"github.com/samcharles93/archie-core/internal/domain/org"
"github.com/samcharles93/archie-core/internal/domain/workflow"
"github.com/samcharles93/archie-core/internal/taskstate"
)
// workflowContext forwards a task's identity so the State Store selects its
// org's definitions. An identity assigned elsewhere cannot supply the pin.
func (d *Daemon) workflowContext(ctx context.Context, task *workflow.Task) (context.Context, error) {
owner := task.Org
if owner == "" {
owner = org.DefaultOrgID
}
if d.Principals == nil {
principal, forwarded := access.PrincipalFromContext(ctx)
if owner != org.DefaultOrgID || org.OrgFromContext(ctx) != owner || (forwarded && principal.Org != "" && principal.Org != owner) {
return nil, pinFailure{taskstate.ParkNeedsDecision, fmt.Errorf("workflow org %s: principal unavailable", owner)}
}
return ctx, nil
}
principal, err := d.principalIn(ctx, identity.IdentityID(task.Identity), owner)
if err != nil {
return nil, pinFailure{taskstate.ParkTransient, fmt.Errorf("workflow principal: %w", err)}
}
if principal.Org != owner {
return nil, pinFailure{taskstate.ParkNeedsDecision, fmt.Errorf("workflow identity belongs to org %s, task belongs to %s", principal.Org, owner)}
}
return org.WithOrg(access.WithPrincipal(ctx, principal), owner), nil
}
// principalIn is id's principal acting in owner: the org it serves, or one it
// is a member of, since a person's task belongs to the org they selected. An
// identity that is no member keeps its own org, which callers refuse.
func (d *Daemon) principalIn(ctx context.Context, id identity.IdentityID, owner org.OrgID) (access.Principal, error) {
principal, err := d.Principals.PrincipalFor(ctx, id)
if err != nil {
return access.Principal{}, err
}
if principal.Org == "" {
principal.Org = org.DefaultOrgID
}
if principal.Org == owner || !principal.Member(owner) {
return principal, nil
}
lister, _ := d.Store.(access.WorkspaceLister)
return principal.Select(org.WithOrg(access.WithPrincipal(ctx, principal), principal.Org), owner, lister)
}