-
Notifications
You must be signed in to change notification settings - Fork 270
feat: Introduce Client-Side Credential Access Boundary (CAB) functionality #1629
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
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
5d32642
feat: Implement ClientSideCredentialAccessBoundaryFactory (#1562)
nbayati 50d9027
feat: Add the generated ClientSideAccessBoundaryProto class for Clien…
huangjiahua 0d96dcf
feat: Implement refreshCredentialsIfRequired for intermediate token r…
nbayati 5573169
feat: Implement Client-Side CAB token generation. (#1598)
huangjiahua 3a90191
Merge branch 'main' into new-branch-name
nbayati 3bad66f
chore: Update version tag in cab-token-generator pom.xml
nbayati 2c7f7a2
Merge branch 'main' into client-side-cab
nbayati 7621caa
feat: Add integration test for the client side cab
nbayati aa1967b
Remove volatile keyword and use refreshLock when reading intermediate…
nbayati e36392c
Define new default values for refreshMargin and minimumTokenLifetime.
nbayati f37586b
Merge branch 'main' into client-side-cab
aeitzman a6d8b94
Update version in pom.xml
nbayati ca338bb
Run formatter to resolve lint errors
nbayati e1b3291
add missing dependency
nbayati 76fae0d
Swap the assertEquals parameters so the expected value is first.
nbayati 02e939e
Docs: Added javadocs
nbayati 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
There are no files selected for viewing
767 changes: 767 additions & 0 deletions
767
...a/com/google/auth/credentialaccessboundary/ClientSideCredentialAccessBoundaryFactory.java
Large diffs are not rendered by default.
Oops, something went wrong.
2,174 changes: 2,174 additions & 0 deletions
2,174
...java/com/google/auth/credentialaccessboundary/protobuf/ClientSideAccessBoundaryProto.java
Large diffs are not rendered by default.
Oops, something went wrong.
989 changes: 989 additions & 0 deletions
989
...m/google/auth/credentialaccessboundary/ClientSideCredentialAccessBoundaryFactoryTest.java
Large diffs are not rendered by default.
Oops, something went wrong.
153 changes: 153 additions & 0 deletions
153
...ts/com/google/auth/credentialaccessboundary/ITClientSideCredentialAccessBoundaryTest.java
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 |
|---|---|---|
| @@ -0,0 +1,153 @@ | ||
| /* | ||
| * Copyright 2025, Google LLC | ||
| * | ||
| * Redistribution and use in source and binary forms, with or without | ||
| * modification, are permitted provided that the following conditions are | ||
| * met: | ||
| * | ||
| * * Redistributions of source code must retain the above copyright | ||
| * notice, this list of conditions and the following disclaimer. | ||
| * * Redistributions in binary form must reproduce the above | ||
| * copyright notice, this list of conditions and the following disclaimer | ||
| * in the documentation and/or other materials provided with the | ||
| * distribution. | ||
| * | ||
| * * Neither the name of Google LLC nor the names of its | ||
| * contributors may be used to endorse or promote products derived from | ||
| * this software without specific prior written permission. | ||
| * | ||
| * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
| * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
| * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
| * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
| * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
| * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
| * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
| * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
| * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| */ | ||
|
|
||
| package com.google.auth.credentialaccessboundary; | ||
|
|
||
| import static org.junit.Assert.assertEquals; | ||
| import static org.junit.Assert.assertThrows; | ||
| import static org.junit.Assert.assertTrue; | ||
|
|
||
| import com.google.api.client.http.GenericUrl; | ||
| import com.google.api.client.http.HttpRequest; | ||
| import com.google.api.client.http.HttpRequestFactory; | ||
| import com.google.api.client.http.HttpResponse; | ||
| import com.google.api.client.http.HttpResponseException; | ||
| import com.google.api.client.http.javanet.NetHttpTransport; | ||
| import com.google.api.client.json.JsonObjectParser; | ||
| import com.google.api.client.json.gson.GsonFactory; | ||
| import com.google.auth.Credentials; | ||
| import com.google.auth.http.HttpCredentialsAdapter; | ||
| import com.google.auth.oauth2.CredentialAccessBoundary; | ||
| import com.google.auth.oauth2.GoogleCredentials; | ||
| import com.google.auth.oauth2.OAuth2CredentialsWithRefresh; | ||
| import com.google.auth.oauth2.ServiceAccountCredentials; | ||
| import dev.cel.common.CelValidationException; | ||
| import java.io.IOException; | ||
| import java.security.GeneralSecurityException; | ||
| import org.junit.Test; | ||
|
|
||
| /** | ||
| * Integration tests for {@link ClientSideCredentialAccessBoundaryFactory}. * | ||
| * | ||
| * <p>The only requirements for this test suite to run is to set the environment variable | ||
| * GOOGLE_APPLICATION_CREDENTIALS to point to the same service account configured in the setup | ||
| * script (downscoping-with-cab-setup.sh). | ||
| */ | ||
| public final class ITClientSideCredentialAccessBoundaryTest { | ||
|
|
||
| // Output copied from the setup script (downscoping-with-cab-setup.sh). | ||
| private static final String GCS_BUCKET_NAME = "cab-int-bucket-cbi3qrv5"; | ||
| private static final String GCS_OBJECT_NAME_WITH_PERMISSION = "cab-first-cbi3qrv5.txt"; | ||
| private static final String GCS_OBJECT_NAME_WITHOUT_PERMISSION = "cab-second-cbi3qrv5.txt"; | ||
|
|
||
| // This Credential Access Boundary enables the objectViewer permission to the specified object in | ||
| // the specified bucket. | ||
| private static final CredentialAccessBoundary CREDENTIAL_ACCESS_BOUNDARY = | ||
| CredentialAccessBoundary.newBuilder() | ||
| .addRule( | ||
| CredentialAccessBoundary.AccessBoundaryRule.newBuilder() | ||
| .setAvailableResource( | ||
| String.format( | ||
| "//storage.googleapis.com/projects/_/buckets/%s", GCS_BUCKET_NAME)) | ||
| .addAvailablePermission("inRole:roles/storage.objectViewer") | ||
| .setAvailabilityCondition( | ||
| CredentialAccessBoundary.AccessBoundaryRule.AvailabilityCondition.newBuilder() | ||
| .setExpression( | ||
| String.format( | ||
| "resource.name.startsWith('projects/_/buckets/%s/objects/%s')", | ||
| GCS_BUCKET_NAME, GCS_OBJECT_NAME_WITH_PERMISSION)) | ||
| .build()) | ||
| .build()) | ||
| .build(); | ||
|
|
||
| /** | ||
| * A downscoped credential is obtained using ClientSideCredentialAccessBoundaryFactory with | ||
| * permissions to access an object in the GCS bucket configured. We should only have access to | ||
| * retrieve this object. | ||
| * | ||
| * <p>We confirm this by: 1. Validating that we can successfully retrieve this object with the | ||
| * downscoped token. 2. Validating that we do not have permission to retrieve a different object | ||
| * in the same bucket. | ||
| */ | ||
| @Test | ||
| public void clientSideCredentialAccessBoundary_serviceAccountSource() throws IOException { | ||
| OAuth2CredentialsWithRefresh.OAuth2RefreshHandler refreshHandler = | ||
| () -> { | ||
| ServiceAccountCredentials sourceCredentials = | ||
| (ServiceAccountCredentials) | ||
| GoogleCredentials.getApplicationDefault() | ||
| .createScoped("https://www.googleapis.com/auth/cloud-platform"); | ||
|
|
||
| ClientSideCredentialAccessBoundaryFactory factory = | ||
| ClientSideCredentialAccessBoundaryFactory.newBuilder() | ||
| .setSourceCredential(sourceCredentials) | ||
| .build(); | ||
|
|
||
| try { | ||
| return factory.generateToken(CREDENTIAL_ACCESS_BOUNDARY); | ||
| } catch (CelValidationException | GeneralSecurityException e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
| }; | ||
|
|
||
| OAuth2CredentialsWithRefresh credentials = | ||
| OAuth2CredentialsWithRefresh.newBuilder().setRefreshHandler(refreshHandler).build(); | ||
|
|
||
| // Attempt to retrieve the object that the downscoped token has access to. | ||
| retrieveObjectFromGcs(credentials, GCS_OBJECT_NAME_WITH_PERMISSION); | ||
|
|
||
| // Attempt to retrieve the object that the downscoped token does not have access to. This should | ||
| // fail. | ||
| HttpResponseException exception = | ||
| assertThrows( | ||
| HttpResponseException.class, | ||
| () -> retrieveObjectFromGcs(credentials, GCS_OBJECT_NAME_WITHOUT_PERMISSION)); | ||
| assertEquals(403, exception.getStatusCode()); | ||
| } | ||
|
|
||
| private void retrieveObjectFromGcs(Credentials credentials, String objectName) | ||
| throws IOException { | ||
| String url = | ||
| String.format( | ||
| "https://storage.googleapis.com/storage/v1/b/%s/o/%s", GCS_BUCKET_NAME, objectName); | ||
|
|
||
| HttpCredentialsAdapter credentialsAdapter = new HttpCredentialsAdapter(credentials); | ||
| HttpRequestFactory requestFactory = | ||
| new NetHttpTransport().createRequestFactory(credentialsAdapter); | ||
| HttpRequest request = requestFactory.buildGetRequest(new GenericUrl(url)); | ||
|
|
||
| JsonObjectParser parser = new JsonObjectParser(GsonFactory.getDefaultInstance()); | ||
| request.setParser(parser); | ||
|
|
||
| HttpResponse response = request.execute(); | ||
| assertTrue(response.isSuccessStatusCode()); | ||
| } | ||
| } |
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 |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <project xmlns="http://maven.apache.org/POM/4.0.0" | ||
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
| <parent> | ||
| <groupId>com.google.auth</groupId> | ||
| <artifactId>google-auth-library-parent</artifactId> | ||
| <version>1.31.1-SNAPSHOT | ||
| </version><!-- {x-version-update:google-auth-library-parent:current} --> | ||
| </parent> | ||
|
|
||
| <artifactId>google-auth-library-cab-token-generator</artifactId> | ||
| <name>Google Auth Library for Java - Cab Token Generator</name> | ||
|
|
||
| <build> | ||
| <sourceDirectory>java</sourceDirectory> | ||
| <testSourceDirectory>javatests</testSourceDirectory> | ||
| </build> | ||
|
|
||
| <dependencies> | ||
| <!-- Compile and Runtime Dependencies --> | ||
| <dependency> | ||
| <groupId>com.google.auth</groupId> | ||
| <artifactId>google-auth-library-oauth2-http</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>com.google.auth</groupId> | ||
| <artifactId>google-auth-library-credentials</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>com.google.http-client</groupId> | ||
| <artifactId>google-http-client</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>com.google.errorprone</groupId> | ||
| <artifactId>error_prone_annotations</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>com.google.guava</groupId> | ||
| <artifactId>guava</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>com.google.protobuf</groupId> | ||
| <artifactId>protobuf-java</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>dev.cel</groupId> | ||
| <artifactId>cel</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>com.google.code.findbugs</groupId> | ||
| <artifactId>jsr305</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>com.google.crypto.tink</groupId> | ||
| <artifactId>tink</artifactId> | ||
| </dependency> | ||
|
|
||
| <!-- Test Dependencies --> | ||
| <dependency> | ||
| <groupId>junit</groupId> | ||
| <artifactId>junit</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>com.google.auth</groupId> | ||
| <artifactId>google-auth-library-oauth2-http</artifactId> | ||
| <scope>test</scope> | ||
| <type>test-jar</type> | ||
| <classifier>testlib</classifier> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.mockito</groupId> | ||
| <artifactId>mockito-core</artifactId> | ||
| <version>4.11.0</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>com.google.http-client</groupId> | ||
| <artifactId>google-http-client-gson</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| </dependencies> | ||
|
|
||
| </project> |
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
Oops, something went wrong.
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.