Skip to content

feat: deployed Keycloak and configure agentcube#367

Open
mahil-2040 wants to merge 2 commits into
volcano-sh:mainfrom
mahil-2040:feat/keycloak-deployment-realm-setup
Open

feat: deployed Keycloak and configure agentcube#367
mahil-2040 wants to merge 2 commits into
volcano-sh:mainfrom
mahil-2040:feat/keycloak-deployment-realm-setup

Conversation

@mahil-2040
Copy link
Copy Markdown
Contributor

What type of PR is this?

/kind feature

What this PR does / why we need it:

Description

This PR deploys Keycloak as the external identity provider for AgentCube and configures the agentcube realm with all necessary clients and roles. This establishes the OIDC/OAuth2 foundation that the Router JWT verification middleware will consume.

Core Changes

Keycloak Kubernetes Deployment: Added Deployment, Service, and ConfigMap manifests for Keycloak in agentcube-system, following the same Helm chart conventions as the existing SPIRE infrastructure. All resources are gated behind keycloak.enabled (default: false) to ensure zero impact on existing deployments. Includes a startupProbe with a 300s window to tolerate Keycloak's JVM startup and realm import phase.

Declarative Realm Configuration: The agentcube realm is defined as a JSON import file mounted into the Keycloak pod via ConfigMap. The realm includes:

  • Clients: agentcube-sdk (confidential, client_credentials + authorization_code), agentcube-router (confidential), workloadmanager (confidential, all auth flows disabled), agentcube-admin (confidential)
  • Realm Roles: sandbox:invoke, sandbox:manage (inherits sandbox:invoke), admin (inherits sandbox:manage)
  • Default Role: New users/service accounts receive sandbox:invoke automatically

**Helm Values Integration: ** Added keycloak: section to values.yaml with configurable image, admin credentials, service ports, and resource limits. Supports both dev mode (embedded H2 database) and production mode toggle.

Verification

Local deployment successfully verified on a kind cluster:

  • Helm template renders cleanly when enabled, produces no resources when disabled
  • Keycloak boots and imports the agentcube realm successfully on startup.
  • Access token with the correct sandbox:invoke role successfully issued via the agentcube-sdk credentials grant.

Successful Realm Import Logs
image

Configured Clients & Role Hierarchy API Checks
image

Decoded SDK JWT Payload with sandbox:invoke Role

mahil@Mahil:~/projects/agentcube$ curl -s -X POST \
  "http://localhost:8080/realms/agentcube/protocol/openid-connect/token" \
  -d "grant_type=client_credentials" \
  -d "client_id=agentcube-sdk" \
  -d "client_secret=$SDK_SECRET" \
  | jq '.access_token' | cut -d. -f2 | base64 -d 2>/dev/null | jq .
Handling connection for 8080
{
  "exp": 1779991579,
  "iat": 1779991279,
  "jti": "bf81f033-fc4f-489d-927e-3aa4081c1dc6",
  "iss": "http://localhost:8080/realms/agentcube",
  "aud": "account",
  "sub": "38fd2928-3af0-4908-a822-59222dc20599",
  "typ": "Bearer",
  "azp": "agentcube-sdk",
  "acr": "1",
  "allowed-origins": [
    "*"
  ],
  "realm_access": {
    "roles": [
      "offline_access",
      "uma_authorization",
      "default-roles-agentcube",
      "sandbox:invoke"
    ]
  },
  "resource_access": {
    "account": {
      "roles": [
        "manage-account",
        "manage-account-links",
        "view-profile"
      ]
    }
  },
  "scope": "profile email",
  "clientHost": "127.0.0.1",
  "email_verified": false,
  "preferred_username": "service-account-agentcube-sdk",
  "clientAddress": "127.0.0.1",
  "client_id": "agentcube-sdk"
} 

Which issue(s) this PR fixes:
Fixes Part of #243

Special notes for your reviewer:

  • Modernized bearer-only: The workloadmanager client is configured as a standard confidential client with all authentication flows disabled (the modern Quarkus replacement for the deprecated bearer-only profile).
  • Import Strategy: The Quarkus-based Keycloak 26 uses OVERWRITE_EXISTING during the --import-realm bootstrap phase, meaning updates to the ConfigMap JSON will correctly overwrite the realm config on pod restart.

Does this PR introduce a user-facing change?:

yes

Adds optional, opt-in deployment of Keycloak (`--set keycloak.enabled=true`) with a pre-configured `agentcube` realm for external authentication and role-based access control.

- Declarative Realm Import: Created a ConfigMap with the realm JSON defining
  clients (agentcube-sdk, agentcube-router, workloadmanager, agentcube-admin)
  and role hierarchy (sandbox:invoke -> sandbox:manage -> admin).
- Deployment & Service: Added Keycloak Deployment and Service manifests
  with management-port health probes and a 300s startupProbe window.
- Helm Integration: Added keycloak configuration values to values.yaml,
  gated behind 'keycloak.enabled: false' to ensure zero impact by default.

Signed-off-by: Mahil Patel <mahilpatel0808@gmail.com>
Copilot AI review requested due to automatic review settings May 28, 2026 18:25
@volcano-sh-bot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign hzxuzhonghu for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a Keycloak deployment, service, and realm configuration to the Helm chart for external user authentication. The reviewer identified several critical security and configuration issues: wildcard redirect URIs and web origins on the confidential SDK client should be configurable; the admin password should be sourced from a Kubernetes Secret instead of plaintext; production mode lacks support for external databases and proxy/HTTPS settings; SSL requirements should be dynamically enabled; and global image pull secrets need to be propagated to the Keycloak pod template.

Comment thread manifests/charts/base/templates/keycloak/keycloak-realm.yaml Outdated
Comment thread manifests/charts/base/templates/keycloak/keycloak.yaml
Comment thread manifests/charts/base/templates/keycloak/keycloak.yaml
Comment thread manifests/charts/base/templates/keycloak/keycloak-realm.yaml Outdated
Comment thread manifests/charts/base/templates/keycloak/keycloak.yaml
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds an optional Keycloak deployment to the Helm base chart to support external user authentication, including default values, a Deployment/Service, and a realm-import ConfigMap.

Changes:

  • Introduces keycloak configuration block in chart values.
  • Adds Keycloak Deployment + Service template gated by keycloak.enabled.
  • Adds a realm JSON import ConfigMap template for bootstrapping clients/roles.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 10 comments.

File Description
manifests/charts/base/values.yaml Adds configurable values for enabling and running a Keycloak instance
manifests/charts/base/templates/keycloak/keycloak.yaml Adds Deployment/Service templates for Keycloak
manifests/charts/base/templates/keycloak/keycloak-realm.yaml Adds ConfigMap for importing an initial realm configuration

Comment thread manifests/charts/base/values.yaml
Comment thread manifests/charts/base/templates/keycloak/keycloak.yaml
Comment thread manifests/charts/base/templates/keycloak/keycloak.yaml
Comment thread manifests/charts/base/templates/keycloak/keycloak-realm.yaml Outdated
Comment thread manifests/charts/base/templates/keycloak/keycloak-realm.yaml Outdated
Comment thread manifests/charts/base/templates/keycloak/keycloak-realm.yaml Outdated
Comment thread manifests/charts/base/templates/keycloak/keycloak.yaml
Comment thread manifests/charts/base/templates/keycloak/keycloak.yaml
Comment thread manifests/charts/base/templates/keycloak/keycloak.yaml
Comment thread manifests/charts/base/templates/keycloak/keycloak.yaml Outdated
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 28, 2026

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 55.54%. Comparing base (524e55e) to head (5f5d385).
⚠️ Report is 103 commits behind head on main.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #367      +/-   ##
==========================================
+ Coverage   47.57%   55.54%   +7.97%     
==========================================
  Files          30       34       +4     
  Lines        2819     3190     +371     
==========================================
+ Hits         1341     1772     +431     
+ Misses       1338     1239      -99     
- Partials      140      179      +39     
Flag Coverage Δ
unittests 55.54% <ø> (+7.97%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

- Parameterized SDK redirect URIs with secure defaults, added support for secretKeyRef for admin/database credentials, and made sslRequired enforcement dynamic based on devMode.
- Added configuration blocks for external databases (PostgreSQL/MySQL) and reverse proxy settings (headers, hostname).
- Propagated global imagePullSecrets, decoupled Service targetPort by using the named 'http' port, and dynamically derived  the realm import filename from Helm values.

Signed-off-by: Mahil Patel <mahilpatel0808@gmail.com>

"clients": [
{
"clientId": "agentcube-sdk",
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.

The confidential client secrets should be explicit. If Keycloak generates them during realm import, SDK/router/admin clients have no stable secret to configure against after Helm install.

name: {{ .Values.keycloak.existingSecret }}
key: {{ .Values.keycloak.existingSecretKey | default "admin-password" }}
{{- else }}
value: {{ .Values.keycloak.adminPassword | quote }}
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 still renders the bootstrap admin password into the Deployment when no Secret is set. We should require a Secret when Keycloak is enabled instead of keeping the plaintext fallback.

name: {{ .Values.keycloak.database.existingSecret }}
key: {{ .Values.keycloak.database.existingSecretKey | default "db-password" }}
{{- else }}
value: {{ .Values.keycloak.database.password | quote }}
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.

Same for the database password. The production path should require database.existingSecret instead of rendering the DB credential as a literal env value.

{{- if .Values.keycloak.devMode }}
args: ["start-dev", "--import-realm"]
{{- else }}
args: ["start", "--import-realm"]
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.

devMode=false should fail template rendering when required production settings are missing. Otherwise Helm succeeds but Keycloak starts with an incomplete production config.

Copy link
Copy Markdown
Member

@hzxuzhonghu hzxuzhonghu left a comment

Choose a reason for hiding this comment

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

before adding a bunch of yamls, can you first add a docs exmplain about the proposal and the workflow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants