Skip to content

refactor(local): use shared idp fixture - #92

Merged
FrankSpitulski merged 5 commits into
mainfrom
codex/refactor/dedup-local-idps
Jul 31, 2026
Merged

refactor(local): use shared idp fixture#92
FrankSpitulski merged 5 commits into
mainfrom
codex/refactor/dedup-local-idps

Conversation

@FrankSpitulski

@FrankSpitulski FrankSpitulski commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • move DemoIdP into shared local/idp Skaffold module
  • add event bus client-credentials issuer at /token and /jwks.json
  • remove Keycloak operator, CRDs, realm import, downloads, and local configuration
  • rename MQTT helpers and configuration from Keycloak-specific names to OIDC/IdP names

Why

The merged local stack deployed two identity-provider fixtures. The lightweight
DemoIdP already supports the controlled issuer, audience, expiry, and
signing-key cases required by Agent Gateway tests, so it can serve both local
consumers without carrying Keycloak infrastructure.

Impact

This is an intentional clean break. Local callers must use IDP_URL, /token,
and /jwks.json; no Keycloak URL aliases remain.

Validation

  • make check
  • go -C local/idp/server test ./...
  • go -C local/mqtt-client test ./pkg/... ./internal/... ./cmd/...
  • compile-only functional checks for local MQTT and Agent Gateway suites
  • helm lint local/idp/chart --set image.repository=test --set image.tag=test
  • Helm render and skaffold diagnose --yaml-only -f skaffold.yaml

Full Kind e2e was not run locally because the shared local environment was in
use by other Codex tasks; CI should exercise that path.

Summary by CodeRabbit

  • New Features

    • Added a shared local identity provider for development and evaluation.
    • Added event-bus authentication with token, health, and key endpoints.
    • Added configurable issuer deployments and credential-based OAuth2/OIDC flows.
  • Security

    • Improved credential handling and validation for token requests.
    • Added comprehensive coverage for valid and invalid authentication scenarios.
  • Documentation

    • Updated setup, validation, troubleshooting, and authentication guidance for the local identity provider.
    • Replaced legacy Keycloak references across local development configurations and workflows.

Signed-off-by: Frank Spitulski <fspitulski@nvidia.com>
@copy-pr-bot

copy-pr-bot Bot commented Jul 31, 2026

Copy link
Copy Markdown

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@coderabbitai

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 65e3434d-7b2e-47e9-8b3a-c5e188eda39c

📥 Commits

Reviewing files that changed from the base of the PR and between 67d5d57 and 467f461.

📒 Files selected for processing (1)
  • local/agent-gateway/tests/functional/internal/runner/token.go

📝 Walkthrough

Walkthrough

The change moves the local DemoIDP into local/idp, adds event-bus issuer deployment, removes Keycloak integration, updates OIDC clients and routing, and adds server and OAuth token tests.

Changes

Local IdP migration

