Commit fab1ebd
authored
Fix double-caching of OAuth tokens in Azure client secret credentials (#1573)
## Summary
Fixes the double-caching of OAuth tokens in Azure client secret
credentials (#1549) and unifies the internal token source infrastructure
on `auth.TokenSource`.
## Why
`AzureClientSecretCredentials.tokenSourceFor` called
`clientcredentials.Config{}.TokenSource(ctx)`, which returns an
`oauth2.ReuseTokenSource` with a hardcoded 10-second `expiryDelta`. This
token source was then wrapped in `azureReuseTokenSource` (a
`cachedTokenSource`) and again in `serviceToServiceVisitor` (another
`cachedTokenSource`). The inner `ReuseTokenSource` swallowed proactive
refresh attempts from the outer layers -- it kept returning its cached
token until only ~10 seconds remained before expiry, defeating the
20-minute async refresh window and causing bursts of 401s at token
expiry.
This is the same class of bug as #1550 (M2M OAuth), but in the Azure
client secret path.
## What changed
### Interface changes
None. All changes are to unexported types and functions.
### Behavioral changes
- `AzureClientSecretCredentials` no longer double-caches tokens. Each
call to the underlying token source results in an HTTP request to the
token endpoint; caching is purely controlled by the outer
`azureReuseTokenSource` and `serviceToServiceVisitor` layers.
### Internal changes
- **`azureHostResolver` interface** now returns `auth.TokenSource`
instead of `oauth2.TokenSource`, and no longer takes a `context.Context`
parameter. Context is passed per-call via `Token(ctx)`.
- **`serviceToServiceVisitor` and `refreshableVisitor`** now accept
`auth.TokenSource` directly, removing the `authconv.AuthTokenSource`
wrapping at call sites.
- **`azureReuseTokenSource` and `wrap`** operate on `auth.TokenSource`
instead of `oauth2.TokenSource`, eliminating the `authconv` round-trip.
- **`AzureClientSecretCredentials`**: removed the duplicate
`tokenSourceFor` (which used `clientcredentials.Config.TokenSource` with
inner caching). The former `authTokenSourceFor` -- which calls
`clientcredentials.Config.Token(ctx)` without inner caching -- is now
the sole `tokenSourceFor`.
- **`AzureCliCredentials.tokenSourceFor`**: returns an
`auth.TokenSource` that creates a fresh `azureCliTokenSource` per call,
properly threading the caller's context.
- **`AzureMsiCredentials.tokenSourceFor`**: wraps
`NewAzureMsiTokenSource` with `authconv.AuthTokenSource`.
- **GCP and M2M credential providers**: callers wrap their
`oauth2.TokenSource` with `authconv.AuthTokenSource` before passing to
the visitor functions.
## How is this tested?
- `TestAzureClientSecretCredentials_tokenSourceFor_noCaching`: calls
`Token()` N times and asserts N HTTP requests hit the token endpoint.
Fails when the fix is reverted (inner caching collapses N calls into 1).
- `TestAzureClientSecretCredentials_Configure`: happy-path test for the
full Azure client secret credential flow.
- All existing `config/` tests pass.
Signed-off-by: Ubuntu <renaud.hartert@databricks.com>1 parent 603757b commit fab1ebd
File tree
3 files changed
+125
-10
lines changed- config
3 files changed
+125
-10
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
12 | | - | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
23 | 28 | | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
33 | 41 | | |
34 | 42 | | |
35 | 43 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
0 commit comments