Skip to content

Commit 6f1e639

Browse files
Galadroscodyoss
authored andcommitted
google/downscope: update documentation
Change-Id: Ib4dfc7b554c1e7565cc61bc372a98ddd390e7453 GitHub-Last-Rev: 63894e5 GitHub-Pull-Request: #512 Reviewed-on: https://go-review.googlesource.com/c/oauth2/+/338389 Reviewed-by: Cody Oss <codyoss@google.com> Reviewed-by: Chris Broadfoot <cbro@golang.org> Trust: Cody Oss <codyoss@google.com> Trust: Chris Broadfoot <cbro@golang.org> Run-TryBot: Cody Oss <codyoss@google.com> Run-TryBot: Chris Broadfoot <cbro@golang.org> TryBot-Result: Go Bot <gobot@golang.org>
1 parent a41e5a7 commit 6f1e639

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

‎google/downscope/downscoping.go

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,34 @@
44

55
/*
66
Package downscope implements the ability to downscope, or restrict, the
7-
Identity and AccessManagement permissions that a short-lived Token
7+
Identity and Access Management permissions that a short-lived Token
88
can use. Please note that only Google Cloud Storage supports this feature.
99
For complete documentation, see https://cloud.google.com/iam/docs/downscoping-short-lived-credentials
10+
11+
To downscope permissions of a source credential, you need to define
12+
a Credential Access Boundary. Said Boundary specifies which resources
13+
the newly created credential can access, an upper bound on the permissions
14+
it has over those resources, and optionally attribute-based conditional
15+
access to the aforementioned resources. For more information on IAM
16+
Conditions, see https://cloud.google.com/iam/docs/conditions-overview.
17+
18+
This functionality would typically be used to provide a third party with
19+
limited access to and permissions on resources held by the owner of the root
20+
credential or internally in conjunction with the principle of least privilege
21+
to ensure that internal services only hold the minimum necessary privileges
22+
for their function.
23+
24+
For example, a token broker can be set up on a server in a private network.
25+
Various workloads (token consumers) in the same network will send authenticated
26+
requests to that broker for downscoped tokens to access or modify specific google
27+
cloud storage buckets. See the NewTokenSource example for an example of how a
28+
token broker would use this package.
29+
30+
The broker will use the functionality in this package to generate a downscoped
31+
token with the requested configuration, and then pass it back to the token
32+
consumer. These downscoped access tokens can then be used to access Google
33+
Storage resources. For instance, you can create a NewClient from the
34+
"cloud.google.com/go/storage" package and pass in option.WithTokenSource(yourTokenSource))
1035
*/
1136
package downscope
1237

@@ -91,7 +116,7 @@ type downscopingTokenSource struct {
91116
config DownscopingConfig
92117
}
93118

94-
// NewTokenSource returns an empty downscopingTokenSource.
119+
// NewTokenSource returns a configured downscopingTokenSource.
95120
func NewTokenSource(ctx context.Context, conf DownscopingConfig) (oauth2.TokenSource, error) {
96121
if conf.RootSource == nil {
97122
return nil, fmt.Errorf("downscope: rootSource cannot be nil")

‎google/downscope/example_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package downscope_test
66

77
import (
88
"context"
9+
"fmt"
910

1011
"golang.org/x/oauth2"
1112
"golang.org/x/oauth2/google/downscope"
@@ -29,8 +30,13 @@ func ExampleNewTokenSource() {
2930

3031
dts, err := downscope.NewTokenSource(ctx, downscope.DownscopingConfig{RootSource: rootSource, Rules: accessBoundary})
3132
if err != nil {
32-
_ = dts
33+
fmt.Printf("failed to generate downscoped token source: %v", err)
34+
return
3335
}
36+
37+
// Enables automatic token refreshing
38+
_ = oauth2.ReuseTokenSource(nil, dts)
39+
3440
// You can now use the token held in myTokenSource to make
3541
// Google Cloud Storage calls, as follows:
3642

0 commit comments

Comments
 (0)