Layer / File(s) Summary
Standalone IdP server
local/idp/server/*, Makefile
The Go module now uses the local IdP path. A multi-stage image builds a non-root scratch runtime. Token credentials use constant-time comparison. Tests cover grants, JWT claims, signatures, and invalid credentials.
IdP deployment and issuer secrets
local/idp/chart/*, local/idp/prepare-secrets.sh, local/idp/skaffold.yaml, local/idp/namespace.yaml, local/idp/httproute.yaml
The Helm chart and Skaffold configuration deploy issuer-specific IdP instances. Generated Secrets include configuration and signing keys for the event-bus issuer. Routing exposes /healthz, /jwks.json, and /token through the event-bus service.
Authentication routing and client migration
local/agent-gateway/*, local/event-bus/*, local/mqtt-client/*
Local services and functional tests now use IdP hostnames and endpoints. MQTT OAuth helpers use generic OIDC names, /token, IDP_URL, and client credentials in request parameters.
Documentation and local tooling
docs/getting-started.md, local/infra/README.md, local/scripts/*, local/validate.sh, .gitignore
Documentation, validation, cleanup, and generated-output paths now reference the local IdP instead of Keycloak and the former fixture DemoIDP.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Skaffold
  participant SecretGenerator
  participant Helm
  participant EventBusIDP
  Skaffold->>SecretGenerator: Generate event-bus configuration and RSA signing key
  Skaffold->>Helm: Render and deploy IdP resources
  Helm->>EventBusIDP: Mount generated Secrets
Loading
sequenceDiagram
  participant MQTTClient
  participant HTTPRoute
  participant EventBusService
  participant EventBusIDP
  MQTTClient->>HTTPRoute: Request /token
  HTTPRoute->>EventBusService: Route request to port 5556
  EventBusService->>EventBusIDP: Validate client credentials
  EventBusIDP-->>MQTTClient: Return OAuth access token
Loading

Possibly related PRs

Suggested reviewers: abhay-krishna

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 19.05% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: refactoring the local stack to use a shared IdP fixture.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/refactor/dedup-local-idps

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.12.2)

level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies"


Comment @coderabbitai help to get the list of available commands.

@FrankSpitulski

Copy link
Copy Markdown
Collaborator Author

/ok to test c35fe41

@github-actions

Copy link
Copy Markdown

🔐 TruffleHog Secret Scan

No secrets or credentials found!

Your code has been scanned for 700+ types of secrets and credentials. All clear! 🎉

🔗 View scan details

🕐 Last updated: 2026-07-31 02:33:58 UTC | Commit: c35fe41

@github-actions

Copy link
Copy Markdown

🛡️ CodeQL Analysis

🚨 Found 1 issue(s)

Severity Breakdown:

  • 🔴 Errors: 0
  • 🟡 Warnings: 0
  • 🔵 Notes: 0
📋 Top Issues

💡 Note: Enable GitHub Advanced Security to see full details in the Security tab.

🕐 Last updated: 2026-07-31 02:35:49 UTC | Commit: c35fe41

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (3)
local/infra/README.md (1)

103-124: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Align the README HTTPRoute example with the deployed route.

Add exact matches for /healthz and /jwks.json; local/idp/httproute.yaml already routes all three endpoints.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@local/infra/README.md` around lines 103 - 124, Update the HTTPRoute YAML
example in the README to include exact path matches for /healthz and /jwks.json
alongside the existing /token match, matching the three endpoints configured in
local/idp/httproute.yaml.
Makefile (1)

44-44: 📐 Maintainability & Code Quality | 🔵 Trivial | 🏗️ Heavy lift

Consider adding executed unit tests for the IdP server's auth logic.

This line only compiles local/idp/server (-run '^$' matches no test names). The package implements handleToken and mintJWT, which parse credentials, choose grant types, and mint JWTs. No test file for this package is in the reviewed file set. Add unit tests for handleToken and mintJWT and change this to run them, so regressions in credential handling or claim/audience selection are caught before deployment.

Do you want me to draft main_test.go covering the password and client_credentials grant paths?

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@Makefile` at line 44, Replace the compile-only command with execution of unit
tests for the IdP server, adding coverage for handleToken and mintJWT, including
password and client_credentials grant handling, credential parsing, and JWT
claim/audience selection. Ensure the Makefile target runs these tests rather
than filtering all test names out.
local/idp/server/main.go (1)

200-221: 🔒 Security & Privacy | 🔵 Trivial | 💤 Low value

Use constant-time comparison for client secrets and passwords.

c.Secret != r.Form.Get("client_secret") and u.Password != r.Form.Get("password") compare secrets with the != operator. This operator does not run in constant time, so it leaks timing information about how much of the guessed secret matches. This server is a local test fixture, so the immediate risk is low. Use crypto/subtle.ConstantTimeCompare to avoid the pattern anyway, in case this code becomes a template for other credential checks.

🔒️ Proposed fix using constant-time comparison
+	"crypto/subtle"
+
 	c, ok := s.clients[r.Form.Get("client_id")]
-	if !ok || c.Secret != r.Form.Get("client_secret") {
+	if !ok || subtle.ConstantTimeCompare([]byte(c.Secret), []byte(r.Form.Get("client_secret"))) != 1 {
 		writeOAuthError(w, http.StatusUnauthorized, "invalid_client", "client authentication failed")
 		return
 	}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@local/idp/server/main.go` around lines 200 - 221, Update the client
authentication check in the request handler to compare c.Secret and the
submitted client_secret with crypto/subtle.ConstantTimeCompare, and apply the
same constant-time comparison to u.Password and the submitted password in the
password grant flow. Preserve the existing invalid_client and invalid_grant
responses and ensure comparisons handle differing secret lengths correctly.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@local/mqtt-client/pkg/auth/oauth2.go`:
- Around line 24-30: Normalize idpURL in GetOIDCTokenContext by removing
trailing slashes before constructing TokenURL, ensuring the result contains
exactly one separator before “token”. Add a test case covering an IDP URL that
ends with a slash and verify the request targets /token.

In `@local/mqtt-client/tests/functional/topic_auth_test.go`:
- Around line 47-65: Update the token setup in the test around the three
GetOIDCTokenContext calls to create one bounded context with a local timeout,
following the pattern used in nats_leaf_test.go. Pass that context to all three
token requests and ensure its cancellation is released appropriately.

---

Nitpick comments:
In `@local/idp/server/main.go`:
- Around line 200-221: Update the client authentication check in the request
handler to compare c.Secret and the submitted client_secret with
crypto/subtle.ConstantTimeCompare, and apply the same constant-time comparison
to u.Password and the submitted password in the password grant flow. Preserve
the existing invalid_client and invalid_grant responses and ensure comparisons
handle differing secret lengths correctly.

In `@local/infra/README.md`:
- Around line 103-124: Update the HTTPRoute YAML example in the README to
include exact path matches for /healthz and /jwks.json alongside the existing
/token match, matching the three endpoints configured in
local/idp/httproute.yaml.

In `@Makefile`:
- Line 44: Replace the compile-only command with execution of unit tests for the
IdP server, adding coverage for handleToken and mintJWT, including password and
client_credentials grant handling, credential parsing, and JWT claim/audience
selection. Ensure the Makefile target runs these tests rather than filtering all
test names out.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 406f78ae-550f-4792-a135-2dcc5bd96073

📥 Commits

Reviewing files that changed from the base of the PR and between c8fb031 and c35fe41.

⛔ Files ignored due to path filters (1)
  • local/idp/server/go.sum is excluded by !**/*.sum
