Workload Identity Federation works with Cloud de Confiance by S3NS authentication libraries (auth libraries) to let external workloads access Cloud de Confiance resources without service account keys. The auth libraries exchange external credentials, such as tokens from Amazon Web Services (AWS), Microsoft Azure, or OpenID Connect (OIDC) and Security Assertion Markup Language (SAML) 2.0 providers, or X.509 client certificates, for short-lived access tokens.
To obtain external credentials, you can use the standard mechanism for common setups, or implement custom credential suppliers for workflows that require custom code.
Before you begin
Enable the required APIs, if any are not already enabled.
Roles required to enable APIs
To enable APIs, you need the
serviceusage.services.enablepermission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.Configure Workload Identity Federation with your identity provider.
Authenticate using the standard credential mechanism
For commonly supported third-party identity providers, you can use the Cloud de Confiance auth library's built-in capabilities to authenticate your workloads by generating a credential configuration file. This file provides the necessary information for the auth libraries to federate identities from external providers.
The credential configuration file, typically loaded using the
GOOGLE_APPLICATION_CREDENTIALS environment variable, can instruct the auth
libraries to obtain the third-party subject token using one of the following methods:
- File-sourced: The library reads the subject token from a local file. A separate process must ensure this file contains a valid, unexpired token.
- URL-sourced: The library fetches the subject token by making a request to a specified local URL endpoint.
- Executable-sourced: The library runs a configured executable command. The standard output of the executable is expected to contain the subject token.
Generate the credential configuration file for your specific provider:
- AWS
- Azure
OIDC or SAML identity provider
This page includes instructions for the following:
Use the credential configuration file to authenticate.
To let the Cloud de Confiance by S3NS client libraries automatically locate and use your credential configuration file, set the
GOOGLE_APPLICATION_CREDENTIALSenvironment variable to the path of the generated JSON file.Export the environment variable in your shell:
bash export GOOGLE_APPLICATION_CREDENTIALS=/path/to/your/config.jsonAfter you set the environment variable, the client libraries handle the authentication flow.
The following code sample shows how to make an authenticated call to a Cloud de Confiance by S3NS API:
Node.js
To learn how to install and use the client library for IAM, see IAM client libraries. For more information, see the IAM Node.js API reference documentation.
To authenticate to IAM, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Before running code samples, set the GOOGLE_CLOUD_UNIVERSE_DOMAIN environment
variable to s3nsapis.fr.
Python
To learn how to install and use the client library for IAM, see IAM client libraries. For more information, see the IAM Python API reference documentation.
To authenticate to IAM, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Before running code samples, set the GOOGLE_CLOUD_UNIVERSE_DOMAIN environment
variable to s3nsapis.fr.
Java
To learn how to install and use the client library for IAM, see IAM client libraries. For more information, see the IAM Java API reference documentation.
To authenticate to IAM, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Before running code samples, set the GOOGLE_CLOUD_UNIVERSE_DOMAIN environment
variable to s3nsapis.fr.
Go
To learn how to install and use the client library for IAM, see IAM client libraries. For more information, see the IAM Go API reference documentation.
To authenticate to IAM, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Before running code samples, set the GOOGLE_CLOUD_UNIVERSE_DOMAIN environment
variable to s3nsapis.fr.
Authenticate using custom credential suppliers
If your environment doesn't support the built-in capabilities of the Google auth library or if you want to implement custom logic to supply credentials to the Google auth library, use custom credential suppliers to authenticate your workloads.
Access resources from AWS
When you initialize the authentication client, provide a custom implementation of a credential supplier. The client instance defers to the supplier to retrieve AWS security credentials to exchange for a Cloud de Confiance access token. The supplier must return valid and unexpired credentials when the client calls it.
The authentication client doesn't cache the returned AWS security credentials or region, so implement caching in the supplier to prevent redundant requests for the same resources.
The following code samples show how you can set up access to Cloud de Confiance resources from AWS with a custom credential supplier.
Node.js
To learn how to install and use the client library for IAM, see IAM client libraries. For more information, see the IAM Node.js API reference documentation.
To authenticate to IAM, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Before running code samples, set the GOOGLE_CLOUD_UNIVERSE_DOMAIN environment
variable to s3nsapis.fr.
Python
To learn how to install and use the client library for IAM, see IAM client libraries. For more information, see the IAM Python API reference documentation.
To authenticate to IAM, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Before running code samples, set the GOOGLE_CLOUD_UNIVERSE_DOMAIN environment
variable to s3nsapis.fr.
Java
To learn how to install and use the client library for IAM, see IAM client libraries. For more information, see the IAM Java API reference documentation.
To authenticate to IAM, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Before running code samples, set the GOOGLE_CLOUD_UNIVERSE_DOMAIN environment
variable to s3nsapis.fr.
Access resources from OIDC and SAML
When you initialize the authentication client, provide a custom token supplier to provide a subject token that is exchanged for a Cloud de Confiance access token. The supplier must return a valid and unexpired subject token when the client calls it.
The authentication client doesn't cache the returned token, so implement caching in the supplier to prevent redundant requests for the same subject token.
The following code samples show how you can set up access to Cloud de Confiance resources from providers that support OpenID Connect (OIDC) or SAML 2.0 with a custom credential supplier.
Node.js
To learn how to install and use the client library for IAM, see IAM client libraries. For more information, see the IAM Node.js API reference documentation.
To authenticate to IAM, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Before running code samples, set the GOOGLE_CLOUD_UNIVERSE_DOMAIN environment
variable to s3nsapis.fr.
Python
To learn how to install and use the client library for IAM, see IAM client libraries. For more information, see the IAM Python API reference documentation.
To authenticate to IAM, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Before running code samples, set the GOOGLE_CLOUD_UNIVERSE_DOMAIN environment
variable to s3nsapis.fr.
Java
To learn how to install and use the client library for IAM, see IAM client libraries. For more information, see the IAM Java API reference documentation.
To authenticate to IAM, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Before running code samples, set the GOOGLE_CLOUD_UNIVERSE_DOMAIN environment
variable to s3nsapis.fr.
What's next
- Learn more about Workload Identity Federation.