Skip to content

Commit f737866

Browse files
committed
TrustBoundaryUrl's universe domain is now configured from the client's universe domain.
1 parent 8cd8f2f commit f737866

File tree

4 files changed

+24
-24
lines changed

4 files changed

+24
-24
lines changed

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

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,6 @@ public abstract class ExternalAccountCredentials extends GoogleCredentials
100100

101101
private EnvironmentProvider environmentProvider;
102102

103-
private static final String WORKFORCE_POOL_URL_FORMAT =
104-
"https://iamcredentials.googleapis.com/v1/locations/global/workforcePools/%s/allowedLocations";
105-
private static final String WORKLOAD_POOL_URL_FORMAT =
106-
"https://iamcredentials.googleapis.com/v1/projects/%s/locations/global/workloadIdentityPools/%s/allowedLocations";
107103

108104
private static final Pattern WORKFORCE_PATTERN =
109105
Pattern.compile(
@@ -633,26 +629,28 @@ public String getServiceAccountEmail() {
633629
return ImpersonatedCredentials.extractTargetPrincipal(serviceAccountImpersonationUrl);
634630
}
635631

636-
// todo Add doc comment.
637632
@Override
638633
public String getTrustBoundaryUrl() throws IOException {
639-
if (isWorkforcePoolConfiguration()) {
640-
Matcher matcher = WORKFORCE_PATTERN.matcher(getAudience());
641-
if (!matcher.matches()) {
642-
throw new IOException(
643-
"The provided audience is not in the correct format for a workforce pool.");
644-
}
645-
String poolId = matcher.group("pool");
646-
return String.format(WORKFORCE_POOL_URL_FORMAT, poolId);
634+
Matcher workforceMatcher = WORKFORCE_PATTERN.matcher(getAudience());
635+
Matcher workloadMatcher = WORKLOAD_PATTERN.matcher(getAudience());
636+
637+
if (workforceMatcher.matches()) {
638+
String poolId = workforceMatcher.group("pool");
639+
return String.format(
640+
OAuth2Utils.IAM_CREDENTIALS_ALLOWED_LOCATIONS_URL_FORMAT_WORKFORCE_POOL,
641+
getUniverseDomain(),
642+
poolId);
643+
} else if (workloadMatcher.matches()) {
644+
String projectNumber = workloadMatcher.group("project");
645+
String poolId = workloadMatcher.group("pool");
646+
return String.format(
647+
OAuth2Utils.IAM_CREDENTIALS_ALLOWED_LOCATIONS_URL_FORMAT_WORKLOAD_POOL,
648+
getUniverseDomain(),
649+
projectNumber,
650+
poolId);
647651
} else {
648-
Matcher matcher = WORKLOAD_PATTERN.matcher(getAudience());
649-
if (!matcher.matches()) {
650-
throw new IOException(
651-
"The provided audience is not in the correct format for a workload identity pool.");
652-
}
653-
String projectNumber = matcher.group("project");
654-
String poolId = matcher.group("pool");
655-
return String.format(WORKLOAD_POOL_URL_FORMAT, projectNumber, poolId);
652+
throw new IOException(
653+
"The provided audience is not in a valid format for either a workload identity pool or a workforce pool.");
656654
}
657655
}
658656

oauth2_http/java/com/google/auth/oauth2/OAuth2Utils.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ public class OAuth2Utils {
9696

9797
static final String IAM_CREDENTIALS_ALLOWED_LOCATIONS_URL_FORMAT_SERVICE_ACCOUNT =
9898
"https://iamcredentials.%s/v1/projects/-/serviceAccounts/%s/allowedLocations";
99+
static final String IAM_CREDENTIALS_ALLOWED_LOCATIONS_URL_FORMAT_WORKFORCE_POOL =
100+
"https://iamcredentials.%s/v1/locations/global/workforcePools/%s/allowedLocations";
101+
static final String IAM_CREDENTIALS_ALLOWED_LOCATIONS_URL_FORMAT_WORKLOAD_POOL =
102+
"https://iamcredentials.%s/v1/projects/%s/locations/global/workloadIdentityPools/%s/allowedLocations";
99103
static final URI USER_AUTH_URI = URI.create("https://accounts.google.com/o/oauth2/auth");
100104

101105
public static final String CLOUD_PLATFORM_SCOPE =

oauth2_http/java/com/google/auth/oauth2/ServiceAccountCredentials.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,7 +1162,6 @@ public static class Builder extends GoogleCredentials.Builder {
11621162
private int lifetime = DEFAULT_LIFETIME_IN_SECONDS;
11631163
private boolean useJwtAccessWithScope = false;
11641164
private boolean defaultRetriesEnabled = true;
1165-
private TrustBoundary trustBoundary;
11661165

11671166
protected Builder() {}
11681167

@@ -1181,7 +1180,6 @@ protected Builder(ServiceAccountCredentials credentials) {
11811180
this.lifetime = credentials.lifetime;
11821181
this.useJwtAccessWithScope = credentials.useJwtAccessWithScope;
11831182
this.defaultRetriesEnabled = credentials.defaultRetriesEnabled;
1184-
this.trustBoundary = credentials.getTrustBoundary();
11851183
}
11861184

11871185
@CanIgnoreReturnValue

oauth2_http/javatests/com/google/auth/TestUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public static HttpResponseException buildHttpResponseException(
150150
public static String getDefaultExpireTime() {
151151
Calendar calendar = Calendar.getInstance();
152152
calendar.setTime(new Date());
153-
calendar.add(Calendar.SECOND, 30000);
153+
calendar.add(Calendar.SECOND, 3000);
154154
return new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'").format(calendar.getTime());
155155
}
156156

0 commit comments

Comments
 (0)