Skip to content

Commit 668a735

Browse files
committed
docs: Update README with X.509 feature details.
1 parent 1669dc8 commit 668a735

File tree

1 file changed

+68
-2
lines changed

1 file changed

+68
-2
lines changed

README.md

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,8 +367,9 @@ configuration file contains non-sensitive metadata to instruct the library on ho
367367
retrieve external subject tokens and exchange them for service account access tokens.
368368
The configuration file can be generated by using the [gcloud CLI](https://cloud.google.com/sdk/).
369369

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).
370+
For OIDC providers, the Auth library can retrieve OIDC tokens from a local file
371+
(file-sourced credentials), a local server (URL-sourced credentials), or a X.509
372+
certificate and private-key combination (X.509 certificate-sourced credentials).
372373

373374
**File-sourced credentials**
374375
For file-sourced credentials, a background process needs to be continuously refreshing the file
@@ -435,6 +436,71 @@ request to `$URL_TO_GET_OIDC_TOKEN`, e.g. `Metadata-Flavor=Google`.
435436
You can now [use the Auth library](#using-external-identities) to call Google Cloud
436437
resources from an OIDC provider.
437438

439+
### Accessing resources using X.509 certificate-sourced credentials
440+
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 and must be renewed to maintain access.
441+
442+
The library constructs a subject token by creating a JSON array containing the base64-encoded leaf certificate, followed by any intermediate certificates from a provided trust chain.
443+
444+
#### Generating Configuration Files for X.509 Federation
445+
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 `gcloud iam workload-identity-pools create-cred-config` command can be used to create both.
446+
447+
The location where the certificate configuration file is created depends on whether you use the `--credential-cert-configuration-output-file` flag.
448+
449+
**Default Behavior (Recommended)**
450+
451+
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.
452+
453+
Example Command (Default Behavior):
454+
455+
```bash
456+
gcloud iam workload-identity-pools create-cred-config \
457+
projects/$PROJECT_NUMBER/locations/global/workloadIdentityPools/$POOL_ID/providers/$PROVIDER_ID \
458+
--service-account $SERVICE_ACCOUNT_EMAIL \
459+
--credential-cert-path "$PATH_TO_CERTIFICATE" \
460+
--credential-cert-private-key-path "$PATH_TO_PRIVATE_KEY" \
461+
--credential-cert-trust-chain-path "$PATH_TO_TRUST_CHAIN" \
462+
--output-file /path/to/config.json
463+
```
464+
465+
Where the following variables need to be substituted:
466+
467+
- `$PROJECT_NUMBER`: The Google Cloud project number.
468+
- `$POOL_ID`: The workload identity pool ID.
469+
- `$PROVIDER_ID`: The provider ID.
470+
- `$SERVICE_ACCOUNT_EMAIL`: The email of the service account to impersonate.
471+
- `$PATH_TO_CERTIFICATE`: The file path where your leaf X.509 certificate is located.
472+
- `$PATH_TO_PRIVATE_KEY`: The file path where the corresponding private key for the leaf certificate is located.
473+
- `$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.
474+
475+
This command results in:
476+
477+
- `/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.
478+
- `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.
479+
480+
**Custom Location Behavior**
481+
482+
If you need to store the certificate configuration file in a non-default location, use the `--credential-cert-configuration-output-file` flag.
483+
484+
Example Command (Custom Location):
485+
486+
```bash
487+
gcloud iam workload-identity-pools create-cred-config \
488+
projects/$PROJECT_NUMBER/locations/global/workloadIdentityPools/$POOL_ID/providers/$PROVIDER_ID \
489+
--service-account $SERVICE_ACCOUNT_EMAIL \
490+
--credential-cert-path "$PATH_TO_CERTIFICATE" \
491+
--credential-cert-private-key-path "$PATH_TO_PRIVATE_KEY" \
492+
--credential-cert-trust-chain-path "$PATH_TO_TRUST_CHAIN" \
493+
--credential-cert-configuration-output-file "/custom/path/cert_config.json" \
494+
--output-file /path/to/config.json
495+
```
496+
497+
This command results in:
498+
499+
- `/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.
500+
- `cert_config.json`: Created at `/custom/path/cert_config.json`, as specified by the flag.
501+
502+
You can now [use the Auth library](#using-external-identities) to call Google Cloud resources with X.509 certificate-sourced credentials.
503+
438504
#### Using Executable-sourced credentials with OIDC and SAML
439505

440506
**Executable-sourced credentials**

0 commit comments

Comments
 (0)