Skip to content

Feat(auth): Keycloak realm roles and API OAuth secret job - #672

Merged
pdettori merged 6 commits into
rossoctl:mainfrom
pdettori:api-auth/4-api-oauth-secret
Feb 16, 2026
Merged

pdettori merged 6 commits into
rossoctl:mainfrom
pdettori:api-auth/4-api-oauth-secret

Conversation

@pdettori

@pdettori pdettori commented Feb 12, 2026 •

Copy link
Copy Markdown
Member

Summary

Phase 3+4 (combined) of API bearer token authentication (Epic #639).

This PR creates a Kubernetes Job that:

  1. Creates RBAC realm roles (kagenti-viewer, kagenti-operator, kagenti-admin) in Keycloak — moved here from the agent-oauth-secret job since these roles are specific to backend API authorization
  2. Assigns kagenti-admin to the Keycloak admin user for full platform access via the UI
  3. Registers a confidential client (kagenti-api) for programmatic API access via Client Credentials Grant
  4. Stores credentials in a Kubernetes secret

Changes

New files:

  • kagenti/auth/api-oauth-secret/register_api_client.py - Registers kagenti-api client and creates RBAC roles
  • kagenti/auth/api-oauth-secret/Dockerfile - Container image
  • kagenti/auth/api-oauth-secret/requirements.txt - Dependencies
  • charts/kagenti/templates/api-oauth-secret-job.yaml - Helm Job template

Modified:

  • charts/kagenti/values.yaml - Add apiOAuthSecret configuration section

Configuration

Value Default Description
apiOAuthSecret.enabled true Enable/disable the job
apiOAuthSecret.clientId kagenti-api Keycloak client ID
apiOAuthSecret.secretName kagenti-api-oauth-secret K8s secret name
apiOAuthSecret.serviceAccountRole kagenti-operator Role for service account

Testing

Deploy to dev cluster and verify:

  • RBAC roles appear in Keycloak Admin UI under Realm Roles
  • Admin user has kagenti-admin role assigned
  • Job completes successfully
  • kagenti-api client exists in Keycloak
  • kagenti-api-oauth-secret secret created with credentials
  • Token can be obtained via Client Credentials Grant
  • Token works against protected API endpoints

Stacked PR

This is PR 3/4 in the API authentication stack (combined Phase 3+4):

  1. #647 RBAC Foundation ✅
  2. #648 Protect Backend Endpoints ✅
  3. This PR - Keycloak Realm Roles + API OAuth Secret Job
  4. Documentation

Supersedes #671 (Keycloak Realm Roles), which was closed since role creation belongs in this job.


🤖 Generated with Claude Code

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 apiOAuthSecret configuration 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.

Comment thread charts/kagenti/values.yaml Resolved
@pdettori

Copy link
Copy Markdown
Member Author

All 6 review comments addressed:

│                 Comment                  │                                     Fix                                      │
├──────────────────────────────────────────┼──────────────────────────────────────────────────────────────────────────────┤
│ pdettori: Add CI build for image         │ Added api-oauth-secret to build matrix in .github/workflows/build.yaml       │
├──────────────────────────────────────────┼──────────────────────────────────────────────────────────────────────────────┤
│ Copilot: enabled defaults to true        │ Changed to enabled: false (opt-in)                                           │
├──────────────────────────────────────────┼──────────────────────────────────────────────────────────────────────────────┤
│ Copilot: Role assignment should be fatal │ Changed from warning to RuntimeError with clear message                      │
├──────────────────────────────────────────┼──────────────────────────────────────────────────────────────────────────────┤
│ Copilot: Update client config on 409     │ Now calls update_client() to reconcile configuration                         │
├──────────────────────────────────────────┼──────────────────────────────────────────────────────────────────────────────┤
│ Copilot: Wrong template gate condition   │ Changed from ui.enabled to keycloak.enabled                                  │
├──────────────────────────────────────────┼──────────────────────────────────────────────────────────────────────────────┤
│ Copilot: RBAC too broad                  │ Split rules: create on all secrets, get/update/patch on specific secret name │
└──────────────────────────────────────────┴──────────────────────────────────────────────────────────────────────────────┘

@pdettori pdettori moved this from Backlog to In review / Needs Testing in Rossoctl Issue Prioritization Feb 12, 2026
pdettori and others added 3 commits February 13, 2026 12:49
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]>
Copilot AI review requested due to automatic review settings February 13, 2026 17:54
@pdettori
pdettori force-pushed the api-auth/4-api-oauth-secret branch from 2acaeb1 to fd57ee4 Compare February 13, 2026 17:54
@pdettori
pdettori changed the base branch from api-auth/3-keycloak-roles to main February 13, 2026 18:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@pdettori pdettori changed the title feat(auth): add API OAuth secret job for Client Credentials Grant Feat(auth): Keycloak realm roles and API OAuth secret job Feb 13, 2026
- 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]>
@pdettori

Copy link
Copy Markdown
Member Author

Latest comments have been addressed

  ┌────────────────────────────────────────────────────────────┬───────────┬───────────────────────────────────────────────────────────────────────────────┐
  │                          Comment                           │  Author   │                                    Action                                     │
  ├────────────────────────────────────────────────────────────┼───────────┼───────────────────────────────────────────────────────────────────────────────┤
  │ Add README for api-oauth-secret folder                     │ maia-iyer │ Added README.md explaining job purpose and relationship to agent-oauth-secret │
  ├────────────────────────────────────────────────────────────┼───────────┼───────────────────────────────────────────────────────────────────────────────┤
  │ Rename agent-oauth-secret to keycloak-setup                │ maia-iyer │ Replied — good idea but scope creep for this PR, will open follow-up issue    │
  ├────────────────────────────────────────────────────────────┼───────────┼───────────────────────────────────────────────────────────────────────────────┤
  │ Role creation duplicates #671                              │ Copilot   │ Replied — #671 was closed, this is now the only place roles are created       │
  ├────────────────────────────────────────────────────────────┼───────────┼───────────────────────────────────────────────────────────────────────────────┤
  │ Unhandled RuntimeError from assign_role_to_service_account │ Copilot   │ Added try-catch with descriptive error message before re-raising              │
  ├────────────────────────────────────────────────────────────┼───────────┼───────────────────────────────────────────────────────────────────────────────┤
  │ Inconsistent version pinning                               │ Copilot   │ Changed to python-keycloak~=5.3.1 matching agent-oauth-secret                 │
  └────────────────────────────────────────────────────────────┴───────────┴───────────────────────────────────────────────────────────────────────────────┘

@pdettori

Copy link
Copy Markdown
Member Author

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]>
Copilot AI review requested due to automatic review settings February 13, 2026 20:07

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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]>

@maia-iyer maia-iyer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM! Thank you!

@pdettori
pdettori merged commit a287aa6 into rossoctl:main Feb 16, 2026
15 checks passed
@pdettori
pdettori deleted the api-auth/4-api-oauth-secret branch February 16, 2026 14:50
@github-project-automation github-project-automation Bot moved this from In review / Needs Testing to Done in Rossoctl Issue Prioritization Feb 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants