Skip to content

Commit 7b51cb3

Browse files
authored
docs: Update README with X.509 feature details (#1790)
* docs: Update README with X.509 feature details. * Address the review comments
1 parent 1669dc8 commit 7b51cb3

File tree

1 file changed

+74
-4
lines changed

1 file changed

+74
-4
lines changed

README.md

Lines changed: 74 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ information, refer to [documentation](https://cloud.google.com/docs/authenticati
4444
* [Accessing resources from AWS](#accessing-resources-from-aws)
4545
* [Accessing resources from Azure](#access-resources-from-microsoft-azure)
4646
* [Accessing resources from an OIDC identity provider](#accessing-resources-from-an-oidc-identity-provider)
47+
* [Accessing resources using X.509 certificate-sourced credentials](#accessing-resources-using-x509-certificate-sourced-credentials)
4748
* [Accessing resources using Executable-sourced credentials](#using-executable-sourced-credentials-with-oidc-and-saml)
4849
* [Accessing resources using a custom supplier for OIDC or SAML](#using-a-custom-supplier-with-oidc-and-saml)
4950
* [Accessing resources using a custom supplier with AWS](#using-a-custom-supplier-with-aws)
@@ -367,10 +368,12 @@ configuration file contains non-sensitive metadata to instruct the library on ho
367368
retrieve external subject tokens and exchange them for service account access tokens.
368369
The configuration file can be generated by using the [gcloud CLI](https://cloud.google.com/sdk/).
369370

370-
For OIDC providers, the Auth library can retrieve OIDC tokens either from a local file location
371-
(file-sourced credentials) or from a local server (URL-sourced credentials).
371+
For OIDC providers, the Auth library can retrieve OIDC tokens from a local file
372+
([file-sourced credentials](#file-sourced-credentials)), a local server
373+
([URL-sourced credentials](#url-sourced-credentials)), or a X.509
374+
certificate and private-key combination (X.509 certificate-sourced credentials).
372375

373-
**File-sourced credentials**
376+
#### File-sourced credentials
374377
For file-sourced credentials, a background process needs to be continuously refreshing the file
375378
location with a new OIDC token prior to expiration. For tokens with one hour lifetimes, the token
376379
needs to be updated in the file every hour. The token can be stored directly as plain text or in
@@ -401,7 +404,7 @@ Where the following variables need to be substituted:
401404

402405
This generates the configuration file in the specified output file.
403406

404-
**URL-sourced credentials**
407+
#### URL-sourced credentials
405408
For URL-sourced credentials, a local server needs to host a GET endpoint to return the OIDC token.
406409
The response can be in plain text or JSON. Additional required request headers can also be
407410
specified.
@@ -435,6 +438,73 @@ request to `$URL_TO_GET_OIDC_TOKEN`, e.g. `Metadata-Flavor=Google`.
435438
You can now [use the Auth library](#using-external-identities) to call Google Cloud
436439
resources from an OIDC provider.
437440

441+
### Accessing resources using X.509 certificate-sourced credentials
442+
For more information, see the [official documentation](https://cloud.google.com/iam/docs/workload-identity-federation-with-x509-certificates).
443+
444+
For X.509 certificate-sourced credentials, the authentication library uses an X.509 certificate and private key to prove your application's identity. The certificate has a built-in expiration date, which is defined in the certificate itself, and must be renewed to maintain access.
445+
446+
#### Prerequisites: Generating Configuration Files for X.509 Federation
447+
To configure X.509 certificate-sourced credentials, you need to generate two separate configuration files: a primary **credential configuration file** and a **certificate configuration file**. The primary credential configuration file contains the necessary metadata for authentication, and it points to the certificate configuration file, which contains the paths to the X.509 certificate, private key, and trust chain.
448+
449+
The [`gcloud iam workload-identity-pools create-cred-config`](https://cloud.google.com/sdk/gcloud/reference/iam/workload-identity-pools/create-cred-config) command can be used to create both.
450+
451+
The location where the certificate configuration file is created depends on whether you use the `--credential-cert-configuration-output-file` flag.
452+
453+
**Default Behavior (Recommended)**
454+
455+
If you omit the `--credential-cert-configuration-output-file` flag, gcloud creates the certificate configuration file at a default, well-known location that the auth library can automatically discover. This is the simplest approach for most use cases. The default credential configuration file is named `config.json` and the default certificate configuration file is named `certificate_config.json`.
456+
457+
Example Command (Default Behavior):
458+
459+
```bash
460+
gcloud iam workload-identity-pools create-cred-config \
461+
projects/$PROJECT_NUMBER/locations/global/workloadIdentityPools/$POOL_ID/providers/$PROVIDER_ID \
462+
--service-account $SERVICE_ACCOUNT_EMAIL \
463+
--credential-cert-path "$PATH_TO_CERTIFICATE" \
464+
--credential-cert-private-key-path "$PATH_TO_PRIVATE_KEY" \
465+
--credential-cert-trust-chain-path "$PATH_TO_TRUST_CHAIN" \
466+
--output-file /path/to/config.json
467+
```
468+
469+
Where the following variables need to be substituted:
470+
471+
- `$PROJECT_NUMBER`: The Google Cloud project number.
472+
- `$POOL_ID`: The workload identity pool ID.
473+
- `$PROVIDER_ID`: The provider ID.
474+
- `$SERVICE_ACCOUNT_EMAIL`: The email of the service account to impersonate.
475+
- `$PATH_TO_CERTIFICATE`: The file path where your leaf X.509 certificate is located.
476+
- `$PATH_TO_PRIVATE_KEY`: The file path where the corresponding private key for the leaf certificate is located.
477+
- `$PATH_TO_TRUST_CHAIN`: The file path of the X.509 certificate trust chain file. This file should be a PEM-formatted file containing any intermediate certificates required to complete the trust chain between the leaf certificate and the trust store configured in the Workload Identity Federation pool. The leaf certificate is optional in this file.
478+
479+
This command results in:
480+
481+
- `/path/to/config.json`: Created at the path you specified. This file will contain `"use_default_certificate_config": true` to instruct clients to look for the certificate configuration at the default path.
482+
- `certificate_config.json`: Created at the default gcloud configuration path, which is typically `~/.config/gcloud/certificate_config.json` on Linux and macOS, or `%APPDATA%\gcloud\certificate_config.json` on Windows.
483+
484+
**Custom Location Behavior**
485+
486+
If you need to store the certificate configuration file in a non-default location, use the `--credential-cert-configuration-output-file` flag.
487+
488+
Example Command (Custom Location):
489+
490+
```bash
491+
gcloud iam workload-identity-pools create-cred-config \
492+
projects/$PROJECT_NUMBER/locations/global/workloadIdentityPools/$POOL_ID/providers/$PROVIDER_ID \
493+
--service-account $SERVICE_ACCOUNT_EMAIL \
494+
--credential-cert-path "$PATH_TO_CERTIFICATE" \
495+
--credential-cert-private-key-path "$PATH_TO_PRIVATE_KEY" \
496+
--credential-cert-trust-chain-path "$PATH_TO_TRUST_CHAIN" \
497+
--credential-cert-configuration-output-file "/custom/path/cert_config.json" \
498+
--output-file /path/to/config.json
499+
```
500+
501+
This command results in:
502+
503+
- `/path/to/config.json`: Created at the path you specified. This file will contain a `"certificate_config_location"` field that points to your custom path.
504+
- `cert_config.json`: Created at `/custom/path/cert_config.json`, as specified by the flag.
505+
506+
You can now [use the Auth library](#using-external-identities) to call Google Cloud resources with X.509 certificate-sourced credentials.
507+
438508
#### Using Executable-sourced credentials with OIDC and SAML
439509

440510
**Executable-sourced credentials**

0 commit comments

Comments
 (0)