You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+219
Original file line number
Diff line number
Diff line change
@@ -106,6 +106,12 @@ access tokens
106
106
-`ServiceAccountJwtAccessCredentials`: credentials for a Service Account - use JSON Web Token (JWT)
107
107
directly in the request metadata to provide authorization
108
108
-`UserCredentials`: credentials for a user identity and consent
109
+
-`ExternalAccountCredentials`: base class for credentials using workload identity federation to
110
+
access Google Cloud resources from non-Google Cloud platforms
111
+
-`IdentityPoolCredentials`: credentials using workload identity federation to access Google Cloud
112
+
resources from Microsoft Azure or any identity provider that supports OpenID Connect (OIDC)
113
+
-`AwsCredentials`: credentials using workload identity federation to access Google Cloud resources
114
+
from Amazon Web Services (AWS)
109
115
110
116
To get Application Default Credentials use `GoogleCredentials.getApplicationDefault()` or
111
117
`GoogleCredentials.getApplicationDefault(HttpTransportFactory)`. These methods return the
@@ -159,6 +165,219 @@ for (Bucket b : storage_service.list().iterateAll())
159
165
System.out.println(b);
160
166
```
161
167
168
+
### Workload Identity Federation
169
+
170
+
Using workload identity federation, your application can access Google Cloud resources from
171
+
Amazon Web Services (AWS), Microsoft Azure, or any identity provider that supports OpenID Connect
172
+
(OIDC).
173
+
174
+
Traditionally, applications running outside Google Cloud have used service account keys to access
175
+
Google Cloud resources. Using identity federation, your workload can impersonate a service account.
176
+
This lets the external workload access Google Cloud resources directly, eliminating the maintenance
177
+
and security burden associated with service account keys.
178
+
179
+
#### Accessing resources from AWS
180
+
181
+
In order to access Google Cloud resources from Amazon Web Services (AWS), the following requirements
182
+
are needed:
183
+
- A workload identity pool needs to be created.
184
+
- AWS needs to be added as an identity provider in the workload identity pool (the Google [organization policy](https://cloud.google.com/iam/docs/manage-workload-identity-pools-providers#restrict) needs to allow federation from AWS).
185
+
- Permission to impersonate a service account needs to be granted to the external identity.
186
+
187
+
Follow the detailed [instructions](https://cloud.google.com/iam/docs/access-resources-aws) on how to
188
+
configure workload identity federation from AWS.
189
+
190
+
After configuring the AWS provider to impersonate a service account, a credential configuration file
191
+
needs to be generated. Unlike service account credential files, the generated credential
192
+
configuration file contains non-sensitive metadata to instruct the library on how to
193
+
retrieve external subject tokens and exchange them for service account access tokens.
194
+
The configuration file can be generated by using the [gcloud CLI](https://cloud.google.com/sdk/).
195
+
196
+
To generate the AWS workload identity configuration, run the following command:
197
+
198
+
```bash
199
+
# Generate an AWS configuration file.
200
+
gcloud iam workload-identity-pools create-cred-config \
Where the following variables need to be substituted:
208
+
-`$PROJECT_NUMBER`: The Google Cloud project number.
209
+
-`$POOL_ID`: The workload identity pool ID.
210
+
-`$AWS_PROVIDER_ID`: The AWS provider ID.
211
+
-`$SERVICE_ACCOUNT_EMAIL`: The email of the service account to impersonate.
212
+
213
+
This generates the configuration file in the specified output file.
214
+
215
+
You can now [use the Auth library](#using-external-identities) to call Google Cloud
216
+
resources from AWS.
217
+
218
+
#### Access resources from Microsoft Azure
219
+
220
+
In order to access Google Cloud resources from Microsoft Azure, the following requirements are
221
+
needed:
222
+
- A workload identity pool needs to be created.
223
+
- Azure needs to be added as an identity provider in the workload identity pool (the Google [organization policy](https://cloud.google.com/iam/docs/manage-workload-identity-pools-providers#restrict) needs to allow federation from Azure).
224
+
- The Azure tenant needs to be configured for identity federation.
225
+
- Permission to impersonate a service account needs to be granted to the external identity.
226
+
227
+
Follow the detailed [instructions](https://cloud.google.com/iam/docs/access-resources-azure) on how
228
+
to configure workload identity federation from Microsoft Azure.
229
+
230
+
After configuring the Azure provider to impersonate a service account, a credential configuration
231
+
file needs to be generated. Unlike service account credential files, the generated credential
232
+
configuration file contains non-sensitive metadata to instruct the library on how to
233
+
retrieve external subject tokens and exchange them for service account access tokens.
234
+
The configuration file can be generated by using the [gcloud CLI](https://cloud.google.com/sdk/).
235
+
236
+
To generate the Azure workload identity configuration, run the following command:
237
+
238
+
```bash
239
+
# Generate an Azure configuration file.
240
+
gcloud iam workload-identity-pools create-cred-config \
Where the following variables need to be substituted:
248
+
-`$PROJECT_NUMBER`: The Google Cloud project number.
249
+
-`$POOL_ID`: The workload identity pool ID.
250
+
-`$AZURE_PROVIDER_ID`: The Azure provider ID.
251
+
-`$SERVICE_ACCOUNT_EMAIL`: The email of the service account to impersonate.
252
+
253
+
This generates the configuration file in the specified output file.
254
+
255
+
You can now [use the Auth library](#using-external-identities) to call Google Cloud
256
+
resources from Azure.
257
+
258
+
#### Accessing resources from an OIDC identity provider
259
+
260
+
In order to access Google Cloud resources from an identity provider that supports [OpenID Connect (OIDC)](https://openid.net/connect/), the following requirements are needed:
261
+
- A workload identity pool needs to be created.
262
+
- An OIDC identity provider needs to be added in the workload identity pool (the Google [organization policy](https://cloud.google.com/iam/docs/manage-workload-identity-pools-providers#restrict) needs to allow federation from the identity provider).
263
+
- Permission to impersonate a service account needs to be granted to the external identity.
264
+
265
+
Follow the detailed [instructions](https://cloud.google.com/iam/docs/access-resources-oidc) on how
266
+
to configure workload identity federation from an OIDC identity provider.
267
+
268
+
After configuring the OIDC provider to impersonate a service account, a credential configuration
269
+
file needs to be generated. Unlike service account credential files, the generated credential
270
+
configuration file contains non-sensitive metadata to instruct the library on how to
271
+
retrieve external subject tokens and exchange them for service account access tokens.
272
+
The configuration file can be generated by using the [gcloud CLI](https://cloud.google.com/sdk/).
273
+
274
+
For OIDC providers, the Auth library can retrieve OIDC tokens either from a local file location
275
+
(file-sourced credentials) or from a local server (URL-sourced credentials).
276
+
277
+
**File-sourced credentials**
278
+
For file-sourced credentials, a background process needs to be continuously refreshing the file
279
+
location with a new OIDC token prior to expiration. For tokens with one hour lifetimes, the token
280
+
needs to be updated in the file every hour. The token can be stored directly as plain text or in
281
+
JSON format.
282
+
283
+
To generate a file-sourced OIDC configuration, run the following command:
284
+
285
+
```bash
286
+
# Generate an OIDC configuration file for file-sourced credentials.
287
+
gcloud iam workload-identity-pools create-cred-config \
0 commit comments