GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — test(auth): enable mTLS and actor_token WIF integration tests by default by macastelaz · Pull Request #14554 · googleapis/google-cloud-java

Conversation

@macastelaz

@macastelaz macastelaz commented Sep 30, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Summary

Enables the 4 mTLS + actor_token Workload Identity Federation integration tests in ITWorkloadIdentityFederationTest to run by default in CI without requiring GOOGLE_API_CERTIFICATE_CONFIG or external Secret Manager secrets:

  1. Default mTLS Certificate Config Fallback: Falls back to the checked-in testresources/mtls/certificate_config.json (test_cert.pem / test_key.pem) when GOOGLE_API_CERTIFICATE_CONFIG is unset, removing the assumeTrue skip.
  2. Signed OIDC JWTs with cnf.x5t#S256 and may_act: Targets oidc-jwt-1 (OIDC_JWT_AUDIENCE) and uses the GOOGLE_APPLICATION_CREDENTIALS service account private key (whose public key is registered in oidc-jwt-1's jwksJson) to sign OIDC JWTs containing RFC 8705 certificate thumbprint binding (cnf.x5t#S256) and delegation (may_act) claims.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

gemini-code-assist[bot] reacted with eyes emoji
All reactions
  • 👀 1 reaction
macastelaz added 30 commits September 17, 2026 03:17
@macastelaz
feat(oauth2): implement IAM impersonation mTLS transport pinning and …
dadeda6
…401 recovery

- Pin mTLS HttpTransportFactory across multi-step STS and IAM token exchanges so both requests use the exact same certificate snapshot within a single refresh cycle.
- Add 401 Unauthorized recovery with automatic certificate reload from X509Provider and single-retry coordination in IdentityPoolCredentials and ImpersonatedCredentials.
- Preserve custom non-default HttpTransportFactory instances when X509Provider is configured.
- Add comprehensive unit tests across IdentityPoolCredentialsTest, ImpersonatedCredentialsTest, and OAuth2UtilsTest.
@macastelaz
fix(oauth2): enforce CLOUD_PLATFORM_SCOPE on impersonation source cre…
5cc87e0
…dentials and address review findings

- Explicitly scope inner sourceCredentials to CLOUD_PLATFORM_SCOPE in ExternalAccountCredentials.buildImpersonatedCredentials and ImpersonatedCredentials.refreshAccessToken so STS issues tokens authorized to call IAM generateAccessToken even when downstream target scopes are configured via createScoped.
- Ensure public no-arg ImpersonatedCredentials.refreshAccessToken delegates without overriding source credential transport settings.
- Preserve custom actorTokenSupplier in IdentityPoolCredentials.Builder copy constructor when credentialSource is present.
- Ensure HTTP response is closed in a finally block in ImpersonatedCredentials.refreshAccessToken.
- Attach initial 401 exception as suppressed when the 401 retry attempt fails in IdentityPoolCredentials.refreshWithRetry.
- Add unit tests in IdentityPoolCredentialsTest and ImpersonatedCredentialsTest covering scoped impersonation, custom actorTokenSupplier preservation, and retry exception chaining.
@macastelaz
fix(oauth2): address PR review feedback for IAM mTLS transport pinning
73c5a0a
@macastelaz
fix(oauth2): address post-review audit edge cases for mTLS pinning
8034525
@macastelaz
fix(oauth2): preserve exact class check for MtlsHttpTransportFactory …
17aae1f
…in IdentityPoolCredentials
@macastelaz
test(oauth2): add coverage for custom MtlsHttpTransportFactory subcla…
f2d752e
…ss and FILE cert pinning
@macastelaz
fix(oauth2): annotate refreshAccessToken(HttpTransportFactory) with @…
a5e69ed
…InternalExtensionOnly
@macastelaz
test(oauth2): add mTLS in-process socket tests and live GCP WIF integ…
031a594
…ration tests

