Skip to content

Commit b45c0dd

Browse files
authored
Merge branch 'main' into aco
2 parents c7c6731 + 825dadd commit b45c0dd

591 files changed

Lines changed: 5246 additions & 4423 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

google-auth-library-java/oauth2_http/java/com/google/auth/oauth2/ComputeEngineCredentials.java

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
import com.google.api.client.http.HttpStatusCodes;
4242
import com.google.api.client.json.JsonObjectParser;
4343
import com.google.api.client.util.GenericData;
44-
import com.google.api.core.InternalApi;
4544
import com.google.auth.CredentialTypeForMetrics;
4645
import com.google.auth.Credentials;
4746
import com.google.auth.Retryable;
@@ -72,7 +71,6 @@
7271
import java.util.Objects;
7372
import java.util.logging.Level;
7473
import java.util.logging.Logger;
75-
import java.util.regex.Pattern;
7674

7775
/**
7876
* OAuth2 credentials representing the built-in service account for a Google Compute Engine VM.
@@ -82,7 +80,7 @@
8280
* <p>These credentials use the IAM API to sign data. See {@link #sign(byte[])} for more details.
8381
*/
8482
public class ComputeEngineCredentials extends GoogleCredentials
85-
implements ServiceAccountSigner, IdTokenProvider, RegionalAccessBoundaryProvider {
83+
implements ServiceAccountSigner, IdTokenProvider {
8684

8785
static final String METADATA_RESPONSE_EMPTY_CONTENT_ERROR_MESSAGE =
8886
"Empty content from metadata token server request.";
@@ -118,7 +116,6 @@ public class ComputeEngineCredentials extends GoogleCredentials
118116

119117
private static final String PARSE_ERROR_PREFIX = "Error parsing token refresh response. ";
120118
private static final String PARSE_ERROR_ACCOUNT = "Error parsing service account response. ";
121-
private static final Pattern EMAIL_PATTERN = Pattern.compile("^[^@]+@[^@]+\\.[^@]+$");
122119
private static final long serialVersionUID = -4113476462526554235L;
123120

124121
private final String transportFactoryClassName;
@@ -457,6 +454,7 @@ public AccessToken refreshAccessToken() throws IOException {
457454
int expiresInSeconds =
458455
OAuth2Utils.validateInt32(responseData, "expires_in", PARSE_ERROR_PREFIX);
459456
long expiresAtMilliseconds = clock.currentTimeMillis() + expiresInSeconds * 1000;
457+
460458
return new AccessToken(accessToken, new Date(expiresAtMilliseconds));
461459
}
462460

@@ -781,11 +779,6 @@ public static Builder newBuilder() {
781779
*
782780
* @throws RuntimeException if the default service account cannot be read
783781
*/
784-
@Override
785-
HttpTransportFactory getTransportFactory() {
786-
return transportFactory;
787-
}
788-
789782
@Override
790783
// todo(#314) getAccount should not throw a RuntimeException
791784
public String getAccount() {
@@ -799,24 +792,6 @@ public String getAccount() {
799792
return principal;
800793
}
801794

802-
@InternalApi
803-
@Override
804-
public String getRegionalAccessBoundaryUrl() throws IOException {
805-
String account = getAccount();
806-
// The MDS may return a non-email value for the account and we should skip RAB refresh in that
807-
// scenario.
808-
if (account == null || !EMAIL_PATTERN.matcher(account).matches()) {
809-
LoggingUtils.log(
810-
LOGGER_PROVIDER,
811-
Level.INFO,
812-
Collections.emptyMap(),
813-
"Unable to retrieve this instance's email and will skip the regional request routing. Proceeding with request");
814-
return null;
815-
}
816-
return String.format(
817-
OAuth2Utils.IAM_CREDENTIALS_ALLOWED_LOCATIONS_URL_FORMAT_SERVICE_ACCOUNT, account);
818-
}
819-
820795
/**
821796
* Signs the provided bytes using the private key associated with the service account.
822797
*

google-auth-library-java/oauth2_http/java/com/google/auth/oauth2/ExternalAccountAuthorizedUserCredentials.java

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@
3131

3232
package com.google.auth.oauth2;
3333

34-
import static com.google.auth.oauth2.OAuth2Utils.IAM_CREDENTIALS_ALLOWED_LOCATIONS_URL_FORMAT_WORKFORCE_POOL;
3534
import static com.google.auth.oauth2.OAuth2Utils.JSON_FACTORY;
36-
import static com.google.auth.oauth2.OAuth2Utils.WORKFORCE_AUDIENCE_PATTERN;
3735

3836
import com.google.api.client.http.GenericUrl;
3937
import com.google.api.client.http.HttpHeaders;
@@ -45,7 +43,6 @@
4543
import com.google.api.client.json.JsonObjectParser;
4644
import com.google.api.client.util.GenericData;
4745
import com.google.api.client.util.Preconditions;
48-
import com.google.api.core.InternalApi;
4946
import com.google.auth.http.HttpTransportFactory;
5047
import com.google.common.base.MoreObjects;
5148
import com.google.common.io.BaseEncoding;
@@ -57,7 +54,6 @@
5754
import java.util.Date;
5855
import java.util.Map;
5956
import java.util.Objects;
60-
import java.util.regex.Matcher;
6157
import javax.annotation.Nullable;
6258

6359
/**
@@ -78,8 +74,7 @@
7874
* }
7975
* </pre>
8076
*/
81-
public class ExternalAccountAuthorizedUserCredentials extends GoogleCredentials
82-
implements RegionalAccessBoundaryProvider {
77+
public class ExternalAccountAuthorizedUserCredentials extends GoogleCredentials {
8378
private static final LoggerProvider LOGGER_PROVIDER =
8479
LoggerProvider.forClazz(ExternalAccountAuthorizedUserCredentials.class);
8580

@@ -234,29 +229,6 @@ public AccessToken refreshAccessToken() throws IOException {
234229
.build();
235230
}
236231

237-
@InternalApi
238-
@Override
239-
public String getRegionalAccessBoundaryUrl() throws IOException {
240-
String audience = getAudience();
241-
if (audience == null) {
242-
throw new IllegalStateException(
243-
"The audience is null, which is not in the correct format for a workforce pool.");
244-
}
245-
Matcher matcher = WORKFORCE_AUDIENCE_PATTERN.matcher(audience);
246-
if (!matcher.matches()) {
247-
throw new IllegalStateException(
248-
"The provided audience is not in the correct format for a workforce pool. "
249-
+ "Refer: https://docs.cloud.google.com/iam/docs/principal-identifiers");
250-
}
251-
String poolId = matcher.group("pool");
252-
return String.format(IAM_CREDENTIALS_ALLOWED_LOCATIONS_URL_FORMAT_WORKFORCE_POOL, poolId);
253-
}
254-
255-
@Override
256-
HttpTransportFactory getTransportFactory() {
257-
return transportFactory;
258-
}
259-
260232
@Nullable
261233
public String getAudience() {
262234
return audience;

google-auth-library-java/oauth2_http/java/com/google/auth/oauth2/ExternalAccountCredentials.java

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,11 @@
3131

3232
package com.google.auth.oauth2;
3333

34-
import static com.google.auth.oauth2.OAuth2Utils.WORKFORCE_AUDIENCE_PATTERN;
35-
import static com.google.auth.oauth2.OAuth2Utils.WORKLOAD_AUDIENCE_PATTERN;
3634
import static com.google.common.base.Preconditions.checkNotNull;
3735

3836
import com.google.api.client.http.HttpHeaders;
3937
import com.google.api.client.json.GenericJson;
4038
import com.google.api.client.util.Data;
41-
import com.google.api.core.InternalApi;
4239
import com.google.auth.RequestMetadataCallback;
4340
import com.google.auth.http.HttpTransportFactory;
4441
import com.google.common.base.MoreObjects;
@@ -57,7 +54,6 @@
5754
import java.util.Locale;
5855
import java.util.Map;
5956
import java.util.concurrent.Executor;
60-
import java.util.regex.Matcher;
6157
import java.util.regex.Pattern;
6258
import javax.annotation.Nullable;
6359

@@ -67,8 +63,7 @@
6763
* <p>Handles initializing external credentials, calls to the Security Token Service, and service
6864
* account impersonation.
6965
*/
70-
public abstract class ExternalAccountCredentials extends GoogleCredentials
71-
implements RegionalAccessBoundaryProvider {
66+
public abstract class ExternalAccountCredentials extends GoogleCredentials {
7267

7368
private static final long serialVersionUID = 8049126194174465023L;
7469

@@ -582,11 +577,6 @@ protected AccessToken exchangeExternalCredentialForAccessToken(
582577
*/
583578
public abstract String retrieveSubjectToken() throws IOException;
584579

585-
@Override
586-
HttpTransportFactory getTransportFactory() {
587-
return transportFactory;
588-
}
589-
590580
public String getAudience() {
591581
return audience;
592582
}
@@ -630,43 +620,6 @@ public String getServiceAccountEmail() {
630620
return ImpersonatedCredentials.extractTargetPrincipal(serviceAccountImpersonationUrl);
631621
}
632622

633-
@InternalApi
634-
@Override
635-
public String getRegionalAccessBoundaryUrl() throws IOException {
636-
if (getServiceAccountEmail() != null) {
637-
return String.format(
638-
OAuth2Utils.IAM_CREDENTIALS_ALLOWED_LOCATIONS_URL_FORMAT_SERVICE_ACCOUNT,
639-
getServiceAccountEmail());
640-
}
641-
642-
String audience = getAudience();
643-
if (audience == null) {
644-
throw new IllegalStateException(
645-
"The audience is null, which is not in a valid format for either a workload identity pool or a workforce pool.");
646-
}
647-
648-
Matcher workforceMatcher = WORKFORCE_AUDIENCE_PATTERN.matcher(audience);
649-
if (workforceMatcher.matches()) {
650-
String poolId = workforceMatcher.group("pool");
651-
return String.format(
652-
OAuth2Utils.IAM_CREDENTIALS_ALLOWED_LOCATIONS_URL_FORMAT_WORKFORCE_POOL, poolId);
653-
}
654-
655-
Matcher workloadMatcher = WORKLOAD_AUDIENCE_PATTERN.matcher(audience);
656-
if (workloadMatcher.matches()) {
657-
String projectNumber = workloadMatcher.group("project");
658-
String poolId = workloadMatcher.group("pool");
659-
return String.format(
660-
OAuth2Utils.IAM_CREDENTIALS_ALLOWED_LOCATIONS_URL_FORMAT_WORKLOAD_POOL,
661-
projectNumber,
662-
poolId);
663-
}
664-
665-
throw new IllegalStateException(
666-
"The provided audience is not in a valid format for either a workload identity pool or a workforce pool."
667-
+ " Refer: https://docs.cloud.google.com/iam/docs/principal-identifiers");
668-
}
669-
670623
@Nullable
671624
public String getClientId() {
672625
return clientId;

0 commit comments

Comments
 (0)