Skip to content

Spiffe keycloak consolidation - #966

Merged
Alan-Cha merged 23 commits into
rossoctl:mainfrom
Alan-Cha:spiffe-keycloak-consolidation
Apr 13, 2026
Merged

Alan-Cha merged 23 commits into
rossoctl:mainfrom
Alan-Cha:spiffe-keycloak-consolidation

Conversation

@Alan-Cha

@Alan-Cha Alan-Cha commented Mar 16, 2026 •

Copy link
Copy Markdown
Member

Configure SPIRE and Keycloak for Federated JWT Authentication

Fixes #106
Replaces #769

This PR configures the Kagenti platform to support SPIFFE-based federated JWT authentication with Keycloak, enabling workload identity without client secrets.

This PR should maintain the original behavior of using client secrets. Federated client authentication can be enabled if desired.

Changes

SPIRE Configuration

  • JWT TTL set to 5 minutes for Keycloak compatibility

    • Keycloak rejects JWTs older than ~3 minutes
    • SPIRE refreshes every ~2.5 minutes, keeping tokens fresh
    • Configured via spire-server.controllerManager.identities.clusterSPIFFEIDs.default.jwtTTL
  • SPIFFE OIDC Discovery Provider configured with set_key_use: true

    • Adds "use" field to JWKS for Keycloak SPIFFE provider compatibility
    • Required for Keycloak to validate SPIFFE JWT-SVIDs

Keycloak Integration

  • SPIFFE IdP configuration for federated client authentication
    • Keycloak configured to trust SPIRE as an identity provider
    • Workloads authenticate using JWT-SVIDs instead of client secrets
    • IdP alias: spire-spiffe (configurable via authBridge.spiffeIdpAlias)

ConfigMap Architecture

  • Added kagenti-webhook-config ConfigMap to agent namespaces

    • CLIENT_AUTH_TYPE: Controls authentication mode (client-secret or federated-jwt)
    • SPIFFE_IDP_ALIAS: Keycloak IdP alias for SPIFFE validation
    • JWT_AUDIENCE: Expected audience for JWT-SVID validation
  • Consolidated Keycloak connection config in environments ConfigMap

    • KEYCLOAK_URL and KEYCLOAK_REALM moved from webhook config
    • Shared between agents and AuthBridge sidecars

Helm Chart Updates

  • agent-namespaces.yaml template updated with new ConfigMaps
  • Values exposed: authBridge.clientAuthType, authBridge.spiffeIdpAlias
  • Default remains client-secret for backward compatibility

Configuration

To enable federated JWT authentication, set in values.yaml:

authBridge:
  clientAuthType: "federated-jwt"
  spiffeIdpAlias: "spire-spiffe"

spire:
  enabled: true
  values:
    global:
      spire:
        jwtIssuer: "spiffe://localtest.me"
    spiffe-oidc-discovery-provider:
      config:
        set_key_use: true
    spire-server:
      controllerManager:
        identities:
          clusterSPIFFEIDs:
            default:
              jwtTTL: "5m"

@Alan-Cha
Alan-Cha force-pushed the spiffe-keycloak-consolidation branch from 6b8a792 to 64281ae Compare March 17, 2026 03:07
@Alan-Cha
Alan-Cha marked this pull request as ready for review March 17, 2026 05:28
@Alan-Cha
Alan-Cha requested review from maia-iyer and mrsabath March 17, 2026 05:29

@mrsabath mrsabath 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

Large feature PR adding SPIFFE-based federated JWT authentication with Keycloak. Well-structured with proper credential handling (reads from K8s Secrets), retry logic, and backward compatibility (default remains client-secret). All CI checks pass including Deploy & Test.

Key concerns: SPIFFE_IDP_FIXES.md is a development artifact that should not be committed at the repo root, Dockerfile should use a non-root user, and the new kagenti-webhook-config ConfigMap should be coordinated with the ConfigMap consolidation in kagenti-extensions PR #233.

Areas reviewed: Python, Helm/K8s, Ansible, Dockerfile, CI, Docs, Security
Commits: 14 commits, all signed-off: yes
CI status: all checks passing (Deploy & Test included)

🤖 Reviewed with Claude Code

Comment thread SPIFFE_IDP_FIXES.md Resolved
@Alan-Cha
Alan-Cha force-pushed the spiffe-keycloak-consolidation branch from 163007a to 01dbd89 Compare March 20, 2026 14:28
@@ -0,0 +1,22 @@
# Dockerfile for SPIFFE Identity Provider Setup Job
FROM python:3.12-slim

Check warning

Code scanning / Scorecard

Pinned-Dependencies Medium

score is 6: containerImage not pinned by hash
Remediation tip: pin your Docker image by updating python:3.12-slim to python:3.12-slim@sha256:804ddf3251a60bbf9c92e73b7566c40428d54d0e79d3428194edf40da6521286
Click Remediation section below for further remediation help

# Copy requirements and install dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

Check warning

Code scanning / Scorecard

Pinned-Dependencies Medium

score is 6: pipCommand not pinned by hash
Click Remediation section below to solve this issue
@akram

akram commented Mar 24, 2026

Copy link
Copy Markdown
Contributor

@Alan-Cha do you think you can rebase this PR?

I am testing it on OpenShift and trying to do the required adaptations so it works ouf of the box, but I am not succeeding yet. Maybe a rebase could help.

@Alan-Cha
Alan-Cha force-pushed the spiffe-keycloak-consolidation branch from 01dbd89 to d143fd7 Compare March 25, 2026 03:15
@Alan-Cha

Copy link
Copy Markdown
Member Author

@akram I was able to rebase the PR. Could you review for me again? I've also tested it and it works on my end.

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

Some preliminary comments. Also it appears there are merge conflicts currently?

Comment thread charts/kagenti-deps/values.yaml Resolved
Comment thread kagenti/auth/spiffe-idp-setup/README.md Resolved
Comment thread kagenti/auth/spiffe-idp-setup/README.md Resolved

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

Additional comments from Claude

Comment thread charts/kagenti-deps/values.yaml Resolved
Comment thread charts/kagenti/values.yaml Resolved

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

I have tested this and it works for configuring keycloak to trust spire
I have also tested a deployment that authenticates to keycloak with SPIRE credentials, adn that works.

What remains is to test with AuthBridge

@pdettori

Copy link
Copy Markdown
Member

@Alan-Cha @maia-iyer - seems all comments are addressed - do you recommend the testing with AuthBridge before merging or this can be merged (still needs rebase though)

@Alan-Cha

Copy link
Copy Markdown
Member Author

I will rebase. I think we can merge. These features are disabled by default anyway.

Alan-Cha added 19 commits April 13, 2026 08:24
Signed-off-by: Alan Cha <[email protected]>
agenti-webhook-config with environments configmap

Signed-off-by: Alan Cha <[email protected]>
- Update Keycloak version from 26.3.3 to 26.5.2
- Enable KC_FEATURES: client-auth-federated:v1,spiffe:v1
- Update preload-images.txt for faster Kind startup

This restores the missing changes from commit ed04fdd that were
lost during the rebase. Keycloak 26.5.2 includes native SPIFFE
support via federated-jwt authentication.

Signed-off-by: Alan Cha <[email protected]>
The SPIFFE IdP setup job's init container needs permission to list pods
in the Keycloak namespace to wait for Keycloak to be ready.

This adds a Role and RoleBinding in the Keycloak namespace to grant
the kagenti-spiffe-idp-setup ServiceAccount read access to pods.

Without this RBAC, the init container fails with:
  Error from server (Forbidden): pods is forbidden: User
  "system:serviceaccount:kagenti-system:kagenti-spiffe-idp-setup"
  cannot list resource "pods" in API group "" in the namespace "keycloak"

Related: Existing RBAC already grants access to SPIRE namespace pods.
Signed-off-by: Alan Cha <[email protected]>
Signed-off-by: Alan Cha <[email protected]>
Signed-off-by: Alan Cha <[email protected]>
Signed-off-by: Alan Cha <[email protected]>
- Delete charts/kagenti-deps/templates/spiffe-idp-setup-job.yaml.disabled
  This template was disabled because Ansible now handles SPIFFE IdP setup
  directly (avoiding race conditions). Keeping disabled templates causes
  confusion for maintainers.

- Remove PR rossoctl#233 reference from agent-namespaces.yaml comment
  Internal PR references don't belong in template comments.

Both changes improve code clarity without affecting functionality.

Signed-off-by: Alan Cha <[email protected]>
Signed-off-by: Alan Cha <[email protected]>
Signed-off-by: Alan Cha <[email protected]>
Signed-off-by: Alan Cha <[email protected]>
Break long logger.error line to comply with line length limits.

Signed-off-by: Alan Cha <[email protected]>
Update requests from 2.32.5 to 2.33.0 to fix GHSA-gc5v-m9x4-r6x2
(Insecure Temp File Reuse in extract_zipped_paths() utility function).

Addresses dependency-review-action moderate severity finding.

Signed-off-by: Alan Cha <[email protected]>
@Alan-Cha
Alan-Cha force-pushed the spiffe-keycloak-consolidation branch from 43b9ca2 to bcf6db9 Compare April 13, 2026 12:26
@Alan-Cha
Alan-Cha requested review from maia-iyer and mrsabath April 13, 2026 12:37

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

re-approving after rebase; all features are default off

@Alan-Cha
Alan-Cha dismissed mrsabath’s stale review April 13, 2026 12:48

This review is outdated

@Alan-Cha
Alan-Cha merged commit 6c12d70 into rossoctl:main Apr 13, 2026
24 checks passed
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.

feature: Replace hardcoded secret with SPIRE identity

6 participants