Skip to content

feat(webhook): operator-managed Keycloak client credentials - #262

Merged
pdettori merged 6 commits into
rossoctl:mainfrom
akram:feature/operator-managed-client-registration
Mar 31, 2026
Merged

pdettori merged 6 commits into
rossoctl:mainfrom
akram:feature/operator-managed-client-registration

Conversation

@akram

@akram akram commented Mar 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Coordinates with kagenti-operator for workloads that opt out of webhook-injected client registration (kagenti.io/client-registration-inject: "false").
requires:

oc patch deployment weather-service  --type merge \
   -p '{"spec": { "template": { "metadata": { "labels": {"kagenti.io/client-registration-inject": "false" }}}}}'

requires: rossoctl/operator#247

Changes

  • Mount Keycloak OAuth2 client id/secret from a namespace Secret named in pod annotation kagenti.io/keycloak-client-credentials-secret-name (volume name matches Secret: kagenti-keycloak-client-credentials-<id>).
  • Replace operator_clientreg with keycloak_client_credentials helpers: ApplyKeycloakClientCredentialsSecretVolumes, NeedsKeycloakClientCredentialsVolumePatch, AnnotationKeycloakClientSecretName.
  • Admission logging for Pod processing and credential delivery path (Keycloak Secret mount vs sidecar vs combined authbridge); logger keycloak-client-registration.
  • Reinvocation path patches missing mounts when annotation appears after first injection.

Related

  • Pair with kagenti-operator PR on the same feature branch (ClientRegistration controller + Secret + annotation).

Testing

  • go test ./internal/webhook/injector/... (unit); deploy webhook + operator together for integration.

fixes rossoctl/rossoctl#397

@cwiklik cwiklik left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Review Summary

