Skip to content

feat(auth): mTLS endpoint for Regional Access Boundaries#13318

Open
vverman wants to merge 5 commits into
googleapis:regional-access-boundariesfrom
vverman:regional-access-boundaries
Open

feat(auth): mTLS endpoint for Regional Access Boundaries#13318
vverman wants to merge 5 commits into
googleapis:regional-access-boundariesfrom
vverman:regional-access-boundaries

Conversation

@vverman
Copy link
Copy Markdown
Contributor

@vverman vverman commented May 31, 2026

Added logic to:

  1. Centralize mTLS enablement logic within the auth library.
  2. Based on 1. determine whether mtls or regular RAB lookup endpoint should be called.
  3. Added tests for the same.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a 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 centralized mTLS enablement checks and adds fallback support for SPIFFE credentials in MtlsUtils and X509Provider, alongside integrating mTLS transport initialization during regional access boundary refreshes. The review feedback suggests optimizing performance by removing redundant configuration checks and file parsing in X509Provider.getKeyStore() and GoogleCredentials.java, and improving robustness in RegionalAccessBoundary.java by replacing only the host name in the IAM credentials URL.

@vverman vverman changed the title Regional access boundaries feat(auth): mTLS endpoint for Regional Access Boundaries Jun 1, 2026
@vverman vverman marked this pull request as ready for review June 4, 2026 08:45
@vverman vverman requested review from a team as code owners June 4, 2026 08:45
@vverman vverman marked this pull request as draft June 4, 2026 08:46
vverman added 2 commits June 4, 2026 14:51
Added an E2E test to check the call to RAB mtls endpoint and check x-allowed-locations header.

Unified redundant method(s) waitForRegionalAccessBoundary.
@vverman vverman marked this pull request as ready for review June 4, 2026 22:05
@vverman vverman requested review from lqiu96 and nbayati June 4, 2026 22:05
Copy link
Copy Markdown
Contributor

@lsirac lsirac left a comment

Choose a reason for hiding this comment

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

Should we be checking GOOGLE_API_USE_MTLS_ENDPOINT?

* @throws IOException if the configuration file is present but contains missing or malformed
* files
*/
public static boolean canMtlsBeEnabled(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I’m not sure that cert being present == automatically use mTLS. They can be using different credentials / not using it at all. So then we’d be adding mTLS setup and calls for credentials that are not actually using it.

I think the decision should be based on the credential type, and perhaps expose some state from the credential that we can use to check if mTLS should happen for these calls.


@Override
public NetHttpTransport create() {
public HttpTransport create() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

qq, is this change necessary for the PR? I know this is marked with @internalapi and this isn't exactly customers are expected to interact with directly.

There are some small source and binary compatibility changes (I think very small chance) but I would prefer to keep it as-is unless we absolutely need to

Comment on lines +61 to +65
public enum MtlsEndpointUsagePolicy {
ALWAYS,
NEVER,
AUTO
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: Add some small javadoc/ comments for this public enum. I think we can reference the AIP as well: https://google.aip.dev/auth/4114


// Locate and process the certificate configuration file
String envPath = envProvider.getEnv(CERTIFICATE_CONFIGURATION_ENV_VARIABLE);
if (certConfigPathOverride != null || !Strings.isNullOrEmpty(envPath)) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is it possible for both certConfigPathOverride and envPath to be null/ empty? Do we need to check for that possibility?

Comment on lines +194 to +198
} catch (CertificateSourceUnavailableException e) {
// Config file is simply not present. This is fine, fallback to SPIFFE.
} catch (IOException e) {
// Config file exists but is malformed or points to invalid paths -> throw hard error
throw e;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

For these cases, do we want to either log a message and/or make these errors actionable?

How will customers know that we have fallen back to SPIFFE or if there config malformed will the exception be clear enough for them to know that?

Comment on lines +215 to +226
File spiffeDir = new File(spiffeDirectory);
if (spiffeDir.isDirectory()) {
File credentialBundle = new File(spiffeDir, SPIFFE_CREDENTIAL_BUNDLE_FILE);
if (credentialBundle.isFile()) {
return true;
}
File certsFile = new File(spiffeDir, SPIFFE_CERTIFICATE_FILE);
File keyFile = new File(spiffeDir, SPIFFE_PRIVATE_KEY_FILE);
if (certsFile.isFile() && keyFile.isFile()) {
return true;
}
}
Copy link
Copy Markdown
Member

@lqiu96 lqiu96 Jun 5, 2026

Choose a reason for hiding this comment

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

Tracing through the getWorkloadCertificateConfiguration's logic, it looks like it read the contents of the file and also does validation inside. Do we need to do similar here?

Hmm, is it possible to move the logic L201 - L212 into WorkloadCertificateConfiguration? That way if we return an object, all the configs inside are valid.

Side note: I'm wondering if we can break this into something like:

  1. canMtlsBeEnabled : boolean -> Checks the env vars and any configs that prevent us from using mtls
  2. loadMtlsConfigs : MtlsConfig -> Reads the workloadcert or SPIFFEE config file and returns all the info needed.

throw new IllegalArgumentException("The provided access token is expired.");
}

if (transportFactory instanceof com.google.auth.mtls.MtlsHttpTransportFactory) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I believe the transportFactory is a setter for a bunch of credentials. Is it possible to make this check a bit more robust and not based on the MtlsHttpTransportFactory class itself?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants