@a5c-ai/krate 5.0.1-staging.f672fe79b

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (174) hide show
  1. package/Dockerfile +29 -0
  2. package/README.md +183 -0
  3. package/bin/krate-demo.mjs +23 -0
  4. package/bin/krate-server.mjs +14 -0
  5. package/dist/krate-controller-ui.json +2407 -0
  6. package/dist/krate-lifecycle.json +201 -0
  7. package/dist/krate-runtime-snapshot.json +2955 -0
  8. package/dist/krate-summary.json +687 -0
  9. package/docs/README.md +61 -0
  10. package/docs/agents/README.md +83 -0
  11. package/docs/agents/acceptance-test-matrix.md +193 -0
  12. package/docs/agents/agent-mux-adapter-contract.md +167 -0
  13. package/docs/agents/agent-mux-source-map.md +310 -0
  14. package/docs/agents/agent-run-memory-import-spec.md +256 -0
  15. package/docs/agents/agent-stack-management-spec.md +421 -0
  16. package/docs/agents/api-contract-spec.md +309 -0
  17. package/docs/agents/artifacts-writeback-spec.md +145 -0
  18. package/docs/agents/chart-packaging-spec.md +128 -0
  19. package/docs/agents/ci-orchestration-spec.md +140 -0
  20. package/docs/agents/context-assembly-spec.md +219 -0
  21. package/docs/agents/controller-reconciliation-spec.md +255 -0
  22. package/docs/agents/crd-schema-spec.md +315 -0
  23. package/docs/agents/decision-log-open-questions.md +169 -0
  24. package/docs/agents/developer-implementation-checklist.md +329 -0
  25. package/docs/agents/dispatching-design.md +262 -0
  26. package/docs/agents/glossary.md +66 -0
  27. package/docs/agents/implementation-blueprint.md +324 -0
  28. package/docs/agents/implementation-rollout-slices.md +251 -0
  29. package/docs/agents/memory-context-integration-spec.md +194 -0
  30. package/docs/agents/memory-ontology-schema-spec.md +253 -0
  31. package/docs/agents/memory-operations-runbook.md +121 -0
  32. package/docs/agents/mvp-vertical-slice-spec.md +146 -0
  33. package/docs/agents/observability-audit-spec.md +265 -0
  34. package/docs/agents/operator-runbook.md +174 -0
  35. package/docs/agents/org-memory-api-payload-examples.md +333 -0
  36. package/docs/agents/org-memory-controller-sequence-spec.md +181 -0
  37. package/docs/agents/org-memory-e2e-fixture-plan.md +161 -0
  38. package/docs/agents/org-memory-ui-implementation-map.md +114 -0
  39. package/docs/agents/org-memory-vertical-slice-spec.md +168 -0
  40. package/docs/agents/org-resource-model-delta-spec.md +111 -0
  41. package/docs/agents/org-route-resource-model-spec.md +183 -0
  42. package/docs/agents/org-scoping-namespace-spec.md +114 -0
  43. package/docs/agents/rbac-secrets-management-spec.md +406 -0
  44. package/docs/agents/repository-page-integration-spec.md +255 -0
  45. package/docs/agents/resource-contract-examples.md +808 -0
  46. package/docs/agents/resource-relationship-map.md +190 -0
  47. package/docs/agents/security-threat-model.md +188 -0
  48. package/docs/agents/shared-memory-company-brain-spec.md +358 -0
  49. package/docs/agents/storage-migration-spec.md +168 -0
  50. package/docs/agents/subagent-orchestration-spec.md +152 -0
  51. package/docs/agents/system-overview.md +88 -0
  52. package/docs/agents/tools-mcp-skills-spec.md +189 -0
  53. package/docs/agents/traceability-matrix.md +79 -0
  54. package/docs/agents/ui-flow-spec.md +211 -0
  55. package/docs/agents/ui-ux-system-spec.md +426 -0
  56. package/docs/agents/workspace-lifecycle-spec.md +166 -0
  57. package/docs/architecture-spec.md +78 -0
  58. package/docs/components/control-plane.md +78 -0
  59. package/docs/components/data-plane.md +69 -0
  60. package/docs/components/hooks-events.md +67 -0
  61. package/docs/components/identity-rbac-policy.md +73 -0
  62. package/docs/components/kubevela-oam.md +70 -0
  63. package/docs/components/operations-publishing.md +81 -0
  64. package/docs/components/runners-ci.md +66 -0
  65. package/docs/components/web-ui.md +94 -0
  66. package/docs/external/README.md +47 -0
  67. package/docs/external/bidirectional-sync-design.md +134 -0
  68. package/docs/external/cicd-interface.md +64 -0
  69. package/docs/external/external-backend-controllers.md +170 -0
  70. package/docs/external/external-backend-crds.md +234 -0
  71. package/docs/external/external-backend-ui-spec.md +151 -0
  72. package/docs/external/external-backend-ux-flows.md +115 -0
  73. package/docs/external/external-object-mapping.md +125 -0
  74. package/docs/external/git-forge-interface.md +68 -0
  75. package/docs/external/github-integration-design.md +151 -0
  76. package/docs/external/issue-tracking-interface.md +66 -0
  77. package/docs/external/provider-capability-manifests.md +204 -0
  78. package/docs/external/provider-catalog.md +139 -0
  79. package/docs/external/provider-rollout-testing.md +78 -0
  80. package/docs/external/research-results.md +48 -0
  81. package/docs/external/security-auth-permissions.md +81 -0
  82. package/docs/external/sync-state-machines.md +108 -0
  83. package/docs/external/unified-external-backend-model.md +107 -0
  84. package/docs/external/user-facing-changes.md +67 -0
  85. package/docs/gaps.md +161 -0
  86. package/docs/install.md +94 -0
  87. package/docs/krate-design.md +334 -0
  88. package/docs/local-minikube.md +55 -0
  89. package/docs/ontology/README.md +32 -0
  90. package/docs/ontology/bounded-contexts.md +29 -0
  91. package/docs/ontology/events-and-hooks.md +32 -0
  92. package/docs/ontology/oam-kubevela.md +32 -0
  93. package/docs/ontology/operations-and-release.md +25 -0
  94. package/docs/ontology/personas-and-actors.md +32 -0
  95. package/docs/ontology/policies-and-invariants.md +33 -0
  96. package/docs/ontology/problem-space.md +30 -0
  97. package/docs/ontology/resource-contracts.md +40 -0
  98. package/docs/ontology/resource-taxonomy.md +42 -0
  99. package/docs/ontology/runners-and-ci.md +29 -0
  100. package/docs/ontology/solution-space.md +24 -0
  101. package/docs/ontology/storage-and-data-boundaries.md +29 -0
  102. package/docs/ontology/validation-matrix.md +24 -0
  103. package/docs/ontology/web-ui-excellent-flows.md +32 -0
  104. package/docs/ontology/workflows.md +39 -0
  105. package/docs/ontology/world.md +35 -0
  106. package/docs/product-requirements.md +62 -0
  107. package/docs/roadmap-mvp.md +87 -0
  108. package/docs/system-requirements.md +90 -0
  109. package/docs/tests/README.md +53 -0
  110. package/docs/tests/agent-qa-plan.md +63 -0
  111. package/docs/tests/browser-ui-tests.md +62 -0
  112. package/docs/tests/ci-quality-gates.md +48 -0
  113. package/docs/tests/coverage-model.md +64 -0
  114. package/docs/tests/e2e-scenario-tests.md +53 -0
  115. package/docs/tests/fixtures-test-data.md +63 -0
  116. package/docs/tests/observability-reliability-tests.md +54 -0
  117. package/docs/tests/product-test-matrix.md +145 -0
  118. package/docs/tests/qa-adoption-roadmap.md +130 -0
  119. package/docs/tests/qa-automation-plan.md +101 -0
  120. package/docs/tests/security-compliance-tests.md +57 -0
  121. package/docs/tests/test-framework-tools.md +88 -0
  122. package/docs/tests/test-suite-layout.md +121 -0
  123. package/docs/tests/unit-integration-tests.md +48 -0
  124. package/docs/todo-kyverno +714 -0
  125. package/docs/user-stories.md +78 -0
  126. package/examples/minikube-demo.yaml +190 -0
  127. package/examples/oam-application.yaml +23 -0
  128. package/examples/policy-kyverno-pr-title.yaml +18 -0
  129. package/package.json +63 -0
  130. package/scripts/build.mjs +29 -0
  131. package/scripts/setup-minikube.mjs +65 -0
  132. package/scripts/smoke.mjs +37 -0
  133. package/scripts/validate-doc-coverage.mjs +152 -0
  134. package/scripts/validate-package.mjs +93 -0
  135. package/scripts/validate-ui.mjs +207 -0
  136. package/src/agent-approval-controller.js +123 -0
  137. package/src/agent-context-bundles.js +242 -0
  138. package/src/agent-dispatch-controller.js +86 -0
  139. package/src/agent-mux-client.js +280 -0
  140. package/src/agent-permission-review.js +162 -0
  141. package/src/agent-stack-controller.js +296 -0
  142. package/src/agent-trigger-controller.js +108 -0
  143. package/src/api-controller.js +206 -0
  144. package/src/argocd-gitops.js +43 -0
  145. package/src/auth.js +265 -0
  146. package/src/component-catalog.js +41 -0
  147. package/src/control-plane.js +136 -0
  148. package/src/controller-client.js +38 -0
  149. package/src/controller-ui.js +538 -0
  150. package/src/data-plane.js +178 -0
  151. package/src/gitea-backend.js +95 -0
  152. package/src/handoff.js +98 -0
  153. package/src/hooks-events.js +63 -0
  154. package/src/http-server.js +151 -0
  155. package/src/identity-policy.js +86 -0
  156. package/src/index.js +30 -0
  157. package/src/kubernetes-controller.js +812 -0
  158. package/src/kubernetes-resource-gateway.js +48 -0
  159. package/src/operations.js +112 -0
  160. package/src/resource-model.js +203 -0
  161. package/src/runners-ci.js +48 -0
  162. package/src/runtime.js +196 -0
  163. package/src/web-ui.js +40 -0
  164. package/tests/agent-approval-controller.test.js +173 -0
  165. package/tests/agent-context-bundles.test.js +278 -0
  166. package/tests/agent-dispatch-controller.test.js +176 -0
  167. package/tests/agent-mux-client.test.js +204 -0
  168. package/tests/agent-permission-review.test.js +209 -0
  169. package/tests/agent-resources.test.js +212 -0
  170. package/tests/agent-stack-controller.test.js +221 -0
  171. package/tests/agent-trigger-controller.test.js +211 -0
  172. package/tests/deployment.test.js +395 -0
  173. package/tests/e2e/lifecycle.test.js +117 -0
  174. package/tests/krate.test.js +727 -0
