Set Up Service Account Authentication

In this guide, you will create and configure the GCP service accounts needed to connect your GCP Organization to Turbot Guardrails using Service Account Impersonation.

This is part of the Connect a GCP Organization series. Complete this guide before running the connection wizard.

Prerequisites

How Service Account Impersonation Works

Service Account Impersonation uses two service accounts that work together:

Guardrails → Master SA (Guardrails' identity) → impersonates → Org SA (your org access) → GCP Organization
Service AccountPurposeWho Creates It
Master SAGuardrails' identity. Generates short-lived tokens to impersonate the Org SA. No long-lived keys are shared with your organization.SaaS: Provided by Guardrails automatically. Self-hosted: You create it.
Organization SAHas IAM permissions on your GCP Organization. Gets impersonated by the Master SA. Its credentials are never exposed.You create it (both SaaS and self-hosted).

The Master SA holds the Service Account Token Creator role on the Organization SA, which allows it to generate short-lived access tokens. This means:


Self-Hosted Only: Set Up the Master Service Account

[!IMPORTANT] Skip this section if you are using Guardrails SaaS. SaaS provides a master service account automatically. You'll see its email in the connection wizard.

Self-hosted Guardrails installations must create their own master service account and store its credentials in AWS SSM.

Step 1: Create the Master Service Account

Create a service account in any GCP project. It does not need to be in the organization you're importing.

Using the GCP Console:

  1. Navigate to IAM & Admin > Service Accounts in any GCP project.
  2. Click Create Service Account.
  3. Enter a name (e.g., turbot-master) and description.
  4. Click Create and Continue.
  5. Grant the Viewer role (roles/viewer) at the project level.
  6. Click Continue, then Done.

Using gcloud:

export MASTER_PROJECT_ID="your-turbot-project"
export MASTER_SA_NAME="turbot-master"

gcloud iam service-accounts create ${MASTER_SA_NAME} \
  --project=${MASTER_PROJECT_ID} \
  --display-name="Turbot Guardrails Master SA" \
  --description="Master identity for Turbot Guardrails service account impersonation"

Step 2: Generate a JSON Key

Generate a JSON credential key for the master service account.

Using the GCP Console:

  1. Click on the master service account.
  2. Go to the Keys tab.
  3. Click Add Key > Create new key.
  4. Select JSON format and click Create.
  5. Save the downloaded JSON file securely.

Using gcloud:

gcloud iam service-accounts keys create master-key.json \
  --iam-account=${MASTER_SA_NAME}@${MASTER_PROJECT_ID}.iam.gserviceaccount.com

Step 3: Store the Key in AWS SSM Parameter Store

Store the master service account JSON credential in AWS Systems Manager Parameter Store. Guardrails reads this parameter to authenticate as the master SA.

  1. Log in to the AWS Console for the Guardrails primary AWS account.
  2. Navigate to AWS Systems Manager > Parameter Store.

AWS SSM Create Parameter

  1. Click Create parameter.
  2. Configure:
    • Name: A descriptive path (e.g., /turbot/gcp/master-service-account)
    • Type: SecureString
    • Tier: Standard
    • Value: Paste the entire JSON credential content from the master service account key file.

Paste JSON credential into SSM parameter

  1. Click Create parameter.

[!IMPORTANT] Store the Master Service Account key here, not the Organization Service Account key. The Organization SA should never have its key downloaded when using impersonation.

Step 4: Update the TED Stack

Update your Turbot Enterprise Database (TED) stack with the SSM parameter name so Guardrails can find the master SA credentials.

Follow the steps in Update TED. Navigate to the GCP Service Account Private Key SSM Parameter section and enter your parameter name (e.g., /turbot/gcp/master-service-account).

Update TED stack with SSM parameter


All Deployments: Set Up the Organization Service Account

These steps apply to both SaaS and self-hosted deployments.

Step 5: Enable Required APIs

Guardrails needs the following APIs enabled in the project where the Organization SA will be created (the SA host project) and in every project you plan to import. Guardrails charges each project's API calls to that project, so enabling the APIs only in the SA host project is not enough. Google enables the Service Usage and Cloud Logging APIs by default only in projects created through the Google Cloud console or gcloud CLI, so projects created programmatically may lack them. The Cloud Resource Manager API is not enabled by default anywhere, so it is the one most often missing.

Enable API in GCP Console

Using gcloud (SA host project):

export ORG_PROJECT_ID="your-org-project"

gcloud services enable \
  cloudresourcemanager.googleapis.com \
  serviceusage.googleapis.com \
  logging.googleapis.com \
  --project=${ORG_PROJECT_ID}

To enable the APIs across every project in the organization, or to have Guardrails enable them for you after the import, see Required GCP APIs.

[!NOTE] The Service Management API (servicemanagement.googleapis.com) is only needed by the API Enabled controls of the BigQuery, Monitoring, Service Networking, and Cloud Scheduler mods. Enable it in the projects where you use those services.

Step 6: Create the Organization Service Account

Create a service account in a project under the organization you want to import.

Using the GCP Console:

  1. Navigate to IAM & Admin > Service Accounts in a project under your organization.
  2. Click Create Service Account.
  3. Enter a name (e.g., guardrails-org-reader) and description.
  4. Click Create and Continue.
  5. Skip project-level role assignment. You'll grant roles at the organization level in the next step.
  6. Click Continue, then Done.

Using gcloud:

export ORG_SA_NAME="guardrails-org-reader"

gcloud iam service-accounts create ${ORG_SA_NAME} \
  --project=${ORG_PROJECT_ID} \
  --display-name="Guardrails Organization Reader" \
  --description="Read-only access for Turbot Guardrails organization discovery"

Step 7: Grant Organization-Level IAM Roles

The Organization SA needs permissions at the organization level. The recommended starting point is read-only access for Project Only discovery. Guardrails will discover and monitor your folders and projects without modifying any resources. You can grant additional roles later when you upgrade projects to All Resources mode or want Guardrails to remediate violations.

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.

(Optional) Let Guardrails Enable APIs

If you want Guardrails to enable the required GCP APIs on your behalf, or to enforce any GCP > {Service} > API Enabled policy, also grant roles/serviceusage.serviceUsageAdmin at the organization level. The read-only set above does not include serviceusage.services.enable, so enforcement fails with PERMISSION_DENIED without it.

(Optional) All Resources mode and remediation: grant Owner per project

The Read-Only set above already covers most All Resources discovery via roles/viewer inheritance from the org. When you upgrade a specific project to All Resources mode and want Guardrails to discover everything comprehensively (including BigQuery tables and Cloud Storage UBLA buckets) or remediate violations, grant roles/owner on the target project:

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

To do this organization-wide instead, grant roles/owner at the org level. roles/browser is still required alongside roles/owner because basic owner does not grant resourcemanager.folders.get/list or resourcemanager.organizations.get.

[!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.

Using the GCP Console:

  1. Navigate to IAM & Admin > IAM at the organization level (select your organization from the project picker).
  2. Click Grant Access.
  3. Enter the Organization SA email: guardrails-org-reader@YOUR_PROJECT_ID.iam.gserviceaccount.com
  4. Add the required roles.
  5. Click Save.

Grant organization-level roles to service account

Using gcloud:

export ORG_ID="your-org-id"
export ORG_SA_EMAIL="${ORG_SA_NAME}@${ORG_PROJECT_ID}.iam.gserviceaccount.com"

# Recommended: Read-Only Discovery
for ROLE in \
  roles/browser \
  roles/viewer \
  roles/serviceusage.serviceUsageConsumer \
  roles/logging.privateLogViewer; do
  gcloud organizations add-iam-policy-binding ${ORG_ID} \
    --member="serviceAccount:${ORG_SA_EMAIL}" --role="$ROLE"
done

# (Optional) For All Resources mode or remediation, grant roles/owner on
# the target project (or org-wide):
# gcloud projects add-iam-policy-binding "<TARGET_PROJECT_ID>" \
#   --member="serviceAccount:${ORG_SA_EMAIL}" --role="roles/owner"

Impersonation Setup

Step 8: Grant the Token Creator Role

Grant the Master SA the Service Account Token Creator role on the Organization SA. This allows the Master SA to generate short-lived tokens to impersonate the Organization SA.

For SaaS: The Guardrails wizard shows the master SA email and provides a ready-to-copy gcloud command. You can also run it now if you know the master SA email (shown during the connection wizard).

For self-hosted: Use the master SA email you created in Step 1.

# SaaS: MASTER_SA_EMAIL is shown in the Guardrails wizard
# Self-hosted: use the email from Step 1
export MASTER_SA_EMAIL="[email protected]"  # SaaS example
# export MASTER_SA_EMAIL="[email protected]"  # Self-hosted example

gcloud iam service-accounts add-iam-policy-binding ${ORG_SA_EMAIL} \
  --member="serviceAccount:${MASTER_SA_EMAIL}" \
  --role="roles/iam.serviceAccountTokenCreator" \
  --project=${ORG_PROJECT_ID} \
  --format=json

Expected output:

{
  "bindings": [
    {
      "members": [
        "serviceAccount:[email protected]"
      ],
      "role": "roles/iam.serviceAccountTokenCreator"
    }
  ],
  "etag": "BwYsqn0-odQ=",
  "version": 1
}

[!TIP] If you're using SaaS and don't know the master SA email yet, you can complete this step during the connection wizard. The wizard provides the gcloud command with the correct email pre-filled. See Connect the Organization.

Step 9: Set the External ID Label

The External ID label is a security measure that verifies the Organization SA belongs to your Guardrails workspace. It prevents the confused deputy problem by ensuring only your Guardrails workspace can use the service account. It must be set as a project label on the project where the Organization SA resides.

The label key is always guardrails_external_id. The value is generated by Guardrails during the connection wizard in the format turbot_{workspace_id}_{unique_id}. For more information, see What is Guardrails External ID Protection?

[!NOTE] You can set this label during the connection wizard, which shows the exact value to use. If you want to set it up in advance, you'll need to start the wizard first to get the value, then come back to complete the label setup.

Create External ID label in GCP Console

Using the GCP Console:

  1. Navigate to the project where the Organization SA resides.
  2. Go to Settings (or Labels in the side navigation).
  3. Add a label: Key = guardrails_external_id, Value = the value from the Guardrails wizard.
  4. Save.

Using gcloud:

gcloud projects update ${ORG_PROJECT_ID} \
  --update-labels=guardrails_external_id=VALUE_FROM_WIZARD

[!WARNING] Do not delete this label after the connection is established. Guardrails requires it for ongoing authentication verification.


Service Account Scaling

Turbot recommends one service account per GCP project for production environments. This maximizes API quota headroom and limits blast radius. A single service account can work for up to ~100 projects with event pollers, but performance degrades as the project count increases. With event handlers (recommended over pollers), a single SA scales better but still benefits from a 1:1 ratio.


Next Steps

Continue to Connect the Organization to run the Guardrails connection wizard.

Troubleshooting

IssueSolution
Wrong SA in SSM Parameter (self-hosted)Verify the SSM parameter contains the Master Service Account JSON key, not the Organization SA key.
Missing Token Creator roleThe Master SA must have roles/iam.serviceAccountTokenCreator on the Organization SA. Re-run the gcloud command from Step 8.
Missing organization-level rolesThe Organization SA needs the recommended read-only set (roles/browser, roles/viewer, roles/serviceusage.serviceUsageConsumer, roles/logging.privateLogViewer) at the organization scope (not project scope). See Step 7.
Every control in Error: organizationcredentials and Cloud Resource Manager API has not been used in projectThe API is disabled in the SA host project, so Guardrails cannot verify the External ID label and no organization-level credentials are issued. Enable cloudresourcemanager.googleapis.com there, wait a few minutes, and rerun GCP > Organization > CMDB. See Required GCP APIs.
GCP > Project > CMDB in Error: Cloud Resource Manager API has not been used in projectThe API is disabled in that project. Enable it there, or let Guardrails enable it, then rerun the control. See Required GCP APIs.
External ID label missingThe guardrails_external_id label must be on the project where the Organization SA resides, with the value from the wizard.
Further assistanceOpen a Support Ticket