Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: adds docs for supplier based external account credentials #1362

Merged
merged 17 commits into from
Feb 7, 2024
Merged
57 changes: 57 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,63 @@ credentials unless they do not meet your specific requirements.
You can now [use the Auth library](#using-external-identities) to call Google Cloud
resources from an OIDC or SAML provider.

#### Using a custom supplier with OIDC and SAML
aeitzman marked this conversation as resolved.
Show resolved Hide resolved
A custom implementation of IdentityPoolSubjectTokenSupplier can be used while building IdentityPoolCredentials
to supply a subject token which can be exchanged for a GCP access token.

```java
class TokenSupplier implements IdentityPoolSubjectTokenSupplier {
aeitzman marked this conversation as resolved.
Show resolved Hide resolved
@Override
String getSubjectToken(){
aeitzman marked this conversation as resolved.
Show resolved Hide resolved
// return a valid subject token for the configured identity.
aeitzman marked this conversation as resolved.
Show resolved Hide resolved
aeitzman marked this conversation as resolved.
Show resolved Hide resolved
}
}
```
```java
TokenSupplier tokenSupplier = new TokenSupplier();
IdentityPoolCredentials identityPoolCredentials =
IdentityPoolCredentials.newBuilder()
.setSubjectTokenSupplier(tokenSupplier) // Set token supplier.
.setAudience(...) // Set GCP audience
.setSubjectTokenType(SubjectTokenTypes.JWT) // Set subject token type.
.build();
aeitzman marked this conversation as resolved.
Show resolved Hide resolved
```
Where the audience is the url of the [workload pool](https://cloud.google.com/iam/docs/best-practices-for-using-workload-identity-federation#provider-audience).
aeitzman marked this conversation as resolved.
Show resolved Hide resolved

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.
aeitzman marked this conversation as resolved.
Show resolved Hide resolved

#### Using a custom supplier with AWS
A custom implementation of AWSSecurityCredentialsSupplier can be used while building AWSCredentials to supply
AWS security credentials which can be exchanged for a GCP access token.
aeitzman marked this conversation as resolved.
Show resolved Hide resolved

```java
class AwsSupplier implements AwsSecurityCredentialsSupplier {
aeitzman marked this conversation as resolved.
Show resolved Hide resolved
@Override
AwsSecurityCredentials getAwsSecurityCredentials(){
// return valid AwsSecurityCredentials for the configured identity.
aeitzman marked this conversation as resolved.
Show resolved Hide resolved
}

@Override
String getRegion(){
// return the current AWS region, i.e. "us-east-2"
aeitzman marked this conversation as resolved.
Show resolved Hide resolved
}
}
```
```java
AwsSecurityCredentialsSupplier awsSupplier = new AwsSupplier();
AwsCredentials credentials = AwsCredentials.newBuilder()
.setSubjectTokenType(SubjectTokenTypes.AWS4) // Set subject token type.
.setAudience(...) // Set GCP audience.
.setAwsSecurityCredentialsSupplier(supplier) // Set supplier.
aeitzman marked this conversation as resolved.
Show resolved Hide resolved
.build();
```

Where the audience is the url of the [workload pool](https://cloud.google.com/iam/docs/best-practices-for-using-workload-identity-federation#provider-audience).
aeitzman marked this conversation as resolved.
Show resolved Hide resolved

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.

#### Configurable Token Lifetime
When creating a credential configuration with workload identity federation using service account impersonation, you can provide an optional argument to configure the service account access token lifetime.

Expand Down
Loading