GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — feat(oauth2): support non-mTLS token URLs and unbound actor tokens in IdentityPoolCredentials by macastelaz · Pull Request #14430 · googleapis/google-cloud-java Conversation
Contributor
SummaryAllows Context & RationaleIn #13955, client-side guardrails ( Changes
Verification
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
… IdentityPoolCredentials
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Code ReviewThis pull request removes the restriction requiring mTLS endpoints and transport configuration for actor token exchanges in IdentityPoolCredentials. Validation checks enforcing mTLS are removed, and unit tests are updated to verify that configuring actor tokens without mTLS now succeeds. Feedback is provided regarding a cross-platform issue in a new test where unescaped backslashes in a file path can cause JSON parsing failures on Windows.
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactionsUh oh!
There was an error while loading. Please reload this page. Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
lsirac
requested changes
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now that
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed the 3 duplicate
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great catch! Updated
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we assert
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we assert
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Can we use a lambda like
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replaced the anonymous inner class with
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Can we just use
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Contributor
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. …sonation caching, and custom transport deserialization
Contributor
Author
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
lsirac
reviewed
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This builder never sets an
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done — the test now sets a
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For streams serialized before
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done —
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done — declared
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit:
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done — setCredentialSource now clears x509Provider when the builder already has a different credential source, so a new source on a cloned builder builds its own provider. Added toBuilder_setCredentialSource_withNewSource_clearsCopiedX509Provider to cover it.
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: The constructor already checks that
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done — removed the inner
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Now that this test asserts
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done — renamed to
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: No test calls
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done — dropped
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Since
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done — added
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions…sport helpers, x509Provider cloning, and actor token tests
lsirac
requested changes
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When impersonation is configured and
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
|
| new MockExternalAccountCredentialsTransportFactory(); | ||
|
|
||
| Map<String, Object> certMap = new HashMap<>(); | ||
| certMap.put("use_default_certificate_config", true); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Because x509Provider is transient, readObject() constructs a new X509Provider with a null path when use_default_certificate_config is true, which throws IOException on getKeyStore() and hits the catch block before this.transportFactory is touched. That makes this test pass even if the shouldUseMtlsTransportFactory() check in readObject() is removed. Can we set use_default_certificate_config to false and point certificate_config_location to "testresources/mtls/certificate_config.json" so getKeyStore() succeeds during deserialization?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
The test now sets use_default_certificate_config to false and points
certificate_config_location at testresources/mtls/certificate_config.json, so
getKeyStore() succeeds during deserialization. I confirmed the test now fails if the
shouldUseMtlsTransportFactory() check in readObject() is bypassed.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| || transportFactory instanceof OAuth2Utils.DefaultHttpTransportFactory | ||
| || transportFactory.getClass() == MtlsHttpTransportFactory.class | ||
| || (transportFactory instanceof MtlsHttpTransportFactory | ||
| && !((MtlsHttpTransportFactory) transportFactory).hasKeyStore()); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Nit: OAuth2Utils.HTTP_TRANSPORT_FACTORY is already an instance of OAuth2Utils.DefaultHttpTransportFactory, and transportFactory.getClass() == MtlsHttpTransportFactory.class short-circuits the hasKeyStore() check since MtlsHttpTransportFactory has no subclasses. Can we simplify this to check transportFactory == null || transportFactory instanceof OAuth2Utils.DefaultHttpTransportFactory || transportFactory instanceof MtlsHttpTransportFactory?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Done, simplified to the null / DefaultHttpTransportFactory / MtlsHttpTransportFactory instanceof checks.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| tokenJson.put("subject_token", "testSubjectToken"); | ||
| OAuth2Utils.writeInputStreamToFile( | ||
| new ByteArrayInputStream(tokenJson.toPrettyString().getBytes(StandardCharsets.UTF_8)), | ||
| tokenFile.toString()); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Nit: Since this test only builds the credentials and never reads from disk, can we drop @TempDir and pass "credential.json" directly like serialize_deserialize_withCustomTransportFactoryAndCertConfig_preservesCustomFactory does at line 3300?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Done. I dropped @tempdir and the token-file write, and the test now passes "credential.json" directly.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
- Skip the per-cycle KeyStore snapshot on the impersonation path; reuse the lazily initialized KeyStore on the first direct cycle. - Simplify isDefaultOrMtlsTransportFactory. - Make the custom-factory serialization test load a real cert config. - Drop the unused TempDir from the toBuilder X509Provider test.
The new constructor and getHttpStatusCode() change the computed serialVersionUID, so instances serialized by released versions would fail to load. Same change as in PR googleapis#14212.
| return ks; | ||
| } | ||
| }; | ||
| ImpersonatedCredentials impersonated = Mockito.mock(ImpersonatedCredentials.class); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Mocking ImpersonatedCredentials without Mockito.withSettings().withoutAnnotations() fails on the JDK 8 CI job with ArrayStoreException: sun.reflect.annotation.EnumConstantNotPresentExceptionProxy because ImpersonatedCredentials is annotated with @NullMarked. Pass Mockito.withSettings().withoutAnnotations() here like IamUtilsTest does.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Updated to pass Mockito.withSettings().withoutAnnotations().
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| static boolean isDefaultOrMtlsTransportFactory(@Nullable HttpTransportFactory transportFactory) { | ||
| return transportFactory == null | ||
| || transportFactory instanceof OAuth2Utils.DefaultHttpTransportFactory | ||
| || transportFactory instanceof MtlsHttpTransportFactory; |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Using transportFactory instanceof MtlsHttpTransportFactory here causes shouldUseMtlsTransportFactory() to return true for caller supplied MtlsHttpTransportFactory subclasses, which overwrites custom subclasses with a plain MtlsHttpTransportFactory and conflicts with CustomMtlsHttpTransportFactory in #14212. Check transportFactory.getClass() == MtlsHttpTransportFactory.class || (transportFactory instanceof MtlsHttpTransportFactory && !((MtlsHttpTransportFactory) transportFactory).hasKeyStore()) instead so custom subclasses are preserved.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Updated isDefaultOrMtlsTransportFactory to check transportFactory.getClass() == MtlsHttpTransportFactory.class || (transportFactory instanceof MtlsHttpTransportFactory && !((MtlsHttpTransportFactory) transportFactory).hasKeyStore()), matching #14212.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| KeyStore freshKeyStore = this.x509Provider.getKeyStore(); | ||
| HttpTransportFactory retryTransportFactory = new MtlsHttpTransportFactory(freshKeyStore); | ||
| HttpTransportFactory retryTransportFactory = createMtlsTransportFactory(freshKeyStore); | ||
| if (!hasInitializedMtlsTransport()) { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Is if (!hasInitializedMtlsTransport()) ever true here? The lazy init check at the top of refreshAccessToken() already initializes this.transportFactory under the same this.x509Provider != null && shouldUseMtlsTransportFactory() condition before the STS call runs.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Good catch! Since this.transportFactory is already initialized at the start of refreshAccessToken() whenever !hasInitializedMtlsTransport() is true, this check in the catch block was unreachable. Removed
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| + " Service Connect (containing '.p.')."); | ||
| } | ||
| private boolean shouldUseMtlsTransportFactory() { | ||
| return this.useMtlsTransportFactory || isDefaultOrMtlsTransportFactory(this.transportFactory); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Can we add a test for the || isDefaultOrMtlsTransportFactory(this.transportFactory) deserialization fallback? Right now serializeAndDeserialize only runs on instances built on this branch where useMtlsTransportFactory is already true, so setting useMtlsTransportFactory to false via reflection before round tripping would cover older serialized streams.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Added CustomMtlsHttpTransportFactory and customMtlsHttpTransportFactorySubclass_preservedInConstructorAndRefresh_rebuiltOnDeserialization (matching #14212).
Passing .setHttpTransportFactory(new CustomMtlsHttpTransportFactory(ks)) sets useMtlsTransportFactory = false, and upon deserialization ServiceCredentials.readObject() instantiates a keyless CustomMtlsHttpTransportFactory() via newInstance(), exercising the || isDefaultOrMtlsTransportFactory(this.transportFactory) fallback branch in shouldUseMtlsTransportFactory().
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| @CanIgnoreReturnValue | ||
| public Builder setHttpTransportFactory(HttpTransportFactory transportFactory) { | ||
| super.setHttpTransportFactory(transportFactory); | ||
| this.useMtlsTransportFactory = isDefaultOrMtlsTransportFactory(transportFactory); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Can we add a test for credential.toBuilder().setHttpTransportFactory(customFactory).build() on a credential with a certificate config? Nothing currently tests that Builder.setHttpTransportFactory updates useMtlsTransportFactory so the custom transport factory is not overwritten by lazy mTLS init.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Added toBuilder_setHttpTransportFactory_withCustomFactoryAndCertConfig_preservesCustomFactory to verify that overriding the transport factory via toBuilder().setHttpTransportFactory(customFactory) preserves customFactory both on build() and across refreshAccessToken().
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
|
||
| assertNotNull(rebuilt.getX509Provider()); | ||
| assertNotSame(trackingProvider, rebuilt.getX509Provider()); | ||
| assertEquals(1, getKeyStoreCount.get()); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Can we also assert assertNotSame(credential.getTransportFactory(), rebuilt.getTransportFactory()) here to verify that setCredentialSource resets isClonedTransportInitialized?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Added assertNotSame(credential.getTransportFactory(), rebuilt.getTransportFactory()).
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| .setAudience("audience") | ||
| .setSubjectTokenType("urn:ietf:params:oauth:token-type:jwt") | ||
| .setTokenUrl("https://sts.googleapis.com/v1/token") | ||
| .setHttpTransportFactory(OAuth2Utils.HTTP_TRANSPORT_FACTORY) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Use MockExternalAccountCredentialsTransportFactory and STS_URL in both builders in this test instead of OAuth2Utils.HTTP_TRANSPORT_FACTORY with https://sts.googleapis.com/v1/token so a validation regression does not make a live network call.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Updated refreshAccessToken_withNullOrWhitespaceActorToken_throwsIOException to use MockExternalAccountCredentialsTransportFactory and STS_URL.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| * Sets the actor token supplier used for certificate-bound OAuth 2.0 token exchanges. The | ||
| * supplier provides an actor token representing the entity on whose behalf the subject is | ||
| * acting. | ||
| * Sets the actor token supplier used for OAuth 2.0 token exchanges. The supplier provides an |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
In RFC 8693 Section 2.1, the actor token represents the acting party that acts on behalf of the subject rather than the entity on whose behalf the subject is acting. Should we update this Javadoc wording to match?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
updated the Javadoc to match RFC 8693 Section 2.1 terminology
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
|
||
| @CanIgnoreReturnValue | ||
| public Builder setCredentialSource(IdentityPoolCredentialSource credentialSource) { | ||
| if (this.credentialSource != null && this.credentialSource != credentialSource) { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This clears x509Provider, but this.transportFactory still holds the old credential's keyed MtlsHttpTransportFactory, so switching to a credential source without a certificate config leaves the rebuilt credential pinned to the old client certificate. Should we also reset this.transportFactory to null here when useMtlsTransportFactory is true, and add a test for setting a new source without a certificate config?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Done - setCredentialSource now also resets this.transportFactory = null when this.useMtlsTransportFactory is true, and toBuilder_setCredentialSource_withNewSource_clearsCopiedX509Provider now verifies that switching to a credential source without a certificate config resets both x509Provider and MtlsHttpTransportFactory.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| + value.getClass().getName()); | ||
| } | ||
| return (String) value; | ||
| return extractField(fileContents, targetFieldName); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Since parseToken now delegates to extractField and rejects blank JSON token values for URL and single-token file sources too, can we add a test for a blank token field on parseToken or getSubjectToken? Right now only readTokens is covered.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Added parseToken_jsonFormat_emptyOrWhitespaceField_throws covering both supplier.getSubjectToken(null) and FileIdentityPoolSubjectTokenSupplier.parseToken(...) when the JSON token field is whitespace.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| validateMtlsEndpoint(getServiceAccountImpersonationUrl(), "serviceAccountImpersonationUrl"); | ||
| } | ||
| } | ||
| static boolean isDefaultOrMtlsTransportFactory(@Nullable HttpTransportFactory transportFactory) { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Nit: Nothing outside IdentityPoolCredentials calls isDefaultOrMtlsTransportFactory. Can we make it private static?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Done — changed isDefaultOrMtlsTransportFactory to private static.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| private @Nullable IdentityPoolActorTokenSupplier actorTokenSupplier; | ||
| private @Nullable String actorTokenType; | ||
| private @Nullable X509Provider x509Provider; | ||
| private @Nullable Boolean useMtlsTransportFactory; |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Nit: Can we declare this as private boolean useMtlsTransportFactory = true; instead of a nullable Boolean? It is only null on a fresh builder when setHttpTransportFactory was never called, where the constructor fallback always evaluates to true anyway.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Done — changed Builder.useMtlsTransportFactory to private boolean useMtlsTransportFactory = true; and simplified the constructor assignment to this.useMtlsTransportFactory = builder.useMtlsTransportFactory;.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| Mockito.mock(ImpersonatedCredentials.class, Mockito.withSettings().withoutAnnotations()); | ||
| Mockito.when(impersonated.refreshAccessToken()) | ||
| .thenReturn(new AccessToken("impersonatedAccessToken", null)); | ||
| List<HttpTransportFactory> factoriesSeenByImpersonation = new java.util.ArrayList<>(); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Nit: Can we use new ArrayList<>() here since java.util.ArrayList is already imported at line 71?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Updated to new ArrayList<>()
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
…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>
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.