Add OAuth2 client credentials grant support - #305
Open
murthy-chelankuri wants to merge 3 commits into
Open
Conversation
grafana/grafana#119576 proposed this for core Grafana before the Prometheus datasource was extracted into this repo; recreating it here per the maintainer's request on that PR. Adds a new "OAuth2 Client Credentials" auth method to the datasource config editor (client ID/secret, token URL, scopes), and a backend middleware that exchanges those for a bearer token via golang.org/x/oauth2/clientcredentials and attaches it to outgoing Prometheus requests, refreshing as needed. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Contributor
Signed commits report3 of 3 commits between
This repository requires all commits to be signed. See GitHub docs on commit signature verification. |
|
|
1 similar comment
|
|
…expiry The oauth2.Transport used for the client-credentials grant only refreshed its cached token once its local expiry timer passed. If the auth server invalidated a token earlier (revocation, secret rotation, clock skew) or a token response omitted expires_in, requests kept sending the stale token and failing indefinitely with no recovery short of a datasource reload. Replace it with a round tripper that, on a 401, forces a fresh token fetch and retries the request once with the new token. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
…pdown The Auth component from @grafana/plugin-ui defaults visibleMethods to [BasicAuth, OAuthForward, NoAuth, ...customMethods], which puts "No Authentication" ahead of the OAuth2 Client Credentials method instead of after it. Pass visibleMethods explicitly to keep NoAuth last; any future auth method needs to be added to this list too. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
pkg/promlib/middleware/oauth2_client_credentials.go) that exchanges those credentials for a bearer token viagolang.org/x/oauth2/clientcredentialsand attaches it to outgoing Prometheus requests, with automatic caching/refresh.Test plan
go build/go vet/go test ./...pass in both the root module and thepkg/promlibmodule, including new middleware and settings-validation testsnpm run typecheckandnpm run lintcleannpm run test:ci— full suite (1080 tests) passes, including new config-editor testsmage -vbackend build andnpm run buildfrontend build both succeed/validate-pluginpackaging check — no new errors/warnings introduceddocker composedev stack) and a mock OAuth2 client-credentials token endpoint:grant_type=client_credentialsoauth2: "invalid_client", proving the request is genuinely gated on a valid token