-
Notifications
You must be signed in to change notification settings - Fork 258
feat: Add TrustBoundaries support for ExternalAccounts. #1836
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
Open
vverman
wants to merge
18
commits into
googleapis:feat-tb-sa
Choose a base branch
from
vverman:feat/trust-boundary-external-account
base: feat-tb-sa
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+518
−45
Open
Changes from 12 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
d305b2f
Initial Changes for trust boundary structure without TB enabled check…
vverman c17e26d
Added changes to authenticate TB endpoint, add correct TB headers.
vverman 2b486bd
Added unit tests for Trust Boundary for Service accounts. Updated. th…
vverman 63f508b
Formatting changes
vverman 5bddb2f
Trust Boundary Recovery
vverman 9fb3547
Changed key for encodedLocations and changed tests.
vverman dab6d3b
minor fixes
vverman d58147c
External Account Initial Changes.
vverman 283d8b5
Added tests for all excepting ExternalAccountCredentials.
vverman b4e5199
Added tests for ExternalAccountCredentials trust boundary. Added comm…
vverman 458bad4
Some nit fixes.
vverman 8cd8f2f
Fixed test failures.
vverman f737866
TrustBoundaryUrl's universe domain is now configured from the client'…
vverman fe772d8
Formatted ExternalAccountCredentials.
vverman 1efce2d
assertThrows changes. Fixed TestUtils getDefaultExpireTime to represe…
vverman 6eb249c
Error thrown when audience doesn't match pattern is IllegalStateExcep…
vverman 2071071
Nit fixes.
vverman f013aa5
Imports are listed. setTrustBoundaries removed.
vverman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -339,6 +339,10 @@ TrustBoundary getTrustBoundary() { | |
| return trustBoundary; | ||
| } | ||
|
|
||
| protected void setTrustBoundary(TrustBoundary trustBoundary) { | ||
| this.trustBoundary = trustBoundary; | ||
| } | ||
|
Comment on lines
+342
to
+344
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. is this still needed? |
||
|
|
||
| /** | ||
| * Refreshes the trust boundary by making a call to the trust boundary URL. | ||
| * | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1399,4 +1399,34 @@ public AwsSecurityCredentials getCredentials(ExternalAccountSupplierContext cont | |
| return credentials; | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testRefresh_trustBoundarySuccess() throws IOException { | ||
| TestEnvironmentProvider environmentProvider = new TestEnvironmentProvider(); | ||
| TrustBoundary.setEnvironmentProviderForTest(environmentProvider); | ||
| environmentProvider.setEnv("GOOGLE_AUTH_TRUST_BOUNDARY_ENABLE_EXPERIMENT", "1"); | ||
|
|
||
| MockExternalAccountCredentialsTransportFactory transportFactory = | ||
| new MockExternalAccountCredentialsTransportFactory(); | ||
|
|
||
| AwsSecurityCredentialsSupplier supplier = | ||
| new TestAwsSecurityCredentialsSupplier("test", programmaticAwsCreds, null, null); | ||
|
|
||
| AwsCredentials awsCredential = | ||
| AwsCredentials.newBuilder() | ||
| .setAwsSecurityCredentialsSupplier(supplier) | ||
| .setHttpTransportFactory(transportFactory) | ||
| .setAudience( | ||
| "//iam.googleapis.com/projects/12345/locations/global/workloadIdentityPools/pool/providers/provider") | ||
| .setTokenUrl(STS_URL) | ||
| .setSubjectTokenType("subjectTokenType") | ||
| .build(); | ||
|
|
||
| awsCredential.refreshAccessToken(); | ||
|
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. nit: I think most of the other test classes use |
||
|
|
||
| TrustBoundary trustBoundary = awsCredential.getTrustBoundary(); | ||
| assertNotNull(trustBoundary); | ||
| assertEquals(TestUtils.TRUST_BOUNDARY_ENCODED_LOCATION, trustBoundary.getEncodedLocations()); | ||
| TrustBoundary.setEnvironmentProviderForTest(null); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,6 +33,7 @@ | |
|
|
||
| import static com.google.auth.oauth2.ComputeEngineCredentials.METADATA_RESPONSE_EMPTY_CONTENT_ERROR_MESSAGE; | ||
| import static com.google.auth.oauth2.ImpersonatedCredentialsTest.SA_CLIENT_EMAIL; | ||
| import static com.google.auth.oauth2.TrustBoundary.TRUST_BOUNDARY_KEY; | ||
| import static org.junit.Assert.assertArrayEquals; | ||
| import static org.junit.Assert.assertEquals; | ||
| import static org.junit.Assert.assertFalse; | ||
|
|
@@ -1159,15 +1160,17 @@ public void refresh_trustBoundarySuccess() throws IOException { | |
| String defaultAccountEmail = "[email protected]"; | ||
| MockMetadataServerTransportFactory transportFactory = new MockMetadataServerTransportFactory(); | ||
| TrustBoundary trustBoundary = | ||
| new TrustBoundary("0x80000", Collections.singletonList("us-central1")); | ||
| new TrustBoundary( | ||
| TestUtils.TRUST_BOUNDARY_ENCODED_LOCATION, TestUtils.TRUST_BOUNDARY_LOCATIONS); | ||
| transportFactory.transport.setTrustBoundary(trustBoundary); | ||
| transportFactory.transport.setServiceAccountEmail(defaultAccountEmail); | ||
|
|
||
| ComputeEngineCredentials credentials = | ||
| ComputeEngineCredentials.newBuilder().setHttpTransportFactory(transportFactory).build(); | ||
|
|
||
| Map<String, List<String>> headers = credentials.getRequestMetadata(); | ||
| assertEquals(headers.get("x-allowed-locations"), Arrays.asList("0x80000")); | ||
| assertEquals( | ||
| headers.get(TRUST_BOUNDARY_KEY), Arrays.asList(TestUtils.TRUST_BOUNDARY_ENCODED_LOCATION)); | ||
| } | ||
|
|
||
| @Test | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.