Set Up Workload Identity Federation
In this guide, you will:
- Import a GCP organization into Guardrails using Workload Identity Federation (WIF), eliminating the need for long-lived service account keys.
- Configure the trust relationship between your GCP project and the Guardrails AWS account.
- Discover projects and folders across your GCP organization.
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.shscript 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:
- 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. - The backend signs a
GetCallerIdentityrequest 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. - 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
generateAccessTokento impersonate the service account you specified. - 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:
- No long-lived credentials: nothing to store in Guardrails policy, nothing to rotate, nothing that can leak.
- Cryptographic identity chain: the trust is anchored to the specific AWS account and IAM role that Guardrails runs as, enforced by your pool provider's attribute condition.
- Audit trail on both sides: every federation event is logged as an
sts:GetCallerIdentitycall in CloudTrail and as a service account impersonation in Cloud Audit Logs.
Where Resources Live
Understanding which resources belong where helps with setup and troubleshooting.
In the Guardrails AWS account:
| Resource | Purpose |
|---|---|
{prefix}_wif_{region} IAM role | Dedicated transit role for GCP WIF. Only worker and API roles can assume it. |
/{prefix}/enterprise/wif_role_arn SSM parameter | Stores the transit role ARN for runtime discovery. |
| Worker Lambda and API Container roles | Existing roles that assume the transit role before federating. |
In your GCP project (SA host project):
| Resource | Purpose |
|---|---|
| Service Account | The identity Guardrails uses to access GCP resources. |
| Workload Identity Pool | Trust 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 label | Verifies you control the project. Prevents confused deputy attacks. |
In your GCP organization:
| Resource | Purpose |
|---|---|
| Org-level IAM bindings on the SA | Grant 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):
- The simplest setup. Grant the org-level roles described in Step 2 on the SA and you are done.
- The external ID label is set on a project already within the org.
- No cross-organization concerns.
SA outside the target organization:
- Works the same way: GCP IAM is identity-based, not location-based. You grant the org-level roles using the SA's email, regardless of which project the SA lives in.
- No additional cross-org permissions are required.
[!CAUTION] If the target organization has the
iam.allowedPolicyMemberDomainsorganization 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
- A GCP project to host the service account and WIF pool (the "SA host project"). See Choosing the SA Host Project above.
- The GCP Organization ID (numeric). Find it in the Google Cloud console under IAM & Admin > Settings.
- The
gcloudCLI installed and authenticated with a user that has organization admin permissions. - The
gcloud alphacomponent installed (gcloud components install alpha) for setting project labels. - The Guardrails
@turbot/gcpmod installed in your workspace. - The required GCP APIs enabled in the SA host project and in every project you plan to import. Neither the steps below nor the wizard's setup script enable APIs.
[!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:
| Role | Purpose |
|---|---|
roles/browser | Browse the organization hierarchy: folders, projects, and IAM bindings on projects. |
roles/viewer | Broad read access: Cloud Asset Inventory, Org Policies, service catalog, and resource metadata across services. |
roles/serviceusage.serviceUsageConsumer | Allows Guardrails to charge API quota to the target project (serviceusage.services.use). Required for per-project API calls. |
roles/logging.privateLogViewer | Read 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 Level | Description | Recommended Role |
|---|---|---|
| Full Remediation | Provides 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-Specific | Granular 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 Level | What Guardrails Does | Permissions Needed |
|---|---|---|
| None | Project is not imported. | The read-only roles above are still required for org/folder enumeration. |
| Project Only | Imports project metadata only (name, ID, labels). No deep resource discovery. | The read-only roles cover this. |
| All Resources | Full 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:
<GUARDRAILS_AWS_PARTITION>isawsfor Guardrails running in commercial AWS regions, oraws-us-govfor Guardrails running in AWS GovCloud (US).- The role name follows the pattern
{prefix}_wif_{region}(e.g.,turbot_wif_us_east_1, orturbot_wif_us_gov_west_1in GovCloud).
[!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:
- Service Account Email: the email from Step 1
- Workload Identity Pool Provider: the resource name from Step 7
- External ID Label Key:
guardrails_external_id(default) - External ID Label Value: the value you set in Step 6
Troubleshooting
| Issue | Description | Resolution |
|---|---|---|
| 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 organization | The 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 project | The 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 policy | Your 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 import | The 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 project | The 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
- GCP Permissions Guide: configure additional permissions for resource-level discovery and remediation.
- Real-Time Events: set up event-driven monitoring for your GCP organization.
- Google Cloud: Workload Identity Federation: Google's documentation on WIF concepts and configuration.