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
feat: adds suppliers for custom subject token and AWS credentials (#1795)
* feat: refactor AWS and identity pool clients to use suppliers (#1776)
* feat: refactor aws and identity pool credentials to use suppliers
* Apply suggestions from code review
Co-authored-by: Leo <[email protected]>
* Apply suggestions from code review
Co-authored-by: Daniel Bankhead <[email protected]>
* updating suppliers to use options objects
* updating docs
* moved transporter to context object and deprecated consts
* fix imports
---------
Co-authored-by: Leo <[email protected]>
Co-authored-by: Daniel Bankhead <[email protected]>
* feat: adds support for creating AWS and Identity Pool credentials with custom suppliers. (#1783)
* feat: adds support for users to build credentials with custom suppliers
Also adds default values to make it easier to instantiate credentials in code.
* Apply suggestions from code review
Co-authored-by: Leo <[email protected]>
* responding to review comments
---------
Co-authored-by: Leo <[email protected]>
* docs: adding documentation for programmatic auth feature (#1790)
* docs: adding documentation for programmatic auth feature
* fix typos
* Apply suggestions from code review
Co-authored-by: Leo <[email protected]>
Co-authored-by: Daniel Bankhead <[email protected]>
* add audience placeholder
---------
Co-authored-by: Leo <[email protected]>
Co-authored-by: Daniel Bankhead <[email protected]>
* 🦉 Updates from OwlBot post-processor
See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md
* fix lint
---------
Co-authored-by: Leo <[email protected]>
Co-authored-by: Daniel Bankhead <[email protected]>
Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
Copy file name to clipboardexpand all lines: .readme-partials.yaml
+126
Original file line number
Diff line number
Diff line change
@@ -356,6 +356,55 @@ body: |-
356
356
357
357
You can now [start using the Auth library](#using-external-identities) to call Google Cloud resources from AWS.
358
358
359
+
### Accessing resources from AWS using a custom AWS security credentials supplier.
360
+
361
+
In order to access Google Cloud resources from Amazon Web Services (AWS), the following requirements are needed:
362
+
- A workload identity pool needs to be created.
363
+
- 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).
364
+
- Permission to impersonate a service account needs to be granted to the external identity.
365
+
366
+
Follow the detailed [instructions](https://cloud.google.com/iam/docs/access-resources-aws) on how to configure workload identity federation from AWS.
367
+
368
+
If you want to use AWS security credentials that cannot be retrieved using methods supported natively by this library,
369
+
a custom AwsSecurityCredentialsSupplier implementation may be specified when creating an AWS client. The supplier must
370
+
return valid, unexpired AWS security credentials when called by the GCP credential.
371
+
372
+
Note that the client does not cache the returned AWS security credentials, so caching logic should be implemented in the supplier to prevent multiple requests for the same resources.
373
+
374
+
```ts
375
+
class AwsSupplier implements AwsSecurityCredentialsSupplier {
// Return the current AWS region, i.e. 'us-east-2'.
378
+
}
379
+
380
+
async getAwsSecurityCredentials(
381
+
context: ExternalAccountSupplierContext
382
+
): Promise<AwsSecurityCredentials> {
383
+
const audience = context.audience;
384
+
// Return valid AWS security credentials for the requested audience.
385
+
}
386
+
}
387
+
388
+
const clientOptions = {
389
+
audience: '//iam.googleapis.com/projects/$PROJECT_NUMBER/locations/global/workloadIdentityPools/$WORKLOAD_POOL_ID/providers/$PROVIDER_ID', // Set the GCP audience.
390
+
subject_token_type: 'urn:ietf:params:aws:token-type:aws4_request', // Set the subject token type.
391
+
aws_security_credentials_supplier: new AwsSupplier() // Set the custom supplier.
392
+
}
393
+
394
+
const client = new AwsClient(clientOptions);
395
+
```
396
+
397
+
Where the [audience](https://cloud.google.com/iam/docs/best-practices-for-using-workload-identity-federation#provider-audience) is: `//iam.googleapis.com/projects/$PROJECT_NUMBER/locations/global/workloadIdentityPools/$WORKLOAD_POOL_ID/providers/$PROVIDER_ID`
398
+
399
+
Where the following variables need to be substituted:
400
+
401
+
* `$PROJECT_NUMBER`: The Google Cloud project number.
402
+
* `$WORKLOAD_POOL_ID`: The workload pool ID.
403
+
* `$PROVIDER_ID`: The provider ID.
404
+
405
+
406
+
The values for audience, service account impersonation URL, and any other builder field can also be found by generating a [credential configuration file with the gcloud CLI](https://cloud.google.com/sdk/gcloud/reference/iam/workload-identity-pools/create-cred-config).
407
+
359
408
### Access resources from Microsoft Azure
360
409
361
410
In order to access Google Cloud resources from Microsoft Azure, the following requirements are needed:
@@ -464,6 +513,44 @@ body: |-
464
513
- `$URL_TO_GET_OIDC_TOKEN`: The URL of the local server endpoint to call to retrieve the OIDC token.
465
514
- `$HEADER_KEY` and `$HEADER_VALUE`: The additional header key/value pairs to pass along the GET request to `$URL_TO_GET_OIDC_TOKEN`, e.g. `Metadata-Flavor=Google`.
466
515
516
+
### Accessing resources from an OIDC or SAML2.0 identity provider using a custom supplier
517
+
518
+
If you want to use OIDC or SAML2.0 that cannot be retrieved using methods supported natively by this library,
519
+
a custom SubjectTokenSupplier implementation may be specified when creating an identity pool client. The supplier must
520
+
return a valid, unexpired subject token when called by the GCP credential.
521
+
522
+
Note that the client does not cache the returned subject token, so caching logic should be implemented in the supplier to prevent multiple requests for the same resources.
523
+
524
+
```ts
525
+
class CustomSupplier implements SubjectTokenSupplier {
// Return a valid subject token for the requested audience and subject token type.
532
+
}
533
+
}
534
+
535
+
const clientOptions = {
536
+
audience: '//iam.googleapis.com/projects/$PROJECT_NUMBER/locations/global/workloadIdentityPools/$WORKLOAD_POOL_ID/providers/$PROVIDER_ID', // Set the GCP audience.
537
+
subject_token_type: 'urn:ietf:params:oauth:token-type:id_token', // Set the subject token type.
538
+
subject_token_supplier: new CustomSupplier() // Set the custom supplier.
539
+
}
540
+
541
+
const client = new CustomSupplier(clientOptions);
542
+
```
543
+
544
+
Where the [audience](https://cloud.google.com/iam/docs/best-practices-for-using-workload-identity-federation#provider-audience) is: `//iam.googleapis.com/projects/$PROJECT_NUMBER/locations/global/workloadIdentityPools/$WORKLOAD_POOL_ID/providers/$PROVIDER_ID`
545
+
546
+
Where the following variables need to be substituted:
547
+
548
+
* `$PROJECT_NUMBER`: The Google Cloud project number.
549
+
* `$WORKLOAD_POOL_ID`: The workload pool ID.
550
+
* `$PROVIDER_ID`: The provider ID.
551
+
552
+
The values for audience, service account impersonation URL, and any other builder field can also be found by generating a [credential configuration file with the gcloud CLI](https://cloud.google.com/sdk/gcloud/reference/iam/workload-identity-pools/create-cred-config).
553
+
467
554
#### Using External Account Authorized User workforce credentials
468
555
469
556
[External account authorized user credentials](https://cloud.google.com/iam/docs/workforce-obtaining-short-lived-credentials#browser-based-sign-in) allow you to sign in with a web browser to an external identity provider account via the
@@ -842,6 +929,45 @@ body: |-
842
929
You can now [use the Auth library](#using-external-identities) to call Google Cloud
843
930
resources from an OIDC or SAML provider.
844
931
932
+
### Accessing resources from an OIDC or SAML2.0 identity provider using a custom supplier
933
+
934
+
If you want to use OIDC or SAML2.0 that cannot be retrieved using methods supported natively by this library,
935
+
a custom SubjectTokenSupplier implementation may be specified when creating an identity pool client. The supplier must
936
+
return a valid, unexpired subject token when called by the GCP credential.
937
+
938
+
Note that the client does not cache the returned subject token, so caching logic should be implemented in the supplier to prevent multiple requests for the same resources.
939
+
940
+
```ts
941
+
class CustomSupplier implements SubjectTokenSupplier {
// Return a valid subject token for the requested audience and subject token type.
948
+
}
949
+
}
950
+
951
+
const clientOptions = {
952
+
audience: '//iam.googleapis.com/locations/global/workforcePools/$WORKLOAD_POOL_ID/providers/$PROVIDER_ID', // Set the GCP audience.
953
+
subject_token_type: 'urn:ietf:params:oauth:token-type:id_token', // Set the subject token type.
954
+
subject_token_supplier: new CustomSupplier() // Set the custom supplier.
955
+
}
956
+
957
+
const client = new CustomSupplier(clientOptions);
958
+
```
959
+
960
+
Where the audience is: `//iam.googleapis.com/locations/global/workforcePools/$WORKLOAD_POOL_ID/providers/$PROVIDER_ID`
961
+
962
+
Where the following variables need to be substituted:
963
+
964
+
* `WORKFORCE_POOL_ID`: The worforce pool ID.
965
+
* `$PROVIDER_ID`: The provider ID.
966
+
967
+
and the workforce pool user project is the project number associated with the [workforce pools user project](https://cloud.google.com/iam/docs/workforce-identity-federation#workforce-pools-user-project).
968
+
969
+
The values for audience, service account impersonation URL, and any other builder field can also be found by generating a [credential configuration file with the gcloud CLI](https://cloud.google.com/iam/docs/workforce-obtaining-short-lived-credentials#use_configuration_files_for_sign-in).
970
+
845
971
### Using External Identities
846
972
847
973
External identities (AWS, Azure and OIDC-based providers) can be used with `Application Default Credentials`.
Copy file name to clipboardexpand all lines: README.md
+126
Original file line number
Diff line number
Diff line change
@@ -400,6 +400,55 @@ The gcloud create-cred-config command will be updated to support this soon.
400
400
401
401
You can now [start using the Auth library](#using-external-identities) to call Google Cloud resources from AWS.
402
402
403
+
### Accessing resources from AWS using a custom AWS security credentials supplier.
404
+
405
+
In order to access Google Cloud resources from Amazon Web Services (AWS), the following requirements are needed:
406
+
- A workload identity pool needs to be created.
407
+
- 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).
408
+
- Permission to impersonate a service account needs to be granted to the external identity.
409
+
410
+
Follow the detailed [instructions](https://cloud.google.com/iam/docs/access-resources-aws) on how to configure workload identity federation from AWS.
411
+
412
+
If you want to use AWS security credentials that cannot be retrieved using methods supported natively by this library,
413
+
a custom AwsSecurityCredentialsSupplier implementation may be specified when creating an AWS client. The supplier must
414
+
return valid, unexpired AWS security credentials when called by the GCP credential.
415
+
416
+
Note that the client does not cache the returned AWS security credentials, so caching logic should be implemented in the supplier to prevent multiple requests for the same resources.
// Return the current AWS region, i.e. 'us-east-2'.
422
+
}
423
+
424
+
async getAwsSecurityCredentials(
425
+
context:ExternalAccountSupplierContext
426
+
):Promise<AwsSecurityCredentials> {
427
+
const audience =context.audience;
428
+
// Return valid AWS security credentials for the requested audience.
429
+
}
430
+
}
431
+
432
+
const clientOptions = {
433
+
audience: '//iam.googleapis.com/projects/$PROJECT_NUMBER/locations/global/workloadIdentityPools/$WORKLOAD_POOL_ID/providers/$PROVIDER_ID', // Set the GCP audience.
434
+
subject_token_type: 'urn:ietf:params:aws:token-type:aws4_request', // Set the subject token type.
435
+
aws_security_credentials_supplier: newAwsSupplier() // Set the custom supplier.
436
+
}
437
+
438
+
const client =newAwsClient(clientOptions);
439
+
```
440
+
441
+
Where the [audience](https://cloud.google.com/iam/docs/best-practices-for-using-workload-identity-federation#provider-audience) is: `//iam.googleapis.com/projects/$PROJECT_NUMBER/locations/global/workloadIdentityPools/$WORKLOAD_POOL_ID/providers/$PROVIDER_ID`
442
+
443
+
Where the following variables need to be substituted:
444
+
445
+
*`$PROJECT_NUMBER`: The Google Cloud project number.
446
+
*`$WORKLOAD_POOL_ID`: The workload pool ID.
447
+
*`$PROVIDER_ID`: The provider ID.
448
+
449
+
450
+
The values for audience, service account impersonation URL, and any other builder field can also be found by generating a [credential configuration file with the gcloud CLI](https://cloud.google.com/sdk/gcloud/reference/iam/workload-identity-pools/create-cred-config).
451
+
403
452
### Access resources from Microsoft Azure
404
453
405
454
In order to access Google Cloud resources from Microsoft Azure, the following requirements are needed:
@@ -508,6 +557,44 @@ Where the following variables need to be substituted:
508
557
-`$URL_TO_GET_OIDC_TOKEN`: The URL of the local server endpoint to call to retrieve the OIDC token.
509
558
-`$HEADER_KEY` and `$HEADER_VALUE`: The additional header key/value pairs to pass along the GET request to `$URL_TO_GET_OIDC_TOKEN`, e.g. `Metadata-Flavor=Google`.
510
559
560
+
### Accessing resources from an OIDC or SAML2.0 identity provider using a custom supplier
561
+
562
+
If you want to use OIDC or SAML2.0 that cannot be retrieved using methods supported natively by this library,
563
+
a custom SubjectTokenSupplier implementation may be specified when creating an identity pool client. The supplier must
564
+
return a valid, unexpired subject token when called by the GCP credential.
565
+
566
+
Note that the client does not cache the returned subject token, so caching logic should be implemented in the supplier to prevent multiple requests for the same resources.
// Return a valid subject token for the requested audience and subject token type.
576
+
}
577
+
}
578
+
579
+
const clientOptions = {
580
+
audience: '//iam.googleapis.com/projects/$PROJECT_NUMBER/locations/global/workloadIdentityPools/$WORKLOAD_POOL_ID/providers/$PROVIDER_ID', // Set the GCP audience.
581
+
subject_token_type: 'urn:ietf:params:oauth:token-type:id_token', // Set the subject token type.
582
+
subject_token_supplier: newCustomSupplier() // Set the custom supplier.
583
+
}
584
+
585
+
const client =newCustomSupplier(clientOptions);
586
+
```
587
+
588
+
Where the [audience](https://cloud.google.com/iam/docs/best-practices-for-using-workload-identity-federation#provider-audience) is: `//iam.googleapis.com/projects/$PROJECT_NUMBER/locations/global/workloadIdentityPools/$WORKLOAD_POOL_ID/providers/$PROVIDER_ID`
589
+
590
+
Where the following variables need to be substituted:
591
+
592
+
*`$PROJECT_NUMBER`: The Google Cloud project number.
593
+
*`$WORKLOAD_POOL_ID`: The workload pool ID.
594
+
*`$PROVIDER_ID`: The provider ID.
595
+
596
+
The values for audience, service account impersonation URL, and any other builder field can also be found by generating a [credential configuration file with the gcloud CLI](https://cloud.google.com/sdk/gcloud/reference/iam/workload-identity-pools/create-cred-config).
597
+
511
598
#### Using External Account Authorized User workforce credentials
512
599
513
600
[External account authorized user credentials](https://cloud.google.com/iam/docs/workforce-obtaining-short-lived-credentials#browser-based-sign-in) allow you to sign in with a web browser to an external identity provider account via the
@@ -886,6 +973,45 @@ credentials unless they do not meet your specific requirements.
886
973
You can now [use the Auth library](#using-external-identities) to call Google Cloud
887
974
resources from an OIDC or SAML provider.
888
975
976
+
### Accessing resources from an OIDC or SAML2.0 identity provider using a custom supplier
977
+
978
+
If you want to use OIDC or SAML2.0 that cannot be retrieved using methods supported natively by this library,
979
+
a custom SubjectTokenSupplier implementation may be specified when creating an identity pool client. The supplier must
980
+
return a valid, unexpired subject token when called by the GCP credential.
981
+
982
+
Note that the client does not cache the returned subject token, so caching logic should be implemented in the supplier to prevent multiple requests for the same resources.
// Return a valid subject token for the requested audience and subject token type.
992
+
}
993
+
}
994
+
995
+
const clientOptions = {
996
+
audience: '//iam.googleapis.com/locations/global/workforcePools/$WORKLOAD_POOL_ID/providers/$PROVIDER_ID', // Set the GCP audience.
997
+
subject_token_type: 'urn:ietf:params:oauth:token-type:id_token', // Set the subject token type.
998
+
subject_token_supplier: newCustomSupplier() // Set the custom supplier.
999
+
}
1000
+
1001
+
const client =newCustomSupplier(clientOptions);
1002
+
```
1003
+
1004
+
Where the audience is: `//iam.googleapis.com/locations/global/workforcePools/$WORKLOAD_POOL_ID/providers/$PROVIDER_ID`
1005
+
1006
+
Where the following variables need to be substituted:
1007
+
1008
+
*`WORKFORCE_POOL_ID`: The worforce pool ID.
1009
+
*`$PROVIDER_ID`: The provider ID.
1010
+
1011
+
and the workforce pool user project is the project number associated with the [workforce pools user project](https://cloud.google.com/iam/docs/workforce-identity-federation#workforce-pools-user-project).
1012
+
1013
+
The values for audience, service account impersonation URL, and any other builder field can also be found by generating a [credential configuration file with the gcloud CLI](https://cloud.google.com/iam/docs/workforce-obtaining-short-lived-credentials#use_configuration_files_for_sign-in).
1014
+
889
1015
### Using External Identities
890
1016
891
1017
External identities (AWS, Azure and OIDC-based providers) can be used with `Application Default Credentials`.
0 commit comments