Set Up Workload Identity Federation

In this guide, you will:

Workload Identity Federation lets Guardrails authenticate to GCP using its AWS IAM identity. No service account keys are created, stored, or rotated. Trust is established by configuring your GCP project to accept credentials from the Guardrails AWS account, and Guardrails assumes a dedicated transit role before federating.

[!TIP] The Guardrails import wizard generates a setup-wif.sh script that performs Steps 3 to 7 of this guide automatically (the pool, the AWS provider, the workloadIdentityUser binding, the external-ID label, and the pool provider lookup) and grants the recommended org-level read-only roles from Step 2. Most users should follow Step 1 here to create the service account, then jump straight to Connect using Workload Identity Federation and let the wizard handle the rest. Use the full manual procedure below only if you need fine-grained control or are setting up WIF outside the wizard.

How It Works

When Guardrails needs to talk to GCP, four steps happen behind the scenes:

  1. The Guardrails backend assumes the WIF transit role. A dedicated, short-lived session on a single IAM role: {prefix}_wif_{region}. AWS STS returns 15-minute credentials.
  2. The backend signs a GetCallerIdentity request with those credentials. This is AWS's standard way of saying "this is who I am". The signature is verifiable by anyone who knows AWS's public keys, including GCP.
  3. The backend sends the signed request to GCP's Security Token Service. GCP STS verifies the signature, checks the AWS account ID and role ARN against your Workload Identity Pool provider's attribute condition, then calls generateAccessToken to impersonate the service account you specified.
  4. GCP returns an access token for your service account (default 1-hour lifetime). The token is cached so repeated calls hit the cache instead of round-tripping back to GCP STS.

The benefits over a service account key:

Where Resources Live

Understanding which resources belong where helps with setup and troubleshooting.

In the Guardrails AWS account:

ResourcePurpose
{prefix}_wif_{region} IAM roleDedicated transit role for GCP WIF. Only worker and API roles can assume it.
/{prefix}/enterprise/wif_role_arn SSM parameterStores the transit role ARN for runtime discovery.
Worker Lambda and API Container rolesExisting roles that assume the transit role before federating.

In your GCP project (SA host project):

ResourcePurpose
Service AccountThe identity Guardrails uses to access GCP resources.
Workload Identity PoolTrust boundary that allows external (AWS) identities to authenticate.
AWS Provider (in the pool)Accepts credentials from the Guardrails AWS account with an attribute condition.
External ID labelVerifies you control the project. Prevents confused deputy attacks.

In your GCP organization:

ResourcePurpose
Org-level IAM bindings on the SAGrant Guardrails read access to the org hierarchy and audit logs. See Step 2 for the recommended role set.

Choosing the SA Host Project

The service account and WIF pool are created in a GCP project called the "SA host project." This project can be located inside or outside the organization you are importing.

SA inside the target organization (recommended):

SA outside the target organization:

[!CAUTION] If the target organization has the iam.allowedPolicyMemberDomains organization policy constraint enabled, it may block SA identities from external domains. If your SA is in a project outside the target org and you receive a policy constraint error when granting roles, ask the target org admin to add the SA's domain to the allowed list.

Prerequisites

[!NOTE] The Guardrails import wizard automatically provides the AWS Account ID and WIF transit role name. You do not need to look these up manually.

Step 1: Create a Service Account

Create a service account in your SA host project. This is the identity Guardrails will use to access your GCP resources.

gcloud iam service-accounts create turbot-guardrails \
  --project="<SA_HOST_PROJECT_ID>" \
  --display-name="Turbot Guardrails"

Note the resulting email address: turbot-guardrails@<SA_HOST_PROJECT_ID>.iam.gserviceaccount.com. You will enter this in the Guardrails wizard.

Step 2: Grant Organization-Level Permissions

The service account needs permissions at the organization level to discover your folder and project hierarchy and stay in sync with changes.

[!TIP] In GCP, service accounts are always associated with a specific project, even if their permissions are applied at the organization level.

Required Permissions

Minimum Required Permissions for Read-Only Discovery

For basic organization import with read-only discovery and monitoring, grant these four roles at the organization level:

RolePurpose
roles/browserBrowse the organization hierarchy: folders, projects, and IAM bindings on projects.
roles/viewerBroad read access: Cloud Asset Inventory, Org Policies, service catalog, and resource metadata across services.
roles/serviceusage.serviceUsageConsumerAllows Guardrails to charge API quota to the target project (serviceusage.services.use). Required for per-project API calls.
roles/logging.privateLogViewerRead access to Cloud Audit Logs. Required for the Organization, Folder, and Project Event Pollers, which keep Guardrails in sync with changes in your environment.

[!NOTE] These four roles are the minimum required to import and monitor an organization. They allow Guardrails to discover resources and keep its CMDB in sync, but not modify any resources.

Additional Permissions for Remediation

For governance and policy enforcement (beyond read-only), add appropriate roles based on your needs:

Permission LevelDescriptionRecommended Role
Full RemediationProvides the broadest level of control across your GCP Organization, allowing full governance and policy enforcement. Required to upgrade a project to All Resources discovery mode and to remediate violations.Owner (roles/owner) granted on each target project, or organization-wide
Service-SpecificGranular control over specific GCP services (e.g., Compute, Storage, IAM)Individual service admin roles (e.g., roles/compute.admin, roles/storage.admin)

Grant Roles Using gcloud

Set the variables, then grant the read-only roles via a single loop:

SA_EMAIL="turbot-guardrails@<SA_HOST_PROJECT_ID>.iam.gserviceaccount.com"
ORG_ID="<YOUR_ORG_ID>"
for ROLE in \
  roles/browser \
  roles/viewer \
  roles/serviceusage.serviceUsageConsumer \
  roles/logging.privateLogViewer; do
  gcloud organizations add-iam-policy-binding "$ORG_ID" \
    --member="serviceAccount:$SA_EMAIL" --role="$ROLE"
done

To grant Owner on a specific project (for All Resources discovery mode or remediation):

gcloud projects add-iam-policy-binding "<TARGET_PROJECT_ID>" \
  --member="serviceAccount:$SA_EMAIL" --role="roles/owner"

To grant Owner organization-wide:

gcloud organizations add-iam-policy-binding "$ORG_ID" \
  --member="serviceAccount:$SA_EMAIL" --role="roles/owner"

Discovery Levels

During the import wizard (Step 8), you choose a discovery level for each project:

Discovery LevelWhat Guardrails DoesPermissions Needed
NoneProject is not imported.The read-only roles above are still required for org/folder enumeration.
Project OnlyImports project metadata only (name, ID, labels). No deep resource discovery.The read-only roles cover this.
All ResourcesFull import: discovers Compute instances, Storage buckets, IAM policies, and all resources from installed mods.The read-only roles cover most services. Grant roles/owner on each target project for full coverage (see Additional Permissions for Remediation).

[!TIP] Most customers start with Project Only for all projects using just the read-only roles, then upgrade individual projects to All Resources later as needed.

[!NOTE] The role lists above assume the Event Pollers real-time-events architecture, which is the default for new organization imports. If you plan to use Event Handlers instead, see Event Handlers: Service Account Permissions for the role swap.

Step 3: Create a Workload Identity Pool

Create a Workload Identity Pool in your SA host project. The pool establishes a trust boundary that allows external identities (AWS) to authenticate with GCP.

gcloud iam workload-identity-pools create turbot-guardrails-pool \
  --project="<SA_HOST_PROJECT_ID>" \
  --location="global" \
  --display-name="Turbot Guardrails Pool"

Step 4: Create an AWS Provider with Attribute Condition

Create an AWS provider in the pool. The --account-id tells GCP which AWS account to trust, and the --attribute-condition restricts federation to only the dedicated Guardrails WIF transit role.

gcloud iam workload-identity-pools providers create-aws turbot-guardrails-aws \
  --project="<SA_HOST_PROJECT_ID>" \
  --location="global" \
  --workload-identity-pool="turbot-guardrails-pool" \
  --account-id="<GUARDRAILS_AWS_ACCOUNT_ID>" \
  --attribute-condition="assertion.arn.startsWith('arn:<GUARDRAILS_AWS_PARTITION>:sts::<GUARDRAILS_AWS_ACCOUNT_ID>:assumed-role/<GUARDRAILS_GCP_WIF_ROLE_NAME>/')"

The Guardrails import wizard auto-populates <GUARDRAILS_AWS_ACCOUNT_ID> and <GUARDRAILS_GCP_WIF_ROLE_NAME> in the setup instructions, and on TE v5.60.8 or higher also <GUARDRAILS_AWS_PARTITION>. You can copy the command directly from the wizard. If running the command outside the wizard:

[!IMPORTANT] Without the attribute condition, any IAM role in the Guardrails AWS account could federate to GCP. The condition ensures only the dedicated WIF transit role is accepted.

Step 5: Grant the Pool Permission to Impersonate the Service Account

Allow the federated AWS identity to act as your service account. Without this binding, authentication succeeds but the SA's permissions cannot be used.

gcloud iam service-accounts add-iam-policy-binding \
  turbot-guardrails@<SA_HOST_PROJECT_ID>.iam.gserviceaccount.com \
  --project="<SA_HOST_PROJECT_ID>" \
  --role="roles/iam.workloadIdentityUser" \
  --member="principalSet://iam.googleapis.com/projects/<SA_HOST_PROJECT_NUMBER>/locations/global/workloadIdentityPools/turbot-guardrails-pool/*"

Replace <SA_HOST_PROJECT_NUMBER> with the numeric project number (not the project ID). Find it with:

gcloud projects describe <SA_HOST_PROJECT_ID> --format="value(projectNumber)"

Step 6: Add the External ID Label

Add a label to the SA's host project to verify that you control it. This prevents unauthorized use of your credentials (confused deputy protection). The label is only required on the SA's host project, not on every project in your organization.

gcloud alpha projects update <SA_HOST_PROJECT_ID> \
  --update-labels="guardrails_external_id=<VALUE_FROM_WIZARD>"

The label key (guardrails_external_id) and value are shown in the Guardrails import wizard.

Step 7: Get the Pool Provider Resource Name

Retrieve the full resource name of the WIF provider. You will paste this into the Guardrails wizard.

gcloud iam workload-identity-pools providers describe turbot-guardrails-aws \
  --project="<SA_HOST_PROJECT_ID>" \
  --location="global" \
  --workload-identity-pool="turbot-guardrails-pool" \
  --format="value(name)"

The output looks like:

projects/1044929683897/locations/global/workloadIdentityPools/turbot-guardrails-pool/providers/turbot-guardrails-aws

Run the Import Wizard

You have completed the GCP-side setup for Workload Identity Federation. Proceed to Connect using Workload Identity Federation to run the Guardrails import wizard.

When running the wizard, you will need:

Troubleshooting

IssueDescriptionResolution
Authentication failed (empty message)The container or Lambda cannot reach GCP STS or AWS credentials are not available.Verify outbound internet access to sts.googleapis.com and iamcredentials.googleapis.com.
Permission denied on organizationThe service account is missing one of the recommended org-level roles.Re-run Step 2 and wait 1-2 minutes for IAM propagation.
Label does not exist on the projectThe external ID label was not set or the value does not match.Re-run Step 6 with the exact value from the Guardrails wizard.
Attribute condition not met (The given credential is rejected by the attribute condition)The WIF transit role name or AWS partition in the attribute condition does not match the actual role.Verify the role name in the Guardrails wizard matches the --attribute-condition in Step 4. For Guardrails in AWS GovCloud (US), the condition must start with arn:aws-us-gov:sts::, not arn:aws:sts::.
Denied by an organization policyYour organization's constraints/iam.workloadIdentityPoolAwsAccounts policy limits which AWS account IDs can access your Google Cloud resources through workload identity federation, and the Guardrails AWS account is not on the list.Add the Guardrails AWS account ID to the constraint's allowed values.
Controls in error after importThe worker Lambda has not been updated with WIF-enabled code.Ensure both the API container and worker Lambda are deployed with the WIF code.
GCP > Project > CMDB in error: Cloud Resource Manager API has not been used in projectThe API is disabled in that project. Guardrails charges each project's calls to the project itself, so the API must be enabled there, not only in the SA host project.Enable cloudresourcemanager.googleapis.com in the project and rerun the control. See Required GCP APIs.
Quota exceeded (Read requests per minute)The service account is missing roles/serviceusage.serviceUsageConsumer at the org level, so API quota is concentrating on the SA's host project instead of being distributed per project.Re-run Step 2 to grant the recommended role set. Controls self-heal on rerun.

API Quota Distribution

Guardrails automatically distributes GCP API quota per project. Each project's CMDB control charges quota to that project rather than concentrating all calls on the service account's host project, which would cause "Read requests per minute" errors on large organizations.

This works because roles/serviceusage.serviceUsageConsumer is in the recommended role set granted at the org level. With that role in place, Guardrails sets the x-goog-user-project header on GCP API requests, and GCP charges quota to the target project for client-project-based APIs (Cloud Resource Manager, Service Usage, Access Approval). Resource-based APIs (Compute, Storage, IAM) always charge quota to the resource's own project regardless of this header.

No configuration is required during import.

Next Steps