feat: Adds Client-Side Credential Access Boundary Factory example.#9994
feat: Adds Client-Side Credential Access Boundary Factory example.#9994minherz merged 9 commits intoGoogleCloudPlatform:mainfrom
Conversation
ghost
left a comment
There was a problem hiding this comment.
Hi team,
I'm currently reviewing this pull request and will provide my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed:
This pull request adds a new sample demonstrating how to use the Client-Side Credential Access Boundary (CAB) factory to generate downscoped tokens. The primary goal is to provide a clear example of how to leverage CAB for more granular access control.
Here's a breakdown of the changes:
- New File:
auth/src/main/java/com/google/cloud/auth/samples/ClientSideCredentialAccessBoundaryFactoryExample.javawas added. This file contains the complete example code, showcasing the generation and usage of downscoped tokens. - Code Changes: The new Java file includes methods for:
- Retrieving source credentials using
GoogleCredentials.getApplicationDefault() - Defining Credential Access Boundary rules, specifying the resource (
//storage.googleapis.com/projects/_/buckets/<bucketName>), permission (inRole:roles/storage.objectViewer), and an expression to control access based on object prefixes. - Creating a
ClientSideCredentialAccessBoundaryFactoryinstance. - Generating a downscoped token using
factory.generateToken(credentialAccessBoundary). - Simulating a token consumer that uses the downscoped token to access a Cloud Storage object.
- Retrieving source credentials using
The checklist in the pull request description indicates that the author has followed the sample format guide, updated the pom.xml, README, CODEOWNERS, and blunderbuss files appropriately. Tests and lint checks have been performed and passed. Static analysis is advisory only.
Overall, the changes appear well-structured and documented. I'll be checking the code for correctness, security, and best practices in my full review.
And now, a little haiku to lighten the mood:
Scoped tokens flow,
Access controlled, precise, clean,
Code's grace takes flight.
ghost
left a comment
There was a problem hiding this comment.
This pull request adds an example for client-side Credential Access Boundary (CAB) token generation. The example demonstrates how to generate downscoped tokens for accessing Google Cloud Storage (GCS) objects. Overall, the code is well-structured and easy to follow. However, there are a few minor improvements that can be made.
I've summarized the Google Java Style Guide elements referenced in this review below:
- Naming: Class names should be nouns, in mixed case with the first letter of each internal word capitalized. Method names should be verbs, in mixed case with the first letter lowercase, with the first letter of each internal word capitalized.
- Comments: Every class, method, and field declaration should have a documentation comment.
- TODO Comments: Use TODO comments for code that is temporary, a short-term solution, or good-enough but not perfect.
I've also included suggestions for updating the README file to reflect the new example.
|
Here is the summary of changes. You are about to add 4 region tags.
This comment is generated by snippet-bot.
|
minherz
left a comment
There was a problem hiding this comment.
please align PR to follow guidelines
...ain/java/com/google/cloud/auth/samples/ClientSideCredentialAccessBoundaryFactoryExample.java
Outdated
Show resolved
Hide resolved
...ain/java/com/google/cloud/auth/samples/ClientSideCredentialAccessBoundaryFactoryExample.java
Outdated
Show resolved
Hide resolved
...t/java/com/google/cloud/auth/samples/ClientSideCredentialAccessBoundaryFactoryExampleIT.java
Outdated
Show resolved
Hide resolved
...t/java/com/google/cloud/auth/samples/ClientSideCredentialAccessBoundaryFactoryExampleIT.java
Outdated
Show resolved
Hide resolved
minherz
left a comment
There was a problem hiding this comment.
lgtm. Very solid and easy to understand code. Please, notice the feedback regarding lengthy comments.
| // The common pattern of usage is to have a token broker pass the downscoped short-lived | ||
| // access tokens to a token consumer via some secure authenticated channel. | ||
| // For illustration purposes, we are generating the downscoped token locally. | ||
| // We want to test the ability to limit access to objects with a certain prefix string | ||
| // in the resource bucket. objectName.substring(0, 3) is the prefix here. This field is | ||
| // not required if access to all bucket resources are allowed. If access to limited | ||
| // resources in the bucket is needed, this mechanism can be used. |
There was a problem hiding this comment.
nit: for further notice, we discourage placing lengthy explanations in the code. you should collaborate with tech writer to have these recommendations placed in the documentation that demonstrates the code snippet instead.
Description
Adds a sample for the client-side CAB token generation.
Note: The client-side cab token generator hasn't been released yet. The SDK team is targeting a release on Feb 3rd (PR)
Checklist
pom.xmlparent set to latestshared-configurationmvn clean verifyrequiredmvn -P lint checkstyle:checkrequiredmvn -P lint clean compile pmd:cpd-check spotbugs:checkadvisory only