Repository navigation
Commit 44dbda5
authored
fix(bigtable): pass unpatched credentials to Cloud Monitoring metrics exporter (#15163)
## Problem
Since commit `b54cc8af5d1` (#2579),
`BigtableClientContext.patchCredentials(...)` unconditionally wraps
`ServiceAccountJwtAccessCredentials` (returned by
`GoogleCredentialsProvider` when ADC uses a service account JSON key) in
`JwtCredentialsWithAudience` locked to `settings.getJwtAudience()`
(defaulting to `https://bigtable.googleapis.com/`).
`JwtCredentialsWithAudience.getRequestMetadata(URI ignored, ...)`
intentionally ignores the requested URI so Bigtable data calls always
use the configured Bigtable JWT audience. However,
`BigtableClientContext.create(...)` called `patchCredentials(builder)`
before reading `builder.getCredentialsProvider().getCredentials()`, and
then passed those already-patched Bigtable-audience-locked credentials
into `MetricsImpl.createBuiltinOtel(...)` ->
`BigtableCloudMonitoringExporter` (and `GoogleCloudMetricExporter`).
When exporting client-side metrics to `monitoring.googleapis.com`, Cloud
Monitoring rejects the Bigtable-audience JWT with `UNAUTHENTICATED`.
## Solution
- Resolve unpatched `credentials` once from
`builder.getCredentialsProvider().getCredentials()` before patching.
- Update `patchCredentials(String audience, @nullable Credentials
credentials)` to eagerly validate the audience URI and return patched
`dataCredentials` (`JwtCredentialsWithAudience`) for
`ServiceAccountJwtAccessCredentials` (or `credentials` unchanged
otherwise).
- Pass the **unpatched** `credentials` to
`MetricsImpl.createBuiltinOtel(...)` (via a `@InternalApi("Visible for
testing") @VisibleForTesting` `BuiltinOtelFactory` seam) so Cloud
Monitoring requests emit JWTs whose `aud` matches the requested
monitoring service URI.
- Pass the **patched** `dataCredentials` to `FixedCredentialsProvider`
(for `ClientContext`), `BigtableChannelPrimer`, and `ShimImpl`.
- Deprecate the accidentally exposed 3-arg
`BigtableClientContext.create(EnhancedBigtableStubSettings, Tagger,
StatsRecorder)` test overload, expose the 4-arg `create(...)` overload
with `@InternalApi("Visible for testing")` and `@VisibleForTesting`, and
migrate OpenCensus test callers (`BigtableTracerCallableTest`,
`MetricsTracerTest`) to the 4-arg overload.
## Testing
- Added `BigtableClientContextTest` (JUnit 5) verifying:
- `ServiceAccountJwtAccessCredentials` passed to `BuiltinOtelFactory`
remain unpatched and emit a JWT with `aud =
https://monitoring.googleapis.com/google.monitoring.v3.MetricService`,
while data credentials are wrapped in `JwtCredentialsWithAudience` and
emit `aud = https://bigtable.googleapis.com/` (and custom `jwtAudience`
overrides apply only to data credentials).
- Non-JWT credentials are shared without wrapping and `getCredentials()`
is called once.
- `NoCredentialsProvider` passes `null` credentials to both metrics and
data contexts.
- Invalid `jwtAudience` still eagerly throws `IllegalStateException`.
- Updated `BigtableDataClientFactoryTest` to verify
`credentialsProvider.getCredentials()` is now called once instead of
twice.
- Updated `BigtableTracerCallableTest` and `MetricsTracerTest` to use
the annotated 4-arg `BigtableClientContext.create(...)` test overload.
- Ran `mvn -f java-bigtable/pom.xml -pl
proto-google-cloud-bigtable-v2,grpc-google-cloud-bigtable-v2,proto-google-cloud-bigtable-admin-v2,grpc-google-cloud-bigtable-admin-v2,google-cloud-bigtable
test
-Dtest=BigtableClientContextTest,BigtableDataClientFactoryTest,EnhancedBigtableStubTest,JwtCredentialsWithAudienceTests,BigtableTracerCallableTest,MetricsTracerTest
-Dsurefire.failIfNoSpecifiedTests=false` (64 tests run, 0 failures, 0
errors; Checkstyle, Error Prone, and Animal Sniffer clean).1 parent 12edf41 commit 44dbda5
5 files changed
Lines changed: 312 additions & 42 deletions
File tree
- java-bigtable/google-cloud-bigtable/src
- main/java/com/google/cloud/bigtable/data/v2/stub
- test/java/com/google/cloud/bigtable/data/v2
- internal/csm/opencensus
- stub
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
22 | 21 | | |
23 | 22 | | |
24 | 23 | | |
| |||
42 | 41 | | |
43 | 42 | | |
44 | 43 | | |
| 44 | + | |
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| |||
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
78 | 93 | | |
79 | 94 | | |
80 | | - | |
| 95 | + | |
| 96 | + | |
81 | 97 | | |
82 | 98 | | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
83 | 104 | | |
84 | 105 | | |
85 | 106 | | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
86 | 118 | | |
87 | 119 | | |
88 | 120 | | |
| |||
91 | 123 | | |
92 | 124 | | |
93 | 125 | | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | 126 | | |
98 | 127 | | |
99 | 128 | | |
100 | 129 | | |
101 | 130 | | |
102 | | - | |
| 131 | + | |
| 132 | + | |
103 | 133 | | |
104 | 134 | | |
105 | 135 | | |
| |||
122 | 152 | | |
123 | 153 | | |
124 | 154 | | |
125 | | - | |
| 155 | + | |
126 | 156 | | |
127 | 157 | | |
128 | 158 | | |
| |||
165 | 195 | | |
166 | 196 | | |
167 | 197 | | |
168 | | - | |
| 198 | + | |
169 | 199 | | |
170 | 200 | | |
171 | 201 | | |
| |||
202 | 232 | | |
203 | 233 | | |
204 | 234 | | |
205 | | - | |
| 235 | + | |
206 | 236 | | |
207 | 237 | | |
208 | 238 | | |
| |||
307 | 337 | | |
308 | 338 | | |
309 | 339 | | |
310 | | - | |
311 | | - | |
312 | | - | |
313 | | - | |
314 | | - | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
315 | 343 | | |
316 | 344 | | |
317 | 345 | | |
318 | 346 | | |
319 | 347 | | |
320 | 348 | | |
321 | | - | |
322 | | - | |
323 | | - | |
324 | | - | |
325 | | - | |
326 | | - | |
327 | | - | |
328 | | - | |
329 | | - | |
330 | | - | |
331 | 349 | | |
332 | | - | |
| 350 | + | |
333 | 351 | | |
334 | 352 | | |
335 | 353 | | |
336 | | - | |
337 | | - | |
| 354 | + | |
338 | 355 | | |
339 | 356 | | |
340 | 357 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
204 | 204 | | |
205 | 205 | | |
206 | 206 | | |
207 | | - | |
208 | | - | |
209 | | - | |
| 207 | + | |
210 | 208 | | |
211 | 209 | | |
212 | 210 | | |
| |||
296 | 294 | | |
297 | 295 | | |
298 | 296 | | |
299 | | - | |
300 | | - | |
301 | | - | |
| 297 | + | |
302 | 298 | | |
303 | 299 | | |
304 | 300 | | |
| |||
341 | 337 | | |
342 | 338 | | |
343 | 339 | | |
344 | | - | |
345 | | - | |
346 | | - | |
| 340 | + | |
347 | 341 | | |
348 | 342 | | |
349 | 343 | | |
| |||
388 | 382 | | |
389 | 383 | | |
390 | 384 | | |
391 | | - | |
392 | | - | |
393 | | - | |
| 385 | + | |
394 | 386 | | |
395 | 387 | | |
396 | 388 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| 38 | + | |
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
| |||
135 | 136 | | |
136 | 137 | | |
137 | 138 | | |
138 | | - | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
139 | 143 | | |
140 | 144 | | |
141 | 145 | | |
| |||
156 | 160 | | |
157 | 161 | | |
158 | 162 | | |
159 | | - | |
| 163 | + | |
| 164 | + | |
160 | 165 | | |
161 | 166 | | |
162 | 167 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
| 37 | + | |
37 | 38 | | |
38 | 39 | | |
39 | 40 | | |
| |||
131 | 132 | | |
132 | 133 | | |
133 | 134 | | |
134 | | - | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
135 | 139 | | |
136 | 140 | | |
137 | 141 | | |
| |||
0 commit comments