Skip to content

feat(operator): add SPIFFE authentication bootstrap for operator client registration - #2141

Merged
Alan-Cha merged 10 commits into
mainfrom
feat/operator-spiffe-auth-v2
Jul 7, 2026
Merged

Alan-Cha merged 10 commits into
mainfrom
feat/operator-spiffe-auth-v2

Conversation

@Alan-Cha

@Alan-Cha Alan-Cha commented Jul 2, 2026

Copy link
Copy Markdown
Member

Summary

Enables the Kagenti operator to register itself as a Keycloak client using its
SPIFFE identity (JWT-SVID) instead of static admin credentials, eliminating
long-lived credentials from the operator's namespace.

What's Changed

Core feature

  • Python bootstrap script (kagenti/auth/operator-spiffe-bootstrap/) that configures:
    • SPIFFE Identity Provider in Keycloak
    • Operator client with clientAuthenticatorType: federated-jwt
    • manage-clients role (scoped, not full admin)
  • Helm post-install/upgrade Job (operator-client-bootstrap-job.yaml)
  • Docker image for the bootstrap job
  • Feature gated behind kagenti-operator-chart.spiffe.operatorAuth.enabled (default: false)

Chart fixes

  • Duplicate resources → STATUS: failed: agent-namespaces.yaml and
    agent-namespace-resources.yaml both rendered the same 12 resources per agent
    namespace, causing 10 "already exists" errors on every install. Stripped
    agent-namespaces.yaml to Namespace objects only.
  • authbridge-config missing in kagenti-system: The operator's client
    registration controller reads Keycloak config from this ConfigMap in its own
    namespace, but it was only created in agent namespaces. Added conditional creation
    in kagenti-system when components.agentOperator.enabled: true.

Script updates

  • scripts/kind/setup-kagenti.sh: adds --enable-operator-spiffe-auth flag;
    corrects helm key from removed kagentiOperator.spiffeAuth.enabled to
    kagenti-operator-chart.spiffe.operatorAuth.enabled

E2E test results

Validated across multiple fresh-cluster runs:

  • ✅ Operator pod: 2/2 containers (manager + spiffe-helper)
  • ✅ Helm release: STATUS: deployed
  • ✅ Test agent registered with SPIFFE ID spiffe://localtest.me/ns/team1/sa/test-agent
  • ✅ Keycloak token endpoint: HTTP 200 with access token

Test materials (procedure + setup script):
https://gist.github.com/Alan-Cha/527be60c79b40aedd54fe7be586c3452

