Skip to content

fix(authserver): bind stored upstream tokens to provider issuer - #7344

Open
aloneangel45 wants to merge 3 commits into
stacklok:mainfrom
aloneangel45:fix/upstream-token-issuer-binding
Open

aloneangel45 wants to merge 3 commits into
stacklok:mainfrom
aloneangel45:fix/upstream-token-issuer-binding

Conversation

@aloneangel45

Copy link
Copy Markdown
Contributor

Summary

  • Record the issuing upstream authority (OIDC issuer URL or pure OAuth 2.0 token endpoint URL) on storage.UpstreamTokens (Issuer) across both memory and Redis storage backends (json:"issuer,omitempty").
  • Refuse upstream token refresh in upstreamTokenRefresher, refresh-grant validation in upstreamRefreshGuard, refresh-token carry-forward in maybeCarryForwardRefreshToken, and chain satisfaction in nextMissingUpstream when a stored row's recorded Issuer does not match the upstream's currently configured authority—preventing stale IdP A refresh tokens from being disclosed to a repointed IdP B.
  • Preserve stamp-on-first-match compatibility for pre-upgrade legacy rows that carry an empty Issuer (refreshes against the current provider and stamps its issuer onto the stored row).
  • Add unit and storage tests covering refresher rejection without contacting the repointed IdP, legacy-row stamping then repoint rejection, refresh grant guard invalid_grant refusal, callback/device carry-forward refusal, unexpired chain-leg invalidation, and Redis persistence.

Fixes #7333

Type of change

  • Bug fix

Test plan

  • Unit tests (targeted runs: go test ./pkg/authserver/server/handlers ./pkg/authserver/storage ./pkg/authserver/upstream ./pkg/auth/upstreamtoken and go test -count=1 ./pkg/authserver -run "TestUpstreamTokenRefresher|TestUpstreamRefreshGuard|TestRefreshGrant|TestProviderIssuer|TestRejectedRefreshes|TestNewServer|TestUpdateUpstreamClientCredentials|TestIntegration")
  • E2E tests (task test-e2e — not run)
  • Linting / static check (gofmt -w on changed files, go vet ./pkg/authserver/... ./pkg/auth/...; golangci-lint not installed locally)

Changes

File Change
pkg/authserver/storage/types.go Add Issuer to UpstreamTokens, ErrIssuerMismatch, and UpstreamIssuerMatches
pkg/authserver/storage/memory.go, redis.go Clone and persist UpstreamTokens.Issuer (backwards-compatible omitempty)
pkg/authserver/upstream/oauth2.go, oidc.go Add optional IssuerIdentifier capability and ProviderIssuer helper without widening OAuth2Provider
pkg/authserver/server_impl.go, server/handlers/handler.go Carry configured authority on NamedUpstream into refresher, guard, and chain evaluation
pkg/authserver/server/handlers/callback.go, device_verification.go Record Issuer on initial write and enforce UpstreamIssuerMatches in maybeCarryForwardRefreshToken
pkg/authserver/refresher.go, refresh_grant_guard.go Reject issuer mismatches before contacting IdP, handle ErrIssuerMismatch as non-transient refusal, and stamp legacy rows on first match
pkg/authserver/*issuer*_test.go Regression tests for refresher, guard, handlers, provider capability, and miniredis round-trip

Special notes for reviewers

  • Existing upstream.OAuth2Provider interface is untouched; IssuerIdentifier is an optional capability mirroring IdleConnectionCloser.
  • All targeted pkg/authserver/... and pkg/auth/upstreamtoken suites pass after final edits; in the unfiltered pkg/authserver run, only pre-existing Windows clock-resolution test TestDelegatedAgentFlow failed on reused client-assertion jti.

@jhrozek

jhrozek commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Please follow CONTRIBUTING.md - ask to be assigned to an issue before working on it. This ensures the work is actually important for the project at the moment and that maintainers have the capacity to review.

@aloneangel45

Copy link
Copy Markdown
Contributor Author

Sorry about that - I missed asking for assignment on #7333 before opening the PR. Could you assign #7333 to me if it's still available and useful, or let me know if I should close this PR?

@aloneangel45

Copy link
Copy Markdown
Contributor Author

Resolved merge conflicts with upstream/main in dceb5a7:

  • Kept upstream/main's NamedUpstream.Issuer + SubjectClaim fields intact for provider-identity binding (upstreamIdentityBinding / validateNamedUpstreams).
  • Stored token-binding authority on NamedUpstream.TokenIssuer (with NamedUpstream.EffectiveIssuer() returning TokenIssuer or falling back to upstream.ProviderIssuer(Provider)), and updated pkg/authserver/server/handlers/issuer_binding_test.go to use TokenIssuer.

Verified locally:

  • go test -count=1 ./pkg/authserver/server/handlers/... ./pkg/authserver/storage/... ./pkg/authserver/upstream/... (passed)
  • go test -count=1 ./pkg/authserver -run "TestUpstreamIssuerBinding|TestRefresh|Issuer" (passed)
  • go vet ./pkg/authserver/... (clean)

…issuer-binding

# Conflicts:
#	pkg/authserver/server/handlers/handler.go
#	pkg/authserver/server_impl.go

This branch has not been deployed

No deployments
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.

Refresh tokens are sent to a repointed upstream's new IdP

2 participants