-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Regional access boundaries #13318
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
base: regional-access-boundaries
Are you sure you want to change the base?
Regional access boundaries #13318
Changes from all commits
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 |
|---|---|---|
|
|
@@ -59,6 +59,11 @@ | |
| import java.util.Map; | ||
| import java.util.Objects; | ||
| import javax.annotation.Nullable; | ||
| import com.google.auth.mtls.MtlsHttpTransportFactory; | ||
| import com.google.auth.mtls.MtlsUtils; | ||
| import com.google.auth.mtls.X509Provider; | ||
| import java.security.KeyStore; | ||
|
|
||
|
|
||
| /** Base type for credentials for authorizing calls to Google APIs using OAuth2. */ | ||
| public class GoogleCredentials extends OAuth2Credentials implements QuotaProjectIdProvider { | ||
|
|
@@ -397,6 +402,24 @@ void refreshRegionalAccessBoundaryIfExpired(@Nullable URI uri, @Nullable AccessT | |
| return; | ||
| } | ||
|
|
||
| try { | ||
| if (MtlsUtils.canMtlsBeEnabled( | ||
| SystemEnvironmentProvider.getInstance(), | ||
| SystemPropertyProvider.getInstance(), | ||
| null)) { | ||
| X509Provider x509Provider = new X509Provider( | ||
| SystemEnvironmentProvider.getInstance(), | ||
| SystemPropertyProvider.getInstance(), | ||
| null); | ||
| KeyStore mtlsKeyStore = x509Provider.getKeyStore(); | ||
| if (mtlsKeyStore != null) { | ||
| transportFactory = new MtlsHttpTransportFactory(mtlsKeyStore); | ||
| } | ||
| } | ||
| } catch (Exception e) { | ||
| // Graceful fallback to standard transport if mTLS initialization fails | ||
| } | ||
|
Comment on lines
+405
to
+421
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. Calling try {
X509Provider x509Provider = new X509Provider(
SystemEnvironmentProvider.getInstance(),
SystemPropertyProvider.getInstance(),
null);
KeyStore mtlsKeyStore = x509Provider.getKeyStore();
if (mtlsKeyStore != null) {
transportFactory = new MtlsHttpTransportFactory(mtlsKeyStore);
}
} catch (Exception e) {
// Graceful fallback to standard transport if mTLS initialization fails
}References
|
||
|
|
||
| regionalAccessBoundaryManager.triggerAsyncRefresh( | ||
| transportFactory, (RegionalAccessBoundaryProvider) this, token); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -189,6 +189,10 @@ static RegionalAccessBoundary refresh( | |||||||||||||
| throw new IllegalArgumentException("The provided access token is expired."); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| if (transportFactory instanceof com.google.auth.mtls.MtlsHttpTransportFactory) { | ||||||||||||||
| url = url.replace("https://iamcredentials.googleapis.com/", "https://iamcredentials.mtls.googleapis.com/"); | ||||||||||||||
| } | ||||||||||||||
|
Comment on lines
+192
to
+194
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. Replacing the entire prefix
Suggested change
|
||||||||||||||
|
|
||||||||||||||
| HttpRequestFactory requestFactory = transportFactory.create().createRequestFactory(); | ||||||||||||||
| HttpRequest request = requestFactory.buildGetRequest(new GenericUrl(url)); | ||||||||||||||
| // Disable automatic logging by google-http-java-client to prevent leakage of sensitive tokens. | ||||||||||||||
|
|
||||||||||||||
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.
The
getKeyStore()method currently callsMtlsUtils.canMtlsBeEnabled(...)at the beginning, which performs redundant file existence checks and parses the JSON configuration file. Immediately after, it callsMtlsUtils.getWorkloadCertificateConfiguration(...)which parses the same JSON configuration file again. This results in unnecessary file I/O and CPU overhead.We can optimize this by directly attempting to load the configuration and credentials, and throwing
CertificateSourceUnavailableExceptionif mTLS is not enabled or cannot be established. This avoids duplicate file checks and JSON parsing.References