Repository navigation
feat: auto-create ServiceAccount for SPIRE-enabled workloads - #142
Merged
mrsabath merged 4 commits intoFeb 23, 2026
Merged
Conversation
When the AuthBridge webhook injects sidecars with SPIRE enabled, it now creates a dedicated ServiceAccount matching the workload name and sets podSpec.ServiceAccountName. This ensures the SPIFFE ID reflects the workload identity (e.g. spiffe://.../sa/git-issue-agent) instead of the generic spiffe://.../sa/default. The SA is only created when SPIRE is enabled and the pod uses the default ServiceAccount. Existing non-default ServiceAccountNames are respected. The creation is idempotent (no-op if the SA already exists). RBAC is updated in both Kustomize and Helm to grant serviceaccounts get/create permissions. Signed-off-by: Mariusz Sabath <[email protected]> Co-authored-by: Cursor <[email protected]>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds auto-creation of dedicated ServiceAccounts for SPIRE-enabled workloads to ensure SPIFFE IDs reflect workload identity rather than using the generic "default" ServiceAccount. The webhook now creates a ServiceAccount matching the workload name when SPIRE is enabled and the pod uses the default ServiceAccount, setting podSpec.ServiceAccountName accordingly.
Changes:
- Auto-creates ServiceAccounts for SPIRE-enabled workloads to provide unique SPIFFE identities
- Adds RBAC permissions for serviceaccounts get/create operations in both Kustomize and Helm configurations
- Implements idempotent ServiceAccount creation with proper error handling for already-exists scenarios
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| kagenti-webhook/internal/webhook/injector/pod_mutator.go | Adds ensureServiceAccount() method and integrates it into InjectAuthBridge() to create dedicated ServiceAccounts for SPIRE-enabled workloads |
| kagenti-webhook/config/rbac/role.yaml | Grants webhook serviceaccounts get/create permissions for auto-creation functionality |
| charts/kagenti-webhook/templates/clusterrole.yaml | Mirrors RBAC changes in Helm chart for consistency |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: cwiklik <[email protected]> Co-authored-by: Copilot <[email protected]>
Signed-off-by: cwiklik <[email protected]> Co-authored-by: Copilot <[email protected]>
Address Copilot review feedback on PR #142: - ensureServiceAccount now fetches existing SAs on AlreadyExists and logs a warning if the SA is not managed by this webhook - Extract label key/value into constants (managedByLabel/managedByValue) - Add comprehensive unit tests for ensureServiceAccount (creation, idempotency, unmanaged SA warning) and InjectAuthBridge SA logic (SA name assignment, respecting existing non-default SA, no SA creation without SPIRE, overriding "default" SA name) Signed-off-by: Mariusz Sabath <[email protected]> Co-authored-by: Cursor <[email protected]>
This was referenced Feb 24, 2026
anatolykoyfman
added a commit
that referenced
this pull request
Aug 26, 2026
Under the DENY-aware PRB the shared pipeline fixture failed closed: the audit task raised PolicyContradictionError for the github-agent policy, erroring out all 43 test_policy_pipeline.py cases at setup. Root cause was policy.explicit.md granting developer the coarse issues-access (read+write bundle) but only fine issues-read, which the auditor read as a coarse-scope prohibition. Keep the fixture ALLOW-only for now (matching the UC-1 demo.md shape), deferring the ALLOW+DENY path to sibling issue #142: - policy.explicit.md: drop the coarse '## Users -> agent capabilities' block; keep purely-positive fine-grained grants. Inbound mapping (a) is now derived from the fine grants, so no coarse read+write bundle can be partly-prohibited by a read-only intent. - policy.abstract.md: remove prohibition prose (exclusively / do not work in source / no access to source / read-only); rely on deny-by-default for absences. Facts unchanged. - policy-pipeline.md: revert Expected-output + Further-Notes to ALLOW-only (both variants, empty *_deny_scopes), point deny-extraction at #142, and sync the embedded policy.md variants + surrounding prose. scenario.py needs no change: its pair-lists already match the demo facts. Unit keep-green gate stays green (528 passed); the 43 integration cases collect cleanly. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Anatoly Koyfman <[email protected]>
anatolykoyfman
added a commit
that referenced
this pull request
Aug 26, 2026
…t loop
Rewrite the policy-pipeline (5.3) and uc1-onboarding-pipeline (5.4.x)
integration-test specs so they describe the current live enforcement
loop instead of the retired "generate Rego, then `opa eval` offline"
model. The live drivers were already migrated (handoff 08); the specs
were the only artifacts still describing the old architecture.
Both specs now describe: onboard through the in-cluster UC-1 Controller
(POST /apply/service/{id}, upserting the AuthorizationPolicy CR) ->
enable the outbound token-exchange leg -> drive real HTTP through
AuthBridge -> assert the deployed OPA plugin's allow/deny, with
AuthBridge's own parsers (jwt-validation, token-exchange, mcp-parser)
building the input documents. Removed opa eval / standalone opa binary /
$OPA_BIN / .rego dumps / REGO_OUTPUT_DIR / rego_out / kubectl cp of
/rego / probe.rego / probe_uc1.rego / uvicorn subprocesses / the
filesystem-stub writer as the test mechanism. Skip condition is now
"cluster/pipeline not wired or env unset," matching aiac/CLAUDE.md.
policy-pipeline now describes a single live policy.md (cross-variant
equivalence deferred to rung 5.4.4); uc1-onboarding no longer claims
"live enforcement out of scope" / "no A2A message is ever sent."
Scenario facts, truth tables, devops deny-by-default, the ALLOW-only
fixture framing (#142), UC-1 discovery semantics, and
onboarding-order-independence are preserved unchanged. Doc-only; no
code, driver, k8s/ file, or aiac/CLAUDE.md touched.
Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Anatoly Koyfman <[email protected]>
anatolykoyfman
added a commit
that referenced
this pull request
Aug 26, 2026
Add test/integration/test_policy_pipeline_denyworld.py, the ALLOW-default sibling of test_policy_pipeline.py (#151, epic #142). It onboards Policy B (permissive-default prose with prohibitions + exclusive scoping) through the real UC-1 pipeline via the #149 policy-agnostic harness (onboarded_stack(..., policy_md=POLICY_DENYWORLD, default_effect=ALLOW, ready_signals=...)), drives real HTTP through AuthBridge, and asserts the deployed OPA plugin enforces the §6 allow/deny matrix from the #148 oracle. Why default_effect=ALLOW: under deny-by-default an explicit DENY is invisible at the enforced seam (an ungranted pair is already denied), so flipping the default makes each DENY the only thing that can deny a pair — proving DENY enforcement end-to-end through PRB -> PCE -> Rego -> bundle -> OPA. The devops -> issues-* = allow cells are the default-flip tracer (deny under Policy A). - pytestmark = pytest.mark.integration (excluded from the keep-green lane). - Expected verdicts computed from the #148 oracle functions (expected_inbound_denyworld / expected_outbound_denyworld_bare) — no second copy of the matrix; the fixture-independent §6 contract stays in the #148 test_scenario_uc1_denyworld.py unit module. - Policy-B-aware convergence signals (dev-user inbound allow; devops-user issues-read allow tracer; test-user source-read deny). - Negative controls resolved against the ALLOW-mode Rego: an unmatched tool name is in no deny map, so no deny gate fires and it falls through to the permissive default = allow (the mirror of the deny-by-default control). - Teardown (in the harness) resets default_effect to Deny + cleans Keycloak so a subsequent Policy-A run on the shared stack is unaffected. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Anatoly Koyfman <[email protected]>
anatolykoyfman
added a commit
that referenced
this pull request
Aug 26, 2026
Under the DENY-aware PRB the shared pipeline fixture failed closed: the audit task raised PolicyContradictionError for the github-agent policy, erroring out all 43 test_policy_pipeline.py cases at setup. Root cause was policy.explicit.md granting developer the coarse issues-access (read+write bundle) but only fine issues-read, which the auditor read as a coarse-scope prohibition. Keep the fixture ALLOW-only for now (matching the UC-1 demo.md shape), deferring the ALLOW+DENY path to sibling issue #142: - policy.explicit.md: drop the coarse '## Users -> agent capabilities' block; keep purely-positive fine-grained grants. Inbound mapping (a) is now derived from the fine grants, so no coarse read+write bundle can be partly-prohibited by a read-only intent. - policy.abstract.md: remove prohibition prose (exclusively / do not work in source / no access to source / read-only); rely on deny-by-default for absences. Facts unchanged. - policy-pipeline.md: revert Expected-output + Further-Notes to ALLOW-only (both variants, empty *_deny_scopes), point deny-extraction at #142, and sync the embedded policy.md variants + surrounding prose. scenario.py needs no change: its pair-lists already match the demo facts. Unit keep-green gate stays green (528 passed); the 43 integration cases collect cleanly. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Anatoly Koyfman <[email protected]>
anatolykoyfman
added a commit
that referenced
this pull request
Aug 26, 2026
…t loop
Rewrite the policy-pipeline (5.3) and uc1-onboarding-pipeline (5.4.x)
integration-test specs so they describe the current live enforcement
loop instead of the retired "generate Rego, then `opa eval` offline"
model. The live drivers were already migrated (handoff 08); the specs
were the only artifacts still describing the old architecture.
Both specs now describe: onboard through the in-cluster UC-1 Controller
(POST /apply/service/{id}, upserting the AuthorizationPolicy CR) ->
enable the outbound token-exchange leg -> drive real HTTP through
AuthBridge -> assert the deployed OPA plugin's allow/deny, with
AuthBridge's own parsers (jwt-validation, token-exchange, mcp-parser)
building the input documents. Removed opa eval / standalone opa binary /
$OPA_BIN / .rego dumps / REGO_OUTPUT_DIR / rego_out / kubectl cp of
/rego / probe.rego / probe_uc1.rego / uvicorn subprocesses / the
filesystem-stub writer as the test mechanism. Skip condition is now
"cluster/pipeline not wired or env unset," matching aiac/CLAUDE.md.
policy-pipeline now describes a single live policy.md (cross-variant
equivalence deferred to rung 5.4.4); uc1-onboarding no longer claims
"live enforcement out of scope" / "no A2A message is ever sent."
Scenario facts, truth tables, devops deny-by-default, the ALLOW-only
fixture framing (#142), UC-1 discovery semantics, and
onboarding-order-independence are preserved unchanged. Doc-only; no
code, driver, k8s/ file, or aiac/CLAUDE.md touched.
Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Anatoly Koyfman <[email protected]>
anatolykoyfman
added a commit
that referenced
this pull request
Aug 26, 2026
Add test/integration/test_policy_pipeline_denyworld.py, the ALLOW-default sibling of test_policy_pipeline.py (#151, epic #142). It onboards Policy B (permissive-default prose with prohibitions + exclusive scoping) through the real UC-1 pipeline via the #149 policy-agnostic harness (onboarded_stack(..., policy_md=POLICY_DENYWORLD, default_effect=ALLOW, ready_signals=...)), drives real HTTP through AuthBridge, and asserts the deployed OPA plugin enforces the §6 allow/deny matrix from the #148 oracle. Why default_effect=ALLOW: under deny-by-default an explicit DENY is invisible at the enforced seam (an ungranted pair is already denied), so flipping the default makes each DENY the only thing that can deny a pair — proving DENY enforcement end-to-end through PRB -> PCE -> Rego -> bundle -> OPA. The devops -> issues-* = allow cells are the default-flip tracer (deny under Policy A). - pytestmark = pytest.mark.integration (excluded from the keep-green lane). - Expected verdicts computed from the #148 oracle functions (expected_inbound_denyworld / expected_outbound_denyworld_bare) — no second copy of the matrix; the fixture-independent §6 contract stays in the #148 test_scenario_uc1_denyworld.py unit module. - Policy-B-aware convergence signals (dev-user inbound allow; devops-user issues-read allow tracer; test-user source-read deny). - Negative controls resolved against the ALLOW-mode Rego: an unmatched tool name is in no deny map, so no deny gate fires and it falls through to the permissive default = allow (the mirror of the deny-by-default control). - Teardown (in the harness) resets default_effect to Deny + cleans Keycloak so a subsequent Policy-A run on the shared stack is unaffected. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Anatoly Koyfman <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
kagenti.io/spire: enabled), it now auto-creates a dedicated ServiceAccount matching the workload name and setspodSpec.ServiceAccountNamespiffe://.../sa/git-issue-agent) instead of the genericspiffe://.../sa/defaultserviceaccountsget/createChanges
kagenti-webhook/internal/webhook/injector/pod_mutator.goensureServiceAccount()method; call it fromInjectAuthBridge()when SPIRE enabled and SA is empty/defaultkagenti-webhook/config/rbac/role.yamlserviceaccountsget/create permissioncharts/kagenti-webhook/templates/clusterrole.yamlTest plan
go build ./...passesSet ServiceAccountName for SPIRE identityspiffe://localtest.me/ns/team1/sa/git-issue-agentServiceAccount already existsMade with Cursor