The setup script requires a local checkout of kagenti-operator on branch
feat/spiffe-auth (this PR's companion). It packages the operator helm chart
from source at test time — the published OCI chart does not yet include the
spiffe-helper sidecar.

Related

Checklist

  • All commits signed-off (DCO)
  • Feature gated (default: disabled)
  • Backward compatible
  • E2E tested (multiple fresh-cluster runs)

Assisted-By: Claude Code

Alan-Cha added 3 commits July 2, 2026 15:26
…nt registration

Enables the Kagenti operator to register itself as a Keycloak client using
its SPIFFE identity (JWT-SVID) instead of static admin credentials.

Components:
- Python bootstrap script (setup_operator_client.py) that configures:
  - SPIFFE Identity Provider in Keycloak
  - Operator client with clientAuthenticatorType: federated-jwt
  - manage-clients role (scoped, not full admin)
- Helm post-install/upgrade Job (operator-client-bootstrap-job.yaml)
- Docker image for the bootstrap job

Feature gated behind kagenti-operator-chart.spiffe.operatorAuth.enabled
(default: false) for backward compatibility.

Depends on: kagenti-operator#349 (operator Go code + spiffe-helper chart)

Signed-off-by: Alan Cha <[email protected]>
Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Alan Cha <[email protected]>
…config

Three chart bugs found during E2E testing:

1. Duplicate resources caused STATUS: failed
   agent-namespaces.yaml and agent-namespace-resources.yaml both rendered
   the same 12 resources per agent namespace, causing 10 'already exists'
   errors on every helm install. Stripped agent-namespaces.yaml to Namespace
   objects only; all other per-namespace resources live in
   agent-namespace-resources.yaml.

2. authbridge-config missing in kagenti-system
   The operator's clientregistration controller reads Keycloak config from
   authbridge-config in its own namespace (kagenti-system), but the ConfigMap
   was only created in agent namespaces (team1, team2). Added conditional
   creation in kagenti-system when components.agentOperator.enabled=true.

3. Helm template syntax
   Removed extra {{- end }} statements in agent-namespace-resources.yaml.

Signed-off-by: Alan Cha <[email protected]>
Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Alan Cha <[email protected]>
Adds --enable-operator-spiffe-auth flag to setup-kagenti.sh (and
propagates ENABLE_OPERATOR_SPIFFE_AUTH through kind-full-test.sh).

Also corrects the helm --set key from the removed legacy path
kagentiOperator.spiffeAuth.enabled to the current path
kagenti-operator-chart.spiffe.operatorAuth.enabled.

Signed-off-by: Alan Cha <[email protected]>
Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Alan Cha <[email protected]>

# Install dependencies with hash verification
COPY auth/operator-spiffe-bootstrap/requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
Alan-Cha added 2 commits July 2, 2026 15:48
…resources.yaml

authbridge-template-configmaps.yaml already creates authbridge-config in
kagenti-system (Release.Namespace) as part of the operator's template
propagation mechanism. Our addition in agent-namespace-resources.yaml was
redundant and caused 'configmaps authbridge-config already exists' during
helm install.

Signed-off-by: Alan Cha <[email protected]>
Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Alan Cha <[email protected]>

@esnible esnible left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR adds a Keycloak bootstrap Job that lets the operator authenticate via SPIFFE JWT-SVID instead of static admin credentials, correctly gated off by default, and also fixes a real duplicate-resource bug in the agent-namespace templates (verified: agent-namespace-resources.yaml is a faithful, non-lossy split of what was removed from agent-namespaces.yaml). The core logic (RBAC scoping to a single named secret, Helm hook idempotency via before-hook-creation, resource limits, non-root pinned-digest Dockerfile) is solid.

The main issue: the new Job's Role/RoleBinding namespace and its KEYCLOAK_URL env var are hardcoded to keycloak instead of following the same {{ .Values.keycloak.namespace }} template used everywhere else in this file (see inline comments) — this will silently break the feature for any deployment that overrides that value. One documentation inconsistency (README references a Helm value path that doesn't match what's implemented) should also be fixed before merge.

A couple of non-blocking notes not tied to a specific line:

  • setup_operator_client.py imports Dict/Any from typing but never uses them (nit).
  • No unit tests for setup_operator_client.py — given it does multi-step, stateful Keycloak API orchestration with idempotency checks, mocked-requests tests for the exists-vs-create branches would be valuable follow-up coverage (suggestion).
  • The vendored kagenti-operator-chart-0.3.0-alpha.6.tgz subchart doesn't yet define the spiffe.operatorAuth.enabled key this PR gates on — harmless today (absent key = falsy = feature stays off), but the feature can't actually be exercised until the companion kagenti-operator chart bump lands, consistent with the PR description's note about the companion PR.

Author: Alan-Cha (MEMBER — maintainer)
Areas reviewed: Python, Helm/K8s, Dockerfile, Shell, Docs
Agent/IDE config (.claude/.vscode): none
Commits: 6 commits, all signed-off: yes
CI status: all required checks passing; E2E HyperShift pending manual /run-e2e trigger (not blocking)

self.token: Optional[str] = None
self.session = requests.Session()
# Disable SSL verification for in-cluster communication
self.session.verify = False

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: self.session.verify = False disables TLS verification for the whole session with no urllib3.disable_warnings() or comment justifying it. Currently inert since KEYCLOAK_URL defaults to http://, but it's a latent footgun if the URL is ever switched to https:// — it would silently skip cert validation. Consider removing or gating behind an explicit, loudly-logged opt-in.

…nd env

Three hardcoded 'keycloak' namespace references in operator-client-bootstrap-job.yaml
were not following .Values.keycloak.namespace like the ServiceAccount/Job do.
If keycloak.namespace is overridden, the Role/RoleBinding landed in the wrong
namespace and the Job couldn't read the admin secret.

Fixed:
- Role metadata.namespace: keycloak → {{ .Values.keycloak.namespace | default "keycloak" }}
- RoleBinding metadata.namespace: same
- KEYCLOAK_URL env var: hardcoded keycloak → templated namespace
- KEYCLOAK_ADMIN_SECRET_NAMESPACE env var: same

Also fix README to use correct helm value path
(kagenti-operator-chart.spiffe.operatorAuth.enabled, not the removed
kagentiOperator.spiffeAuth.enabled), and remove unused Dict/Any imports
from setup_operator_client.py.

Signed-off-by: Alan Cha <[email protected]>
Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Alan Cha <[email protected]>
@Alan-Cha

Alan-Cha commented Jul 7, 2026

Copy link
Copy Markdown
Member Author

Thanks for the thorough review @esnible!

Addressed in commit 3016ff46:

  • ✅ must-fix — Role/RoleBinding namespace: now uses {{ .Values.keycloak.namespace | default "keycloak" }}
  • ✅ must-fix — KEYCLOAK_URL and KEYCLOAK_ADMIN_SECRET_NAMESPACE: same templated value
  • ✅ suggestion — README: corrected all references from kagentiOperator.spiffeAuth.enabled to kagenti-operator-chart.spiffe.operatorAuth.enabled
  • ✅ nit — Removed unused Dict/Any imports from setup_operator_client.py

Remaining open:

  • self.session.verify = False — acknowledged, currently inert since the URL defaults to http://. Will address in a follow-up once HTTPS for in-cluster Keycloak is added.
  • :latest bootstrap image default — noted; the canonical tagged version should be pinned here, will address.
  • Dockerfile.local — absent from this branch (was excluded during the clean-branch squash merge).
  • Unit tests for setup_operator_client.py — tracked as follow-up work.

@esnible esnible left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review — verifying the fixes to my prior CHANGES_REQUESTED against branch feat/operator-spiffe-auth-v2. Both must-fix items are resolved (commit 3016ff46) and confirmed:

  • Role/RoleBinding namespace — now {{ .Values.keycloak.namespace | default "keycloak" }}, matching the ServiceAccount/Job (job template lines 22, 38). ✅
  • KEYCLOAK_URL + admin-secret namespace — now templated off keycloak.namespace instead of the hardcoded literal (lines 82, 88). ✅

Prior suggestions also addressed: README now references the actual kagenti-operator-chart.spiffe.operatorAuth.enabled path; unused Dict/Any imports removed; Dockerfile.local (the file the security bot flagged) removed; session.verify = False now carries an explanatory comment and is inert for the in-cluster http:// endpoint.

CI note: the failing "Deploy & Test" check is an unrelated infrastructure flake, not a defect in this PR — the weather-tool Shipwright BuildRun failed pulling quay.io/containers/buildah:v1.37.5 with a truncated download (short read: expected 60771241 bytes but got 35651584: unexpected EOF). This PR touches none of weather-tool, Shipwright, or buildah; a re-run should clear it. All required lint/security/chart/backend checks pass; E2E HyperShift is pending a manual /run-e2e trigger.

One carried-over non-blocking suggestion inline (:latest bootstrap image fallback), and one follow-up: unit tests for setup_operator_client.py remain absent — worthwhile given the stateful Keycloak orchestration, but not a merge blocker.

This APPROVE supersedes my prior CHANGES_REQUESTED.

Assisted-By: Claude Code

Alan-Cha added 3 commits July 7, 2026 10:34
Default bootstrap image now uses .Chart.AppVersion (currently v0.7.0-alpha.3)
matching the convention for all other kagenti platform images (backend,
ui-v2, oauth-secret jobs, etc.). The :latest tag is non-reproducible and
a supply-chain risk.

Signed-off-by: Alan Cha <[email protected]>
Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Alan Cha <[email protected]>
…efaulting

The operator-spiffe-bootstrap image has not been published to ghcr.io yet
(this PR introduces it). Defaulting to .Chart.AppVersion would produce a
tag that doesn't exist in the registry, causing ImagePullBackOff whenever
the feature is enabled.

Using required instead: since spiffe.operatorAuth.enabled defaults to false,
no existing deployment is affected. Anyone enabling the feature will get a
clear helm install error with the expected image path rather than a silent
pod failure.

Signed-off-by: Alan Cha <[email protected]>
Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Alan Cha <[email protected]>
…omment

The operator-spiffe-bootstrap image has not been published yet; :latest is
a placeholder until it is built and pushed as part of the release pipeline.
Override via kagenti-operator-chart.spiffe.operatorAuth.bootstrapImage.

Signed-off-by: Alan Cha <[email protected]>
Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Alan Cha <[email protected]>
@Alan-Cha
Alan-Cha merged commit 9885b69 into main Jul 7, 2026
26 checks passed
@github-project-automation github-project-automation Bot moved this from New/ToDo to Done in Rossoctl Issue Prioritization Jul 7, 2026
@pdettori
pdettori deleted the feat/operator-spiffe-auth-v2 branch July 15, 2026 22:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants