Repository navigation
feat(operator): add SPIFFE authentication bootstrap for operator client registration - #2141
Conversation
…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 |
…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]>
Signed-off-by: Alan Cha <[email protected]>
Signed-off-by: Alan Cha <[email protected]>
esnible
left a comment
There was a problem hiding this comment.
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.pyimportsDict/Anyfromtypingbut 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-requeststests for the exists-vs-create branches would be valuable follow-up coverage (suggestion). - The vendored
kagenti-operator-chart-0.3.0-alpha.6.tgzsubchart doesn't yet define thespiffe.operatorAuth.enabledkey this PR gates on — harmless today (absent key = falsy = feature stays off), but the feature can't actually be exercised until the companionkagenti-operatorchart 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 |
There was a problem hiding this comment.
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]>
|
Thanks for the thorough review @esnible! Addressed in commit
Remaining open:
|
esnible
left a comment
There was a problem hiding this comment.
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 offkeycloak.namespaceinstead 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
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]>
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
kagenti/auth/operator-spiffe-bootstrap/) that configures:clientAuthenticatorType: federated-jwtmanage-clientsrole (scoped, not full admin)operator-client-bootstrap-job.yaml)kagenti-operator-chart.spiffe.operatorAuth.enabled(default: false)Chart fixes
STATUS: failed:agent-namespaces.yamlandagent-namespace-resources.yamlboth rendered the same 12 resources per agentnamespace, causing 10 "already exists" errors on every install. Stripped
agent-namespaces.yamlto Namespace objects only.authbridge-configmissing inkagenti-system: The operator's clientregistration controller reads Keycloak config from this ConfigMap in its own
namespace, but it was only created in agent namespaces. Added conditional creation
in
kagenti-systemwhencomponents.agentOperator.enabled: true.Script updates
scripts/kind/setup-kagenti.sh: adds--enable-operator-spiffe-authflag;corrects helm key from removed
kagentiOperator.spiffeAuth.enabledtokagenti-operator-chart.spiffe.operatorAuth.enabledE2E test results
Validated across multiple fresh-cluster runs:
STATUS: deployedspiffe://localtest.me/ns/team1/sa/test-agentTest materials (procedure + setup script):
https://gist.github.com/Alan-Cha/527be60c79b40aedd54fe7be586c3452
Related
Checklist
Assisted-By: Claude Code