📒 Files selected for processing (36)
  • .gitignore
  • Makefile
  • docs/getting-started.md
  • local/agent-gateway/charts/demoidp/.helmignore
  • local/agent-gateway/skaffold.fixtures.yaml
  • local/agent-gateway/skaffold.images.yaml
  • local/agent-gateway/tests/functional/auth_dispatch_test.go
  • local/agent-gateway/values/values.local-common.yaml
  • local/event-bus/k8s/local-dev-values.yaml
  • local/event-bus/skaffold.yaml
  • local/idp/chart/Chart.yaml
  • local/idp/chart/templates/demoidp.yaml
  • local/idp/chart/values.yaml
  • local/idp/httproute.yaml
  • local/idp/namespace.yaml
  • local/idp/prepare-secrets.sh
  • local/idp/secret-generator/credentials.yaml.tmpl
  • local/idp/secret-generator/kustomization.yaml
  • local/idp/server/Dockerfile
  • local/idp/server/go.mod
  • local/idp/server/main.go
  • local/idp/skaffold.yaml
  • local/infra/README.md
  • local/infra/keycloak/keycloak.yaml
  • local/infra/keycloak/operator/kustomization.yaml
  • local/infra/keycloak/realm-import.yaml
  • local/infra/keycloak/skaffold.yaml
  • local/infra/skaffold.yaml
  • local/mqtt-client/pkg/auth/oauth2.go
  • local/mqtt-client/pkg/auth/oauth2_test.go
  • local/mqtt-client/pkg/config/config.go
  • local/mqtt-client/tests/functional/nats_leaf_test.go
  • local/mqtt-client/tests/functional/topic_auth_test.go
  • local/scripts/cleanup.sh
  • local/scripts/prepare-dependencies.sh
  • local/validate.sh
💤 Files with no reviewable changes (8)
  • local/infra/keycloak/keycloak.yaml
  • local/agent-gateway/charts/demoidp/.helmignore
  • local/scripts/prepare-dependencies.sh
  • local/infra/skaffold.yaml
  • local/infra/keycloak/operator/kustomization.yaml
  • local/infra/keycloak/skaffold.yaml
  • local/infra/keycloak/realm-import.yaml
  • local/agent-gateway/skaffold.images.yaml