Clean webhook-side implementation of the operator-managed Keycloak client credentials contract. The code correctly mounts operator-provisioned Secrets into shared-data containers, handles reinvocation for late annotations, and logs credential delivery paths. The annotation constant matches the operator PR (rossoctl/operator#247) exactly. Idempotency is well-handled throughout.

Must-fix: Made-with: Cursor trailer in 2 of 3 commits — should be Assisted-By: per kagenti conventions. Same issue flagged on the paired operator PR.

Areas reviewed: Go, Tests
Commits: 3 commits, all signed-off: yes
CI status: DCO passing
Cross-repo consistency: Annotation kagenti.io/keycloak-client-credentials-secret-name matches operator PR #247 ✓

akram added 4 commits March 27, 2026 15:50
…gistration

When workloads opt out of webhook-injected client-registration, the
kagenti-operator reconciler registers OAuth clients and annotates the pod
template with the secret name. The mutating webhook now skips injecting
the client-registration container in that case while still injecting
AuthBridge sidecars, and wires the operator-provided secret for mounts.

Signed-off-by: Akram <[email protected]>
- Replace operator_clientreg with keycloak_client_credentials (annotation, volume naming)
- Add keycloak-client-registration logger; align deliveryPaths labels with Keycloak terminology

Assisted-By: Cursor
Signed-off-by: Akram <[email protected]>
Use AnnotationKeycloakClientSecretName, NeedsKeycloakClientCredentialsVolumePatch,
ApplyKeycloakClientCredentialsSecretVolumes, and updated log field names.

Assisted-By: Cursor
Signed-off-by: Akram <[email protected]>
@akram
akram force-pushed the feature/operator-managed-client-registration branch from 019144b to 8a25d04 Compare March 27, 2026 14:51

@Alan-Cha Alan-Cha 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 successfully implements the webhook-side coordination for operator-managed Keycloak client registration. The code quality is excellent: idempotent, well-tested, secure (ReadOnly SubPath mounts), and provides good observability. The prior review issue (Made-with: Cursor → Assisted-By: Cursor) has been fixed ✅.

Remaining issues:

  • All 4 commits and PR title are missing emoji prefixes (Kagenti convention)
  • Final commit message is too generic

Prior review issues:
✅ Assisted-By: Cursor trailer fixed (was Made-with: Cursor)

Areas reviewed: Go, Tests, Security, Cross-repo consistency
Commits: 4 commits, all signed-off ✅, all missing emoji prefixes ❌
CI status: DCO passing ✅
Code quality: Excellent - idempotent, well-tested, secure mounts, good observability

@Alan-Cha

Copy link
Copy Markdown
Member

The PR looks good to me. I will approve for now but I will do some more testing in the mean time

@Alan-Cha

Copy link
Copy Markdown
Member

I asked Claude to help me test a number of scenarios

7 Test Scenarios Executed:

✅ Baseline Webhook Injection - Verified all 4 sidecars injected without opt-out label
✅ Opt-Out Label Behavior - Verified client-registration sidecar correctly omitted
✅ RBAC Fix Validation - Fixed missing permissions, operator reconciled successfully
✅ Operator Secret Creation - Real Keycloak credentials created in Secret
✅ Rolling Update Trigger - Annotation change created new ReplicaSet
✅ Webhook Secret Mounting - Secret mounted at correct paths with subPath
⚠️ Sidecar Image Availability - Images loaded, pods blocked only by missing SPIRE (expected)
Pass Rate: 100% for integration testing (6/6 core scenarios + 1 partial due to infrastructure)

Key Validation Points:

Opt-out label prevents sidecar injection ✅
Operator registers OAuth clients with Keycloak ✅
Operator creates Secrets with real credentials ✅
Webhook reads annotation and mounts Secret ✅
Volume mounts use correct subPath for individual files ✅
Both PRs work together seamlessly ✅

…idecar opt-in

- Inject kagenti-client-registration only when kagenti.io/client-registration-inject=true
- Update precedence tests and test-precedence.sh; refresh README/CLAUDE docs

Signed-off-by: Akram <[email protected]>
@akram

akram commented Mar 30, 2026

Copy link
Copy Markdown
Contributor Author

Hi @Alan-Cha , thank you for the review.
This morning I was doing extensive tests and added a commit that changes the opt-in / opt-out logic, so the sidecar injection becomes the NON-default because I was finding that user experience was bad.
And for user who wants to force client registration with sidecar container, they can use the annotation. I can still change the logic by removing the commit. What do you think?

@Alan-Cha

Copy link
Copy Markdown
Member

@akram I think we will eventually retire the sidecar client registration in favor of the operator. I'm just not sure what is the best way to do the switch. It sounds like we are doing it in this PR as well.

@akram

akram commented Mar 30, 2026

Copy link
Copy Markdown
Contributor Author

@akram I think we will eventually retire the sidecar client registration in favor of the operator. I'm just not sure what is the best way to do the switch. It sounds like we are doing it in this PR as well.

sounds good

@Alan-Cha Alan-Cha 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.

Review Summary

This PR successfully implements the webhook-side coordination for operator-managed Keycloak client registration. The implementation is high quality: idempotent, well-tested, secure (ReadOnly SubPath mounts), and provides good observability through structured logging.

What this PR does:

  • Mounts operator-provisioned Secrets when the annotation is present
  • Handles reinvocation for late annotations (sidecars injected, then annotation appears)
  • Changes client-registration from opt-out to opt-in semantics (default: operator-managed)
  • Provides clear logging of credential delivery paths

Cross-repo consistency: Annotation constant kagenti.io/keycloak-client-credentials-secret-name matches operator PR rossoctl/operator#247 ✅

Previous review issues resolved:

  • ✅ Assisted-By: Cursor trailer (was flagged in prior review as Made-with: Cursor, now correct)

Commits: 5 commits, all signed-off ✅
CI status: DCO passing ✅
Areas reviewed: Go, Tests, Security, Shell, Documentation


Remaining Nits (non-blocking)

All commits and the PR title are missing emoji prefixes per Kagenti conventions (see .claude/skills/git/commit.md). Examples:

  • Commit 1: Should start with ✨ feat(kagenti-webhook): coordinate operator-managed...
  • Commit 4: Generic "Address review comments" should describe what changed
  • PR title: Should be ✨ feat(webhook): operator-managed Keycloak client credentials

These are style nits that don't block merge.


Code Quality Highlights

keycloak_client_credentials.go:

  • 💯 Excellent structured logging with deliveryPaths field makes debugging straightforward
  • 🔒 ReadOnly SubPath mounts are the correct security choice - prevents containers from modifying credentials
  • ✅ Idempotent volume/mount application via existence checks

precedence.go:

  • 👍 Clear separation of client-registration logic into evaluateClientRegistration() with detailed comments explaining opt-in semantics

authbridge_webhook.go:

  • 🎯 Excellent reinvocation handling (L626-639) catches the edge case where sidecars are injected first, then operator adds the annotation later - subtle but important

test coverage:

  • ✅ Unit tests for idempotency and patching logic
  • ✅ Integration test script (test-precedence.sh) updated for new opt-in semantics
  • ✅ All precedence tests updated to reflect operator-managed default

Overall: This is production-ready code. Well architected, secure, and thoroughly tested. 🚀

@akram

akram commented Mar 30, 2026

Copy link
Copy Markdown
Contributor Author

@cwiklik @pdettori can you PTAL ?

@pdettori pdettori 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.

Review Summary

All prior review comments have been addressed:

  • ✅ Assisted-By: Cursor trailer (was Made-with: Cursor)
  • ✅ Delivery path labels shortened (operator-secret, combined-authbridge, sidecar, skip)
  • ✅ V(1) for verbose admission logs
  • ℹ️ Emoji prefixes on commits — non-blocking nit (noted by Alan-Cha)

Commit 5 (02d61e8) adds a well-implemented behavioral change: client-registration sidecar defaults to operator-managed (not injected), with explicit kagenti.io/client-registration-inject: "true" to opt in to the legacy sidecar. The evaluateClientRegistration() function cleanly handles the 3-way decision (gate off → skip, label "true" → inject, default → operator-managed).

Code quality highlights:

  • Idempotent volume/mount application with volumeExists + appendSubPathMount guards
  • ReadOnly SubPath mounts — correct security choice for credential files
  • Reinvocation path (authbridge_webhook.go:626-639) correctly handles late annotation timing
  • Comprehensive test updates: 10+ precedence tests updated, Test 13 flipped from opt-out to opt-in, integration script updated
  • Documentation updated across README, CLAUDE.md, and demo README

Cross-repo consistency: Annotation kagenti.io/keycloak-client-credentials-secret-name matches operator PR rossoctl/operator#247 ✅

Commits: 5 commits, all signed-off ✅
CI status: 12/15 passing, 3 pending (Pre-commit, CodeQL Go, Kind E2E)
Areas reviewed: Go, Tests, Security, Shell, Documentation

@pdettori pdettori 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.

E2E tests need updating for opt-in semantics

The Kind E2E tests are failing because tests/e2e/test_webhook_injection.py still expects kagenti-client-registration to be injected by default, but commit 5 changed it to opt-in.

Failing tests:

  • test_agent_pod_gets_client_registration — expects the sidecar on a plain agent pod (no opt-in label)
  • test_agent_pod_gets_all_sidecars — includes kagenti-client-registration in the expected set

The unit tests and test-precedence.sh were updated for the new semantics, but the Python E2E tests were missed.

Suggested fix:

  • test_agent_pod_gets_all_sidecars: remove kagenti-client-registration from the expected sidecars set (default agent pods no longer get it)
  • test_agent_pod_gets_client_registration: either update to deploy a pod with kagenti.io/client-registration-inject: "true" and assert injection, or flip to assert it is not present by default

This is not blocked by the operator PR — it's purely a test update to match the behavioral change already in this PR. Merging with failing E2E tests would break main for other PRs.

Default agent pods no longer get kagenti-client-registration; update Kind E2E
expectations, add opt-in label case, and keep opt-out checks against all
possible injected sidecars.

Signed-off-by: Akram <[email protected]>
@akram

akram commented Mar 31, 2026

Copy link
Copy Markdown
Contributor Author

I have fixed the e2e tests accordingly

Suggested fix:

  • test_agent_pod_gets_all_sidecars: remove kagenti-client-registration from the expected sidecars set (default agent pods no longer get it)
  • test_agent_pod_gets_client_registration: either update to deploy a pod with kagenti.io/client-registration-inject: "true" and assert injection, or flip to assert it is not present by default

This is not blocked by the operator PR — it's purely a test update to match the behavioral change already in this PR. Merging with failing E2E tests would break main for other PRs.

@akram
akram requested review from cwiklik and pdettori March 31, 2026 11:56

@pdettori pdettori 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.

/lgtm

@pdettori
pdettori merged commit a3c797b into rossoctl:main Mar 31, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feature: Refactor Keycloak secrets handling for agent operator and centralized credential management

4 participants