Skip to content
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

feat: Adds Client-Side Credential Access Boundary Factory example. #9994

Merged
merged 9 commits into from
Feb 11, 2025

Conversation

nbayati
Copy link
Contributor

@nbayati nbayati commented Jan 24, 2025

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

  • I have followed Sample Format Guide
  • pom.xml parent set to latest shared-configuration
  • Appropriate changes to README are included in PR
  • These samples need a new API enabled in testing projects to pass (let us know which ones)
  • These samples need a new/updated env vars in testing projects set to pass (let us know which ones)
  • Tests pass: mvn clean verify required
  • Lint passes: mvn -P lint checkstyle:check required
  • Static Analysis: mvn -P lint clean compile pmd:cpd-check spotbugs:check advisory only
  • This sample adds a new sample directory, and I updated the CODEOWNERS file with the codeowners for this sample
  • This sample adds a new Product API, and I updated the Blunderbuss issue/PR auto-assigner with the codeowners for this sample
  • Please merge this PR for me once it is approved

@nbayati nbayati requested review from yoshi-approver and a team as code owners January 24, 2025 20:39
Copy link
Contributor

@code-review-assist code-review-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.java was 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 ClientSideCredentialAccessBoundaryFactory instance.
    • Generating a downscoped token using factory.generateToken(credentialAccessBoundary).
    • Simulating a token consumer that uses the downscoped token to access a Cloud Storage object.

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.

@product-auto-label product-auto-label bot added samples Issues that are directly related to samples. api: auth labels Jan 24, 2025
Copy link
Contributor

@code-review-assist code-review-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link

snippet-bot bot commented Jan 24, 2025

Here is the summary of changes.

You are about to add 4 region tags.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

Copy link
Contributor

@minherz minherz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please align PR to follow guidelines

@nbayati nbayati requested a review from minherz February 5, 2025 23:43
Copy link
Contributor

@minherz minherz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm. Very solid and easy to understand code. Please, notice the feedback regarding lengthy comments.

Comment on lines +65 to +71
// 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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@minherz minherz added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Feb 10, 2025
@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Feb 10, 2025
@minherz minherz added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Feb 10, 2025
@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Feb 10, 2025
@ldetmer ldetmer added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Feb 11, 2025
@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Feb 11, 2025
@ldetmer ldetmer added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Feb 11, 2025
@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Feb 11, 2025
@ldetmer ldetmer added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Feb 11, 2025
@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Feb 11, 2025
@minherz minherz added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Feb 11, 2025
@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Feb 11, 2025
@minherz minherz added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Feb 11, 2025
@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Feb 11, 2025
@minherz minherz merged commit d9f01f1 into GoogleCloudPlatform:main Feb 11, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: auth samples Issues that are directly related to samples.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants