-
Notifications
You must be signed in to change notification settings - Fork 247
feat: Add support for mTLS authentication via X.509 certificates #1736
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This commit introduces a new credential source type, 'certificate', enabling the use of mTLS for authentication with X.509 certificates. It includes the necessary logic to load certificate configurations (both explicit paths and default locations) and establish an mTLS-enabled transport.
oauth2_http/java/com/google/auth/oauth2/IdentityPoolCredentialSource.java
Show resolved
Hide resolved
oauth2_http/java/com/google/auth/oauth2/IdentityPoolCredentialSource.java
Show resolved
Hide resolved
oauth2_http/java/com/google/auth/oauth2/IdentityPoolCredentialSource.java
Outdated
Show resolved
Hide resolved
oauth2_http/java/com/google/auth/oauth2/IdentityPoolCredentialSource.java
Outdated
Show resolved
Hide resolved
oauth2_http/java/com/google/auth/oauth2/CertificateIdentityPoolSubjectTokenSupplier.java
Outdated
Show resolved
Hide resolved
oauth2_http/java/com/google/auth/oauth2/CertificateIdentityPoolSubjectTokenSupplier.java
Show resolved
Hide resolved
oauth2_http/java/com/google/auth/oauth2/CertificateIdentityPoolSubjectTokenSupplier.java
Show resolved
Hide resolved
oauth2_http/javatests/com/google/auth/oauth2/IdentityPoolCredentialsTest.java
Show resolved
Hide resolved
oauth2_http/java/com/google/auth/oauth2/IdentityPoolCredentialSource.java
Outdated
Show resolved
Hide resolved
oauth2_http/java/com/google/auth/oauth2/IdentityPoolCredentials.java
Outdated
Show resolved
Hide resolved
oauth2_http/java/com/google/auth/oauth2/IdentityPoolCredentials.java
Outdated
Show resolved
Hide resolved
oauth2_http/java/com/google/auth/oauth2/IdentityPoolCredentials.java
Outdated
Show resolved
Hide resolved
oauth2_http/java/com/google/auth/oauth2/IdentityPoolCredentials.java
Outdated
Show resolved
Hide resolved
oauth2_http/java/com/google/auth/oauth2/IdentityPoolCredentials.java
Outdated
Show resolved
Hide resolved
oauth2_http/java/com/google/auth/oauth2/CertificateIdentityPoolSubjectTokenSupplier.java
Outdated
Show resolved
Hide resolved
oauth2_http/java/com/google/auth/oauth2/CertificateIdentityPoolSubjectTokenSupplier.java
Show resolved
Hide resolved
oauth2_http/javatests/com/google/auth/oauth2/IdentityPoolCredentialsTest.java
Outdated
Show resolved
Hide resolved
oauth2_http/javatests/com/google/auth/oauth2/IdentityPoolCredentialsTest.java
Show resolved
Hide resolved
oauth2_http/javatests/com/google/auth/oauth2/IdentityPoolCredentialsTest.java
Show resolved
Hide resolved
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.
I think things LGTM. Added a few additional comments.
and move the certificate content to a file instead of local variable.
IdentityPoolCredentialSourceType credentialSourceType; | ||
CredentialFormatType credentialFormatType; | ||
String credentialLocation; | ||
private String credentialLocation; |
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.
Made credentialLocation
and certificateConfig
fields private and added public getters to improve encapsulation and provide the ability to properly mock the object.
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.
LGTM overall. Small comment about X509Provider caching.
* configuration file does not specify a certificate path. | ||
* @throws CertificateSourceUnavailableException if the configuration file is not found. | ||
*/ | ||
public String getCertificatePath() throws IOException { |
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.
So we previously envisioned X509Provider will implement an "MtlsProvider" interface with a single "getKeyStore()" public method exposed. (SecureConnectProvider will also implement the same interface) As such, it doesn't feel like the getCertificatePath() helper should live inside the X509Provider. I don't see a lot of value with caching the cert config loading (this pattern is not common in client libraries IMO given the low anticipated QPS for auth or setting up an mTLS transport) Furthermore, having 2 separate public methods sharing this internal state could make code execution unpredictable - what if the underlying cert config changed between the call between getCertificatePath and getKeyStore()? And getKeyStore() may be stuck with an outdated loadedConfig in memory as long is the object instance is alive with no way to refresh the internal state. We have to handle cert rotation in the future as well. IMO, it's much safer to call getWorkloadCertificateConfiguration on demand instead of attempting to cache the result. Rest of your PR looks good!
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.
Makes sense. I've removed the caching, but I realized that if I want to move getCertificatePath()
out of X509Provider, I'd need to move getWorkloadCertificateConfiguration()
as well. I've created an issue to refactor the class in a separate PR.
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.
Looks good!
oauth2_http/java/com/google/auth/oauth2/CertificateIdentityPoolSubjectTokenSupplier.java
Outdated
Show resolved
Hide resolved
oauth2_http/java/com/google/auth/oauth2/CertificateIdentityPoolSubjectTokenSupplier.java
Outdated
Show resolved
Hide resolved
oauth2_http/java/com/google/auth/oauth2/CertificateIdentityPoolSubjectTokenSupplier.java
Show resolved
Hide resolved
oauth2_http/java/com/google/auth/oauth2/IdentityPoolCredentials.java
Outdated
Show resolved
Hide resolved
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.
lgtm. Thanks for working on this PR!
| Package | Type | Package file | Manager | Update | Change | |---|---|---|---|---|---| | [com.google.auth:google-auth-library-oauth2-http](https://github.com/googleapis/google-auth-library-java) | dependencies | misk/gradle/libs.versions.toml | gradle | minor | `1.34.0` -> `1.35.0` | | [com.google.auth:google-auth-library-credentials](https://github.com/googleapis/google-auth-library-java) | dependencies | misk/gradle/libs.versions.toml | gradle | minor | `1.34.0` -> `1.35.0` | | [software.amazon.awssdk:sdk-core](https://aws.amazon.com/sdkforjava) | dependencies | misk/gradle/libs.versions.toml | gradle | patch | `2.31.40` -> `2.31.41` | | [software.amazon.awssdk:sqs](https://aws.amazon.com/sdkforjava) | dependencies | misk/gradle/libs.versions.toml | gradle | patch | `2.31.40` -> `2.31.41` | | [software.amazon.awssdk:dynamodb-enhanced](https://aws.amazon.com/sdkforjava) | dependencies | misk/gradle/libs.versions.toml | gradle | patch | `2.31.40` -> `2.31.41` | | [software.amazon.awssdk:dynamodb](https://aws.amazon.com/sdkforjava) | dependencies | misk/gradle/libs.versions.toml | gradle | patch | `2.31.40` -> `2.31.41` | --- ### Release Notes <details> <summary>googleapis/google-auth-library-java (com.google.auth:google-auth-library-oauth2-http)</summary> ### [`v1.35.0`](https://github.com/googleapis/google-auth-library-java/blob/HEAD/CHANGELOG.md#1350-2025-05-12) ##### Features - Add support for mTLS authentication via X.509 certificates ([#​1736](googleapis/google-auth-library-java#1736)) ([b347603](googleapis/google-auth-library-java@b347603)) - Return X509 certificate chain as the subject token. ([#​1746](googleapis/google-auth-library-java#1746)) ([6d05be8](googleapis/google-auth-library-java@6d05be8)) ##### Bug Fixes - Handle optional fields in ExternalAccountCredentials with null JSON value gracefully ([#​1706](googleapis/google-auth-library-java#1706)) ([f1f306d](googleapis/google-auth-library-java@f1f306d)) </details> --- ### Configuration π **Schedule**: Branch creation - "after 6pm every weekday,before 2am every weekday" in timezone Australia/Melbourne, Automerge - At any time (no schedule defined). π¦ **Automerge**: Enabled. β» **Rebasing**: Never, or you tick the rebase/retry checkbox. π» **Immortal**: This PR will be recreated if closed unmerged. Get [config help](https://github.com/renovatebot/renovate/discussions) if that's undesired. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). GitOrigin-RevId: abc60fba8102e94da5ecb2e7537ccaf5d3d8628f
This commit introduces a new credential source type, 'certificate', enabling the use of mTLS for authentication with X.509 certificates. It includes the necessary logic to load certificate configurations (both explicit paths and default locations) and establish an mTLS-enabled transport.