- Add MtlsPipelineLocalTest providing hermetic in-process socket tests over JDK HttpsServer with client certificate authentication (peer cert verification, 401 retry with cert rotation, concurrent refreshes, atomic token read, IAM impersonation mTLS transport pinning, and 401 retry with fresh cert).
- Add ITWorkloadIdentityFederationTest extensions for certificate-bound workload + actor token JSON config and programmatic mTLS token suppliers covering both direct STS and Service Account Impersonation.
- Fix OAuthException to safely handle null HTTP error response content.
@macastelaz
test(oauth2): escape Windows path backslashes in MtlsPipelineLocalTes…
fdfea4f
…t JSON templates
@macastelaz
test(oauth2): ensure executor shutdown and temp file cleanup in mTLS …
4266196
…integration tests
@macastelaz
test(oauth2): verify real Cert A -> Cert B rotation on 401 and harden…
7ac9e63
… OAuthException
@macastelaz
fix(oauth2): address review feedback on mTLS transport pinning and 40…
13e8be0
…1 recovery
@macastelaz
fix(oauth2): address PR googleapis#14212 round 2 review feedback
44ca6d7
@macastelaz
Merge branch 'cert-bound-oauth-iam-pinning' into cert-bound-oauth-int…
ffe2b6d
…egration-tests
@macastelaz
fix: address PR googleapis#14220 review comments on OAuthException, M…
08e026b
…tlsPipelineLocalTest, and ITWorkloadIdentityFederationTest
@macastelaz
fix(oauth2): pin leaf subject token from KeyStore, cache STS token wi…
9313161
…th mTLS impersonation, and retry torn cert rotations
@macastelaz
fix(oauth2): support mTLS pinning for standalone ImpersonatedCredenti…
6e5f7fe
…als and retry bare IOExceptions on split cert writes
@macastelaz
fix(oauth2): handle mid-rotation invalid_grant, cached STS 401 retry,…
ddd5ea8
… and single cert read on impersonated refresh
@macastelaz
fix(auth): harden concurrency and nullability in ImpersonatedCredenti…
b47ab2a
…als and CertificateIdentityPoolSubjectTokenSupplier
@macastelaz
Merge branch 'cert-bound-oauth-iam-pinning' into cert-bound-oauth-int…
fb1a9c8
…egration-tests
@macastelaz
fix(oauth2): address PR googleapis#14220 round 2 review feedback
22556ff
@macastelaz
style(oauth2): remove unused body variable in MtlsPipelineLocalTest
849c4e5
@macastelaz
fix(oauth2): address review feedback on cached STS token retry and mT…
1f062f2
…LS pinning

- Replace the ThreadLocal 401 signal with CachedStsTokenRejectedException.
- Only clear the cached STS token on IAM failure when this refresh used it and
  it is still the cached token.
- Scope the external source before taking the pinned impersonation path, and
  clear any access token copied by createScoped().
- Simplify isRetryableTransportException and drop redundant retry checks.
- Pass the cycle transport factory through for Aws/Pluggable impersonation.
- Javadoc and comment clarifications.
- Add tests for concurrent STS cache handling, standalone
  ImpersonatedCredentials 401 retries, transport factory upgrade, source
  scoping, isInvalidGrantException, and Aws/Pluggable cycle factories.
@macastelaz
Merge remote-tracking branch 'fork/cert-bound-oauth-iam-pinning' into…
d28d8c8
… cert-bound-oauth-integration-tests
@macastelaz
test(oauth2): assert pinned KeyStore per refresh cycle in cert rotati…
4e06ff0
…on test
@macastelaz
test(oauth2): address review feedback on mTLS pipeline and WIF integr…
231e06c
…ation tests
@macastelaz
Merge branch 'cert-bound-oauth-iam-pinning' into cert-bound-oauth-int…
ad119fd
…egration-tests
@macastelaz
Merge branch 'cert-bound-oauth-iam-pinning' into cert-bound-oauth-int…
45aa304
…egration-tests
@macastelaz
fix(oauth2): address follow-up review feedback on transport visibilit…
d5317c2
…y and tests
@macastelaz
test(oauth2): skip mTLS WIF integration tests when GOOGLE_API_CERTIFI…
f96ff1a
…CATE_CONFIG is unset
macastelaz added 5 commits September 25, 2026 20:42
@macastelaz
test(oauth2): exercise public programmatic mTLS path in WIF integrati…
683b765
…on and local pipeline tests
@macastelaz
fix(oauth2): fall back to response content when OAuth error field has…
efa9d9e
… no usable description
@macastelaz
fix(auth): address PR googleapis#14212 follow-up review comments
091a91b
- Clear the copied access token before building the impersonation source credentials, so a rebuilt source (e.g. after deserialization) mints a fresh STS token instead of sending the cached service account token to IAM.
- Pin serialVersionUID for CertificateIdentityPoolSubjectTokenSupplier and OAuthException to their released computed values so previously serialized instances still load.
@macastelaz
Merge remote-tracking branch 'fork/cert-bound-oauth-iam-pinning' into…
395e3af
… cert-bound-oauth-integration-tests

