Repository navigation
fix(auth,gax): align Java mTLS and agent identity certificate handling with Python parity #14658
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
Changes from all commits
4f50c0d
b6f62b5
de2cafe
a14152d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -81,7 +81,7 @@ | |
| * the certificate used for mTLS and the certificate bound to tokens always come from the same | ||
| * source. | ||
| */ | ||
| public static boolean hasCertificateConfiguration( | ||
|
Check warning on line 84 in google-auth-library-java/oauth2_http/java/com/google/auth/mtls/MtlsUtils.java
|
||
| EnvironmentProvider envProvider, PropertyProvider propProvider) { | ||
| if (!Strings.isNullOrEmpty(envProvider.getEnv(CERTIFICATE_CONFIGURATION_ENV_VARIABLE))) { | ||
| return true; | ||
|
|
@@ -111,7 +111,7 @@ | |
| * Returns {@code true} if the GKE credential bundle at {@code path} is a readable, non-empty | ||
| * regular file. | ||
| */ | ||
| public static boolean isGkeCredentialBundleReady(String path) { | ||
|
Check warning on line 114 in google-auth-library-java/oauth2_http/java/com/google/auth/mtls/MtlsUtils.java
|
||
| File bundle = new File(path); | ||
| return bundle.isFile() && bundle.canRead() && bundle.length() > 0; | ||
| } | ||
|
|
@@ -131,16 +131,23 @@ | |
| gkeCredentialBundlePath = path != null ? path : GKE_CREDENTIAL_BUNDLE_PATH; | ||
| } | ||
|
|
||
| private static boolean isUseClientCertificateExplicitlyDisabled( | ||
| @Nullable String useClientCertificate) { | ||
| return !Strings.isNullOrEmpty(useClientCertificate) | ||
| && !"true".equalsIgnoreCase(useClientCertificate); | ||
| } | ||
|
|
||
| /** | ||
| * Returns if mutual TLS client certificate should be used. Returns true if valid workload | ||
| * certificates are configured or if GOOGLE_API_USE_CLIENT_CERTIFICATE is explicitly set to true | ||
| * (e.g. for Enterprise Certificate Proxy or custom MtlsProviders), unless explicitly disabled via | ||
| * GOOGLE_API_USE_CLIENT_CERTIFICATE=false. | ||
| * GOOGLE_API_USE_CLIENT_CERTIFICATE (set to a non-empty value other than "true"). | ||
| */ | ||
| public static boolean useMtlsClientCertificate( | ||
|
Check warning on line 146 in google-auth-library-java/oauth2_http/java/com/google/auth/mtls/MtlsUtils.java
|
||
| EnvironmentProvider envProvider, PropertyProvider propProvider) { | ||
| String useClientCertificate = envProvider.getEnv("GOOGLE_API_USE_CLIENT_CERTIFICATE"); | ||
| if ("false".equalsIgnoreCase(useClientCertificate)) { | ||
| String rawVal = envProvider.getEnv("GOOGLE_API_USE_CLIENT_CERTIFICATE"); | ||
| String useClientCertificate = rawVal != null ? rawVal.trim() : null; | ||
| if (isUseClientCertificateExplicitlyDisabled(useClientCertificate)) { | ||
| return false; | ||
| } | ||
| if (getWorkloadCertPath(envProvider, propProvider) != null) { | ||
|
|
@@ -167,17 +174,18 @@ | |
| * configuration file is missing, unreadable, malformed, or references missing/unreadable | ||
| * certificate or private key files. This is treated as an unrecoverable misconfiguration. | ||
| * <li><b>{@code null} (Safe fallback / fail open):</b> Client certificates are explicitly | ||
| * disabled via {@code GOOGLE_API_USE_CLIENT_CERTIFICATE=false}, no explicit configuration | ||
| * is set and neither the default well-known configuration file nor a readable GKE | ||
| * credential bundle exists on disk, or the configuration specifies an non-workload source | ||
| * (e.g., ECP/PKCS11 without a {@code workload} section). Callers can proceed without | ||
| * workload certificate file polling. | ||
| * disabled via {@code GOOGLE_API_USE_CLIENT_CERTIFICATE} (any non-empty value other than | ||
| * {@code "true"}), no explicit configuration is set and neither the default well-known | ||
| * configuration file nor a readable GKE credential bundle exists on disk, or the | ||
| * configuration specifies an non-workload source (e.g., ECP/PKCS11 without a {@code | ||
| * workload} section). Callers can proceed without workload certificate file polling. | ||
| * </ol> | ||
| */ | ||
| public static @Nullable String getWorkloadCertPath( | ||
| EnvironmentProvider envProvider, PropertyProvider propProvider) { | ||
| String useClientCertificate = envProvider.getEnv("GOOGLE_API_USE_CLIENT_CERTIFICATE"); | ||
| if ("false".equalsIgnoreCase(useClientCertificate)) { | ||
| String rawVal = envProvider.getEnv("GOOGLE_API_USE_CLIENT_CERTIFICATE"); | ||
| String useClientCertificate = rawVal != null ? rawVal.trim() : null; | ||
| if (isUseClientCertificateExplicitlyDisabled(useClientCertificate)) { | ||
| return null; | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.