Comment thread local/mqtt-client/pkg/auth/oauth2.go
Comment thread local/mqtt-client/tests/functional/topic_auth_test.go Outdated
Signed-off-by: Frank Spitulski <fspitulski@nvidia.com>
@FrankSpitulski

Copy link
Copy Markdown
Collaborator Author

/ok to test 754e65c

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
local/idp/server/main_test.go (1)

116-124: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add coverage for /jwks.json and the kid header.

The test verifies the access token with signingKey.PublicKey directly. It never exercises the JWKS endpoint, so a broken or missing /jwks.json response stays undetected. Local callers depend on /jwks.json for verification.

Fetch the JWKS through s.routes(), then select the key by the kid header of the parsed token and use it for token.Claims. Consider also a case for a grant-type mismatch, which handleToken rejects with unauthorized_client and status 400.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@local/idp/server/main_test.go` around lines 116 - 124, Extend the
access-token test around the parsed token to fetch JWKS through s.routes(), read
the token’s kid header, select the matching public key, and pass that key to
token.Claims instead of signingKey.PublicKey. Add coverage for a grant-type
mismatch rejected by handleToken, asserting unauthorized_client with HTTP status
400.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@local/idp/server/main_test.go`:
- Around line 116-124: Extend the access-token test around the parsed token to
fetch JWKS through s.routes(), read the token’s kid header, select the matching
public key, and pass that key to token.Claims instead of signingKey.PublicKey.
Add coverage for a grant-type mismatch rejected by handleToken, asserting
unauthorized_client with HTTP status 400.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 85170127-08a8-4243-a55e-a7ca42113896

📥 Commits

Reviewing files that changed from the base of the PR and between c35fe41 and 754e65c.

📒 Files selected for processing (7)
  • Makefile
  • local/idp/server/main.go
  • local/idp/server/main_test.go
  • local/infra/README.md
  • local/mqtt-client/pkg/auth/oauth2.go
  • local/mqtt-client/pkg/auth/oauth2_test.go
  • local/mqtt-client/tests/functional/topic_auth_test.go
🚧 Files skipped from review as they are similar to previous changes (3)
  • local/idp/server/main.go
  • Makefile
  • local/infra/README.md

Signed-off-by: Frank Spitulski <fspitulski@nvidia.com>
@FrankSpitulski

Copy link
Copy Markdown
Collaborator Author

/ok to test 077d9ab

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@local/idp/chart/templates/secrets.yaml`:
- Around line 18-31: Update the generated secret reads in the template to
validate their inputs with Helm’s required check before base64 encoding: apply
this to both the config.json expression and the tls.key expression, using clear
missing-file messages so rendering fails when either generated file is absent.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 79066a12-9f71-447d-a2ad-732ad7c4234d

📥 Commits

Reviewing files that changed from the base of the PR and between 754e65c and 077d9ab.

📒 Files selected for processing (4)
  • .gitignore
  • local/idp/chart/templates/secrets.yaml
  • local/idp/prepare-secrets.sh
  • local/idp/skaffold.yaml
💤 Files with no reviewable changes (1)
  • local/idp/skaffold.yaml
🚧 Files skipped from review as they are similar to previous changes (2)
  • .gitignore
  • local/idp/prepare-secrets.sh

Comment thread local/idp/chart/templates/secrets.yaml Outdated
Signed-off-by: Frank Spitulski <fspitulski@nvidia.com>
@FrankSpitulski

Copy link
Copy Markdown
Collaborator Author

/ok to test 67d5d57

@FrankSpitulski
FrankSpitulski marked this pull request as ready for review July 31, 2026 03:44
@FrankSpitulski
FrankSpitulski requested a review from a team July 31, 2026 03:44
Signed-off-by: Frank Spitulski <fspitulski@nvidia.com>
@FrankSpitulski

Copy link
Copy Markdown
Collaborator Author

/ok to test 467f461

@FrankSpitulski
FrankSpitulski enabled auto-merge (squash) July 31, 2026 16:39
@FrankSpitulski
FrankSpitulski merged commit a2e09af into main Jul 31, 2026
22 checks passed
@FrankSpitulski
FrankSpitulski deleted the codex/refactor/dedup-local-idps branch July 31, 2026 18:53
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.

2 participants