Skip to content

feat: Support add GrantType and JWT Bearer options in OAuth2 config#8565

Open
dongjiang1989 wants to merge 1 commit into
prometheus-operator:mainfrom
kubeservice-stack:update-oauth2
Open

feat: Support add GrantType and JWT Bearer options in OAuth2 config#8565
dongjiang1989 wants to merge 1 commit into
prometheus-operator:mainfrom
kubeservice-stack:update-oauth2

Conversation

@dongjiang1989

@dongjiang1989 dongjiang1989 commented May 11, 2026

Copy link
Copy Markdown
Member

Description

Describe the big picture of your changes here to communicate to the maintainers why we should accept this pull request.

ref: prometheus/common#862 and prometheus/alertmanager#2735

  • Add GrantType field to the OAuth2 configuration, supporting both client_credentials (default) and urn:ietf:params:oauth:grant-type:jwt-bearer (RFC 7523)
  • Add new OAuth2 fields: clientCertificateKey, clientCertificateKeyId, signatureAlgorithm, iss, audience, and claims
  • Add validation logic for grant type, signature algorithm, and field mutual exclusivity
  • Update CRD schemas (jsonnet, json, yaml bundle) to reflect the new fields
  • TODO: Requires Prometheus >= v3.9.0; not yet supported by Alertmanager

If you're contributing for the first-time, check our contribution guidelines.

Type of change

What type of changes does your code introduce to the Prometheus operator? Put an x in the box that apply.

  • CHANGE (fix or feature that would cause existing functionality to not work as expected)
  • FEATURE (non-breaking change which adds functionality)
  • BUGFIX (non-breaking change which fixes an issue)
  • ENHANCEMENT (non-breaking change which improves existing functionality)
  • NONE (if none of the other choices apply. Example, tooling, build system, CI, docs, etc.)

Verification

Please check the Prometheus-Operator testing guidelines for recommendations about automated tests.

Changelog entry

Please put a one-line changelog entry below. This will be copied to the changelog file during the release process.

add `GrantType` and `JWT Bearer` options in OAuth2 config

@dongjiang1989
dongjiang1989 requested a review from a team as a code owner May 11, 2026 07:57
@dongjiang1989 dongjiang1989 reopened this May 11, 2026
@dongjiang1989 dongjiang1989 reopened this May 11, 2026

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

All fields which say Only used when grantType is set to "urn:ietf:params:oauth:grant-type:jwt-bearer" can be enforced by CEL validations.

Comment thread pkg/apis/monitoring/v1/types.go Outdated
Comment thread pkg/apis/monitoring/v1/types.go Outdated
Comment thread pkg/apis/monitoring/v1/types.go Outdated
Comment thread pkg/apis/monitoring/v1/types.go Outdated
Comment thread pkg/apis/monitoring/v1/types.go Outdated
Comment thread pkg/apis/monitoring/v1/types.go Outdated
Comment thread pkg/apis/monitoring/v1/types.go
Comment thread pkg/apis/monitoring/v1/types.go
Comment thread pkg/apis/monitoring/v1/types.go
Comment thread pkg/apis/monitoring/v1/types.go
@dongjiang1989

dongjiang1989 commented May 13, 2026

Copy link
Copy Markdown
Member Author

Changed

  • Add CEL checker
  • Remove xxFile support
  • add ProxyConfig.Validate()

@dongjiang1989
dongjiang1989 force-pushed the update-oauth2 branch 4 times, most recently from f9ba4d5 to 4e0094c Compare May 13, 2026 10:25
@dongjiang1989

Copy link
Copy Markdown
Member Author

@simonpasquier PTAL, thanks

Comment thread pkg/apis/monitoring/v1/types.go
Comment thread pkg/apis/monitoring/v1/types.go Outdated
Comment thread pkg/apis/monitoring/v1/types.go Outdated
Comment thread pkg/apis/monitoring/v1/types.go Outdated
Comment thread pkg/apis/monitoring/v1/types.go Outdated
Comment thread pkg/apis/monitoring/v1/types.go
Comment thread pkg/apis/monitoring/v1/types.go Outdated
Comment thread pkg/apis/monitoring/v1/types.go Outdated
Comment thread pkg/apis/monitoring/v1/types.go
Comment thread pkg/assets/store.go Outdated
Comment thread pkg/assets/store.go Outdated
Comment thread pkg/assets/store.go Outdated
Comment thread pkg/alertmanager/amcfg.go
Comment thread pkg/prometheus/promcfg.go
@dongjiang1989

Copy link
Copy Markdown
Member Author

Thanks @simonpasquier

Please re-check, thanks

Comment thread pkg/apis/monitoring/v1/types.go Outdated
Comment thread pkg/apis/monitoring/v1/types.go
Comment thread pkg/apis/monitoring/v1/types.go Outdated
dongjiang1989 added a commit to kubeservice-stack/prometheus-operator that referenced this pull request Jul 2, 2026
Add two new CEL validation rules to the OAuth2 CRD:
- clientSecret is required when grantType is 'ClientCredentials' or empty
- clientCertificateKey is required when grantType is 'JWTBearer'

Update documentation to reflect Alertmanager >= v0.30.0 support for
JWTBearer grant type (previously stated as "not supported").

Add e2e test cases for the new CEL rules.

Address review feedback from simonpasquier on PR prometheus-operator#8565.
@dongjiang1989

Copy link
Copy Markdown
Member Author

Thanks @simonpasquier Please re-check it

dongjiang1989 added a commit to kubeservice-stack/prometheus-operator that referenced this pull request Jul 22, 2026
Add two new CEL validation rules to the OAuth2 CRD:
- clientSecret is required when grantType is 'ClientCredentials' or empty
- clientCertificateKey is required when grantType is 'JWTBearer'

Update documentation to reflect Alertmanager >= v0.30.0 support for
JWTBearer grant type (previously stated as "not supported").

Add e2e test cases for the new CEL rules.

Address review feedback from simonpasquier on PR prometheus-operator#8565.
Add GrantType field to OAuth2 struct with support for client_credentials
and jwt-bearer grant types. Add CEL validations to enforce required
fields based on grant type:
- client_credentials: requires clientSecret
- jwt-bearer: requires clientCertificateKey
- default (no grantType): requires clientSecret

Also add TokenURL validation annotations (pattern + minLength) and
corresponding unit/e2e tests.

Signed-off-by: dongjiang <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants