Skip to content

feat(router): re-fetch the cached OAuth token when the control plane holds a newer secret (PRO-5947) - #7478

Merged
tipped73 merged 3 commits into
masterfrom
feat/pro-5947-oauth-token-eviction-newer-secret
Oct 20, 2026
Merged

tipped73 merged 3 commits into
masterfrom
feat/pro-5947-oauth-token-eviction-newer-secret

Conversation

@tipped73

@tipped73 tipped73 commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Description

When a customer re-authorizes a destination, config-backend stores a new secret and bumps the account's secretVersion, but a pod keeps using the token it cached until it expires or a delivery fails with the refresh-token class. The inactive (403) class never re-asks (INT-6859; spec rudderlabs/rudder-specs#193, LLD 3.9).

The handler now re-fetches a cached token when the control plane's version for the account is strictly newer than the token's own, which it parses from the token response. A token with version 0 is never superseded, and the re-fetch is a plain fetch, not a forced refresh.

How the version reaches the handler, with no new goroutine and no process-wide state. This is the design from #7492, cherry-picked here as its author's commit; the second commit only adds tests and doc lines:

  • Router and regulation worker: every job carries a fresh destination from their own config loop, with the account attached, so the transport copies GetSecretVersion(flow) into the token params.
  • Batch router: its async managers keep their destination until the revision changes, which a re-authorization does not do. So the batch router fills an account-to-version map inside its existing config loop and hands it to them as a SecretVersionProvider. The map is filled from the delivery account config-backend attaches to each async destination.
  • Handler: compares the cached version against the larger of the two.

Tests: GetSecretVersion; the transport passing the version for both flows; the batch router provider; the handler suite (fetch once then serve from cache for the router param, the provider, a stale snapshot and a caller newer than the provider; cached when same version, older config, version 0 or no version; cold cache keeps the response's version); and the response parsing. Build, vet, golangci-lint and go test -race ./services/oauth/... are green. On mini, bumping the account's version while the pod held its token made the branch log the superseded token and fetch once; the stock image kept the old token.

Related: #7477 touches the same handler file; no conflicts today.

Linear Ticket

https://linear.app/rudderstack/issue/PRO-5947/rudder-server-re-fetch-the-cached-oauth-token-when-the-control-plane

Security

  • The code changed/added as part of this pull request won't create any security issues with how the software is being used.

@tipped73 tipped73 changed the title feat(oauth): re-fetch the cached token when the control plane holds a newer secret feat(router): re-fetch the cached OAuth token when the control plane holds a newer secret (PRO-5947) Oct 14, 2026
@tipped73
tipped73 force-pushed the feat/pro-5947-oauth-token-eviction-newer-secret branch from dfdebc4 to aa15a93 Compare October 14, 2026 08:18
@codecov

codecov Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 84.21053% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.07%. Comparing base (9baa89f) to head (cf62e2a).

Files with missing lines Patch % Lines
...ter/batchrouter/asyncdestinationmanager/manager.go 20.00% 4 Missing ⚠️
...yncdestinationmanager/bing-ads/audience/manager.go 0.00% 1 Missing ⚠️
...ionmanager/bing-ads/offline-conversions/manager.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7478      +/-   ##
==========================================
+ Coverage   85.05%   85.07%   +0.02%     
==========================================
  Files         632      633       +1     
  Lines       62877    62905      +28     
==========================================
+ Hits        53479    53518      +39     
+ Misses       9395     9384      -11     
  Partials        3        3              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@tipped73
tipped73 force-pushed the feat/pro-5947-oauth-token-eviction-newer-secret branch 2 times, most recently from d275148 to a3b7464 Compare October 15, 2026 08:56

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

I'd rather we avoid the package-level SecretVersions registry, since package-level state is always risky: it doesn't fit components that start and stop at runtime, it leaks, and it holds resources that nobody needs. In this example, WithReauthEviction subscribes to the backend config and starts a goroutine on context.Background() the first time a handler is built. Nothing ever stops it, and every distinct BackendConfig adds another goroutine and map entry for the life of the process. That's also why five test fixtures had to start allowing a Subscribe they never asked for.

Furthermore, we don't need it for the router path. The latest version of the destination always carries the account's version: enrichDestinationWithAccounts copies the config's account (including secretVersion) onto DeliveryAccount / DeleteAccount. Router jobs look up their destination in the current destinationsMap, and the regulation-worker does the same per job. So the transport can pass SecretVersion in OAuthTokenParams, exactly as it already passes AccountID.

Async destinations are the exception. Their manager keeps the destination it was built with, and the batch router rebuilds it only when the destination's RevisionID changes.

So I propose a hybrid:

Router and regulation-worker: the version travels with the request.
Batch router: fills a small account → version map in the config loop it already runs, and hands it to the OAuth handlers of async destinations through asyncManagerFactory / WithSecretVersions.
Handler: compares the cached token's version against max(params.SecretVersion, provider.SecretVersion(accountID)).

Example implementation: #7492.

@tipped73

Copy link
Copy Markdown
Contributor Author

@atzoum cherry-picked your commit from #7492

One fix on top. The batch router was building its account version map from the enriched delivery account, and enrichment skips disabled destinations. But the batch router keeps polling pending uploads for disabled destinations too, with whatever token the manager holds, so those accounts were never tracked and a stale token would survive a re-authorization there. The map now reads from ConfigT.Accounts, which covers every account regardless of the destination's state. There is a test for it that fails on the draft and passes with the change.

@tipped73
tipped73 requested a review from atzoum October 20, 2026 04:30
Comment thread router/batchrouter/handle_lifecycle.go Resolved
@tipped73
tipped73 force-pushed the feat/pro-5947-oauth-token-eviction-newer-secret branch 2 times, most recently from abc260c to 1a3563f Compare October 20, 2026 07:42
@tipped73
tipped73 requested a review from atzoum October 20, 2026 08:19
@atzoum atzoum mentioned this pull request Oct 20, 2026
1 task done

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

@tipped73 please rebase the branch

@atzoum
atzoum self-requested a review October 20, 2026 13:19
atzoum and others added 2 commits October 20, 2026 18:58
…holds a newer secret

Router and transport callers pass the account's secretVersion from the request's destination; the
batch router keeps its destinations' versions from its config loop and hands them to the OAuth
handlers of async destinations, whose destination snapshot only changes with the revision.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

🔒 Scanned for secrets using gitleaks 8.30.1
…e parsing test

The transport test returned a []byte from DoAndReturn where the mock asserts
json.RawMessage, so the secret read as nil and the request failed inside the
transport without the test noticing. Also restores the token-response parsing
test, adds two handler cases, and documents the provider contract.
@tipped73
tipped73 force-pushed the feat/pro-5947-oauth-token-eviction-newer-secret branch from 1a3563f to d73a11f Compare October 20, 2026 13:28
master now denies new ginkgo imports (#7502); same cases and assertions.
@tipped73
tipped73 merged commit 742779d into master Oct 20, 2026
112 of 115 checks passed
@tipped73
tipped73 deleted the feat/pro-5947-oauth-token-eviction-newer-secret branch October 20, 2026 17:14
tipped73 added a commit that referenced this pull request Oct 21, 2026
…AUTH_STATUS_INACTIVE (PRO-5946) (#7477)

# Description

The Integration Accounts Auth Alerts feature (spec:
rudderlabs/rudder-specs#193, LLD 3.1) needs two things from the OAuth
metrics that they do not provide today: which destination a token
failure belongs to, and a count for the "account inactive" class, which
never emitted anything.

What changes:

- `oauth_action_request`, `oauth_action_request_sent` and
`oauth_action_proactive_token_refresh` get a `destinationId` tag. The
two latency histograms keep their per-account labels: a token call is
per account, and nothing reads latency per destination.
- `AUTH_STATUS_INACTIVE` is now counted on `oauth_action_request`. The
transport still decides the class from the destination's response and
still answers 400, but it reports it through a new
`OAuthHandler.ReportAuthStatusInactive`, so the metric stays with the
handler. The breaker wrapper forwards the report without touching its
circuits.
- Fixes a latent bug: the handler's flow was pinned to `delivery`, so
the regulation worker's token metrics were labelled as deliveries. Added
`WithRudderFlow`, and `NewOAuthHttpClient` now passes its own flow.
- `oauthStats`, `oauthStatsHandler`, `newOAuthStatsHandler` and
`oauthV2StatPrefix` are unexported, and the `id` field is renamed to
`accountID`. The emitted tag is still `id`.

No new metric names, no delivery behaviour change. Counter cardinality
goes from one series per (account, reason) to one per (account,
destination, reason): 322 series for 84 accounts on US multi-tenant
today.

Known and out of scope: the response classifiers take the first
recognised category, so a `REFRESH_TOKEN` entry ahead of an inactive one
hides it; Bing Ads uploads through the SDK's own HTTP client, so an
inactive verdict from Bing never reaches this counter.

Tests: tag sets, the handler method for both flows, the breaker
pass-through with the circuit open, a transport table (delivery and
delete inactive, inactive without an augmenter, `REFRESH_TOKEN` and
classifier errors emit nothing), and a delete-flow client built the
production way. Build, vet, golangci-lint and `go test -race
./services/oauth/...` are green, and both fixes were checked red without
them. On mini the inactive sample shows up with all its labels.

Related: #7478 (re-fetch the token on re-authorization) touches the same
handler file.

## Linear Ticket


https://linear.app/rudderstack/issue/PRO-5946/rudder-server-destinationid-tag-on-the-oauth-counters-and-count-auth

## Security

- [x] The code changed/added as part of this pull request won't create
any security issues with how the software is being used.
itsmihir pushed a commit that referenced this pull request Oct 26, 2026
🤖 I have created a release *beep* *boop*
---


##
[1.92.0-rc.1](v1.91.0...v1.92.0-rc.1)
(2026-10-26)


### Features

* **processor:** pyt test-pod deployer sets PYT_MODE=test
([#7506](#7506))
([a050ed6](a050ed6))
* **processor:** reset the per-workspace pyt client on 421
([#7494](#7494))
([83db4d6](83db4d6))
* **router:** re-fetch the cached OAuth token when the control plane
holds a newer secret (PRO-5947)
([#7478](#7478))
([742779d](742779d))
* **router:** tag oauth_action counters with destinationId and count
AUTH_STATUS_INACTIVE (PRO-5946)
([#7477](#7477))
([0e15eb4](0e15eb4))


### Bug Fixes

* flaky TestDrainConfigRoutine failing with "database is closed"
([#7489](#7489))
([9baa89f](9baa89f))


### Miscellaneous

* block new ginkgo/gomega usage in tests
([#7502](#7502))
([e1c9d38](e1c9d38))
* bump dependency versions
([#7522](#7522))
([1067ff4](1067ff4))
* enforce errors.AsType and point CLAUDE.md at AGENTS.md
([#7521](#7521))
([5c7e088](5c7e088))
* go 1.27.3
([#7516](#7516))
([3c240a3](3c240a3))
* migrate debugger, services, async destination and utils tests from
ginkgo to testify
([#7503](#7503))
([1a8c85a](1a8c85a))
* migrate gateway, rsources, reporting, batchrouter and manager tests
from ginkgo to testify
([#7507](#7507))
([ffdd505](ffdd505))
* remove ginkgo and gomega from tests
([#7508](#7508))
([d3e7e0f](d3e7e0f))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: rudderstack-github-actions[bot] <236995729+rudderstack-github-actions[bot]@users.noreply.github.com>
itsmihir pushed a commit that referenced this pull request Oct 27, 2026
🤖 I have created a release *beep* *boop*
---


##
[1.92.0](v1.91.0...v1.92.0)
(2026-10-26)


### Features

* **processor:** pyt test-pod deployer sets PYT_MODE=test
([#7506](#7506))
([a050ed6](a050ed6))
* **processor:** reset the per-workspace pyt client on 421
([#7494](#7494))
([83db4d6](83db4d6))
* **router:** re-fetch the cached OAuth token when the control plane
holds a newer secret (PRO-5947)
([#7478](#7478))
([742779d](742779d))
* **router:** tag oauth_action counters with destinationId and count
AUTH_STATUS_INACTIVE (PRO-5946)
([#7477](#7477))
([0e15eb4](0e15eb4))


### Bug Fixes

* flaky TestDrainConfigRoutine failing with "database is closed"
([#7489](#7489))
([9baa89f](9baa89f))


### Miscellaneous

* block new ginkgo/gomega usage in tests
([#7502](#7502))
([e1c9d38](e1c9d38))
* bump dependency versions
([#7522](#7522))
([1067ff4](1067ff4))
* enforce errors.AsType and point CLAUDE.md at AGENTS.md
([#7521](#7521))
([5c7e088](5c7e088))
* go 1.27.3
([#7516](#7516))
([3c240a3](3c240a3))
* migrate debugger, services, async destination and utils tests from
ginkgo to testify
([#7503](#7503))
([1a8c85a](1a8c85a))
* migrate gateway, rsources, reporting, batchrouter and manager tests
from ginkgo to testify
([#7507](#7507))
([ffdd505](ffdd505))
* remove ginkgo and gomega from tests
([#7508](#7508))
([d3e7e0f](d3e7e0f))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: rudderstack-github-actions[bot] <236995729+rudderstack-github-actions[bot]@users.noreply.github.com>
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.

3 participants