fix(daemon): refuse a disabled workflow on every start path
This commit is contained in:
2 files changed
+37
-7
No files matched your search
@@ -1781,9 +1781,26 @@ func validateProfileMeetsNeeds(profile config.AgentProfile, needs workflowtask.W
|
||||
}
|
||||
|
||||
// pinWorkflowDefinition ensures the task carries a valid definition pin for
|
||||
// the workflow it names. A valid pin is kept; a missing or mismatched one is
|
||||
// resolved again from the active definitions.
|
||||
// the workflow it names and that its org has the workflow enabled. Every run
|
||||
// passes through here, whatever started it, so this is the one enablement
|
||||
// check for issue labels, handoffs, approvals, calls and playbooks alike.
|
||||
func (d *Daemon) pinWorkflowDefinition(ctx context.Context, task *workflow.Task) error {
|
||||
if err := d.pinDefinition(ctx, task); err != nil {
|
||||
return err
|
||||
}
|
||||
enablement, err := d.workflowEnablement(ctx)
|
||||
if err != nil {
|
||||
return pinFailure{taskstate.ParkTransient, fmt.Errorf("workflow enablement: %w", err)}
|
||||
}
|
||||
if !enablement.Enabled(task.Org, task.Workflow) {
|
||||
return pinFailure{taskstate.ParkNeedsHuman, fmt.Errorf("workflow %s is disabled", task.Workflow)}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// pinDefinition keeps a valid pin and resolves a missing or mismatched one
|
||||
// again from the active definitions.
|
||||
func (d *Daemon) pinDefinition(ctx context.Context, task *workflow.Task) error {
|
||||
pinned, ok, err := pinnedDefinitionID(task)
|
||||
if err != nil {
|
||||
return pinFailure{taskstate.ParkNeedsHuman, err}
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"github.com/samcharles93/archie-core/internal/domain/identity"
|
||||
"github.com/samcharles93/archie-core/internal/domain/storecontract"
|
||||
"github.com/samcharles93/archie-core/internal/domain/workflow"
|
||||
workflowtask "github.com/samcharles93/archie-core/internal/domain/workflow/task"
|
||||
"github.com/samcharles93/archie-core/internal/taskstate"
|
||||
)
|
||||
|
||||
@@ -42,9 +43,16 @@ func (r runAllowed) Authorize(p access.Principal, _ access.Action, _ access.Reso
|
||||
|
||||
func (runAllowed) Reload(context.Context) error { return nil }
|
||||
|
||||
type enablementOf workflowtask.WorkflowEnablement
|
||||
|
||||
func (e enablementOf) WorkflowEnablement(context.Context) (workflowtask.WorkflowEnablement, error) {
|
||||
return workflowtask.WorkflowEnablement(e), nil
|
||||
}
|
||||
|
||||
// TestWorkflowIdentity pins that a workflow naming an identity runs as it
|
||||
// only when the dispatcher may run the workflow, and that a workflow naming
|
||||
// none runs as the dispatcher.
|
||||
// none runs as the dispatcher. A workflow its org disabled is parked whatever
|
||||
// started it.
|
||||
func TestWorkflowIdentity(t *testing.T) {
|
||||
const named = "id: deploy\nidentity: deployer\n"
|
||||
const plain = "id: deploy\n"
|
||||
@@ -55,11 +63,13 @@ func TestWorkflowIdentity(t *testing.T) {
|
||||
allowed runAllowed
|
||||
wantIdentity string
|
||||
wantParked bool
|
||||
disabled bool
|
||||
}{
|
||||
{"allowed dispatcher runs as the workflow's identity", named, "", runAllowed{"root": true}, "deployer", false},
|
||||
{"refused dispatcher is parked", named, "", runAllowed{}, "", true},
|
||||
{"unconfigured identity is parked", "id: deploy\nidentity: ghost\n", "", runAllowed{"root": true}, "", true},
|
||||
{"no named identity runs as the dispatcher", plain, "bot", runAllowed{}, "bot", false},
|
||||
{"allowed dispatcher runs as the workflow's identity", named, "", runAllowed{"root": true}, "deployer", false, false},
|
||||
{"refused dispatcher is parked", named, "", runAllowed{}, "", true, false},
|
||||
{"unconfigured identity is parked", "id: deploy\nidentity: ghost\n", "", runAllowed{"root": true}, "", true, false},
|
||||
{"no named identity runs as the dispatcher", plain, "bot", runAllowed{}, "bot", false, false},
|
||||
{"disabled workflow is parked", plain, "bot", runAllowed{}, "", true, true},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
@@ -69,6 +79,9 @@ func TestWorkflowIdentity(t *testing.T) {
|
||||
Access: tt.allowed, Principals: principalOf{},
|
||||
Identities: []*IdentityRunner{{ID: "id-deployer", Name: "deployer"}, {ID: "id-bot", Name: "bot"}},
|
||||
}
|
||||
if tt.disabled {
|
||||
d.WorkflowEnablement = enablementOf(workflowtask.WorkflowEnablement{}.SetEnabled("", "deploy", false))
|
||||
}
|
||||
task := &workflow.Task{
|
||||
ID: 1, Identity: tt.dispatcher, Workflow: "deploy",
|
||||
WorkflowDefinitionYAML: tt.yaml, WorkflowDefinitionDigest: workflow.DigestDefinition(tt.yaml),
|
||||
|
||||
Reference in new issue
Block a user