feat(broker): OAuth-refresh auth type for upstream credentials#170
Open
mvanhorn wants to merge 1 commit into
Open
feat(broker): OAuth-refresh auth type for upstream credentials#170mvanhorn wants to merge 1 commit into
mvanhorn wants to merge 1 commit into
Conversation
Adds a new "oauth" auth type alongside bearer, basic, api-key, custom, and passthrough. The stored credential is an OAuth2 refresh token; the broker exchanges it for an access token at request time, caches the access token until just before expiry, and injects it as a bearer Authorization. Three catalog templates ship: GitHub OAuth, Google OAuth, and Microsoft Identity. Closes Infisical#149.
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
Adds a new
oauthauth type alongside the existingbearer,basic,api-key,custom, andpassthrough. The stored credential is an OAuth2 refresh token; the broker exchanges it for an access token at request time, caches the access token until just before expiry, and injects it as a bearer Authorization. Three catalog templates ship:github-oauth,google-oauth,microsoft-oauth.Fixes #149.
Type of change
Test plan
make test)New tests:
internal/broker/broker_test.gocovers oauth validation: required fields, https-only token endpoint, UPPER_SNAKE_CASE credential keys, rejection of unexpected fields on oauth, and rejection of oauth fields on other auth typesinternal/brokercore/oauth_test.gocovers the access-token cache: fresh fetch, cache hit, cache expiry (TTL =expires_inminus 60s), and non-200 responses mapping toErrOAuthRefreshFailedinternal/brokercore/credential_test.gocovers the inject path end-to-end with an injected fake token sourceManual testing:
agent-vault catalog --json | jq '.[] | select(.auth_type=="oauth")'and verified the three new templates appear with correcttoken_endpointvaluesvault service add --auth-type oauth ...rejectshttp://endpoints, rejects lowercase credential keys, and accepts a valid configurationvault service listround-trips the new fields (client_id, token_endpoint, scopes)Security checklist
Threat-model notes:
https://with a non-empty host (validated at config time)UPPER_SNAKE_CASE(existing convention, enforced viavalidateCredentialKey)proposal_hintso the operator can replace the revoked credentials via the existing proposal flowgolang.org/x/oauth2was deliberately not pulled in; the refresh-token grant is one stdlibnet/httpPOST)AI was used for assistance.