diff --git a/internal/app/archiegateway/tools.go b/internal/app/archiegateway/tools.go index f3d4d748d..3e2e861d1 100644 --- a/internal/app/archiegateway/tools.go +++ b/internal/app/archiegateway/tools.go @@ -11,6 +11,7 @@ import ( "github.com/samcharles93/archie-core/internal/agentexec/modelloop" "github.com/samcharles93/archie-core/internal/config" + "github.com/samcharles93/archie-core/internal/domain/access" "github.com/samcharles93/archie-core/internal/domain/applystatus" "github.com/samcharles93/archie-core/internal/domain/binding" "github.com/samcharles93/archie-core/internal/domain/eventtype" @@ -110,8 +111,8 @@ func (b *server) registerWorkflowTools(ctx context.Context) { } } -// integrationSource reads settings through the control plane and event types -// and bindings through the State Store. +// integrationSource reads settings through the control plane and event types, +// bindings and access policies through the State Store. type integrationSource struct { controlplanerpc.Workflows store *staterpc.Client @@ -125,6 +126,10 @@ func (s integrationSource) Bindings(ctx context.Context) ([]binding.Binding, err return s.store.ListBindings(ctx) } +func (s integrationSource) Policies(ctx context.Context) ([]access.Policy, error) { + return s.store.ListPolicies(ctx) +} + func (b *server) registerWebFetchTool(cfg config.Config) { log := b.log entry := webfetch.Tool(webfetch.Config{ diff --git a/internal/gateway/integration_tools.go b/internal/gateway/integration_tools.go index b1e4a7026..ef4a37449 100644 --- a/internal/gateway/integration_tools.go +++ b/internal/gateway/integration_tools.go @@ -18,14 +18,35 @@ type IntegrationSource interface { Resource(ctx context.Context, kind string) (json.RawMessage, error) EventTypes(ctx context.Context) ([]eventtype.EventType, error) Bindings(ctx context.Context) ([]binding.Binding, error) + Policies(ctx context.Context) ([]access.Policy, error) } -// readableKinds are the settings that shape what a workflow can do and what -// starts it. Provider, channel and connection settings are left out: they -// carry endpoints and secret references an agent has no use for. +// readableKinds are the settings that shape what a workflow can do, what starts +// it and what it is told to do. Provider, channel and connection settings are +// left out: they carry endpoints and secret references an agent has no use for. +// soul is the instructions text, task-policy and org-model-policy carry limits +// and settings whose secrets are references, never values. var readableKinds = []string{ "workflow-execution-settings", "workflow-enablement", "agent-profiles", "skills", "schedules", "eda-playbooks", "credential-bindings", "identity-grants", + "soul", "task-policy", "org-model-policy", +} + +// visiblePolicies keeps what the caller's dashboard shows: the caller org's +// policies, and the instance policies when the caller owns the instance. +func visiblePolicies(ctx context.Context, policies []access.Policy) []access.Policy { + principal, ok := access.PrincipalFromContext(ctx) + if !ok { + return nil + } + out := make([]access.Policy, 0, len(policies)) + for _, policy := range policies { + instance := policy.Level == access.LevelInstance + if (instance && principal.InstanceAdmin()) || (!instance && policy.OrgID == principal.Org) { + out = append(out, policy) + } + } + return out } // IntegrationTools returns read-only tools for investigating what starts @@ -72,6 +93,20 @@ func IntegrationTools(source IntegrationSource, authz access.Authorizer) []tools return types, nil }, }), + guarded(authz, access.ActionRead, access.KindPolicy, nil, tools.ToolEntry{ + Name: "access_policies_list", + Toolset: "workflows", + Description: "List the Cedar access policies that decide what a workflow and its caller may do: each one's id, level, scope and policy text.", + Classification: tools.ClassIdempotent, + Schema: tools.JSONSchema{"type": "object", "properties": map[string]any{}}, + Handler: func(ctx context.Context, _ map[string]any) (any, error) { + policies, err := source.Policies(ctx) + if err != nil { + return nil, fmt.Errorf("access_policies_list: %w", err) + } + return visiblePolicies(ctx, policies), nil + }, + }), guarded(authz, access.ActionRead, access.KindBinding, nil, tools.ToolEntry{ Name: "bindings_list", Toolset: "workflows", diff --git a/internal/gateway/workflow_tools.go b/internal/gateway/workflow_tools.go index 3a1546408..effd56b99 100644 --- a/internal/gateway/workflow_tools.go +++ b/internal/gateway/workflow_tools.go @@ -84,7 +84,7 @@ func workflowGetTool(source WorkflowSource) tools.ToolEntry { return tools.ToolEntry{ Name: "workflow_get", Toolset: "workflows", - Description: "Return one workflow's YAML: its draft when the operator has one open, else the published definition. Read a similar workflow before writing a new one.", + Description: "Return one workflow's YAML: its draft when the operator has one open, else the published definition. Read a similar workflow before writing a new one. Its instructions field is one layer of the agent's brief, given after the instance's and the organisation's and before the repository's; a narrower layer refines the one above it.", Classification: tools.ClassIdempotent, Schema: tools.JSONSchema{ "type": "object",