# Conflicts:
#	google-auth-library-java/oauth2_http/java/com/google/auth/oauth2/OAuthException.java
#	google-auth-library-java/oauth2_http/javatests/com/google/auth/oauth2/OAuthExceptionTest.java
@macastelaz
test(auth): enable mTLS and actor_token WIF integration tests by default
f8c15f6
@macastelaz
macastelaz requested review from a team as code owners September 30, 2026 02:33
gemini-code-assist[bot]
gemini-code-assist Bot reviewed Sep 30, 2026
View reviewed changes

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces robust support for per-cycle mTLS transport pinning, certificate rotation, and automatic retry recovery across both STS and IAM token exchanges in Google Workload Identity Federation. Key changes include extracting leaf certificates directly from pinned KeyStores, caching intermediate STS tokens in ImpersonatedCredentials to prevent redundant exchanges, and implementing a retry mechanism in IdentityPoolCredentials that reloads rotated certificates upon encountering 401 Unauthorized or 400 invalid_grant errors. Additionally, helper utilities for comparing KeyStore entries and parsing structured OAuth exceptions were added, along with a comprehensive hermetic integration test suite (MtlsPipelineLocalTest) to validate the entire mTLS pipeline. There are no review comments, so I have no feedback to provide.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
macastelaz added 2 commits September 30, 2026 03:18
@macastelaz
test(auth): refine leaf cert extraction, assertions, and WIF setup sc…
8788dc2
…ript
@macastelaz
chore(auth): merge origin/oauth2-bound-tokens into enable-mtls-wif-in…
55226e2
…tegration-tests
@macastelaz
macastelaz requested review from lsirac and nbayati October 15, 2026 19:47
nbayati
nbayati approved these changes Oct 16, 2026
View reviewed changes

