Skip to content

Commit f145937

Browse files
bojeil-googlecodyoss
authored andcommitted
google: update documentation for workload identity federation
Document using workload identity federation from non-Google Cloud platforms to access Google Cloud resources. This covers federation from AWS, Azure and OIDC providers via Application Default Credentials. Change-Id: I77ee7f6aac5a75d095304f07f3004ec3fb7b9613 GitHub-Last-Rev: 07c9dd0 GitHub-Pull-Request: #478 Reviewed-on: https://go-review.googlesource.com/c/oauth2/+/293751 Reviewed-by: Cody Oss <codyoss@google.com> Trust: Cody Oss <codyoss@google.com> Trust: Tyler Bui-Palsulich <tbp@google.com> Run-TryBot: Cody Oss <codyoss@google.com> TryBot-Result: Go Bot <gobot@golang.org>
1 parent 16ff188 commit f145937

File tree

2 files changed

+53
-4
lines changed

2 files changed

+53
-4
lines changed

google/default.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ import (
2121
// Credentials holds Google credentials, including "Application Default Credentials".
2222
// For more details, see:
2323
// https://developers.google.com/accounts/docs/application-default-credentials
24+
// Credentials from external accounts (workload identity federation) are used to
25+
// identify a particular application from an on-prem or non-Google Cloud platform
26+
// including Amazon Web Services (AWS), Microsoft Azure or any identity provider
27+
// that supports OpenID Connect (OIDC).
2428
type Credentials struct {
2529
ProjectID string // may be empty
2630
TokenSource oauth2.TokenSource
@@ -65,6 +69,10 @@ func DefaultTokenSource(ctx context.Context, scope ...string) (oauth2.TokenSourc
6569
//
6670
// 1. A JSON file whose path is specified by the
6771
// GOOGLE_APPLICATION_CREDENTIALS environment variable.
72+
// For workload identity federation, refer to
73+
// https://cloud.google.com/iam/docs/how-to#using-workload-identity-federation on
74+
// how to generate the JSON configuration file for on-prem/non-Google cloud
75+
// platforms.
6876
// 2. A JSON file in a location known to the gcloud command-line tool.
6977
// On Windows, this is %APPDATA%/gcloud/application_default_credentials.json.
7078
// On other systems, $HOME/.config/gcloud/application_default_credentials.json.
@@ -119,8 +127,10 @@ func FindDefaultCredentials(ctx context.Context, scopes ...string) (*Credentials
119127

120128
// CredentialsFromJSON obtains Google credentials from a JSON value. The JSON can
121129
// represent either a Google Developers Console client_credentials.json file (as in
122-
// ConfigFromJSON) or a Google Developers service account key file (as in
123-
// JWTConfigFromJSON).
130+
// ConfigFromJSON), a Google Developers service account key file (as in
131+
// JWTConfigFromJSON) or the JSON configuration file for workload identity federation
132+
// in non-Google cloud platforms (see
133+
// https://cloud.google.com/iam/docs/how-to#using-workload-identity-federation).
124134
func CredentialsFromJSON(ctx context.Context, jsonData []byte, scopes ...string) (*Credentials, error) {
125135
var f credentialsFile
126136
if err := json.Unmarshal(jsonData, &f); err != nil {

google/doc.go

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@
44

55
// Package google provides support for making OAuth2 authorized and authenticated
66
// HTTP requests to Google APIs. It supports the Web server flow, client-side
7-
// credentials, service accounts, Google Compute Engine service accounts, and Google
8-
// App Engine service accounts.
7+
// credentials, service accounts, Google Compute Engine service accounts, Google
8+
// App Engine service accounts and workload identity federation from non-Google
9+
// cloud platforms.
910
//
1011
// A brief overview of the package follows. For more information, please read
1112
// https://developers.google.com/accounts/docs/OAuth2
1213
// and
1314
// https://developers.google.com/accounts/docs/application-default-credentials.
15+
// For more information on using workload identity federation, refer to
16+
// https://cloud.google.com/iam/docs/how-to#using-workload-identity-federation.
1417
//
1518
// OAuth2 Configs
1619
//
@@ -19,6 +22,35 @@
1922
// the other by JWTConfigFromJSON. The returned Config can be used to obtain a TokenSource or
2023
// create an http.Client.
2124
//
25+
// Workload Identity Federation
26+
//
27+
// Using workload identity federation, your application can access Google Cloud
28+
// resources from Amazon Web Services (AWS), Microsoft Azure or any identity
29+
// provider that supports OpenID Connect (OIDC).
30+
// Traditionally, applications running outside Google Cloud have used service
31+
// account keys to access Google Cloud resources. Using identity federation,
32+
// you can allow your workload to impersonate a service account.
33+
// This lets you access Google Cloud resources directly, eliminating the
34+
// maintenance and security burden associated with service account keys.
35+
//
36+
// Follow the detailed instructions on how to configure Workload Identity Federation
37+
// in various platforms:
38+
//
39+
// Amazon Web Services (AWS): https://cloud.google.com/iam/docs/access-resources-aws
40+
// Microsoft Azure: https://cloud.google.com/iam/docs/access-resources-azure
41+
// OIDC identity provider: https://cloud.google.com/iam/docs/access-resources-oidc
42+
//
43+
// For OIDC providers, the library can retrieve OIDC tokens either from a
44+
// local file location (file-sourced credentials) or from a local server
45+
// (URL-sourced credentials).
46+
// For file-sourced credentials, a background process needs to be continuously
47+
// refreshing the file location with a new OIDC token prior to expiration.
48+
// For tokens with one hour lifetimes, the token needs to be updated in the file
49+
// every hour. The token can be stored directly as plain text or in JSON format.
50+
// For URL-sourced credentials, a local server needs to host a GET endpoint to
51+
// return the OIDC token. The response can be in plain text or JSON.
52+
// Additional required request headers can also be specified.
53+
//
2254
//
2355
// Credentials
2456
//
@@ -29,6 +61,13 @@
2961
// FindDefaultCredentials looks in some well-known places for a credentials file, and
3062
// will call AppEngineTokenSource or ComputeTokenSource as needed.
3163
//
64+
// Application Default Credentials also support workload identity federation to
65+
// access Google Cloud resources from non-Google Cloud platforms including Amazon
66+
// Web Services (AWS), Microsoft Azure or any identity provider that supports
67+
// OpenID Connect (OIDC). Workload identity federation is recommended for
68+
// non-Google Cloud environments as it avoids the need to download, manage and
69+
// store service account private keys locally.
70+
//
3271
// DefaultClient and DefaultTokenSource are convenience methods. They first call FindDefaultCredentials,
3372
// then use the credentials to construct an http.Client or an oauth2.TokenSource.
3473
//

0 commit comments

Comments
 (0)