feat(harness): ingest OAuth storage and recover workflow write handling
Recover the OAuth storage slice from f6079e9d and the missing workflow persistence error handling from f07c314e, adapted to the current step contract. Require encryption for OAuth token storage and verify RPC round trips and task-grant denial.
This commit is contained in:
26 files changed
+2047
-935
No files matched your search
@@ -142,7 +142,7 @@
|
||||
"url": "/dev/development/state-store/",
|
||||
"title": "State Store",
|
||||
"section": "Development",
|
||||
"body": "# State Store\n\nAuthority: `docs/prds/state-store-contract.md` and the State Store section of\n`CLAUDE.md`. All persistence is PostgreSQL behind the standalone State Store\nprocess; nothing else opens the database.\n\n## Adding a column\n\n1. Write the next migration in `internal/infrastructure/postgres/migrations/`\n (`00NN_name.sql`, goose Up and Down). Give the column a `NOT NULL DEFAULT`\n that is correct for existing rows.\n2. Update the queries in `internal/infrastructure/postgres/queries/` and\n regenerate with sqlc. A query that lists columns (`ListTaskSummaries`, the\n binding selects) does not pick the new one up; `SELECT *` queries do.\n3. Map it in the store (`taskFromRow`, `bindingValue` and friends). If the\n column holds encoded data, the package that owns the type owns the encoding\n (`task.EncodeInputs`), and the store and the wire both use it.\n4. Carry it over the wire (next section) if any process other than the State\n Store reads it.\n\n## Adding a field to a wire message\n\n1. Add it to `proto/state/v1/state.proto` with a new field number. Never reuse\n a number; retire one with `deprecated = true`.\n2. `task proto:generate`, then map it both ways in\n `internal/infrastructure/staterpc/values.go`.\n3. `TestTaskProtoCarriesEveryDomainField` fills every `task.Task` field and\n fails on one the mapping forgets. If it cannot fill the field's kind, extend\n it. Other messages have no such test, so add a round trip to\n `conformance_test.go`.\n\n## Adding an RPC or a store method\n\n1. Put the Go method on the narrow consumer interface in\n `internal/domain/storecontract` (keep each at eight methods or fewer) and add\n the matching RPC. A Go method without an RPC does not cross the process.\n2. Implement it in the Postgres store, in `staterpc.Client` (with its `var _`\n assertion) and in `staterpc.server`. A missing dependency answers\n `codes.Unavailable`, never a fabricated default.\n3. Wire the dependency in every composition that serves or consumes it:\n `stateStoreDeps` in `internal/app/archied/state_store.go`, the daemon's\n assertions in `bootstrap.go`, and `internal/app/archieui/compose.go` for the\n dashboard process.\n4. Task-scoped tokens may call only `Update`, `Transition` and `InsertEvent` on\n their own task (`staterpc.TaskGrants`). A new RPC is admin-only unless it is\n added there deliberately.\n5. Add it to `conformance_test.go`, which runs every surface over a real gRPC\n connection.\n\n## Adding an error sentinel\n\nAdd the sentinel to `storecontract`, a row to `wireErrors` in `values.go`, and\na case to `error_test.go`. The canonical message is part of the wire contract:\nchanging it breaks `errors.Is` on the client silently.\n"
|
||||
"body": "# State Store\n\nAuthority: `docs/prds/state-store-contract.md` and the State Store section of\n`CLAUDE.md`. All persistence is PostgreSQL behind the standalone State Store\nprocess; nothing else opens the database.\n\n## Adding a column\n\n1. Write the next migration in `internal/infrastructure/postgres/migrations/`\n (`00NN_name.sql`, goose Up and Down). Give the column a `NOT NULL DEFAULT`\n that is correct for existing rows.\n2. Update the queries in `internal/infrastructure/postgres/queries/` and\n regenerate with sqlc. A query that lists columns (`ListTaskSummaries`, the\n binding selects) does not pick the new one up; `SELECT *` queries do.\n3. Map it in the store (`taskFromRow`, `bindingValue` and friends). If the\n column holds encoded data, the package that owns the type owns the encoding\n (`task.EncodeInputs`), and the store and the wire both use it.\n4. Carry it over the wire (next section) if any process other than the State\n Store reads it.\n\n## Adding a field to a wire message\n\n1. Add it to `proto/state/v1/state.proto` with a new field number. Never reuse\n a number; retire one with `deprecated = true`.\n2. `task proto:generate`, then map it both ways in\n `internal/infrastructure/staterpc/values.go`.\n3. `TestTaskProtoCarriesEveryDomainField` fills every `task.Task` field and\n fails on one the mapping forgets. If it cannot fill the field's kind, extend\n it. Other messages have no such test, so add a round trip to\n `conformance_test.go`.\n\n## Adding an RPC or a store method\n\n1. Put the Go method on the narrow consumer interface in\n `internal/domain/storecontract` (keep each at eight methods or fewer) and add\n the matching RPC. A Go method without an RPC does not cross the process.\n2. Implement it in the Postgres store, in `staterpc.Client` (with its `var _`\n assertion) and in `staterpc.server`. A missing dependency answers\n `codes.Unavailable`, never a fabricated default.\n3. Wire the dependency in every composition that serves or consumes it:\n `stateStoreDeps` in `internal/app/archied/state_store.go`, the daemon's\n assertions in `bootstrap.go`, and `internal/app/archieui/compose.go` for the\n dashboard process.\n4. Task-scoped tokens may call only `Update`, `Transition` and `InsertEvent` on\n their own task (`staterpc.TaskGrants`). A new RPC is admin-only unless it is\n added there deliberately.\n5. Add it to `conformance_test.go`, which runs every surface over a real gRPC\n connection.\n\n## Adding an error sentinel\n\nAdd the sentinel to `storecontract`, a row to `wireErrors` in `values.go`, and\na case to `error_test.go`. The canonical message is part of the wire contract:\nchanging it breaks `errors.Is` on the client silently.\n\n## Harness OAuth secrets\n\n`HarnessSecretStore` stores token sets by org and credential service through\nadmin-only State Store RPCs. The EDA store seals them with the binding cipher's\nkeyring and a separate `HarnessSecretDomain`. OAuth writes require a configured\nbinding encryption key; the legacy binding plaintext fallback does not apply.\nThe proxy interception and setup terminal are separate harness slices.\n"
|
||||
},
|
||||
{
|
||||
"url": "/dev/development/wiring/",
|
||||
|
||||
@@ -52,3 +52,11 @@ process; nothing else opens the database.
|
||||
Add the sentinel to `storecontract`, a row to `wireErrors` in `values.go`, and
|
||||
a case to `error_test.go`. The canonical message is part of the wire contract:
|
||||
changing it breaks `errors.Is` on the client silently.
|
||||
|
||||
## Harness OAuth secrets
|
||||
|
||||
`HarnessSecretStore` stores token sets by org and credential service through
|
||||
admin-only State Store RPCs. The EDA store seals them with the binding cipher's
|
||||
keyring and a separate `HarnessSecretDomain`. OAuth writes require a configured
|
||||
binding encryption key; the legacy binding plaintext fallback does not apply.
|
||||
The proxy interception and setup terminal are separate harness slices.
|
||||
@@ -330,6 +330,10 @@ func (b *boot) stateStoreDeps(grants *staterpc.TaskGrants) staterpc.Deps {
|
||||
deps.EventTypes = b.eda
|
||||
deps.Sources = b.eda
|
||||
deps.MappingMatches = b.eda
|
||||
// HarnessSecrets rides the same encrypted-at-rest store as source
|
||||
// webhook secrets (docs/prds/binding-secret-encryption.md), under its
|
||||
// own domain separator (bindingcipher.HarnessSecretDomain).
|
||||
deps.HarnessSecrets = b.eda
|
||||
}
|
||||
// tool_call events project into the tool_calls collection on the same
|
||||
// event-capture store: this process legitimately owns both, so the
|
||||
|
||||
@@ -17,6 +17,7 @@ type eventCaptureStore interface { //nolint:interfacebloat // composite of the s
|
||||
storecontract.PlaybookDispatcher
|
||||
storecontract.EventTypeStore
|
||||
storecontract.SourceStore
|
||||
storecontract.HarnessSecretStore
|
||||
toolCallWriter
|
||||
}
|
||||
|
||||
|
||||
+1190
-885
File diff suppressed because it is too large.
Load diff
@@ -44,6 +44,8 @@ const (
|
||||
StateStoreService_FinishStep_FullMethodName = "/state.v1.StateStoreService/FinishStep"
|
||||
StateStoreService_CancelExecution_FullMethodName = "/state.v1.StateStoreService/CancelExecution"
|
||||
StateStoreService_ListSteps_FullMethodName = "/state.v1.StateStoreService/ListSteps"
|
||||
StateStoreService_GetHarnessSecret_FullMethodName = "/state.v1.StateStoreService/GetHarnessSecret"
|
||||
StateStoreService_PutHarnessSecret_FullMethodName = "/state.v1.StateStoreService/PutHarnessSecret"
|
||||
StateStoreService_Requeue_FullMethodName = "/state.v1.StateStoreService/Requeue"
|
||||
StateStoreService_ParkTask_FullMethodName = "/state.v1.StateStoreService/ParkTask"
|
||||
StateStoreService_RecoverStale_FullMethodName = "/state.v1.StateStoreService/RecoverStale"
|
||||
@@ -164,6 +166,12 @@ type StateStoreServiceClient interface {
|
||||
// ListSteps is a dashboard/API/dispatch action (Authorizer: read on the
|
||||
// run), not task-scoped-grant callable like StartStep/FinishStep.
|
||||
ListSteps(ctx context.Context, in *ListStepsRequest, opts ...grpc.CallOption) (*ListStepsResponse, error)
|
||||
// Harness OAuth secrets (docs/prds/external-agent-harness.md,
|
||||
// Credentials). Administrative: the setup terminal (an `update` action on
|
||||
// the secret, Authorizer-gated) and the egress proxy's token-endpoint
|
||||
// interception (acting as the daemon, not a worker) are the only callers.
|
||||
GetHarnessSecret(ctx context.Context, in *GetHarnessSecretRequest, opts ...grpc.CallOption) (*GetHarnessSecretResponse, error)
|
||||
PutHarnessSecret(ctx context.Context, in *PutHarnessSecretRequest, opts ...grpc.CallOption) (*PutHarnessSecretResponse, error)
|
||||
Requeue(ctx context.Context, in *RequeueRequest, opts ...grpc.CallOption) (*RequeueResponse, error)
|
||||
ParkTask(ctx context.Context, in *ParkTaskRequest, opts ...grpc.CallOption) (*ParkTaskResponse, error)
|
||||
RecoverStale(ctx context.Context, in *RecoverStaleRequest, opts ...grpc.CallOption) (*RecoverStaleResponse, error)
|
||||
@@ -547,6 +555,26 @@ func (c *stateStoreServiceClient) ListSteps(ctx context.Context, in *ListStepsRe
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *stateStoreServiceClient) GetHarnessSecret(ctx context.Context, in *GetHarnessSecretRequest, opts ...grpc.CallOption) (*GetHarnessSecretResponse, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(GetHarnessSecretResponse)
|
||||
err := c.cc.Invoke(ctx, StateStoreService_GetHarnessSecret_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *stateStoreServiceClient) PutHarnessSecret(ctx context.Context, in *PutHarnessSecretRequest, opts ...grpc.CallOption) (*PutHarnessSecretResponse, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(PutHarnessSecretResponse)
|
||||
err := c.cc.Invoke(ctx, StateStoreService_PutHarnessSecret_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *stateStoreServiceClient) Requeue(ctx context.Context, in *RequeueRequest, opts ...grpc.CallOption) (*RequeueResponse, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(RequeueResponse)
|
||||
@@ -1295,6 +1323,12 @@ type StateStoreServiceServer interface {
|
||||
// ListSteps is a dashboard/API/dispatch action (Authorizer: read on the
|
||||
// run), not task-scoped-grant callable like StartStep/FinishStep.
|
||||
ListSteps(context.Context, *ListStepsRequest) (*ListStepsResponse, error)
|
||||
// Harness OAuth secrets (docs/prds/external-agent-harness.md,
|
||||
// Credentials). Administrative: the setup terminal (an `update` action on
|
||||
// the secret, Authorizer-gated) and the egress proxy's token-endpoint
|
||||
// interception (acting as the daemon, not a worker) are the only callers.
|
||||
GetHarnessSecret(context.Context, *GetHarnessSecretRequest) (*GetHarnessSecretResponse, error)
|
||||
PutHarnessSecret(context.Context, *PutHarnessSecretRequest) (*PutHarnessSecretResponse, error)
|
||||
Requeue(context.Context, *RequeueRequest) (*RequeueResponse, error)
|
||||
ParkTask(context.Context, *ParkTaskRequest) (*ParkTaskResponse, error)
|
||||
RecoverStale(context.Context, *RecoverStaleRequest) (*RecoverStaleResponse, error)
|
||||
@@ -1503,6 +1537,12 @@ func (UnimplementedStateStoreServiceServer) CancelExecution(context.Context, *Ca
|
||||
func (UnimplementedStateStoreServiceServer) ListSteps(context.Context, *ListStepsRequest) (*ListStepsResponse, error) {
|
||||
return nil, status.Error(codes.Unimplemented, "method ListSteps not implemented")
|
||||
}
|
||||
func (UnimplementedStateStoreServiceServer) GetHarnessSecret(context.Context, *GetHarnessSecretRequest) (*GetHarnessSecretResponse, error) {
|
||||
return nil, status.Error(codes.Unimplemented, "method GetHarnessSecret not implemented")
|
||||
}
|
||||
func (UnimplementedStateStoreServiceServer) PutHarnessSecret(context.Context, *PutHarnessSecretRequest) (*PutHarnessSecretResponse, error) {
|
||||
return nil, status.Error(codes.Unimplemented, "method PutHarnessSecret not implemented")
|
||||
}
|
||||
func (UnimplementedStateStoreServiceServer) Requeue(context.Context, *RequeueRequest) (*RequeueResponse, error) {
|
||||
return nil, status.Error(codes.Unimplemented, "method Requeue not implemented")
|
||||
}
|
||||
@@ -2175,6 +2215,42 @@ func _StateStoreService_ListSteps_Handler(srv interface{}, ctx context.Context,
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _StateStoreService_GetHarnessSecret_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(GetHarnessSecretRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(StateStoreServiceServer).GetHarnessSecret(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: StateStoreService_GetHarnessSecret_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(StateStoreServiceServer).GetHarnessSecret(ctx, req.(*GetHarnessSecretRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _StateStoreService_PutHarnessSecret_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(PutHarnessSecretRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(StateStoreServiceServer).PutHarnessSecret(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: StateStoreService_PutHarnessSecret_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(StateStoreServiceServer).PutHarnessSecret(ctx, req.(*PutHarnessSecretRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _StateStoreService_Requeue_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(RequeueRequest)
|
||||
if err := dec(in); err != nil {
|
||||
@@ -3467,6 +3543,14 @@ var StateStoreService_ServiceDesc = grpc.ServiceDesc{
|
||||
MethodName: "ListSteps",
|
||||
Handler: _StateStoreService_ListSteps_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "GetHarnessSecret",
|
||||
Handler: _StateStoreService_GetHarnessSecret_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "PutHarnessSecret",
|
||||
Handler: _StateStoreService_PutHarnessSecret_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "Requeue",
|
||||
Handler: _StateStoreService_Requeue_Handler,
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
// Package harnesssecret is the OAuth token set a credential binding's
|
||||
// service holds for one org (docs/prds/external-agent-harness.md,
|
||||
// Credentials). The setup terminal writes the first capture; the egress
|
||||
// proxy overwrites it on every token refresh. It is never a Kit-declared
|
||||
// value and never resolved through the config secret registry the way an
|
||||
// API-key binding's SecretRef is -- it is state archie itself captures and
|
||||
// mutates.
|
||||
package harnesssecret
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Secret is one org's captured OAuth token set for a credential binding's
|
||||
// service.
|
||||
type Secret struct {
|
||||
Org string
|
||||
Service string
|
||||
AccessToken string
|
||||
RefreshToken string
|
||||
TokenType string
|
||||
ExpiresAt time.Time
|
||||
UpdatedAt time.Time
|
||||
}
|
||||
|
||||
// Validate rejects a Secret with no identity or no access token: the setup
|
||||
// terminal capture and the proxy's refresh write both produce a complete
|
||||
// token set or nothing.
|
||||
func (s Secret) Validate() error {
|
||||
if s.Org == "" {
|
||||
return errors.New("harnesssecret: org is required")
|
||||
}
|
||||
if s.Service == "" {
|
||||
return errors.New("harnesssecret: service is required")
|
||||
}
|
||||
if s.AccessToken == "" {
|
||||
return errors.New("harnesssecret: access token is required")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package harnesssecret
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestValidateRejectsIncomplete(t *testing.T) {
|
||||
cases := []Secret{
|
||||
{Service: "claude-code", AccessToken: "at"},
|
||||
{Org: "org-1", AccessToken: "at"},
|
||||
{Org: "org-1", Service: "claude-code"},
|
||||
}
|
||||
for _, s := range cases {
|
||||
if err := s.Validate(); err == nil {
|
||||
t.Errorf("Validate(%+v) = nil, want error", s)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateAcceptsComplete(t *testing.T) {
|
||||
s := Secret{Org: "org-1", Service: "claude-code", AccessToken: "at"}
|
||||
if err := s.Validate(); err != nil {
|
||||
t.Errorf("Validate() = %v, want nil", err)
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,7 @@ import (
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/domain/binding"
|
||||
"github.com/samcharles93/archie-core/internal/domain/eventtype"
|
||||
"github.com/samcharles93/archie-core/internal/domain/harnesssecret"
|
||||
"github.com/samcharles93/archie-core/internal/domain/mapping"
|
||||
"github.com/samcharles93/archie-core/internal/domain/source"
|
||||
"github.com/samcharles93/archie-core/internal/domain/workflow/task"
|
||||
@@ -99,6 +100,19 @@ type StepReader interface {
|
||||
ListSteps(ctx context.Context, executionID int64, attempt int) ([]task.StepExecution, error)
|
||||
}
|
||||
|
||||
// HarnessSecretStore persists one org's OAuth token set per credential
|
||||
// binding service (docs/prds/external-agent-harness.md, Credentials). The
|
||||
// setup terminal writes the first capture (an `update` action on the
|
||||
// secret, Authorizer-gated); the egress proxy's token-endpoint interception
|
||||
// overwrites it on every refresh with no Authorizer check of its own -- it
|
||||
// acts as the run, not as an operator. Encrypted at rest under its own
|
||||
// domain separator (docs/prds/binding-secret-encryption.md,
|
||||
// bindingcipher.HarnessSecretDomain).
|
||||
type HarnessSecretStore interface {
|
||||
GetHarnessSecret(ctx context.Context, org, service string) (harnesssecret.Secret, error)
|
||||
PutHarnessSecret(ctx context.Context, s harnesssecret.Secret) error
|
||||
}
|
||||
|
||||
// TaskArchiver removes one terminal task's local record with an optimistic
|
||||
// status guard. It is separate from the already broad lifecycle contract so
|
||||
// consumers that only run tasks do not acquire an operator-only capability.
|
||||
@@ -493,6 +507,10 @@ var (
|
||||
// ErrSourceSigningStale is returned when a signing write's expected
|
||||
// from state does not match the stored one.
|
||||
ErrSourceSigningStale = errors.New("store: source signing does not match expected state")
|
||||
// ErrHarnessSecretNotFound is returned when no OAuth token set is
|
||||
// stored for an org/service pair -- the setup terminal has not
|
||||
// captured one yet.
|
||||
ErrHarnessSecretNotFound = errors.New("store: harness secret not found")
|
||||
|
||||
// ErrResourceNotFound is returned when a control-plane resource kind has
|
||||
// no stored document. It is in-process only (not on the gRPC wire): the
|
||||
|
||||
@@ -313,7 +313,10 @@ func Run(ctx context.Context, wf Workflow, tc *TaskContext) {
|
||||
|
||||
for _, stage := range wf.Stages {
|
||||
tc.Stage = stage.Name
|
||||
_ = tc.Store.Update(ctx, t)
|
||||
if err := tc.Store.Update(ctx, t); err != nil {
|
||||
park(ctx, tc, fmt.Sprintf("persist task before stage %s: %v", stage.Name, err))
|
||||
return
|
||||
}
|
||||
// Every stage is a StepExecution (docs/prds/execution-tree-state-machine.md):
|
||||
// the store records pending -> running and writes the stage_start event
|
||||
// in the same transaction, and refuses a start the state machine
|
||||
@@ -355,10 +358,13 @@ func Run(ctx context.Context, wf Workflow, tc *TaskContext) {
|
||||
// steps. A recording failure on this path is logged and left to the
|
||||
// same recovery: the process is on its way out either way.
|
||||
if ctx.Err() != nil && err != nil {
|
||||
if finishEvent, recordErr := tc.Store.FinishStep(ctx, StepFinish{
|
||||
finishCtx, cancel := context.WithTimeout(context.WithoutCancel(ctx), 5*time.Second)
|
||||
finishEvent, recordErr := tc.Store.FinishStep(finishCtx, StepFinish{
|
||||
StepID: stepID, ExecutionID: t.ID,
|
||||
From: taskstate.StepRunning, To: taskstate.StepInterrupted, Detail: err.Error(),
|
||||
}); recordErr != nil {
|
||||
})
|
||||
cancel()
|
||||
if recordErr != nil {
|
||||
stageLog.Warn("interrupted step finish could not be recorded", "stage", stage.Name, "err", recordErr)
|
||||
} else {
|
||||
publishEvent(tc, finishEvent)
|
||||
@@ -420,8 +426,14 @@ func finish(ctx context.Context, tc *TaskContext, log *slog.Logger) {
|
||||
park(ctx, tc, tc.Outcome.Detail)
|
||||
return
|
||||
}
|
||||
_ = tc.Store.Update(ctx, t)
|
||||
_ = tc.Store.Transition(ctx, t.ID, StatusRunning, tc.Outcome.Status, tc.Outcome.Detail)
|
||||
if err := tc.Store.Update(ctx, t); err != nil {
|
||||
park(ctx, tc, fmt.Sprintf("persist workflow outcome: %v", err))
|
||||
return
|
||||
}
|
||||
if err := tc.Store.Transition(ctx, t.ID, StatusRunning, tc.Outcome.Status, tc.Outcome.Detail); err != nil {
|
||||
log.Error("workflow outcome transition failed", "err", err)
|
||||
return
|
||||
}
|
||||
tc.Emit(events.KindOutcome, tc.Stage, tc.Outcome.Detail, map[string]any{"status": tc.Outcome.Status})
|
||||
log.Info("workflow finished", "status", tc.Outcome.Status)
|
||||
}
|
||||
@@ -429,8 +441,13 @@ func finish(ctx context.Context, tc *TaskContext, log *slog.Logger) {
|
||||
func park(ctx context.Context, tc *TaskContext, reason string) {
|
||||
t := tc.Task
|
||||
t.ParkReason = reason
|
||||
_ = tc.Store.Update(ctx, t)
|
||||
_ = tc.Store.Transition(ctx, t.ID, StatusRunning, StatusParked, reason)
|
||||
if err := tc.Store.Update(ctx, t); err != nil {
|
||||
tc.Log.Error("task fields could not be persisted while parking", "err", err)
|
||||
}
|
||||
if err := tc.Store.Transition(ctx, t.ID, StatusRunning, StatusParked, reason); err != nil {
|
||||
tc.Log.Error("task park transition failed", "err", err)
|
||||
return
|
||||
}
|
||||
tc.Emit(events.KindParked, tc.Stage, reason, nil)
|
||||
// The run's own log is the surface an operator downloads to answer "why did
|
||||
// this park?", and the event above lands on the timeline, which the log
|
||||
|
||||
@@ -192,3 +192,104 @@ func TestRunParksWhenAChildStepWriteFails(t *testing.T) {
|
||||
t.Fatalf("transitions = %+v, want the execution parked after the child's recording failed", store.transitions)
|
||||
}
|
||||
}
|
||||
|
||||
// persistenceFailureStore fails the selected write while retaining the normal
|
||||
// recording store's event and step behaviour.
|
||||
type persistenceFailureStore struct {
|
||||
recordingStore
|
||||
failUpdate int
|
||||
updates int
|
||||
transitionErr error
|
||||
finishContextErr error
|
||||
finishHasDeadline bool
|
||||
}
|
||||
|
||||
func (s *persistenceFailureStore) Update(context.Context, *Task) error {
|
||||
s.updates++
|
||||
if s.updates == s.failUpdate {
|
||||
return errStepWrite
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *persistenceFailureStore) Transition(ctx context.Context, id int64, from, to, detail string) error {
|
||||
if s.transitionErr != nil {
|
||||
return s.transitionErr
|
||||
}
|
||||
return s.recordingStore.Transition(ctx, id, from, to, detail)
|
||||
}
|
||||
|
||||
func (s *persistenceFailureStore) FinishStep(ctx context.Context, finish StepFinish) (events.Event, error) {
|
||||
s.finishContextErr = ctx.Err()
|
||||
_, s.finishHasDeadline = ctx.Deadline()
|
||||
if ctx.Err() != nil {
|
||||
return events.Event{}, ctx.Err()
|
||||
}
|
||||
return s.recordingStore.FinishStep(ctx, finish)
|
||||
}
|
||||
|
||||
func TestRunDoesNotReportUnpersistedOutcomes(t *testing.T) {
|
||||
for _, tt := range []struct {
|
||||
name string
|
||||
failUpdate int
|
||||
transitionErr error
|
||||
stageErr error
|
||||
wantRan bool
|
||||
wantParked bool
|
||||
}{
|
||||
{name: "update before stage", failUpdate: 1, wantParked: true},
|
||||
{name: "update before outcome", failUpdate: 2, wantRan: true, wantParked: true},
|
||||
{name: "outcome transition", transitionErr: errStepWrite, wantRan: true},
|
||||
{name: "park transition", transitionErr: errStepWrite, stageErr: errStepWrite, wantRan: true},
|
||||
} {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
store := &persistenceFailureStore{failUpdate: tt.failUpdate, transitionErr: tt.transitionErr}
|
||||
bus := events.NewBus()
|
||||
sub := bus.Subscribe(16)
|
||||
defer sub.Close()
|
||||
tc := &TaskContext{Task: &Task{ID: 9, Attempt: 1, Status: StatusRunning}, Store: store, Bus: bus, Log: slog.New(slog.DiscardHandler)}
|
||||
ran := false
|
||||
Run(t.Context(), Workflow{Name: "persist", Stages: []Stage{{Name: "work", Run: func(_ context.Context, tc *TaskContext) error {
|
||||
ran = true
|
||||
tc.Outcome = Outcome{Status: StatusCompleted}
|
||||
return tt.stageErr
|
||||
}}}}, tc)
|
||||
if ran != tt.wantRan {
|
||||
t.Errorf("stage ran = %v, want %v", ran, tt.wantRan)
|
||||
}
|
||||
parked := false
|
||||
for len(sub.C) > 0 {
|
||||
event := <-sub.C
|
||||
if event.Kind == events.KindOutcome {
|
||||
t.Error("published an outcome whose write failed")
|
||||
}
|
||||
if event.Kind == events.KindParked {
|
||||
parked = true
|
||||
}
|
||||
}
|
||||
if parked != tt.wantParked {
|
||||
t.Errorf("published parked = %v, want %v", parked, tt.wantParked)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunRecordsInterruptionAfterContextCancellation(t *testing.T) {
|
||||
store := &persistenceFailureStore{}
|
||||
ctx, cancel := context.WithCancel(t.Context())
|
||||
defer cancel()
|
||||
tc := &TaskContext{Task: &Task{ID: 9, Attempt: 1, Status: StatusRunning}, Store: store, Log: slog.New(slog.DiscardHandler)}
|
||||
Run(ctx, Workflow{Name: "interrupt", Stages: []Stage{{Name: "work", Run: func(context.Context, *TaskContext) error {
|
||||
cancel()
|
||||
return ctx.Err()
|
||||
}}}}, tc)
|
||||
if store.finishContextErr != nil || !store.finishHasDeadline {
|
||||
t.Fatalf("finish context error = %v, bounded = %v; want a live, bounded cleanup context", store.finishContextErr, store.finishHasDeadline)
|
||||
}
|
||||
if len(store.finishes) != 1 || store.finishes[0].To != "interrupted" {
|
||||
t.Fatalf("finishes = %+v, want one interrupted step", store.finishes)
|
||||
}
|
||||
if len(store.transitions) != 0 {
|
||||
t.Fatalf("transitions = %+v, interruption must leave recovery to the store", store.transitions)
|
||||
}
|
||||
}
|
||||
@@ -14,22 +14,36 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
// bindingSecretAAD is the additional-authenticated-data domain separator. It
|
||||
// binds a ciphertext to the binding-secret payload context so it cannot be
|
||||
// relocated to a different field/column and still authenticate. It is
|
||||
// deliberately NOT row-bound: binding secrets are random HMAC keys and are
|
||||
// never used as lookup keys, so cross-row relocation is not a meaningful
|
||||
// attack here (see docs/prds/binding-secret-encryption.md).
|
||||
var bindingSecretAAD = []byte("arcie-binding-secret")
|
||||
// bindingEnvelopeVersion identifies the format version. A future cipher or
|
||||
// KDF change bumps it so old rows stay readable while new writes use the new
|
||||
// format. The version is shared by every domain; only the marker and AAD
|
||||
// differ between them.
|
||||
const bindingEnvelopeVersion = "v1"
|
||||
|
||||
// bindingEnvelopeMarker and bindingEnvelopeVersion identify a sealed binding
|
||||
// secret and the format version. A future cipher or KDF change bumps the
|
||||
// version so old rows stay readable while new writes use the new format.
|
||||
const (
|
||||
bindingEnvelopeMarker = "arcie-binding"
|
||||
bindingEnvelopeVersion = "v1"
|
||||
// bindingNonceLen is GCM's recommended 12-byte nonce.
|
||||
bindingNonceLen = 12
|
||||
// bindingNonceLen is GCM's recommended 12-byte nonce.
|
||||
const bindingNonceLen = 12
|
||||
|
||||
// Domain is an envelope's marker and additional-authenticated-data: the
|
||||
// separator that stops a ciphertext sealed for one column being relocated to
|
||||
// a different one and still authenticating (docs/prds/binding-secret-encryption.md).
|
||||
// Domains share the same keyring; only the marker and AAD differ.
|
||||
type Domain struct {
|
||||
marker string
|
||||
aad []byte
|
||||
}
|
||||
|
||||
var (
|
||||
// BindingDomain seals binding.Binding.Secret and source webhook
|
||||
// secrets -- the original domain this package was built for. It is
|
||||
// deliberately NOT row-bound: these are random HMAC keys, never used
|
||||
// as lookup keys, so cross-row relocation within the domain is not a
|
||||
// meaningful attack.
|
||||
BindingDomain = Domain{marker: "arcie-binding", aad: []byte("arcie-binding-secret")}
|
||||
// HarnessSecretDomain seals harness OAuth token sets
|
||||
// (docs/prds/external-agent-harness.md, Credentials) -- its own
|
||||
// separator, so a row cannot be moved from oauth_secrets into a
|
||||
// bindings-secret column (or back) and still authenticate.
|
||||
HarnessSecretDomain = Domain{marker: "arcie-harness", aad: []byte("arcie-harness-secret")}
|
||||
)
|
||||
|
||||
// bindingKeyFingerprintLen is the number of hex characters of the
|
||||
@@ -42,10 +56,17 @@ const bindingKeyFingerprintLen = 16
|
||||
// plaintext (legacy behaviour). Implementations must be safe for concurrent
|
||||
// use.
|
||||
type BindingCipher interface {
|
||||
// Encrypt returns the sealed envelope for a plaintext secret.
|
||||
// Encrypt returns the sealed envelope for a plaintext secret, under
|
||||
// BindingDomain.
|
||||
Encrypt(plaintext string) (string, error)
|
||||
// Decrypt returns the plaintext secret for a sealed envelope.
|
||||
// Decrypt returns the plaintext secret for a sealed envelope sealed
|
||||
// under BindingDomain.
|
||||
Decrypt(envelope string) (string, error)
|
||||
// EncryptDomain and DecryptDomain are Encrypt/Decrypt for a caller-named
|
||||
// domain, so a second column (e.g. harness OAuth secrets) can share this
|
||||
// cipher's keyring without sharing BindingDomain's AAD.
|
||||
EncryptDomain(d Domain, plaintext string) (string, error)
|
||||
DecryptDomain(d Domain, envelope string) (string, error)
|
||||
}
|
||||
|
||||
// bindingCipher is the AES-256-GCM BindingCipher. Keys are derived as
|
||||
@@ -84,9 +105,19 @@ func NewBindingCipher(active string, previous []string) (*bindingCipher, error)
|
||||
return c, nil
|
||||
}
|
||||
|
||||
// Encrypt seals plaintext with the active key and returns the versioned
|
||||
// envelope: "arcie-binding:v1:<fingerprint>:<base64url(nonce‖ct‖tag)>".
|
||||
// Encrypt seals plaintext under BindingDomain with the active key.
|
||||
func (c *bindingCipher) Encrypt(plaintext string) (string, error) {
|
||||
return c.EncryptDomain(BindingDomain, plaintext)
|
||||
}
|
||||
|
||||
// Decrypt opens an envelope sealed under BindingDomain.
|
||||
func (c *bindingCipher) Decrypt(envelope string) (string, error) {
|
||||
return c.DecryptDomain(BindingDomain, envelope)
|
||||
}
|
||||
|
||||
// EncryptDomain seals plaintext with the active key and returns the versioned
|
||||
// envelope: "<marker>:v1:<fingerprint>:<base64url(nonce‖ct‖tag)>".
|
||||
func (c *bindingCipher) EncryptDomain(d Domain, plaintext string) (string, error) {
|
||||
block, err := aes.NewCipher(c.activeKey)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("store: binding cipher: %w", err)
|
||||
@@ -99,20 +130,22 @@ func (c *bindingCipher) Encrypt(plaintext string) (string, error) {
|
||||
if _, err := rand.Read(nonce); err != nil {
|
||||
return "", fmt.Errorf("store: binding cipher: nonce: %w", err)
|
||||
}
|
||||
sealed := gcm.Seal(nil, nonce, []byte(plaintext), bindingSecretAAD)
|
||||
sealed := gcm.Seal(nil, nonce, []byte(plaintext), d.aad)
|
||||
payload := make([]byte, 0, bindingNonceLen+len(sealed))
|
||||
payload = append(payload, nonce...)
|
||||
payload = append(payload, sealed...)
|
||||
return fmt.Sprintf("%s:%s:%s:%s", bindingEnvelopeMarker, bindingEnvelopeVersion,
|
||||
return fmt.Sprintf("%s:%s:%s:%s", d.marker, bindingEnvelopeVersion,
|
||||
c.activeFingerprint, base64.RawURLEncoding.EncodeToString(payload)), nil
|
||||
}
|
||||
|
||||
// Decrypt parses the envelope, looks up the key by its embedded fingerprint,
|
||||
// and returns the plaintext. A fingerprint not present in the keyring (an old
|
||||
// key dropped from config) fails rather than returning garbage.
|
||||
func (c *bindingCipher) Decrypt(envelope string) (string, error) {
|
||||
// DecryptDomain parses an envelope sealed under d, looks up the key by its
|
||||
// embedded fingerprint, and returns the plaintext. A fingerprint not present
|
||||
// in the keyring (an old key dropped from config), or an envelope sealed
|
||||
// under a different domain's marker/AAD, fails rather than returning
|
||||
// garbage.
|
||||
func (c *bindingCipher) DecryptDomain(d Domain, envelope string) (string, error) {
|
||||
parts := strings.SplitN(envelope, ":", 4)
|
||||
if len(parts) != 4 || parts[0] != bindingEnvelopeMarker || parts[1] != bindingEnvelopeVersion {
|
||||
if len(parts) != 4 || parts[0] != d.marker || parts[1] != bindingEnvelopeVersion {
|
||||
return "", errors.New("store: binding cipher: unrecognised envelope")
|
||||
}
|
||||
key, ok := c.keys[parts[2]]
|
||||
@@ -135,7 +168,7 @@ func (c *bindingCipher) Decrypt(envelope string) (string, error) {
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("store: binding cipher: %w", err)
|
||||
}
|
||||
plaintext, err := gcm.Open(nil, nonce, sealed, bindingSecretAAD)
|
||||
plaintext, err := gcm.Open(nil, nonce, sealed, d.aad)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("store: binding cipher: authenticate: %w", err)
|
||||
}
|
||||
|
||||
@@ -120,6 +120,31 @@ func TestBindingCipherDerivesDistinctKeys(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestDomainSeparationRejectsRelocation(t *testing.T) {
|
||||
c, _ := NewBindingCipher(testBindingKey, nil)
|
||||
plain := "refresh-token-0123456789abcdef"
|
||||
env, err := c.EncryptDomain(HarnessSecretDomain, plain)
|
||||
if err != nil {
|
||||
t.Fatalf("EncryptDomain: %v", err)
|
||||
}
|
||||
if !strings.HasPrefix(env, "arcie-harness:v1:") {
|
||||
t.Fatalf("envelope prefix = %q, want arcie-harness:v1:", env)
|
||||
}
|
||||
// The envelope sealed for HarnessSecretDomain must not authenticate
|
||||
// under BindingDomain's AAD, even with the same keyring: a row moved
|
||||
// from oauth_secrets into a bindings-secret column must not decrypt.
|
||||
if _, err := c.Decrypt(env); err == nil {
|
||||
t.Fatal("Decrypt (BindingDomain) of a HarnessSecretDomain envelope succeeded, want error")
|
||||
}
|
||||
got, err := c.DecryptDomain(HarnessSecretDomain, env)
|
||||
if err != nil {
|
||||
t.Fatalf("DecryptDomain: %v", err)
|
||||
}
|
||||
if got != plain {
|
||||
t.Fatalf("round-trip = %q, want %q", got, plain)
|
||||
}
|
||||
}
|
||||
|
||||
// tamperEnvelope flips one byte inside the ciphertext region so Decrypt must
|
||||
// fail authentication rather than return altered plaintext.
|
||||
func tamperEnvelope(t *testing.T, envelope string) string {
|
||||
|
||||
@@ -0,0 +1,107 @@
|
||||
package postgres
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/jackc/pgx/v5"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/domain/harnesssecret"
|
||||
"github.com/samcharles93/archie-core/internal/domain/storecontract"
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/bindingcipher"
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/postgres/postgresdb"
|
||||
)
|
||||
|
||||
var _ storecontract.HarnessSecretStore = (*EDA)(nil)
|
||||
|
||||
// harnessSecretPayload is the JSON shape sealed into harness_secrets.secret_enc:
|
||||
// the whole token set behind one envelope, never separate plaintext columns.
|
||||
type harnessSecretPayload struct {
|
||||
AccessToken string `json:"access_token"`
|
||||
RefreshToken string `json:"refresh_token"`
|
||||
TokenType string `json:"token_type"`
|
||||
ExpiresAt time.Time `json:"expires_at"`
|
||||
}
|
||||
|
||||
// GetHarnessSecret returns the stored OAuth token set for an org/service
|
||||
// credential binding, or storecontract.ErrHarnessSecretNotFound.
|
||||
func (s *EDA) GetHarnessSecret(ctx context.Context, org, service string) (harnesssecret.Secret, error) {
|
||||
row, err := s.q.GetHarnessSecret(ctx, postgresdb.GetHarnessSecretParams{Org: org, Service: service})
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return harnesssecret.Secret{}, storecontract.ErrHarnessSecretNotFound
|
||||
}
|
||||
if err != nil {
|
||||
return harnesssecret.Secret{}, fmt.Errorf("postgres: get harness secret: %w", err)
|
||||
}
|
||||
payload, err := s.openHarnessSecret(row.SecretEnc)
|
||||
if err != nil {
|
||||
return harnesssecret.Secret{}, err
|
||||
}
|
||||
return harnesssecret.Secret{
|
||||
Org: row.Org, Service: row.Service,
|
||||
AccessToken: payload.AccessToken, RefreshToken: payload.RefreshToken,
|
||||
TokenType: payload.TokenType, ExpiresAt: payload.ExpiresAt,
|
||||
UpdatedAt: row.UpdatedAt,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// PutHarnessSecret upserts an org/service credential binding's OAuth token
|
||||
// set. Called by the setup terminal's first capture and by the egress
|
||||
// proxy's every refresh.
|
||||
func (s *EDA) PutHarnessSecret(ctx context.Context, secret harnesssecret.Secret) error {
|
||||
if err := secret.Validate(); err != nil {
|
||||
return err
|
||||
}
|
||||
sealed, err := s.sealHarnessSecret(harnessSecretPayload{
|
||||
AccessToken: secret.AccessToken, RefreshToken: secret.RefreshToken,
|
||||
TokenType: secret.TokenType, ExpiresAt: secret.ExpiresAt,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.q.PutHarnessSecret(ctx, postgresdb.PutHarnessSecretParams{
|
||||
Org: secret.Org, Service: secret.Service, SecretEnc: sealed,
|
||||
}); err != nil {
|
||||
return fmt.Errorf("postgres: put harness secret: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// sealHarnessSecret JSON-marshals the token set and encrypts it under
|
||||
// bindingcipher.HarnessSecretDomain -- its own domain separator, distinct
|
||||
// from BindingDomain's, so a row cannot be relocated between the two tables
|
||||
// and still authenticate. OAuth tokens require a configured encryption key;
|
||||
// the binding store's legacy plaintext fallback does not apply here.
|
||||
func (s *EDA) sealHarnessSecret(payload harnessSecretPayload) (string, error) {
|
||||
if s.cipher == nil {
|
||||
return "", errors.New("postgres: harness secrets require an encryption key")
|
||||
}
|
||||
raw, err := json.Marshal(payload)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("postgres: marshal harness secret: %w", err)
|
||||
}
|
||||
sealed, err := s.cipher.EncryptDomain(bindingcipher.HarnessSecretDomain, string(raw))
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("postgres: encrypt harness secret: %w", err)
|
||||
}
|
||||
return sealed, nil
|
||||
}
|
||||
|
||||
// openHarnessSecret reverses sealHarnessSecret.
|
||||
func (s *EDA) openHarnessSecret(stored string) (harnessSecretPayload, error) {
|
||||
if s.cipher == nil {
|
||||
return harnessSecretPayload{}, errors.New("postgres: harness secrets require an encryption key")
|
||||
}
|
||||
raw, err := s.cipher.DecryptDomain(bindingcipher.HarnessSecretDomain, stored)
|
||||
if err != nil {
|
||||
return harnessSecretPayload{}, fmt.Errorf("postgres: decrypt harness secret: %w", err)
|
||||
}
|
||||
var payload harnessSecretPayload
|
||||
if err := json.Unmarshal([]byte(raw), &payload); err != nil {
|
||||
return harnessSecretPayload{}, fmt.Errorf("postgres: unmarshal harness secret: %w", err)
|
||||
}
|
||||
return payload, nil
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
package postgres
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/domain/harnesssecret"
|
||||
"github.com/samcharles93/archie-core/internal/domain/storecontract"
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/bindingcipher"
|
||||
)
|
||||
|
||||
func readRawHarnessSecret(t *testing.T, pool *pgxpool.Pool, org, service string) string {
|
||||
t.Helper()
|
||||
var stored string
|
||||
err := pool.QueryRow(t.Context(), "SELECT secret_enc FROM harness_secrets WHERE org = $1 AND service = $2", org, service).Scan(&stored)
|
||||
if err != nil {
|
||||
t.Fatalf("read raw harness secret: %v", err)
|
||||
}
|
||||
return stored
|
||||
}
|
||||
|
||||
// A stored OAuth token set is a cipher envelope on disk and reads back as
|
||||
// plaintext, and the column never holds the raw access or refresh token.
|
||||
func TestHarnessSecretRoundTripEncrypts(t *testing.T) {
|
||||
cipher, err := bindingcipher.NewBindingCipher(edaTestKey, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("NewBindingCipher() error = %v", err)
|
||||
}
|
||||
pool, s := edaWithCipher(t, cipher)
|
||||
in := harnesssecret.Secret{
|
||||
Org: "org-1", Service: "claude-code",
|
||||
AccessToken: "at-0123456789abcdef", RefreshToken: "rt-0123456789abcdef",
|
||||
TokenType: "Bearer", ExpiresAt: time.Now().Add(time.Hour).UTC().Truncate(time.Second),
|
||||
}
|
||||
if err := s.PutHarnessSecret(t.Context(), in); err != nil {
|
||||
t.Fatalf("PutHarnessSecret() error = %v", err)
|
||||
}
|
||||
raw := readRawHarnessSecret(t, pool, in.Org, in.Service)
|
||||
if raw == "" {
|
||||
t.Fatal("stored secret is empty")
|
||||
}
|
||||
for _, want := range []string{in.AccessToken, in.RefreshToken} {
|
||||
if strings.Contains(raw, want) {
|
||||
t.Fatalf("stored column contains a real token: %q", raw)
|
||||
}
|
||||
}
|
||||
got, err := s.GetHarnessSecret(t.Context(), in.Org, in.Service)
|
||||
if err != nil {
|
||||
t.Fatalf("GetHarnessSecret() error = %v", err)
|
||||
}
|
||||
if got.AccessToken != in.AccessToken || got.RefreshToken != in.RefreshToken ||
|
||||
got.TokenType != in.TokenType || !got.ExpiresAt.Equal(in.ExpiresAt) {
|
||||
t.Fatalf("GetHarnessSecret() = %+v, want %+v", got, in)
|
||||
}
|
||||
}
|
||||
|
||||
// A refresh (a second Put for the same org/service) overwrites the row
|
||||
// rather than accumulating one per token: exactly the upsert semantics the
|
||||
// egress proxy's every refresh depends on.
|
||||
func TestHarnessSecretPutOverwritesOnRefresh(t *testing.T) {
|
||||
cipher, err := bindingcipher.NewBindingCipher(edaTestKey, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, s := edaWithCipher(t, cipher)
|
||||
org, service := "org-1", "claude-code"
|
||||
first := harnesssecret.Secret{Org: org, Service: service, AccessToken: "at-first", RefreshToken: "rt-first"}
|
||||
if err := s.PutHarnessSecret(t.Context(), first); err != nil {
|
||||
t.Fatalf("PutHarnessSecret(first) error = %v", err)
|
||||
}
|
||||
second := harnesssecret.Secret{Org: org, Service: service, AccessToken: "at-second", RefreshToken: "rt-second"}
|
||||
if err := s.PutHarnessSecret(t.Context(), second); err != nil {
|
||||
t.Fatalf("PutHarnessSecret(second) error = %v", err)
|
||||
}
|
||||
got, err := s.GetHarnessSecret(t.Context(), org, service)
|
||||
if err != nil {
|
||||
t.Fatalf("GetHarnessSecret() error = %v", err)
|
||||
}
|
||||
if got.AccessToken != second.AccessToken {
|
||||
t.Fatalf("AccessToken = %q, want the refreshed value %q", got.AccessToken, second.AccessToken)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHarnessSecretNotFound(t *testing.T) {
|
||||
_, s := edaWithCipher(t, nil)
|
||||
_, err := s.GetHarnessSecret(t.Context(), "org-1", "no-such-service")
|
||||
if !errors.Is(err, storecontract.ErrHarnessSecretNotFound) {
|
||||
t.Fatalf("GetHarnessSecret() error = %v, want ErrHarnessSecretNotFound", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHarnessSecretPutRejectsIncomplete(t *testing.T) {
|
||||
_, s := edaWithCipher(t, nil)
|
||||
if err := s.PutHarnessSecret(t.Context(), harnesssecret.Secret{Org: "org-1"}); err == nil {
|
||||
t.Fatal("PutHarnessSecret() with no service or access token succeeded, want error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestHarnessSecretRequiresEncryption(t *testing.T) {
|
||||
pool, store := edaWithCipher(t, nil)
|
||||
err := store.PutHarnessSecret(t.Context(), harnesssecret.Secret{Org: "org", Service: "service", AccessToken: "access"})
|
||||
if err == nil {
|
||||
t.Fatal("OAuth token stored without an encryption key")
|
||||
}
|
||||
var count int
|
||||
if err := pool.QueryRow(t.Context(), "SELECT count(*) FROM harness_secrets").Scan(&count); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if count != 0 {
|
||||
t.Fatalf("stored %d rows without encryption", count)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
-- +goose Up
|
||||
CREATE TABLE harness_secrets (
|
||||
org TEXT NOT NULL,
|
||||
service TEXT NOT NULL,
|
||||
secret_enc TEXT NOT NULL,
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
||||
PRIMARY KEY (org, service)
|
||||
);
|
||||
|
||||
-- +goose Down
|
||||
DROP TABLE harness_secrets;
|
||||
@@ -0,0 +1,54 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.31.1
|
||||
// source: harness_secrets.sql
|
||||
|
||||
package postgresdb
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
const getHarnessSecret = `-- name: GetHarnessSecret :one
|
||||
|
||||
SELECT org, service, secret_enc, updated_at
|
||||
FROM harness_secrets WHERE org = $1 AND service = $2
|
||||
`
|
||||
|
||||
type GetHarnessSecretParams struct {
|
||||
Org string
|
||||
Service string
|
||||
}
|
||||
|
||||
// Harness OAuth secret queries (docs/prds/external-agent-harness.md,
|
||||
// Credentials). One row per org/service; secret_enc holds the whole token
|
||||
// set (access token, refresh token, token type, expiry) as one encrypted
|
||||
// envelope over a JSON payload, never separate plaintext columns.
|
||||
func (q *Queries) GetHarnessSecret(ctx context.Context, arg GetHarnessSecretParams) (HarnessSecret, error) {
|
||||
row := q.db.QueryRow(ctx, getHarnessSecret, arg.Org, arg.Service)
|
||||
var i HarnessSecret
|
||||
err := row.Scan(
|
||||
&i.Org,
|
||||
&i.Service,
|
||||
&i.SecretEnc,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const putHarnessSecret = `-- name: PutHarnessSecret :exec
|
||||
INSERT INTO harness_secrets (org, service, secret_enc, updated_at)
|
||||
VALUES ($1, $2, $3, now())
|
||||
ON CONFLICT (org, service) DO UPDATE SET secret_enc = EXCLUDED.secret_enc, updated_at = now()
|
||||
`
|
||||
|
||||
type PutHarnessSecretParams struct {
|
||||
Org string
|
||||
Service string
|
||||
SecretEnc string
|
||||
}
|
||||
|
||||
func (q *Queries) PutHarnessSecret(ctx context.Context, arg PutHarnessSecretParams) error {
|
||||
_, err := q.db.Exec(ctx, putHarnessSecret, arg.Org, arg.Service, arg.SecretEnc)
|
||||
return err
|
||||
}
|
||||
@@ -143,6 +143,13 @@ type EventType struct {
|
||||
WorkspaceID string
|
||||
}
|
||||
|
||||
type HarnessSecret struct {
|
||||
Org string
|
||||
Service string
|
||||
SecretEnc string
|
||||
UpdatedAt time.Time
|
||||
}
|
||||
|
||||
type Identity struct {
|
||||
ID string
|
||||
Kind string
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
-- Harness OAuth secret queries (docs/prds/external-agent-harness.md,
|
||||
-- Credentials). One row per org/service; secret_enc holds the whole token
|
||||
-- set (access token, refresh token, token type, expiry) as one encrypted
|
||||
-- envelope over a JSON payload, never separate plaintext columns.
|
||||
|
||||
-- name: GetHarnessSecret :one
|
||||
SELECT org, service, secret_enc, updated_at
|
||||
FROM harness_secrets WHERE org = $1 AND service = $2;
|
||||
|
||||
-- name: PutHarnessSecret :exec
|
||||
INSERT INTO harness_secrets (org, service, secret_enc, updated_at)
|
||||
VALUES ($1, $2, $3, now())
|
||||
ON CONFLICT (org, service) DO UPDATE SET secret_enc = EXCLUDED.secret_enc, updated_at = now();
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
controlpb "github.com/samcharles93/archie-core/internal/contracts/controlplane/v1"
|
||||
pb "github.com/samcharles93/archie-core/internal/contracts/state/v1"
|
||||
"github.com/samcharles93/archie-core/internal/domain/binding"
|
||||
"github.com/samcharles93/archie-core/internal/domain/harnesssecret"
|
||||
"github.com/samcharles93/archie-core/internal/domain/identity"
|
||||
"github.com/samcharles93/archie-core/internal/domain/mapping"
|
||||
"github.com/samcharles93/archie-core/internal/domain/source"
|
||||
@@ -43,6 +44,7 @@ func (c *Client) ControlPlane() controlpb.ControlPlaneServiceClient { return c.c
|
||||
func (c *Client) Close() error { return nil }
|
||||
|
||||
var (
|
||||
_ storecontract.HarnessSecretStore = (*Client)(nil)
|
||||
_ task.Store = (*Client)(nil)
|
||||
_ task.Caller = (*Client)(nil)
|
||||
_ storecontract.TaskStore = (*Client)(nil)
|
||||
@@ -714,6 +716,24 @@ func (c *Client) TaskLogContent(ctx context.Context, taskID int64, attempt int,
|
||||
}
|
||||
}
|
||||
|
||||
// GetHarnessSecret returns the stored OAuth token set for an org/service
|
||||
// credential binding, or storecontract.ErrHarnessSecretNotFound.
|
||||
func (c *Client) GetHarnessSecret(ctx context.Context, org, service string) (harnesssecret.Secret, error) {
|
||||
r, err := c.client.GetHarnessSecret(ctx, &pb.GetHarnessSecretRequest{Org: org, Service: service})
|
||||
if err != nil {
|
||||
return harnesssecret.Secret{}, unmapError(err)
|
||||
}
|
||||
return harnessSecretValue(r.Secret), nil
|
||||
}
|
||||
|
||||
// PutHarnessSecret upserts an org/service credential binding's OAuth token
|
||||
// set, called by the setup terminal's first capture and by the egress
|
||||
// proxy's every refresh.
|
||||
func (c *Client) PutHarnessSecret(ctx context.Context, s harnesssecret.Secret) error {
|
||||
_, err := c.client.PutHarnessSecret(ctx, &pb.PutHarnessSecretRequest{Secret: harnessSecretProto(s)})
|
||||
return unmapError(err)
|
||||
}
|
||||
|
||||
func derefTasks(in []*pb.Task) []task.Task {
|
||||
if in == nil {
|
||||
return nil
|
||||
|
||||
@@ -12,10 +12,12 @@ import (
|
||||
"google.golang.org/grpc/test/bufconn"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/domain/binding"
|
||||
"github.com/samcharles93/archie-core/internal/domain/harnesssecret"
|
||||
"github.com/samcharles93/archie-core/internal/domain/mapping"
|
||||
"github.com/samcharles93/archie-core/internal/domain/storecontract"
|
||||
"github.com/samcharles93/archie-core/internal/domain/workflow"
|
||||
"github.com/samcharles93/archie-core/internal/events"
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/bindingcipher"
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/postgres"
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/postgres/pgstore"
|
||||
)
|
||||
@@ -95,6 +97,7 @@ func remoteTaskStore(t *testing.T, local *pgstore.TaskDB, logs storecontract.Tas
|
||||
deps.Bindings = eda
|
||||
deps.BindingDispatcher = eda
|
||||
deps.PlaybookDispatcher = eda
|
||||
deps.HarnessSecrets = eda
|
||||
}
|
||||
RegisterServer(server, deps)
|
||||
go func() { _ = server.Serve(listener) }()
|
||||
@@ -610,3 +613,40 @@ func TestConfigSnapshotContract(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestHarnessSecretConformance(t *testing.T) {
|
||||
for _, mode := range []string{"local", "grpc"} {
|
||||
t.Run(mode, func(t *testing.T) {
|
||||
cipher, err := bindingcipher.NewBindingCipher("conformance-encryption-material", nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
eda := pgstore.EDA(t, cipher)
|
||||
var store storecontract.HarnessSecretStore = eda
|
||||
if mode == "grpc" {
|
||||
store = remoteEDA(t, pgstore.Open(t), eda)
|
||||
}
|
||||
secret := harnesssecret.Secret{Org: "org-a", Service: "service", AccessToken: "access", RefreshToken: "refresh", TokenType: "Bearer", ExpiresAt: time.Now().UTC().Truncate(time.Microsecond).Add(time.Hour)}
|
||||
for _, token := range []string{"access", "refreshed-access"} {
|
||||
secret.AccessToken = token
|
||||
if err := store.PutHarnessSecret(t.Context(), secret); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
got, err := store.GetHarnessSecret(t.Context(), secret.Org, secret.Service)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got.UpdatedAt.IsZero() {
|
||||
t.Fatal("missing store timestamp")
|
||||
}
|
||||
got.UpdatedAt = time.Time{}
|
||||
if got != secret {
|
||||
t.Fatalf("round trip mismatch: got %+v, want %+v", got, secret)
|
||||
}
|
||||
}
|
||||
if _, err := store.GetHarnessSecret(t.Context(), "org-b", secret.Service); !errors.Is(err, storecontract.ErrHarnessSecretNotFound) {
|
||||
t.Fatalf("other org read = %v, want not found", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -75,6 +75,7 @@ func TestUnmapErrorSentinelFidelity(t *testing.T) {
|
||||
store error
|
||||
rehyd error
|
||||
}{
|
||||
{name: "harness secret not found", store: storecontract.ErrHarnessSecretNotFound, rehyd: storecontract.ErrHarnessSecretNotFound},
|
||||
{name: "stale transition", store: storecontract.ErrStaleTransition, rehyd: storecontract.ErrStaleTransition},
|
||||
{name: "illegal transition", store: storecontract.ErrIllegalTransition, rehyd: storecontract.ErrIllegalTransition},
|
||||
{name: "invalid step", store: storecontract.ErrInvalidStep, rehyd: storecontract.ErrInvalidStep},
|
||||
|
||||
@@ -111,6 +111,10 @@ type Deps struct {
|
||||
// task-scoped-grant callable. Optional: nil answers ListSteps with
|
||||
// codes.Unavailable.
|
||||
StepReader storecontract.StepReader
|
||||
// HarnessSecrets persists harness OAuth token sets
|
||||
// (docs/prds/external-agent-harness.md, Credentials). Optional: nil
|
||||
// answers both RPCs with codes.Unavailable.
|
||||
HarnessSecrets storecontract.HarnessSecretStore
|
||||
// PlaybookDispatcher is the side-effecting-action idempotency ledger
|
||||
// (docs/prds/eda-playbook-engine.md gap 2). Optional: nil disables the
|
||||
// two playbook dispatch RPCs with codes.Unavailable.
|
||||
@@ -264,6 +268,27 @@ func (s *server) ListSteps(ctx context.Context, r *pb.ListStepsRequest) (*pb.Lis
|
||||
return &pb.ListStepsResponse{Steps: mapValues(steps, stepExecutionProto)}, nil
|
||||
}
|
||||
|
||||
func (s *server) GetHarnessSecret(ctx context.Context, r *pb.GetHarnessSecretRequest) (*pb.GetHarnessSecretResponse, error) {
|
||||
if s.deps.HarnessSecrets == nil {
|
||||
return nil, status.Error(codes.Unavailable, "harness secret store unavailable")
|
||||
}
|
||||
secret, err := s.deps.HarnessSecrets.GetHarnessSecret(ctx, r.Org, r.Service)
|
||||
if err != nil {
|
||||
return nil, s.logErr("GetHarnessSecret", err)
|
||||
}
|
||||
return &pb.GetHarnessSecretResponse{Secret: harnessSecretProto(secret)}, nil
|
||||
}
|
||||
|
||||
func (s *server) PutHarnessSecret(ctx context.Context, r *pb.PutHarnessSecretRequest) (*pb.PutHarnessSecretResponse, error) {
|
||||
if s.deps.HarnessSecrets == nil {
|
||||
return nil, status.Error(codes.Unavailable, "harness secret store unavailable")
|
||||
}
|
||||
if err := s.deps.HarnessSecrets.PutHarnessSecret(ctx, harnessSecretValue(r.Secret)); err != nil {
|
||||
return nil, s.logErr("PutHarnessSecret", err)
|
||||
}
|
||||
return &pb.PutHarnessSecretResponse{}, nil
|
||||
}
|
||||
|
||||
func (s *server) Update(ctx context.Context, r *pb.UpdateRequest) (*pb.UpdateResponse, error) {
|
||||
if r.Task == nil {
|
||||
return nil, status.Error(codes.InvalidArgument, "task is required")
|
||||
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/domain/binding"
|
||||
"github.com/samcharles93/archie-core/internal/domain/eventtype"
|
||||
"github.com/samcharles93/archie-core/internal/domain/harnesssecret"
|
||||
"github.com/samcharles93/archie-core/internal/domain/mapping"
|
||||
"github.com/samcharles93/archie-core/internal/domain/storecontract"
|
||||
"github.com/samcharles93/archie-core/internal/domain/workflow"
|
||||
@@ -247,6 +248,13 @@ func TestTaskGrantScopesWorkerToItsOwnRPCs(t *testing.T) {
|
||||
t.Fatal("task grant must not authorize the streaming capture surface")
|
||||
}
|
||||
|
||||
if _, err := workerA.GetHarnessSecret(ctx, "org-a", "service"); status.Code(err) != codes.PermissionDenied {
|
||||
t.Fatalf("task grant secret read = %v, want PermissionDenied", err)
|
||||
}
|
||||
if err := workerA.PutHarnessSecret(ctx, harnesssecret.Secret{Org: "org-a", Service: "service", AccessToken: "token"}); status.Code(err) != codes.PermissionDenied {
|
||||
t.Fatalf("task grant secret write = %v, want PermissionDenied", err)
|
||||
}
|
||||
|
||||
if err := admin.RevokeTaskGrant(ctx, workerToken); err != nil {
|
||||
t.Fatalf("RevokeTaskGrant: %v", err)
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
pb "github.com/samcharles93/archie-core/internal/contracts/state/v1"
|
||||
"github.com/samcharles93/archie-core/internal/domain/binding"
|
||||
"github.com/samcharles93/archie-core/internal/domain/eventtype"
|
||||
"github.com/samcharles93/archie-core/internal/domain/harnesssecret"
|
||||
"github.com/samcharles93/archie-core/internal/domain/mapping"
|
||||
"github.com/samcharles93/archie-core/internal/domain/org"
|
||||
"github.com/samcharles93/archie-core/internal/domain/source"
|
||||
@@ -328,6 +329,25 @@ func stepExecutionValue(s *pb.StepExecution) task.StepExecution {
|
||||
}
|
||||
}
|
||||
|
||||
func harnessSecretProto(s harnesssecret.Secret) *pb.HarnessSecret {
|
||||
return &pb.HarnessSecret{
|
||||
Org: s.Org, Service: s.Service, AccessToken: s.AccessToken,
|
||||
RefreshToken: s.RefreshToken, TokenType: s.TokenType,
|
||||
ExpiresAt: timestamp(s.ExpiresAt), UpdatedAt: timestamp(s.UpdatedAt),
|
||||
}
|
||||
}
|
||||
|
||||
func harnessSecretValue(s *pb.HarnessSecret) harnesssecret.Secret {
|
||||
if s == nil {
|
||||
return harnesssecret.Secret{}
|
||||
}
|
||||
return harnesssecret.Secret{
|
||||
Org: s.Org, Service: s.Service, AccessToken: s.AccessToken,
|
||||
RefreshToken: s.RefreshToken, TokenType: s.TokenType,
|
||||
ExpiresAt: timeValue(s.ExpiresAt), UpdatedAt: timeValue(s.UpdatedAt),
|
||||
}
|
||||
}
|
||||
|
||||
func stageStatProto(s storecontract.StageStat) *pb.StageStat {
|
||||
return &pb.StageStat{Workflow: s.Workflow, Stage: s.Stage, Runs: int64(s.Runs), AvgMs: int64(s.AvgMs), Errors: int64(s.Errors)}
|
||||
}
|
||||
@@ -354,21 +374,22 @@ func dayTokensValue(d *pb.DayTokens) storecontract.DayTokens {
|
||||
// are the wire contract for sentinel identity -- the client rehydrates by
|
||||
// matching (code, message), never by parsing free-form text.
|
||||
const (
|
||||
msgStaleTransition = "stale transition"
|
||||
msgIllegalTransition = "illegal transition"
|
||||
msgInvalidStep = "step execution invalid"
|
||||
msgBindingNotFound = "binding not found"
|
||||
msgMappingNotFound = "mapping not found"
|
||||
msgEventTypeNotFound = "event type not found"
|
||||
msgEventTypeOverlap = "event type overlap"
|
||||
msgEventTypeInvalid = "event type invalid"
|
||||
msgBindingOverlap = "binding overlap"
|
||||
msgBindingTransition = "binding transition rejected"
|
||||
msgAlreadyDispatched = "already dispatched"
|
||||
msgSourceNotFound = "source not found"
|
||||
msgSourcePathTaken = "source path taken"
|
||||
msgSourceSigning = "source signing stale"
|
||||
msgInternal = "state store: internal error"
|
||||
msgStaleTransition = "stale transition"
|
||||
msgIllegalTransition = "illegal transition"
|
||||
msgInvalidStep = "step execution invalid"
|
||||
msgBindingNotFound = "binding not found"
|
||||
msgMappingNotFound = "mapping not found"
|
||||
msgEventTypeNotFound = "event type not found"
|
||||
msgEventTypeOverlap = "event type overlap"
|
||||
msgEventTypeInvalid = "event type invalid"
|
||||
msgBindingOverlap = "binding overlap"
|
||||
msgBindingTransition = "binding transition rejected"
|
||||
msgAlreadyDispatched = "already dispatched"
|
||||
msgSourceNotFound = "source not found"
|
||||
msgSourcePathTaken = "source path taken"
|
||||
msgSourceSigning = "source signing stale"
|
||||
msgHarnessSecretNotFound = "harness secret not found"
|
||||
msgInternal = "state store: internal error"
|
||||
// msgTaskLogsUnavailable is the public phrase for "this service has no
|
||||
// task-log reader". It is a wire contract like the sentinels above: the
|
||||
// client rehydrates logging.ErrTaskLogsUnavailable from (Unavailable, this
|
||||
@@ -485,6 +506,7 @@ var wireErrors = []struct {
|
||||
{storecontract.ErrCallCallerNotRunning, codes.FailedPrecondition, storecontract.ErrCallCallerNotRunning.Error()},
|
||||
{storecontract.ErrCallDepthExceeded, codes.FailedPrecondition, storecontract.ErrCallDepthExceeded.Error()},
|
||||
{storecontract.ErrSourcePathTaken, codes.AlreadyExists, msgSourcePathTaken},
|
||||
{storecontract.ErrHarnessSecretNotFound, codes.NotFound, msgHarnessSecretNotFound},
|
||||
{storepkg.ErrNotFound, codes.NotFound, storepkg.ErrNotFound.Error()},
|
||||
{storepkg.ErrInstalled, codes.AlreadyExists, storepkg.ErrInstalled.Error()},
|
||||
{storepkg.ErrRequired, codes.FailedPrecondition, storepkg.ErrRequired.Error()},
|
||||
|
||||
@@ -51,6 +51,12 @@ service StateStoreService {
|
||||
// ListSteps is a dashboard/API/dispatch action (Authorizer: read on the
|
||||
// run), not task-scoped-grant callable like StartStep/FinishStep.
|
||||
rpc ListSteps(ListStepsRequest) returns (ListStepsResponse);
|
||||
// Harness OAuth secrets (docs/prds/external-agent-harness.md,
|
||||
// Credentials). Administrative: the setup terminal (an `update` action on
|
||||
// the secret, Authorizer-gated) and the egress proxy's token-endpoint
|
||||
// interception (acting as the daemon, not a worker) are the only callers.
|
||||
rpc GetHarnessSecret(GetHarnessSecretRequest) returns (GetHarnessSecretResponse);
|
||||
rpc PutHarnessSecret(PutHarnessSecretRequest) returns (PutHarnessSecretResponse);
|
||||
rpc Requeue(RequeueRequest) returns (RequeueResponse);
|
||||
rpc ParkTask(ParkTaskRequest) returns (ParkTaskResponse);
|
||||
rpc RecoverStale(RecoverStaleRequest) returns (RecoverStaleResponse);
|
||||
@@ -612,6 +618,28 @@ message ListStepsRequest {
|
||||
}
|
||||
message ListStepsResponse { repeated StepExecution steps = 1; }
|
||||
|
||||
// HarnessSecret mirrors internal/domain/harnesssecret.Secret -- one org's
|
||||
// captured OAuth token set for a credential binding's service
|
||||
// (docs/prds/external-agent-harness.md, Credentials).
|
||||
message HarnessSecret {
|
||||
string org = 1;
|
||||
string service = 2;
|
||||
string access_token = 3;
|
||||
string refresh_token = 4;
|
||||
string token_type = 5;
|
||||
google.protobuf.Timestamp expires_at = 6;
|
||||
google.protobuf.Timestamp updated_at = 7;
|
||||
}
|
||||
|
||||
message GetHarnessSecretRequest {
|
||||
string org = 1;
|
||||
string service = 2;
|
||||
}
|
||||
message GetHarnessSecretResponse { HarnessSecret secret = 1; }
|
||||
|
||||
message PutHarnessSecretRequest { HarnessSecret secret = 1; }
|
||||
message PutHarnessSecretResponse {}
|
||||
|
||||
message UpdateRequest { Task task = 1; }
|
||||
message UpdateResponse {}
|
||||
|
||||
|
||||
Reference in new issue
Block a user