Commit 75172cf
fix(idtoken): avoid double impersonation in tokenSourceFromBytes (#3576)
This PR fixes a parallel double impersonation bug in the `idtoken` package.
The library incorrectly does not use the `source_credentials` subfield in
the JSON struct when constructing the inner client, and instead passes the
entire credential JSON. This causes the lower layers (`htransport.NewClient`)
to correctly (but unexpectedly for this context) build an authenticated HTTP
client that is already impersonated, leading to self-impersonation when
calling `generateIdToken`.
This PR fixes the issue by extracting or recreating non-impersonated
credentials before calling `impersonate.IDTokenSource`, avoiding the double
wrap.
Note: This PR does not add new unit tests for the call sequence because
`impersonate.IDTokenSource` hardcodes the IAM credentials endpoint, making it
impossible to intercept with a mock client or server without modifying that
package. The existing unit tests in this package only cover type validation
and do not successfully execute the full impersonation flow due to this same
limitation.
closes: #2301
Co-authored-by: Alex Hong <9397363+hongalex@users.noreply.github.com>1 parent 2de1a5a commit 75172cf
1 file changed
Lines changed: 49 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
231 | 231 | | |
232 | 232 | | |
233 | 233 | | |
234 | | - | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
235 | 247 | | |
236 | 248 | | |
237 | 249 | | |
| |||
241 | 253 | | |
242 | 254 | | |
243 | 255 | | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
244 | 292 | | |
245 | 293 | | |
246 | 294 | | |
| |||
0 commit comments