fix(daemon): run-time workflow check sees the binding event's signature and address

Issue: archie-core-bmro8
This commit is contained in:
sam committed 2026-10-13 15:10:31 +11:00
1 parent 1b561402cf
commit bf17cd3a13
12 files changed
+143 -21

No files matched your search

+25 -5
View File
@@ -1857,9 +1857,13 @@ type Task struct {
Origin string `protobuf:"bytes,44,opt,name=origin,proto3" json:"origin,omitempty"`
// workspace is the workspace of its org the task belongs to; read-only
// here.
Workspace string `protobuf:"bytes,45,opt,name=workspace,proto3" json:"workspace,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
Workspace string `protobuf:"bytes,45,opt,name=workspace,proto3" json:"workspace,omitempty"`
// binding_signature and binding_addr are the signature result and address
// of the captured event that started a binding task.
BindingSignature string `protobuf:"bytes,46,opt,name=binding_signature,json=bindingSignature,proto3" json:"binding_signature,omitempty"`
BindingAddr string `protobuf:"bytes,47,opt,name=binding_addr,json=bindingAddr,proto3" json:"binding_addr,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *Task) Reset() {
@@ -2208,6 +2212,20 @@ func (x *Task) GetWorkspace() string {
return ""
}
func (x *Task) GetBindingSignature() string {
if x != nil {
return x.BindingSignature
}
return ""
}
func (x *Task) GetBindingAddr() string {
if x != nil {
return x.BindingAddr
}
return ""
}
// Event mirrors internal/events.Event. Data is carried as a JSON object
// string (matching the store's own on-disk representation) rather than
// google.protobuf.Struct, to stay a direct mirror of the existing column.
@@ -17697,7 +17715,7 @@ const file_state_v1_state_proto_rawDesc = "" +
"\x06tokens\x18\x01 \x03(\v2\x17.state.v1.PersonalTokenR\x06tokens\",\n" +
"\x1aRevokePersonalTokenRequest\x12\x0e\n" +
"\x02id\x18\x01 \x01(\tR\x02id\"\x1d\n" +
"\x1bRevokePersonalTokenResponse\"\xe8\v\n" +
"\x1bRevokePersonalTokenResponse\"\xb8\f\n" +
"\x04Task\x12\x0e\n" +
"\x02id\x18\x01 \x01(\x03R\x02id\x12\x14\n" +
"\x05owner\x18\x02 \x01(\tR\x05owner\x12\x12\n" +
@@ -17758,7 +17776,9 @@ const file_state_v1_state_proto_rawDesc = "" +
"resumeFrom\x12%\n" +
"\x0eresume_results\x18+ \x01(\fR\rresumeResults\x12\x16\n" +
"\x06origin\x18, \x01(\tR\x06origin\x12\x1c\n" +
"\tworkspace\x18- \x01(\tR\tworkspace\"\xf8\x02\n" +
"\tworkspace\x18- \x01(\tR\tworkspace\x12+\n" +
"\x11binding_signature\x18. \x01(\tR\x10bindingSignature\x12!\n" +
"\fbinding_addr\x18/ \x01(\tR\vbindingAddr\"\xf8\x02\n" +
"\x05Event\x12\x0e\n" +
"\x02id\x18\x01 \x01(\x03R\x02id\x12*\n" +
"\x02at\x18\x02 \x01(\v2\x1a.google.protobuf.TimestampR\x02at\x12\x12\n" +
+1 -1
View File
@@ -84,7 +84,7 @@ func (d *Daemon) mayRunWorkflow(ctx context.Context, task *workflow.Task, id ide
if resource.Org == "" {
resource.Org = principal.Org
}
decision := d.Access.Authorize(principal, access.ActionRun, resource, access.Context{})
decision := d.Access.Authorize(principal, access.ActionRun, resource, access.Context{Signature: task.BindingSignature, Addr: task.BindingAddr})
if decision.Allowed {
return true
}
+38
View File
@@ -137,3 +137,41 @@ func TestIdentityTasksUseLiveSettings(t *testing.T) {
}
}
}
// signedOnly permits run only for a verified signature, as a policy
// conditioned on context.signature does.
type signedOnly struct{ runAllowed }
func (s signedOnly) Authorize(p access.Principal, a access.Action, r access.Resource, c access.Context) access.Decision {
if c.Signature != "valid" {
return access.DeniedAt(access.LevelOrg, nil)
}
return s.runAllowed.Authorize(p, a, r, c)
}
// TestWorkflowRunCarriesEventContext pins that the run-time re-check sees the
// signature the binding's capture carried, so a signature-conditioned policy
// that admitted the dispatch admits the task, and an unsigned event stays
// refused.
func TestWorkflowRunCarriesEventContext(t *testing.T) {
const deploy = "id: deploy\nidentity: deployer\n"
for _, tt := range []struct {
signature string
want bool
}{{"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}},
Principals: principalOf{}, Identities: []*IdentityRunner{{ID: "id-deployer", Name: "deployer"}},
}
task := &workflow.Task{
ID: 1, Workflow: "deploy", BindingSignature: tt.signature,
WorkflowDefinitionYAML: deploy, WorkflowDefinitionDigest: workflow.DigestDefinition(deploy),
}
if got := d.adoptWorkflowIdentity(context.Background(), task); got != tt.want {
t.Fatalf("admitted %v, want %v", got, tt.want)
}
})
}
}
+5
View File
@@ -107,6 +107,11 @@ type Task struct {
// silently rewrite history.
BindingID string `json:"binding_id"`
BindingVersion int `json:"binding_version"`
// BindingSignature and BindingAddr are the signature result and address
// of the captured event that started the task, for the run-time access
// check.
BindingSignature string `json:"binding_signature,omitempty"`
BindingAddr string `json:"binding_addr,omitempty"`
// Inputs are the workflow inputs the binding assigned, checked against
// the workflow's declared inputs at dispatch. They reach the agent as
// structured data, never as body text.
@@ -0,0 +1,11 @@
-- The signature result and address of the captured event that started a
-- binding task, so the run-time access check evaluates the facts the
-- dispatch check did.
-- +goose Up
ALTER TABLE tasks
ADD COLUMN binding_signature text NOT NULL DEFAULT '',
ADD COLUMN binding_addr text NOT NULL DEFAULT '';
-- +goose Down
ALTER TABLE tasks DROP COLUMN binding_signature, DROP COLUMN binding_addr;
@@ -24,7 +24,7 @@ func (q *Queries) CallStatusDetail(ctx context.Context, taskID int64) (string, e
const enqueueCallTask = `-- name: EnqueueCallTask :one
WITH caller AS (
SELECT t.id, t.owner, t.repo, t.issue_number, t.title, t.body, t.labels, t.status, t.workflow, t.branch, t.plan, t.notes, t.pr_number, t.tokens_used, t.iterations, t.attempt, t.park_reason, t.watch_comment_id, t.park_class, t.remediation_rounds, t.retry_count, t.source, t.identity, t.binding_id, t.binding_version, t.review_payload, t.workflow_definition_version, t.workflow_definition_digest, t.workflow_definition_yaml, t.created_at, t.updated_at, t.review_cursor, t.inputs, t.org_id, t.workspace_id, t.call_parent_task_id, t.call_depth, t.outputs, t.review_gate, t.rereview_rounds, t.retry_mode, t.resume_from, t.resume_results, t.pending_reviews, t.origin, t.call_key, t.outcome_posted FROM tasks t WHERE t.id = $1 FOR UPDATE
SELECT t.id, t.owner, t.repo, t.issue_number, t.title, t.body, t.labels, t.status, t.workflow, t.branch, t.plan, t.notes, t.pr_number, t.tokens_used, t.iterations, t.attempt, t.park_reason, t.watch_comment_id, t.park_class, t.remediation_rounds, t.retry_count, t.source, t.identity, t.binding_id, t.binding_version, t.review_payload, t.workflow_definition_version, t.workflow_definition_digest, t.workflow_definition_yaml, t.created_at, t.updated_at, t.review_cursor, t.inputs, t.org_id, t.workspace_id, t.call_parent_task_id, t.call_depth, t.outputs, t.review_gate, t.rereview_rounds, t.retry_mode, t.resume_from, t.resume_results, t.pending_reviews, t.origin, t.call_key, t.outcome_posted, t.binding_signature, t.binding_addr FROM tasks t WHERE t.id = $1 FOR UPDATE
), number AS (
INSERT INTO chat_issue_numbers (owner, repo, last_number)
SELECT caller.owner, caller.repo, $9::bigint + 1 FROM caller
@@ -43,7 +43,7 @@ SELECT
FROM caller, number
WHERE caller.status = 'running' AND caller.call_depth + 1 <= $8::int
ON CONFLICT (call_parent_task_id, call_key) WHERE call_key <> '' AND status NOT IN ('dead', 'closed_wont_do') DO UPDATE SET call_key = EXCLUDED.call_key
RETURNING id, owner, repo, issue_number, title, body, labels, status, workflow, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth, outputs, review_gate, rereview_rounds, retry_mode, resume_from, resume_results, pending_reviews, origin, call_key, outcome_posted
RETURNING id, owner, repo, issue_number, title, body, labels, status, workflow, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth, outputs, review_gate, rereview_rounds, retry_mode, resume_from, resume_results, pending_reviews, origin, call_key, outcome_posted, binding_signature, binding_addr
`
type EnqueueCallTaskParams struct {
@@ -133,6 +133,8 @@ func (q *Queries) EnqueueCallTask(ctx context.Context, arg EnqueueCallTaskParams
&i.Origin,
&i.CallKey,
&i.OutcomePosted,
&i.BindingSignature,
&i.BindingAddr,
)
return i, err
}
@@ -499,6 +499,8 @@ type Task struct {
Origin string
CallKey string
OutcomePosted bool
BindingSignature string
BindingAddr string
}
type ToolCall struct {
@@ -13,7 +13,7 @@ import (
)
const activeTasksByOrigin = `-- name: ActiveTasksByOrigin :many
SELECT id, owner, repo, issue_number, title, body, labels, status, workflow, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth, outputs, review_gate, rereview_rounds, retry_mode, resume_from, resume_results, pending_reviews, origin, call_key, outcome_posted FROM tasks
SELECT id, owner, repo, issue_number, title, body, labels, status, workflow, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth, outputs, review_gate, rereview_rounds, retry_mode, resume_from, resume_results, pending_reviews, origin, call_key, outcome_posted, binding_signature, binding_addr FROM tasks
WHERE origin = $1 AND origin <> '' AND status IN ('queued', 'running') AND ($2::text IS NULL OR org_id = $2)
ORDER BY id
`
@@ -81,6 +81,8 @@ func (q *Queries) ActiveTasksByOrigin(ctx context.Context, arg ActiveTasksByOrig
&i.Origin,
&i.CallKey,
&i.OutcomePosted,
&i.BindingSignature,
&i.BindingAddr,
); err != nil {
return nil, err
}
@@ -160,7 +162,7 @@ func (q *Queries) BeginRemediationTask(ctx context.Context, arg BeginRemediation
const claimByIssue = `-- name: ClaimByIssue :one
UPDATE tasks SET status = 'running', attempt = attempt + 1, outputs = '', updated_at = now()
WHERE owner = $1 AND repo = $2 AND issue_number = $3 AND status = 'queued'
RETURNING id, owner, repo, issue_number, title, body, labels, status, workflow, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth, outputs, review_gate, rereview_rounds, retry_mode, resume_from, resume_results, pending_reviews, origin, call_key, outcome_posted
RETURNING id, owner, repo, issue_number, title, body, labels, status, workflow, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth, outputs, review_gate, rereview_rounds, retry_mode, resume_from, resume_results, pending_reviews, origin, call_key, outcome_posted, binding_signature, binding_addr
`
type ClaimByIssueParams struct {
@@ -222,6 +224,8 @@ func (q *Queries) ClaimByIssue(ctx context.Context, arg ClaimByIssueParams) (Tas
&i.Origin,
&i.CallKey,
&i.OutcomePosted,
&i.BindingSignature,
&i.BindingAddr,
)
return i, err
}
@@ -236,7 +240,7 @@ WHERE id = (
FOR UPDATE SKIP LOCKED
LIMIT 1
)
RETURNING id, owner, repo, issue_number, title, body, labels, status, workflow, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth, outputs, review_gate, rereview_rounds, retry_mode, resume_from, resume_results, pending_reviews, origin, call_key, outcome_posted
RETURNING id, owner, repo, issue_number, title, body, labels, status, workflow, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth, outputs, review_gate, rereview_rounds, retry_mode, resume_from, resume_results, pending_reviews, origin, call_key, outcome_posted, binding_signature, binding_addr
`
// FOR UPDATE SKIP LOCKED replaces the SQLite single-writer assumption: two
@@ -296,6 +300,8 @@ func (q *Queries) ClaimNextTask(ctx context.Context) (Task, error) {
&i.Origin,
&i.CallKey,
&i.OutcomePosted,
&i.BindingSignature,
&i.BindingAddr,
)
return i, err
}
@@ -413,7 +419,7 @@ FROM number, (SELECT COALESCE(
'org-sys'
) AS id) AS owner_org
WHERE $11::text IS NULL OR owner_org.id = $11
RETURNING id, owner, repo, issue_number, title, body, labels, status, workflow, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth, outputs, review_gate, rereview_rounds, retry_mode, resume_from, resume_results, pending_reviews, origin, call_key, outcome_posted
RETURNING id, owner, repo, issue_number, title, body, labels, status, workflow, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth, outputs, review_gate, rereview_rounds, retry_mode, resume_from, resume_results, pending_reviews, origin, call_key, outcome_posted, binding_signature, binding_addr
`
type InsertChatTaskParams struct {
@@ -507,6 +513,8 @@ func (q *Queries) InsertChatTask(ctx context.Context, arg InsertChatTaskParams)
&i.Origin,
&i.CallKey,
&i.OutcomePosted,
&i.BindingSignature,
&i.BindingAddr,
)
return i, err
}
@@ -946,22 +954,34 @@ func (q *Queries) SetReviewUnits(ctx context.Context, arg SetReviewUnitsParams)
}
const stampTaskBinding = `-- name: StampTaskBinding :exec
UPDATE tasks SET binding_id = $2, binding_version = $3 WHERE id = $1
UPDATE tasks SET binding_id = $1, binding_version = $2,
binding_signature = c.signature, binding_addr = c.remote_addr
FROM (SELECT CASE WHEN authenticated THEN 'valid' WHEN unsigned THEN 'unsigned' ELSE 'unverified' END AS signature,
remote_addr
FROM captures WHERE captures.id = $4) c
WHERE tasks.id = $3
`
type StampTaskBindingParams struct {
ID int64
BindingID string
BindingVersion int64
ID int64
CaptureID string
}
// The capture's signature result is spelled as the access context spells it.
func (q *Queries) StampTaskBinding(ctx context.Context, arg StampTaskBindingParams) error {
_, err := q.db.Exec(ctx, stampTaskBinding, arg.ID, arg.BindingID, arg.BindingVersion)
_, err := q.db.Exec(ctx, stampTaskBinding,
arg.BindingID,
arg.BindingVersion,
arg.ID,
arg.CaptureID,
)
return err
}
const taskByID = `-- name: TaskByID :one
SELECT id, owner, repo, issue_number, title, body, labels, status, workflow, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth, outputs, review_gate, rereview_rounds, retry_mode, resume_from, resume_results, pending_reviews, origin, call_key, outcome_posted FROM tasks WHERE id = $1 AND ($2::text IS NULL OR org_id = $2)
SELECT id, owner, repo, issue_number, title, body, labels, status, workflow, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth, outputs, review_gate, rereview_rounds, retry_mode, resume_from, resume_results, pending_reviews, origin, call_key, outcome_posted, binding_signature, binding_addr FROM tasks WHERE id = $1 AND ($2::text IS NULL OR org_id = $2)
`
type TaskByIDParams struct {
@@ -1020,12 +1040,14 @@ func (q *Queries) TaskByID(ctx context.Context, arg TaskByIDParams) (Task, error
&i.Origin,
&i.CallKey,
&i.OutcomePosted,
&i.BindingSignature,
&i.BindingAddr,
)
return i, err
}
const taskByIssue = `-- name: TaskByIssue :one
SELECT id, owner, repo, issue_number, title, body, labels, status, workflow, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth, outputs, review_gate, rereview_rounds, retry_mode, resume_from, resume_results, pending_reviews, origin, call_key, outcome_posted FROM tasks WHERE owner = $1 AND repo = $2 AND issue_number = $3
SELECT id, owner, repo, issue_number, title, body, labels, status, workflow, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth, outputs, review_gate, rereview_rounds, retry_mode, resume_from, resume_results, pending_reviews, origin, call_key, outcome_posted, binding_signature, binding_addr FROM tasks WHERE owner = $1 AND repo = $2 AND issue_number = $3
AND ($4::text IS NULL OR org_id = $4)
`
@@ -1092,12 +1114,14 @@ func (q *Queries) TaskByIssue(ctx context.Context, arg TaskByIssueParams) (Task,
&i.Origin,
&i.CallKey,
&i.OutcomePosted,
&i.BindingSignature,
&i.BindingAddr,
)
return i, err
}
const taskByPR = `-- name: TaskByPR :one
SELECT id, owner, repo, issue_number, title, body, labels, status, workflow, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth, outputs, review_gate, rereview_rounds, retry_mode, resume_from, resume_results, pending_reviews, origin, call_key, outcome_posted FROM tasks WHERE owner = $1 AND repo = $2 AND pr_number = $3 AND status = $4
SELECT id, owner, repo, issue_number, title, body, labels, status, workflow, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth, outputs, review_gate, rereview_rounds, retry_mode, resume_from, resume_results, pending_reviews, origin, call_key, outcome_posted, binding_signature, binding_addr FROM tasks WHERE owner = $1 AND repo = $2 AND pr_number = $3 AND status = $4
AND ($5::text IS NULL OR org_id = $5)
`
@@ -1169,6 +1193,8 @@ func (q *Queries) TaskByPR(ctx context.Context, arg TaskByPRParams) (Task, error
&i.Origin,
&i.CallKey,
&i.OutcomePosted,
&i.BindingSignature,
&i.BindingAddr,
)
return i, err
}
@@ -1207,7 +1233,7 @@ func (q *Queries) TransitionTask(ctx context.Context, arg TransitionTaskParams)
}
const unpostedOutcomes = `-- name: UnpostedOutcomes :many
SELECT id, owner, repo, issue_number, title, body, labels, status, workflow, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth, outputs, review_gate, rereview_rounds, retry_mode, resume_from, resume_results, pending_reviews, origin, call_key, outcome_posted FROM tasks
SELECT id, owner, repo, issue_number, title, body, labels, status, workflow, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth, outputs, review_gate, rereview_rounds, retry_mode, resume_from, resume_results, pending_reviews, origin, call_key, outcome_posted, binding_signature, binding_addr FROM tasks
WHERE origin <> '' AND NOT outcome_posted
AND status IN ('merged', 'rejected', 'dead', 'closed_wont_do', 'completed')
AND ($1::text IS NULL OR org_id = $1)
@@ -1273,6 +1299,8 @@ func (q *Queries) UnpostedOutcomes(ctx context.Context, scopeOrg pgtype.Text) ([
&i.Origin,
&i.CallKey,
&i.OutcomePosted,
&i.BindingSignature,
&i.BindingAddr,
); err != nil {
return nil, err
}
@@ -114,7 +114,13 @@ LIMIT 50;
UPDATE tasks SET outcome_posted = true WHERE id = $1;
-- name: StampTaskBinding :exec
UPDATE tasks SET binding_id = $2, binding_version = $3 WHERE id = $1;
-- The capture's signature result is spelled as the access context spells it.
UPDATE tasks SET binding_id = @binding_id, binding_version = @binding_version,
binding_signature = c.signature, binding_addr = c.remote_addr
FROM (SELECT CASE WHEN authenticated THEN 'valid' WHEN unsigned THEN 'unsigned' ELSE 'unverified' END AS signature,
remote_addr
FROM captures WHERE captures.id = @capture_id) c
WHERE tasks.id = @id;
-- name: UpdateTask :exec
-- An update without a definition keeps the stored pin: a task's own
+3 -1
View File
@@ -112,6 +112,8 @@ func taskFromRow(t postgresdb.Task) *workflow.Task {
Workspace: org.WorkspaceID(t.WorkspaceID),
BindingID: t.BindingID,
BindingVersion: int(t.BindingVersion),
BindingSignature: t.BindingSignature,
BindingAddr: t.BindingAddr,
Inputs: inputs,
Outputs: outputs,
ReviewPayload: t.ReviewPayload,
@@ -219,7 +221,7 @@ func (s *Store) EnqueueBindingTask(ctx context.Context, owner, repo, title, body
return nil, err
}
if err := q.StampTaskBinding(ctx, postgresdb.StampTaskBindingParams{
ID: t.ID, BindingID: bindingID, BindingVersion: int64(bindingVersion),
ID: t.ID, BindingID: bindingID, BindingVersion: int64(bindingVersion), CaptureID: captureID,
}); err != nil {
return nil, fmt.Errorf("store: stamp binding provenance: %w", err)
}
@@ -86,6 +86,8 @@ func taskProto(t *task.Task) *pb.Task { // mirror-image field-by-field proto<->d
CallParentTaskId: t.CallParentTaskID,
CallDepth: int32(t.CallDepth),
Origin: t.Origin,
BindingSignature: t.BindingSignature,
BindingAddr: t.BindingAddr,
}
}
@@ -120,6 +122,8 @@ func taskValue(t *pb.Task) *task.Task { // see taskProto above
CallParentTaskID: t.CallParentTaskId,
CallDepth: int(t.CallDepth),
Origin: t.Origin,
BindingSignature: t.BindingSignature,
BindingAddr: t.BindingAddr,
}
}
+4
View File
@@ -483,6 +483,10 @@ message Task {
// workspace is the workspace of its org the task belongs to; read-only
// here.
string workspace = 45;
// binding_signature and binding_addr are the signature result and address
// of the captured event that started a binding task.
string binding_signature = 46;
string binding_addr = 47;
}
// Event mirrors internal/events.Event. Data is carried as a JSON object