@nbayati nbayati left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a small nit.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread ...rary-java/oauth2_http/javatests/com/google/auth/oauth2/ITWorkloadIdentityFederationTest.java Outdated
assumeTrue(
certConfigPath != null && !certConfigPath.isEmpty(),
"Skipping mTLS test: GOOGLE_API_CERTIFICATE_CONFIG env variable is not set.");
if (certConfigPath == null || certConfigPath.isEmpty()) {

@nbayati nbayati Oct 16, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Cloudtop, GOOGLE_API_CERTIFICATE_CONFIG is set by default to /etc/gcloud/certificate_config.json (which only has a pkcs11 config for device certificates and no workload section.

Since these tests are not testing environment discovery, could we drop getMtlsCertificateConfigPath() and use DEFAULT_MTLS_CERT_CONFIG_PATH directly so they run hermetically everywhere?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@macastelaz macastelaz Oct 16, 2026

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 1e02910. Dropped getMtlsCertificateConfigPath() and updated the tests to use DEFAULT_MTLS_CERT_CONFIG_PATH directly.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@macastelaz
test(auth): use DEFAULT_MTLS_CERT_CONFIG_PATH directly in WIF mTLS ITs
1e02910
@macastelaz
macastelaz merged commit 47374cf into googleapis:oauth2-bound-tokens Oct 16, 2026
274 of 277 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@macastelaz macastelaz mentioned this pull request Oct 27, 2026
feat(oauth2): support certificate-bound OAuth2 tokens and mTLS rotation for Workload Identity Federation #14781
Merged
macastelaz added a commit that referenced this pull request Oct 30, 2026
@macastelaz @jinseopkim0
@blakeli0 @sakthivelmanii @gemini-code-assist
feat(oauth2): support certificate-bound OAuth2 tokens and mTLS rotati…
dcb29b0
…on for Workload Identity Federation (#14781)

### Summary

Merges the `oauth2-bound-tokens` feature branch into `main`, adding
end-to-end support for certificate-bound OAuth 2.0 tokens and automatic
mTLS certificate rotation in Workload Identity Federation
(`IdentityPoolCredentials` and `ImpersonatedCredentials`).

#### Included Feature Branch PRs
- #13955 — `feat(oauth2): Extract actor tokens for cert-bound OAuth2 STS
exchange`
- #14212 — `feat(oauth2): implement IAM impersonation mTLS transport
pinning and 401 recovery`
- #14220 — `test(oauth2): add mTLS in-process socket tests and live GCP
WIF integration tests`
- #14430 — `feat(oauth2): support non-mTLS token URLs and unbound actor
tokens in IdentityPoolCredentials`
- #14554 — `test(auth): enable mTLS and actor_token WIF integration
tests by default`

#### Key Capabilities
- **Actor Token Support for Hybrid Certificate-Bound WIF
(`IdentityPoolActorTokenSupplier`,
`FileIdentityPoolSubjectTokenSupplier`)**:
- Supports extracting both a primary X.509 leaf certificate subject
token and a secondary file-sourced `actor_token` (text or JSON via
`actor_token_field_name` and `actor_token_type`) for STS token exchange.
- Caches file-sourced tokens using file metadata (`mtime`, size, file
key) and JWT `exp` claims with a 5-minute expiration margin to avoid
redundant disk reads.
- **Per-Cycle mTLS Transport Pinning & Certificate Rotation
(`IdentityPoolCredentials`, `ImpersonatedCredentials`,
`MtlsHttpTransportFactory`)**:
- Snapshots the `KeyStore` once per refresh cycle so leaf certificate
extraction, the STS token exchange, and downstream IAM Service Account
impersonation (`generateAccessToken` / `generateIdToken`) share the
exact same certificate and private key snapshot.
- Automatically recovers from `401 Unauthorized`, OAuth `invalid_grant`,
and transient TLS/KeyStore load failures during non-atomic split
cert/key writes by reloading the `KeyStore` once and retrying when a
certificate change is detected (`OAuth2Utils.hasCertificateChanged`).
- Supports standalone `ImpersonatedCredentials` configured with
`MtlsProvider` as well as delegated `ImpersonatedCredentials` chains.
- **Test Coverage**:
- Comprehensive unit tests across `IdentityPoolCredentialsTest`,
`ImpersonatedCredentialsTest`,
`FileIdentityPoolSubjectTokenSupplierTest`,
`MtlsHttpTransportFactoryTest`, `OAuth2UtilsTest`, and
`OAuthExceptionTest`.
- In-process mTLS socket tests (`MtlsPipelineLocalTest`) and live GCP
Workload Identity Federation integration tests
(`ITWorkloadIdentityFederationTest`).
  
  ### Manual & Live Verification
End-to-end live GCP and real-TLS socket fault-injection testing was
executed against `oauth2-bound-tokens` (`65d592bd783`):
- **Full verification report, logs, and test harness**:
https://paste.googleplex.com/6755399436525184
- **Scenarios verified (15 / 15 passed)**:
1. **Live Direct mTLS STS Exchange (`sts.mtls.googleapis.com`)**:
File-based JSON `subject_token` + `actor_token` with RFC 8705
`cnf.x5t#S256` certificate binding and atomic single-supplier file
reads.
2. **Serialization Round-Trip (`readObject`) + `createScoped()`**:
Deserialization of `IdentityPoolCredentials` with mTLS state
reconstruction across multiple live STS refresh cycles.
3. **Full 3-Hop Live mTLS Chain (`STS mTLS` -> `IAM Impersonation mTLS`
-> `GCS mTLS`)**: Cert-bound workload + actor token exchange at
`sts.mtls.googleapis.com`, service account impersonation at
`iamcredentials.mtls.googleapis.com`, and bucket access at
`storage.mtls.googleapis.com` (`HTTP 200`).
4. **Programmatic Builder (`Suppliers` + `MtlsHttpTransportFactory`)
Live 3-Hop mTLS**: End-to-end `STS mTLS` -> `IAM mTLS` -> `GCS mTLS`
(`HTTP 200`) and verification of `OAuth2Utils` mTLS helpers
(`hasMtlsKeyStore`, `isKeylessMtlsTransportFactory`,
`isDefaultOrMtlsTransportFactory`).
5. **Non-mTLS Unbound Actor Token over Public Endpoints**: Unbound
`subject_token` + `actor_token` exchange over public
`sts.googleapis.com` -> `iamcredentials.googleapis.com` ->
`storage.googleapis.com` (`HTTP 200`).
6. **X.509 Certificate Workload Identity Federation**: Leaf certificate
extraction and `trust_chain` handshake against `sts.mtls.googleapis.com`
via `CertificateIdentityPoolSubjectTokenSupplier`.
7. **`PluggableAuthCredentials` Impersonation Transport
Reconciliation**: Rebuilding `PluggableAuthCredentials` with a custom
`HttpTransportFactory` and verifying both STS and
`ImpersonatedCredentials` use the reconciled transport against live STS,
IAM, and GCS (`HTTP 200`).
8. **Review Feedback Edge Cases**:
`FileIdentityPoolSubjectTokenSupplier` TEXT format subject/actor token
handling and `OAuthException.createFromJsonErrorResponse` parsing across
live STS 400 errors, nested `google.rpc.Status` JSON, and empty-body
HTTP error fallbacks.
9. **Real-TLS Socket Fault Injection**: Mid-cycle cert rotation pinning
between STS and IAM, `401 Unauthorized` IAM recovery (both fresh and
cached STS token eviction), `400 invalid_grant` STS cert rotation
recovery, and 8-thread concurrent mTLS refresh.

---------

Co-authored-by: Jin Seop Kim <[email protected]>
Co-authored-by: Blake Li <[email protected]>
Co-authored-by: Sakthivel Subramanian <[email protected]>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@nbayati nbayati nbayati approved these changes
@lsirac lsirac Awaiting requested review from lsirac
+1 more reviewer
@gemini-code-assist gemini-code-assist[bot] gemini-code-assist[bot] left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@macastelaz @nbayati
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.