Skip to content

Add namespace-scoped Kubernetes configuration and generated CRDs - #5

Merged
NiklasRosenstein merged 3 commits into
developfrom
codex/kubernetes-provider
Sep 12, 2026
Merged

NiklasRosenstein merged 3 commits into
developfrom
codex/kubernetes-provider

Conversation

@NiklasRosenstein

@NiklasRosenstein NiklasRosenstein commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Allow oauthrelay to consume Upstream and Relay Kubernetes custom resources from one configurable namespace, defaulting to the pod namespace in-cluster. CR and Secret metadata watches trigger complete validated snapshots; failed updates retain the last valid configuration. Enable discovery with OAUTHRELAY_PROVIDER_KUBERNETES=true.

  • Resolve same-namespace secretKeyRef values alongside the existing inline, environment, file, and AWS sources. Periodic refresh handles sources without Kubernetes events.
  • Generate namespaced CRDs from shared Rust types and schemars through oauthrelay crds. Commit the generated bundle, check regeneration in CI, and validate schemas and provider behavior against Kubernetes 1.35.
  • Include a read-only RBAC/deployment example and provider documentation. File and SSM accept optional metadata.namespace without changing resource identities or URL keys.

Compatibility: PrivateKeyJwt URL sources must use jwksUrl; jwks accepts typed inline RSA, EC, or OKP public keys. This replaces URL strings under jwks across all providers. The default build includes the Kubernetes feature, and the declared Rust minimum is 1.89.

Test plan

  • Passed workspace tests with all features, including OAuth regression and documentation-example tests, plus focused configuration/provider tests after final refinements.
  • Passed Clippy with all targets/features, the feature matrix, formatting, actionlint, and the documentation build.
  • Verified JSON schema and CRD regeneration matches the committed artifacts.
  • Passed the disposable Kind CI harness: CRD establishment, valid/invalid authentication and JWKS schemas, key-field preservation, namespace isolation under the example RBAC, Secret rotation, and resource deletion. Test clusters were removed.

View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

Read Upstream and Relay custom resources and referenced Secrets from one
namespace, with watch-driven updates and complete validated snapshots.
Generate structural CRDs from shared Rust types and validate them in CI
against a disposable Kubernetes API server.

Require jwksUrl for PrivateKeyJwt URL sources and typed jwks for inline
keys so both forms have structural schemas. File and SSM accept optional
namespace metadata without changing resource identities.
Keep the installable CRD bundle under deploy/ and point generation, CI
drift checks, and Kubernetes integration tests at that artifact.

Copilot AI 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.

🔵 Needs a closer look

It is a large, security-sensitive change (namespace RBAC, secret resolution, auth key material, a breaking PrivateKeyJwt config change) introducing a new crate and generated CRD/schema artifacts that cannot be fully verified without the toolchain, so it warrants final human review.

Pull request overview

This PR adds a namespace-scoped Kubernetes configuration provider to oauthrelay. It introduces a new oauthrelay-provider-kubernetes crate that watches Upstream/Relay custom resources and Secret metadata in one namespace, resolves secretKeyRef values, and publishes complete validated snapshots (retaining the last valid config on failure). It also generates installable, structural CRDs from shared Rust types via a new oauthrelay crds command, and reworks PrivateKeyJwt to use typed inline jwks (RSA/EC/OKP) or a separate jwksUrl.

Changes:

  • New read-only, single-namespace Kubernetes provider (OAUTHRELAY_PROVIDER_KUBERNETES=true) with watches, periodic refresh, and secretKeyRef resolution; precedence File → SSM → Kubernetes.
  • Typed public JWKS model (PublicJwkSet/PublicJwk) replacing the untyped jwks value; PrivateKeyJwt now requires exactly one of jwks (inline) or jwksUrl (breaking change, documented).
  • Generated namespaced CRD bundle plus CI checks (crds:check, disposable Kind harness), RBAC/deployment example, and provider documentation.
File summaries
File Description
crates/oauthrelay-provider-kubernetes/src/lib.rs New provider: CR discovery, watches, store, secret resolution, CRD YAML
crates/oauthrelay-provider-kubernetes/src/schema.rs Converts serde union schemas into structural OpenAPI for CRDs
crates/oauthrelay-provider-kubernetes/src/tests.rs Mock-based unit tests for reads, watches, refresh, RBAC errors
crates/oauthrelay-provider-kubernetes/tests/kubernetes.rs Integration test against a Kind cluster (validation, isolation, rotation)
crates/oauthrelay-provider-kubernetes/Cargo.toml New crate manifest and dependencies
crates/oauthrelay-core/src/jwks.rs New typed public JWK/JWKS model
crates/oauthrelay-core/src/config.rs jwks/jwksUrl split, Metadata.namespace, SecretKeyRef, redacted secret Debug, tests
crates/oauthrelay-core/src/lib.rs Exposes the new jwks module
crates/oauthrelay-secret-resolver/src/lib.rs Adds Kubernetes secret resolution dispatch
crates/oauthrelay-provider-ssm/src/lib.rs Treats SecretKeyRef as a non-AWS source
crates/oauthrelay/src/main.rs Adds crds command and Kubernetes provider wiring
crates/oauthrelay/Cargo.toml Adds default kubernetes feature and deps
Cargo.toml / Cargo.lock Adds kube/k8s-openapi/serde-saphyr; MSRV bump to 1.89
docs/public/oauthrelay.crds.yaml Generated CRD bundle
docs/public/oauthrelay.schema.json Regenerated JSON schema
docs/* , README.md, SPEC.md Kubernetes provider docs and reference updates
deploy/kubernetes.yaml Read-only RBAC + Deployment/Service example
mise.toml, .github/workflows/ci.yml, tests/kubernetes/run.py CRD checks and Kind-based CI harness
Review details
  • Files reviewed: 25/26 changed files
  • Comments generated: 0
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@NiklasRosenstein
NiklasRosenstein merged commit 9cee754 into develop Sep 12, 2026
8 checks passed
@NiklasRosenstein
NiklasRosenstein deleted the codex/kubernetes-provider branch September 12, 2026 22:20
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