Repository navigation
Feat(auth): Keycloak realm roles and API OAuth secret job - #672
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a new Helm-managed Kubernetes Job + containerized script to provision a Keycloak confidential client (kagenti-api) for API access via the OAuth2 Client Credentials Grant, and stores the resulting credentials in a Kubernetes Secret for dev/testing workflows (Phase 4 of the bearer-token auth epic).
Changes:
- Add a Python-based Keycloak client registration script and container image for creating/updating the API OAuth Secret.
- Add a new Helm Job template (plus RBAC) to run the provisioning flow in-cluster.
- Extend chart values with an
apiOAuthSecretconfiguration block.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| kagenti/auth/api-oauth-secret/register_api_client.py | Implements Keycloak client creation, role assignment, and K8s Secret creation/update. |
| kagenti/auth/api-oauth-secret/Dockerfile | Builds a minimal non-root Python image to run the provisioning script. |
| kagenti/auth/api-oauth-secret/requirements.txt | Pins dependencies for Keycloak and Kubernetes API interaction. |
| charts/kagenti/templates/api-oauth-secret-job.yaml | Adds the Job + RBAC resources to run the script and write the Secret. |
| charts/kagenti/values.yaml | Introduces apiOAuthSecret values (enabled/image/tag/clientId/secretName/role/CA option). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
All 6 review comments addressed: |
Phase 4 of API bearer token authentication (Epic rossoctl#639). Creates a confidential OAuth2 client in Keycloak for programmatic API access: - Add register_api_client.py script to create kagenti-api client - Enable Client Credentials Grant with service account - Assign kagenti-operator role to service account - Store credentials in kagenti-api-oauth-secret K8s secret - Add Helm chart template and values configuration The secret contains CLIENT_ID, CLIENT_SECRET, and TOKEN_ENDPOINT for external services to authenticate via Client Credentials flow. WARNING: This is a shared credential for testing/dev only. Production deployments should use dedicated service accounts per client. Co-Authored-By: Claude Opus 4.6 <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
- Add api-oauth-secret to CI build matrix - Default apiOAuthSecret.enabled to false (opt-in for security) - Fix template gate: use keycloak.enabled instead of UI enabled - Restrict RBAC to specific secret name (least privilege) - Update existing client config on 409 instead of just retrieving - Make role assignment failures fatal with clear error message Co-Authored-By: Claude Opus 4.6 <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
Move RBAC realm role creation (kagenti-viewer, kagenti-operator, kagenti-admin) from the agent-oauth-secret job into this job, since these roles are specific to the backend API authorization — not agent auth. Also assigns kagenti-admin to the Keycloak admin user. Co-Authored-By: Claude Opus 4.6 <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
2acaeb1 to
fd57ee4
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Add README explaining job purpose and relationship to agent-oauth-secret - Fix version pinning: use ~= for python-keycloak (matches agent-oauth-secret) - Add try-catch for assign_role_to_service_account RuntimeError in main() with descriptive error message before re-raising Co-Authored-By: Claude Opus 4.6 <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
|
Latest comments have been addressed |
|
now going to look into latest security scan issues |
Remove sensitive-named variables from log statements to resolve 8 CodeQL "clear-text logging of sensitive information" findings. The logged values were resource names (not secret values), but CodeQL's taint analysis flagged them due to variable naming heuristics and data flow from K8s secret reads. Signed-off-by: Paolo Dettori <[email protected]> Co-Authored-By: Claude Opus 4.6 <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: Paolo Dettori <[email protected]> Co-Authored-By: Claude Opus 4.6 <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
Summary
Phase 3+4 (combined) of API bearer token authentication (Epic #639).
This PR creates a Kubernetes Job that:
kagenti-viewer,kagenti-operator,kagenti-admin) in Keycloak — moved here from the agent-oauth-secret job since these roles are specific to backend API authorizationkagenti-adminto the Keycloak admin user for full platform access via the UIkagenti-api) for programmatic API access via Client Credentials GrantChanges
New files:
kagenti/auth/api-oauth-secret/register_api_client.py- Registerskagenti-apiclient and creates RBAC roleskagenti/auth/api-oauth-secret/Dockerfile- Container imagekagenti/auth/api-oauth-secret/requirements.txt- Dependenciescharts/kagenti/templates/api-oauth-secret-job.yaml- Helm Job templateModified:
charts/kagenti/values.yaml- AddapiOAuthSecretconfiguration sectionConfiguration
apiOAuthSecret.enabledtrueapiOAuthSecret.clientIdkagenti-apiapiOAuthSecret.secretNamekagenti-api-oauth-secretapiOAuthSecret.serviceAccountRolekagenti-operatorTesting
Deploy to dev cluster and verify:
kagenti-adminrole assignedkagenti-apiclient exists in Keycloakkagenti-api-oauth-secretsecret created with credentialsStacked PR
This is PR 3/4 in the API authentication stack (combined Phase 3+4):
Supersedes #671 (Keycloak Realm Roles), which was closed since role creation belongs in this job.
🤖 Generated with Claude Code