@@ -0,0 +1,114 @@
1
+ # Org scoping and namespace spec
2
+
3
+ ## Purpose
4
+
5
+ Every Krate resource that belongs to a business tenant must be scoped under an organization. Each organization owns a Kubernetes namespace, and repositories, deployments, agents, runners, triggers, memory repositories, secrets, config, sessions, workspaces, and audit records must resolve through that org boundary before any controller side effect occurs.
6
+
7
+ ## Org namespace model
8
+
9
+ ```text
10
+ Organization a5c
11
+ -> Kubernetes namespace krate-org-a5c
12
+ -> repositories
13
+ -> deployments/environments
14
+ -> runner pools and service accounts
15
+ -> agent stacks, triggers, skills, tools, subagents
16
+ -> company brain memory repository
17
+ -> sessions, dispatch runs, workspaces, journals
18
+ -> secrets, config maps, roles, role bindings
19
+ ```
20
+
21
+ The namespace is the default isolation unit. Cluster-scoped resources exist only for installation, CRDs, API aggregation, shared controllers, and explicitly shared platform services.
22
+
23
+ ## Core resources
24
+
25
+ ### `Organization`
26
+
27
+ ```yaml
28
+ kind: Organization
29
+ metadata:
30
+ name: a5c
31
+ spec:
32
+ namespaceName: krate-org-a5c
33
+ displayName: a5c.ai
34
+ slug: a5c
35
+ defaultVisibility: internal
36
+ memoryRepositoryRef: org-company-brain
37
+ policyProfileRef: default-org-policy
38
+ status:
39
+ phase: Ready
40
+ namespaceReady: true
41
+ ```
42
+
43
+ ### `OrgNamespaceBinding`
44
+
45
+ ```yaml
46
+ kind: OrgNamespaceBinding
47
+ spec:
48
+ organizationRef: a5c
49
+ namespace: krate-org-a5c
50
+ createNamespace: true
51
+ labels:
52
+ krate.a5c.ai/org: a5c
53
+ serviceAccountPolicy:
54
+ defaultRunnerPrefix: runner-
55
+ defaultAgentPrefix: agent-
56
+ ```
57
+
58
+ ## Required labels
59
+
60
+ All namespaced resources must carry:
61
+
62
+ - `krate.a5c.ai/org`;
63
+ - `krate.a5c.ai/namespace`;
64
+ - `krate.a5c.ai/repository` when repository-scoped;
65
+ - `krate.a5c.ai/environment` when deployment-scoped;
66
+ - `krate.a5c.ai/agent-stack` when agent-scoped.
67
+
68
+ Controllers must reject cross-org references unless a cluster-admin has created an explicit sharing policy.
69
+
70
+ ## Scope hierarchy
71
+
72
+ ```text
73
+ Cluster
74
+ -> Organization
75
+ -> Repository
76
+ -> PullRequest / Issue / Pipeline / Job / WebhookDelivery
77
+ -> AgentWorkspace / AgentSession / AgentDispatchRun
78
+ -> Deployment / Environment
79
+ -> release policy / runtime status / environment secrets
80
+ -> CompanyBrainMemory
81
+ -> AgentMemoryRepository / Source / Snapshot / Query / Update
82
+ ```
83
+
84
+ Repositories, deployments, and memory repositories are sibling org-scoped domains. Agent dispatches may reference all three only through org-compatible resource refs.
85
+
86
+ ## RBAC requirements
87
+
88
+ - Org admins can manage org-scoped resources within their namespace.
89
+ - Repo admins can manage repository settings but cannot read unrelated memory paths or deployment secrets.
90
+ - Runner ServiceAccounts are namespaced to the org and bound only to permitted repo/ref/environment scopes.
91
+ - Agent ServiceAccounts are namespaced to the org and cannot mount secrets/config from another org namespace.
92
+ - Memory read/update grants are org-scoped and path/kind-scoped.
93
+ - Cross-org actions require an explicit `OrgSharingPolicy` and audit event.
94
+
95
+ ## UI requirements
96
+
97
+ - Global navigation starts with an org switcher.
98
+ - Repository URLs should be org-aware, for example `/orgs/[org]/repositories/[repo]/code`, while legacy `/orgs/[org]/repositories/[repo]` may redirect when unambiguous.
99
+ - Agent pages are org-scoped by default: `/orgs/[org]/agents/runs`, `/orgs/[org]/agents/memory`, `/orgs/[org]/agents/settings`.
100
+ - Deployment and environment pages are org-scoped and can link to repository runs and agent dispatches.
101
+ - Resource YAML panels must show namespace and org labels.
102
+
103
+ ## Acceptance criteria
104
+
105
+ - Creating an organization creates or binds exactly one Kubernetes namespace.
106
+ - Creating a repository, deployment, runner pool, agent stack, trigger, memory source, or secret grant requires an org.
107
+ - Controllers reject cross-org references by default.
108
+ - UI always shows current org context and never mixes runs, memory, secrets, or workspaces across orgs.
109
+ - Audit events include org, namespace, actor, resource ref, and source controller.
110
+
111
+ ## Detailed companion specs
112
+
113
+ - [Org route and resource model spec](./org-route-resource-model-spec.md) expands route shape, API shape, resource refs, deployment scope, and controller enforcement.
114
+ - [Agent run memory import spec](./agent-run-memory-import-spec.md) expands how `MEMORY.md`, sessions, `.a5c` journals, task results, artifacts, and retrospectives enter the org company brain.
@@ -0,0 +1,406 @@
1
+ # Agent RBAC, service account, secret, and config management spec
2
+
3
+ ## Purpose
4
+
5
+ Krate must use native Kubernetes identity and RBAC for humans, agents, and runners. Agent orchestration must not introduce a parallel permission system. The UI can make permission management easy, but the authoritative checks must resolve to Kubernetes users, groups, ServiceAccounts, Roles, ClusterRoles, RoleBindings, ClusterRoleBindings, Secrets, ConfigMaps, and admission decisions.
6
+
7
+ This spec adds the missing permission layer for agent dispatch: service account management for runners and agents, role synchronization for users and teams, secret/config access grants, tool-secret and skill-secret associations, and UI warnings when a stack requests a capability whose required secret/config is not admitted.
8
+
9
+ ## Design goals
10
+
11
+ - Keep Kubernetes RBAC as the enforcement point for humans, agents, runners, and controllers.
12
+ - Make permission intent easy to manage from Krate without hiding the native objects that enforce it.
13
+ - Separate identity (`ServiceAccount`), authorization (`RoleBinding`), secret access (`AgentSecretGrant`), and non-secret config access (`AgentConfigGrant`).
14
+ - Treat tool, MCP, skill, model, and subagent requirements as typed dependencies that can be validated before dispatch.
15
+ - Fail closed for missing or stale grants, but explain the exact missing ServiceAccount, role, Secret key, ConfigMap key, repository, ref, and trigger source.
16
+ - Never pass broad cluster credentials into Agent Mux; pass only admitted scoped references or projected mounts for the selected attempt.
17
+
18
+ ## Non-goals
19
+
20
+ - Do not store Secret values in Krate resources, events, prompt previews, audit logs, or Agent Mux transcripts.
21
+ - Do not replace Kubernetes RBAC with a Krate-only ACL system.
22
+ - Do not allow label/comment-triggered dispatches to grant themselves new roles or secrets.
23
+ - Do not let a tool or skill imply secret access through prompt text; every dependency must be declared and admitted.
24
+ - Do not allow untrusted/forked refs to inherit trusted runner or agent ServiceAccounts.
25
+ ## Native identity model
26
+
27
+ | Actor | Kubernetes identity | Krate management surface | Notes |
28
+ | --- | --- | --- | --- |
29
+ | Human user | Kubernetes user from OIDC/delegated identity, plus groups | `User`, `Team`, `IdentityMapping`, `RepositoryPermission`, native `RoleBinding` projection | UI actions must be authorized by API/server checks, not local role flags. |
30
+ | Team/group | Kubernetes group | `Team`, `RepositoryPermission`, `AgentRoleBinding` | Team membership changes must refresh repository and agent permissions. |
31
+ | Agent stack | ServiceAccount selected by `AgentStack.spec.runtimeIdentity` | `AgentServiceAccount`, `AgentRoleBinding`, `AgentSecretGrant`, `AgentConfigGrant` | Stack readiness depends on the selected ServiceAccount having all required permissions. |
32
+ | Dispatch attempt | Projected ServiceAccount token for the attempt | `AgentDispatchAttempt.status.runtimeIdentity` | Attempt identity is immutable once launched. |
33
+ | Runner pool | ServiceAccount used by runner pods | `RunnerPool.spec.serviceAccountRef`, `AgentRunnerIdentityBinding` | Runner identity controls pod creation, logs, caches, and workspace access. |
34
+ | Tool/MCP server/skill | Secret/config requirements attached to the capability | `AgentToolSecretRequirement`, `AgentSkillSecretRequirement`, `AgentMcpServer.spec.secretRefs` | Requirements are validated against grants before dispatch. |
35
+
36
+ ## Resources to add
37
+
38
+ ### `AgentServiceAccount`
39
+
40
+ Declarative wrapper for a Kubernetes `ServiceAccount` used by an agent stack or runner pool.
41
+
42
+ Important fields:
43
+
44
+ - `spec.namespace`;
45
+ - `spec.serviceAccountName`;
46
+ - `spec.owner`: agent-stack, runner-pool, repository, organization;
47
+ - `spec.allowedRepositories`;
48
+ - `spec.allowedRunnerPools`;
49
+ - `spec.tokenAudience`;
50
+ - `spec.tokenExpirationSeconds`;
51
+ - `spec.imagePullSecretRefs`;
52
+ - `spec.automountServiceAccountToken`: should default to false except where projected tokens are required;
53
+ - `status.syncedServiceAccount`;
54
+ - `status.conditions`: `ServiceAccountSynced`, `TokenProjectionAllowed`, `ImagePullSecretsReady`, `Ready`.
55
+
56
+ ### `AgentRoleBinding`
57
+
58
+ Krate-managed projection to Kubernetes `Role`, `ClusterRole`, `RoleBinding`, and `ClusterRoleBinding` resources.
59
+
60
+ Important fields:
61
+
62
+ - `spec.subject`: user, group, team, agent-stack, runner-pool, service-account;
63
+ - `spec.scope`: namespace, repository, organization, cluster;
64
+ - `spec.roleRef`: native Kubernetes Role/ClusterRole or Krate role template;
65
+ - `spec.resourceRules`: optional generated rules for Krate resources;
66
+ - `spec.nativeRoleBindingName`;
67
+ - `spec.escalationPolicy`: deny, require-admin-approval, allow-if-owner;
68
+ - `status.syncedRoleRefs`;
69
+ - `status.conditions`: `RoleResolved`, `SubjectsResolved`, `NativeBindingSynced`, `EscalationAdmitted`, `Ready`.
70
+
71
+ ### `AgentSecretGrant`
72
+
73
+ Declarative permission for an actor to consume a Kubernetes `Secret` for a specific purpose.
74
+
75
+ Important fields:
76
+
77
+ - `spec.subject`: agent-stack, service-account, runner-pool, user, team;
78
+ - `spec.secretRef`: namespace/name and optional keys;
79
+ - `spec.purpose`: model-provider-token, git-credential, mcp-server, tool, skill, webhook-signing, image-pull, cache, deployment;
80
+ - `spec.allowedRepositories`;
81
+ - `spec.allowedRefs`;
82
+ - `spec.allowedTriggerSources`;
83
+ - `spec.mountPolicy`: env, file, projected-volume, never-mount-pass-by-reference;
84
+ - `spec.requiredApproval`: never, on-untrusted-ref, always;
85
+ - `spec.rotationPolicy`;
86
+ - `status.conditions`: `SecretExists`, `KeysExist`, `SubjectAuthorized`, `PolicyAdmitted`, `Ready`.
87
+
88
+ ### `AgentConfigGrant`
89
+
90
+ Declarative permission for an actor to consume a Kubernetes `ConfigMap` or typed non-secret config.
91
+
92
+ Important fields:
93
+
94
+ - `spec.subject`;
95
+ - `spec.configMapRef`: namespace/name and optional keys;
96
+ - `spec.purpose`: tool-config, skill-config, mcp-config, runner-config, prompt-template, repository-policy;
97
+ - `spec.allowedRepositories`;
98
+ - `spec.mountPolicy`: env, file, projected-volume, api-read;
99
+ - `status.conditions`: `ConfigMapExists`, `KeysExist`, `SubjectAuthorized`, `PolicyAdmitted`, `Ready`.
100
+
101
+ ### `AgentCapabilityRequirement`
102
+
103
+ Normalized requirement record created from tools, MCP servers, skills, subagents, and model providers. This can be an aggregated resource or a computed projection.
104
+
105
+ Important fields:
106
+
107
+ - `spec.ownerRef`: `AgentToolProfile`, `AgentMcpServer`, `AgentSkill`, `AgentSubagent`, or `AgentStack`;
108
+ - `spec.requiredSecretRefs`;
109
+ - `spec.requiredConfigRefs`;
110
+ - `spec.requiredRoles`;
111
+ - `spec.requiredServiceAccountCapabilities`;
112
+ - `status.missingGrants`;
113
+ - `status.invalidGrants`;
114
+ - `status.conditions`: `RequirementsDiscovered`, `GrantsResolved`, `Ready`.
115
+
116
+ ## Role templates
117
+
118
+ Krate should ship role templates that compile into native Kubernetes roles. Users may still bind pre-existing native Roles/ClusterRoles, but templates make safe paths obvious.
119
+
120
+ | Template | Intended subject | Native capabilities | Guardrails |
121
+ | --- | --- | --- | --- |
122
+ | `krate-agent-readonly` | agent stack, subagent | get/list/watch repository, issue, PR, pipeline, job, context bundle metadata | no Secret read, no write-back, no pod exec. |
123
+ | `krate-agent-repository-repair` | trusted repair agent | read repo graph, create dispatch artifacts, patch allowed PR/issue records | branch push and PR comments still require write-back approval. |
124
+ | `krate-agent-ci-diagnoser` | CI diagnosis agent | read pipeline/job/log/artifact projections | no repository mutation and no privileged secrets. |
125
+ | `krate-agent-workspace-manager` | workspace controller/agent | create/link/archive/recover agent workspaces | cannot access unrelated namespaces or runner pools. |
126
+ | `krate-runner-untrusted` | untrusted runner pool | create own pods/jobs, stream own logs, read no Secrets | forced for forks and untrusted refs. |
127
+ | `krate-runner-trusted` | trusted runner pool | create own pods/jobs, mount admitted Secrets/ConfigMaps | only trusted refs and approved task kinds. |
128
+ | `krate-secret-grant-admin` | platform admin | create/update `AgentSecretGrant` and `AgentConfigGrant` resources | native RBAC must also allow binding or reading target metadata. |
129
+ | `krate-agent-approver` | maintainer/team | approve selected `AgentApproval` classes | cannot approve grants that would escalate beyond their own bind permissions. |
130
+
131
+ Role templates should include generated YAML preview and native object names before apply. Binding a template must call a server-side permission review equivalent to Kubernetes `SelfSubjectAccessReview` plus bind/escalate checks.
132
+
133
+ ## Grant resolution algorithm
134
+
135
+ For every stack save, trigger dry-run, and dispatch creation, Krate should run the same deterministic resolver:
136
+
137
+ 1. Expand the selected `AgentStack` into model provider, base adapter, tool profile, MCP servers, skills, subagents, context labels, workspace policy, runner pool, and write-back policy.
138
+ 2. Collect `AgentCapabilityRequirement` records from each expanded capability.
139
+ 3. Resolve the runtime `AgentServiceAccount` and runner `ServiceAccount`.
140
+ 4. Resolve native Kubernetes RBAC for required API verbs/resources using subject access reviews or equivalent server-side checks.
141
+ 5. Resolve `AgentSecretGrant` records by exact subject first, then stack, tool/skill/MCP owner, team/group, and repository policy, without allowing broader grants to override explicit denies.
142
+ 6. Resolve `AgentConfigGrant` records using the same precedence as Secret grants.
143
+ 7. Apply source constraints: repository, ref, pull request trust tier, actor, trigger source, workflow/job, and task kind.
144
+ 8. Produce a normalized decision with `allowed`, `requiresApproval`, `denied`, `missingGrant`, `staleGrant`, and `driftedNativeObject` entries.
145
+ 9. Snapshot the decision into `AgentDispatchAttempt.status.permissionSnapshot` before launch.
146
+
147
+ Resolution precedence:
148
+
149
+ 1. explicit deny policy;
150
+ 2. missing/deleted native object;
151
+ 3. subject-specific grant;
152
+ 4. stack-specific grant;
153
+ 5. capability-specific grant for tool, skill, MCP, or model provider;
154
+ 6. repository/team grant;
155
+ 7. organization default grant;
156
+ 8. no grant.
157
+
158
+ ## Admission decision matrix
159
+
160
+ | Scenario | Save stack | Dry-run trigger | Create dispatch | Launch attempt |
161
+ | --- | --- | --- | --- | --- |
162
+ | Missing runtime ServiceAccount | block | show blocked | block | block |
163
+ | Missing runner ServiceAccount | warn if external gateway, otherwise block | show blocked | block unless external gateway | block |
164
+ | Tool requires Secret with no grant | block by default | show missing grant | block | block |
165
+ | Skill requires ConfigMap with no grant | block by default | show missing grant | block | block |
166
+ | Grant exists but Secret key is missing | block | show missing key | block | block |
167
+ | Grant exists but ref is untrusted | allow only if grant explicitly allows untrusted source | show policy decision | approval or block | enforce decision |
168
+ | Native RoleBinding drifted | warn or block based on role criticality | show drift | block for required roles | block |
169
+ | Approval required for secret use | save allowed with warning | show approval requirement | create run waiting for approval | wait until approved |
170
+ | Secret rotation happened after context snapshot | save allowed | show changed metadata | require fresh permission snapshot on retry | use current admitted version only |
171
+
172
+ ## Permission review API
173
+
174
+ The UI needs a fast, explainable server-side review endpoint. Proposed action:
175
+
176
+ `POST /api/agents/permissions/review`
177
+
178
+ Request fields:
179
+
180
+ - `repository`;
181
+ - `ref`;
182
+ - `actor`;
183
+ - `agentStack`;
184
+ - `triggerSource`;
185
+ - `taskKind`;
186
+ - `runnerPool`;
187
+ - optional `toolRefs`, `skillRefs`, `mcpServerRefs`, `contextLabelRefs`.
188
+
189
+ Response fields:
190
+
191
+ - `decision`: allowed, denied, requires-approval;
192
+ - `runtimeIdentity` and `runnerIdentity`;
193
+ - `requiredRoles` with native review result;
194
+ - `requiredSecrets` with grant and metadata status only;
195
+ - `requiredConfigs` with grant and key status;
196
+ - `missingGrants` with suggested safe grants;
197
+ - `approvalRequirements`;
198
+ - `yamlPreview` for resources the current user may create;
199
+ - `reasons` sorted by blocking severity.
200
+ ## Controller responsibilities
201
+
202
+ ### Identity/RBAC sync controller
203
+
204
+ - Watches `User`, `Team`, `RepositoryPermission`, `AgentServiceAccount`, `AgentRoleBinding`, and native Kubernetes RBAC objects.
205
+ - Creates or updates native `ServiceAccount`, `Role`, `ClusterRole`, `RoleBinding`, and `ClusterRoleBinding` resources when Krate owns them.
206
+ - Imports externally managed native RBAC into read-only projections when Krate does not own them.
207
+ - Prevents privilege escalation by checking whether the actor applying an `AgentRoleBinding` can bind the requested role.
208
+ - Emits clear conditions for missing subjects, forbidden roles, escalation attempts, and drift from native RBAC.
209
+
210
+ ### Secret/config access controller
211
+
212
+ - Watches `Secret`, `ConfigMap`, `AgentSecretGrant`, `AgentConfigGrant`, `AgentToolProfile`, `AgentMcpServer`, `AgentSkill`, `AgentStack`, and `AgentDispatchRun`.
213
+ - Validates that every requested secret/config key exists and is allowed for the subject, repository, ref, trigger source, and trust tier.
214
+ - Produces stack/rule/run warnings when a tool, MCP server, model provider, or skill requires a secret/config that the selected agent ServiceAccount cannot access.
215
+ - Never exposes secret values to the UI; only names, keys, purposes, status, age, rotation metadata, and access graph edges.
216
+ - Supports config injection through ConfigMaps and secret injection through projected volumes/env only after admission.
217
+
218
+ ### Stack readiness integration
219
+
220
+ The `AgentStack` controller must combine capability validation with native permission validation:
221
+
222
+ 1. Discover tool/MCP/skill/model/subagent requirements.
223
+ 2. Resolve selected runtime ServiceAccount and runner ServiceAccount.
224
+ 3. Check native Kubernetes RBAC for each required API verb/resource.
225
+ 4. Check `AgentSecretGrant` and `AgentConfigGrant` for each required Secret/ConfigMap key.
226
+ 5. Set `AgentStack.status.conditions` with actionable reasons such as `MissingSecretGrant`, `MissingConfigGrant`, `ServiceAccountCannotUseRunner`, `RoleBindingDrifted`, or `SecretKeyMissing`.
227
+ 6. Block dispatch or require approval according to policy.
228
+
229
+ ### Reconciliation ownership and drift
230
+
231
+ Krate must distinguish native objects it owns from native objects it only observes:
232
+
233
+ - Owned objects carry Krate labels/owner references and are reconciled back to desired state.
234
+ - Imported objects appear in the UI as external and read-only unless the user claims ownership.
235
+ - Drift in owned objects sets `NativeBindingDrifted`, `ServiceAccountDrifted`, or `GrantTargetDrifted` conditions.
236
+ - Drift should not silently repair privilege escalation; dangerous drift blocks dispatch and requires a human/admin decision.
237
+ - Deleting a Krate grant should remove only Krate-owned native bindings/mount wiring, never arbitrary external RBAC objects.
238
+
239
+ ### Secret and ConfigMap lifecycle
240
+
241
+ - Secret value entry is write-only; after save, the UI can show key names, metadata, hash/version, age, and rotation state only.
242
+ - ConfigMap values may be shown only when native RBAC allows `get` and Krate marks the key non-sensitive.
243
+ - Secret/ConfigMap deletion or key removal must show affected stacks, tools, skills, MCP servers, trigger rules, runner pools, and active dispatches.
244
+ - Rotation should create a new metadata version and mark active dispatches as using an older snapshot without revealing the old value.
245
+ - A retry/resume after rotation must rerun permission review and produce a fresh permission snapshot.
246
+ ## UI management requirements
247
+
248
+ ### Global pages
249
+
250
+ - `/agents/identities`: agent ServiceAccounts, runner ServiceAccounts, users, teams, groups, and native RBAC projection.
251
+ - `/agents/secrets`: Secret/ConfigMap inventory filtered by what the current user can see, with grants and consumers.
252
+ - `/agents/permissions`: role templates, native RoleBindings, ClusterRoleBindings, grant graph, drift, and escalation warnings.
253
+
254
+ ### Repository settings
255
+
256
+ `/orgs/[org]/repositories/[repo]/settings/agents` should include:
257
+
258
+ - allowed agent stacks and runtime ServiceAccounts;
259
+ - allowed runner pools and runner ServiceAccounts;
260
+ - secret grants by stack/tool/skill/MCP server;
261
+ - config grants by stack/tool/skill/MCP server;
262
+ - role bindings for users, teams, agents, and runners;
263
+ - dry-run permission check for a selected stack + trigger + ref;
264
+ - generated YAML preview for native ServiceAccount/RBAC/SecretGrant/ConfigGrant changes.
265
+
266
+ ### Stack builder
267
+
268
+ The stack builder should show a permission matrix:
269
+
270
+ | Capability | Requires | Current grant | UI state |
271
+ | --- | --- | --- | --- |
272
+ | model provider | Secret key | `AgentSecretGrant` | ready/missing/forbidden |
273
+ | MCP server | Secret + ConfigMap + network policy | grant + RBAC | ready/missing/drifted |
274
+ | shell tool | Role + runner trust | `AgentRoleBinding` | allowed/needs approval/denied |
275
+ | skill | Secret + ConfigMap + required tools | grants + tool profile | ready/missing dependency |
276
+ | subagent | ServiceAccount + tool subset | stack permission | ready/incompatible |
277
+
278
+ If a tool or skill references a secret without an admitted grant, the UI must show a blocking warning before save and before dispatch: `This stack enables <tool/skill> but <serviceAccount> cannot access Secret <namespace>/<name>:<key>. Add a grant, choose another ServiceAccount, or remove the capability.`
279
+
280
+ ### Permission management user flows
281
+
282
+ #### Grant a Secret to a tool
283
+
284
+ 1. User opens `/agents/secrets` or the stack builder warning.
285
+ 2. UI shows the tool, stack, selected ServiceAccount, missing Secret key, repository/ref scope, and why it is required.
286
+ 3. User selects an existing Secret/key or creates a write-only Secret key if RBAC permits it.
287
+ 4. UI previews `AgentSecretGrant`, affected stacks/rules, and native permission review result.
288
+ 5. Saving creates the grant and immediately recomputes stack readiness.
289
+
290
+ #### Grant a ConfigMap to a skill
291
+
292
+ 1. User opens the skill dependency panel.
293
+ 2. UI shows required ConfigMap keys and whether values are visible, write-only, or metadata-only.
294
+ 3. User grants selected keys for selected repositories/task kinds.
295
+ 4. UI previews `AgentConfigGrant` and the mount/injection mode.
296
+ 5. Stack readiness moves from blocked to ready only after the grant and native RBAC pass.
297
+
298
+ #### Bind an agent stack to a ServiceAccount
299
+
300
+ 1. User selects or creates an `AgentServiceAccount` from the stack builder.
301
+ 2. UI shows runner pools that may use it, native RBAC templates, Secret/ConfigMap grants, and trust-tier restrictions.
302
+ 3. UI previews `ServiceAccount`, `RoleBinding`, and grant changes.
303
+ 4. Server checks bind/escalate permission before applying.
304
+ 5. Existing active runs keep their original ServiceAccount snapshot; new attempts use the new identity.
305
+
306
+ #### Explain a denied dispatch
307
+
308
+ Denied dispatch views should show:
309
+
310
+ - source actor and Kubernetes identity;
311
+ - selected agent stack and ServiceAccounts;
312
+ - missing or denied native role checks;
313
+ - missing Secret/ConfigMap grants by capability owner;
314
+ - trust-tier reason such as fork/untrusted ref;
315
+ - suggested fix with least-privilege grant YAML;
316
+ - whether a human approval can unblock it or whether policy hard-blocks it.
317
+
318
+ ### UI information architecture
319
+
320
+ - Stack builder: capability requirements, ServiceAccount picker, readiness, and missing grants.
321
+ - Tool profile page: required Secret/ConfigMap inputs and consuming stacks.
322
+ - Skill page: required tools, Secrets, ConfigMaps, and compatible ServiceAccounts.
323
+ - MCP page: server health, secret refs, config refs, and allowed stacks.
324
+ - Runner pool page: runner ServiceAccount, trust tier, allowed stacks, Secret/ConfigMap policy.
325
+ - Secret detail page: metadata, key names, grants, consumers, rotation state, active dispatch snapshots.
326
+ - ConfigMap detail page: keys, sensitivity, grants, consumers, drift, active dispatch snapshots.
327
+ - Permission page: role templates, native RBAC graph, ownership, drift, escalation checks.
328
+ ## Secret and ConfigMap UX rules
329
+
330
+ - The UI must never render secret values.
331
+ - Users can create/update Secret metadata and key names only if native RBAC permits the operation; value entry should use write-only forms.
332
+ - ConfigMaps can show values only when RBAC permits `get` on the ConfigMap and Krate policy marks the key non-sensitive.
333
+ - Every grant must show consumers: stacks, tools, skills, MCP servers, trigger rules, runner pools, and recent dispatches.
334
+ - Every Secret/ConfigMap must show reverse dependencies and breakage warnings before deletion or key removal.
335
+ - Rotation state should show last updated time, affected stacks, pending restarts, and dispatches still using old snapshots.
336
+
337
+ ## Audit model
338
+
339
+ Every permission-sensitive operation must emit an audit event with enough context to reconstruct the decision without exposing secret values.
340
+
341
+ | Event | Required fields |
342
+ | --- | --- |
343
+ | `AgentServiceAccountCreated` | actor, namespace, ServiceAccount, owner, allowed repositories, runner pools. |
344
+ | `AgentRoleBindingApplied` | actor, subject, roleRef, scope, native binding, escalation review result. |
345
+ | `AgentSecretGrantApplied` | actor, subject, Secret namespace/name, key names, purpose, repository/ref scope, approval policy. |
346
+ | `AgentConfigGrantApplied` | actor, subject, ConfigMap namespace/name, key names, purpose, repository scope. |
347
+ | `AgentPermissionReviewDenied` | actor, stack, source, missing roles/grants, trust tier, hard-block reason. |
348
+ | `AgentDispatchPermissionSnapshotCreated` | dispatch run, attempt, ServiceAccounts, grant names, metadata versions, decision digest. |
349
+ | `AgentSecretRotated` | Secret metadata, key names, affected stacks/rules/runs, old/new metadata version only. |
350
+ | `NativeRbacDriftDetected` | owned object, desired hash, observed hash, severity, dispatch impact. |
351
+
352
+ Audit records should link to source repository, trigger, dispatch run, stack generation, capability requirement generation, and approving user where applicable.
353
+
354
+ ## Failure modes
355
+
356
+ | Failure | Expected behavior |
357
+ | --- | --- |
358
+ | Kubernetes API cannot perform subject access review | fail closed for dispatch; show review unavailable. |
359
+ | Secret exists but key metadata cannot be listed | fail closed unless an admin configured metadata-blind grants for that namespace. |
360
+ | ConfigMap value is sensitive by policy | show key metadata only; do not render values. |
361
+ | RoleBinding apply succeeds but later drifts | mark dependent stacks not ready and block new attempts requiring that role. |
362
+ | Secret deleted while dispatch is running | running attempt continues only if already mounted; retries require fresh review. |
363
+ | Agent Mux launch rejects secret/config reference | mark attempt failed with adapter rejection and keep Krate permission snapshot. |
364
+ | User loses permission while editing grant form | server rejects save and UI refreshes permission review. |
365
+ ## Dispatch-time enforcement
366
+
367
+ At dispatch creation:
368
+
369
+ 1. Snapshot the selected stack, runtime ServiceAccount, runner ServiceAccount, tool/MCP/skill/subagent requirements, SecretGrants, ConfigGrants, RoleBindings, and ConfigMaps/Secret metadata.
370
+ 2. Refuse untrusted/forked refs from receiving privileged secrets unless policy explicitly allows a safe read-only grant.
371
+ 3. Create `AgentApproval` when policy allows a secret/config/tool but requires human approval for this source.
372
+ 4. Launch Agent Mux with only admitted secret/config references, never with the full cluster credential set.
373
+ 5. Record the exact secret/config names and key hashes in the audit snapshot, not secret values.
374
+
375
+ ## Acceptance criteria
376
+
377
+ - A repository admin can create an agent ServiceAccount and bind it to an agent stack from the UI.
378
+ - A platform admin can create runner ServiceAccounts and bind them to runner pools.
379
+ - A user can grant a specific stack/tool/skill/MCP server access to a specific Secret key or ConfigMap key without writing YAML by hand.
380
+ - The stack builder warns when a capability requires a Secret/ConfigMap/Role that the selected ServiceAccount lacks.
381
+ - Dispatch creation fails closed when required permissions, SecretGrants, ConfigGrants, or native RBAC are missing.
382
+ - Native Kubernetes RBAC remains the enforcement point; Krate resources are declarative management and UI projection, not a parallel authorization backend.
383
+
384
+ ## Memory repository permissions
385
+
386
+ Company brain memory requires explicit permissions separate from repository code permissions.
387
+
388
+ | Permission | Grants |
389
+ | --- | --- |
390
+ | `memory.repositories.read` | view memory repository metadata and health. |
391
+ | `memory.graph.query` | query graph records for allowed kinds and paths. |
392
+ | `memory.docs.grep` | grep free-form Markdown in allowed paths. |
393
+ | `memory.records.read` | read full memory records or documents. |
394
+ | `memory.snapshots.diff` | diff memory refs and historical snapshots. |
395
+ | `memory.updates.propose` | create memory update artifacts or PR branches. |
396
+ | `memory.updates.approve` | approve proposed memory updates. |
397
+ | `memory.updates.merge` | merge approved memory updates. |
398
+ | `memory.ontology.manage` | change ontology node kinds, edge kinds, vocabularies, and validators. |
399
+
400
+ `AgentMemorySource` acts like a read grant for memory paths and graph kinds. `AgentMemoryUpdate` admission checks write permissions, ontology validity, secret scan, target branch policy, and reviewer requirements before opening or merging a PR. Tools and skills that require memory secrets or restricted memory paths must surface missing grants in `AgentCapabilityRequirement` so the UI can explain why a stack is blocked.
401
+
402
+ ## Org-scoped memory and run imports
403
+
404
+ Memory and Babysitter run imports are namespace-scoped to an organization. The importing controller uses an org ServiceAccount and can read only admitted `.a5c` paths, session summaries, and artifacts for repositories in that org. `MEMORY.md` updates, journal imports, and retrospective promotion require memory update permissions and cannot cross namespace boundaries.
405
+
406
+ Secret grants remain separate: importing a run journal does not imply permission to expose secrets that appeared in logs or artifacts. Secret scans and redaction happen before content enters the company brain.