Skip to content

Commit 893257f

Browse files
committed
chore: readme file wording updated based on comments feedback.
1 parent 53f81e1 commit 893257f

File tree

1 file changed

+36
-5
lines changed

1 file changed

+36
-5
lines changed

README.md

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -997,28 +997,41 @@ CredentialAccessBoundary:
997997

998998
* Server-side: Uses the `DownscopedCredentials` class. Each time a
999999
downscoped token is needed, the client makes a call to the Security Token Service (STS).
1000-
This is suitable for applications that require downscoped tokens infrequently.
1000+
This is suitable for applications that require downscoped tokens infrequently, or applications that reuse a single downscoped credential many times.
10011001
* Client-side: Uses the `ClientSideCredentialAccessBoundaryFactory` class. This
10021002
approach minimizes calls to STS. The client retrieves necessary cryptographic
10031003
material once and then generates multiple downscoped tokens locally. This is
1004-
more efficient for applications that need to generate many downscoped tokens.
1004+
more efficient for applications that need to generate many unique downscoped tokens.
10051005

10061006
#### Server-side CAB
10071007

10081008
The `DownscopedCredentials` class can be used to produce a downscoped access
1009-
token from a source credential and the `CredentialAccessBoundary` created above
1010-
in the Token Broker:
1009+
token from a source credential and the `CredentialAccessBoundary`.
10111010

10121011
```java
10131012
// Retrieve the source credentials from ADC.
10141013
GoogleCredentials sourceCredentials = GoogleCredentials.getApplicationDefault()
10151014
.createScoped("https://www.googleapis.com/auth/cloud-platform");
10161015

1016+
// Create an Access Boundary Rule which will restrict the downscoped token to having readonly
1017+
// access to objects starting with "customer-a" in bucket "bucket-123".
1018+
String availableResource = "//storage.googleapis.com/projects/_/buckets/bucket-123";
1019+
String availablePermission = "inRole:roles/storage.objectViewer";
1020+
String expression = "resource.name.startsWith('projects/_/buckets/bucket-123/objects/customer-a')";
1021+
1022+
CredentialAccessBoundary.AccessBoundaryRule rule =
1023+
CredentialAccessBoundary.AccessBoundaryRule.newBuilder()
1024+
.setAvailableResource(availableResource)
1025+
.addAvailablePermission(availablePermission)
1026+
.setAvailabilityCondition(
1027+
new AvailabilityCondition(expression, /* title= */ null, /* description= */ null))
1028+
.build();
1029+
10171030
// Initialize the DownscopedCredentials class.
10181031
DownscopedCredentials downscopedCredentials =
10191032
DownscopedCredentials.newBuilder()
10201033
.setSourceCredential(sourceCredentials)
1021-
.setCredentialAccessBoundary(credentialAccessBoundary)
1034+
.setCredentialAccessBoundary(CredentialAccessBoundary.newBuilder().addRule(rule).build())
10221035
.build();
10231036

10241037
// Retrieve the downscoped access token.
@@ -1038,12 +1051,30 @@ objects to create multiple downscoped tokens.
10381051
GoogleCredentials sourceCredentials = GoogleCredentials.getApplicationDefault()
10391052
.createScoped("https://www.googleapis.com/auth/cloud-platform");
10401053

1054+
// Create an Access Boundary Rule which will restrict the downscoped token to having readonly
1055+
// access to objects starting with "customer-a" in bucket "bucket-123".
1056+
String availableResource = "//storage.googleapis.com/projects/_/buckets/bucket-123";
1057+
String availablePermission = "inRole:roles/storage.objectViewer";
1058+
String expression = "resource.name.startsWith('projects/_/buckets/bucket-123/objects/customer-a')";
1059+
1060+
CredentialAccessBoundary.AccessBoundaryRule rule =
1061+
CredentialAccessBoundary.AccessBoundaryRule.newBuilder()
1062+
.setAvailableResource(availableResource)
1063+
.addAvailablePermission(availablePermission)
1064+
.setAvailabilityCondition(
1065+
new AvailabilityCondition(expression, /* title= */ null, /* description= */ null))
1066+
.build();
1067+
10411068
// Initialize the ClientSideCredentialAccessBoundaryFactory.
10421069
ClientSideCredentialAccessBoundaryFactory factory =
10431070
ClientSideCredentialAccessBoundaryFactory.newBuilder()
10441071
.setSourceCredential(sourceCredentials)
10451072
.build();
10461073

1074+
// Create the CredentialAccessBoundary with the rule.
1075+
CredentialAccessBoundary credentialAccessBoundary =
1076+
CredentialAccessBoundary.newBuilder().addRule(rule).build();
1077+
10471078
// Generate the downscoped access token.
10481079
// This will need to be passed to the Token Consumer.
10491080
AccessToken downscopedAccessToken = factory.generateToken(credentialAccessBoundary);

0 commit comments

Comments
 (0)