Required GCP APIs

Guardrails talks to Google Cloud through its public APIs, and Google only serves an API to a project that has that API enabled. Granting IAM roles is not enough: if the Cloud Resource Manager API is disabled in a project, Guardrails cannot read that project after the import, even when the service account has every role it needs.

This page lists the APIs Guardrails depends on, which projects each one must be enabled in, and how to enable them across an entire organization before you connect it. Doing this first is the single biggest step toward an import where every organization, folder, and project control lands in OK.

Why Each Project Needs the APIs

Guardrails charges each project's API calls to that project itself, not to the service account's home project. That spreads API quota across your organization, but it also means Google checks the API state in whichever project Guardrails is working on. Enabling the APIs only in the service account's project is not enough: enable them in every project you connect.

APIs Guardrails Requires

In Every Project Guardrails Manages

Enable these in every project you connect to Guardrails. Projects you exclude from the import are not touched.

APIService nameUsed byIf it is disabled
Cloud Resource Manager APIcloudresourcemanager.googleapis.comGCP > Project > CMDB (project metadata, labels, organization policy constraints), all gcp-orgpolicy controlsGCP > Project > CMDB goes to Error and does not retry. Every control on the project that depends on CMDB data is stale.
Service Usage APIserviceusage.googleapis.comGCP > Project > CMDB (list of enabled services), every GCP > {Service} > CMDB, Discovery, and API Enabled controlGCP > Project > CMDB and every service-level control go to Error.
Cloud Logging APIlogging.googleapis.comGCP > Turbot > Event Poller (enabled by default for new organization imports), GCP > Turbot > Event HandlersThe project's event poller or Logging event handler goes to Error and Guardrails stops seeing changes in the project.

In the Service Account's Home Project

The project that hosts the Guardrails service account (the "SA host project") needs the same three APIs above, plus the Cloud Resource Manager API for one extra reason: Guardrails verifies the guardrails_external_id project label there every time it obtains credentials. If the API is disabled in this one project, Guardrails cannot authenticate to your organization at all.

APIService nameUsed byIf it is disabled
Cloud Resource Manager APIcloudresourcemanager.googleapis.comExternal ID label verification, GCP > Organization > CMDB, GCP > Folder > CMDB, GCP > Folder > Discovery, GCP > Project > Discovery, organization and folder event pollersGuardrails cannot authenticate, and everything under the organization stops syncing at once. See Troubleshooting.
Cloud Logging APIlogging.googleapis.comGCP > Turbot > Organization Event Poller, GCP > Turbot > Folder Event PollerOrganization and folder pollers go to Error.

Only When You Govern a Service

Each service mod (Compute Engine, Storage, IAM, and so on) needs that service's API enabled in a project before Guardrails can discover its resources there. A missing service API is handled gracefully: the resource Discovery and CMDB controls for that service go to Skipped with the reason {Service} API is disabled. Please enable the policy GCP > {Service} > API Enabled. They do not error. See Enabling GCP Services for the list of API Enabled policies and how to use them.

Two service APIs are worth calling out:

For Event Handlers, the Cloud Pub/Sub API (pubsub.googleapis.com) is also required in every project that hosts an event handler stack. The event handler stacks deploy a Pub/Sub topic, a Pub/Sub subscription, and a Cloud Logging sink in each of those projects.

[!TIP] If you plan to turn on Event Handlers after the import, enable the Pub/Sub API at the same time as the baseline APIs above. Enabling an API across an organization often needs an internal approval, so request all of them up front.

Enable the APIs

You have two ways to bring every project up to the required baseline. Use the gcloud approach if you want the APIs in place before the import so that every control is OK on the first run. Use the Guardrails approach if you prefer Guardrails to converge projects, including projects created later, but expect the affected GCP > Project > CMDB controls to sit in Error until the API is on and the control reruns.

Option A: Enable with gcloud

Enabling an API is idempotent, so it is safe to run this against projects that already have the APIs enabled. The command below enables the three baseline APIs in every active project visible to the caller. Run it as a user with serviceusage.services.enable on the projects (for example roles/serviceusage.serviceUsageAdmin or roles/owner at the organization level).

for PROJECT in $(gcloud projects list --filter="lifecycleState=ACTIVE" --format="value(projectId)"); do
  echo "Enabling APIs in ${PROJECT}"
  gcloud services enable \
    cloudresourcemanager.googleapis.com \
    serviceusage.googleapis.com \
    logging.googleapis.com \
    --project="${PROJECT}"
done

[!TIP] gcloud projects list returns every project the caller can see, including projects outside the organization you are importing. Add a filter such as --filter="lifecycleState=ACTIVE AND parent.id=<FOLDER_OR_ORG_ID>" to scope it, or feed the loop from your own project inventory. Projects you plan to exclude from the import can be skipped.

To enable a single project, such as the service account's home project when organization-level syncing is failing:

gcloud services enable cloudresourcemanager.googleapis.com --project="<PROJECT_ID>"

[!NOTE] Google may take a few minutes to propagate a newly enabled API. If Guardrails controls still report the API as disabled right after you enable it, wait and rerun them.

Option B: Enable with Guardrails

The gcp-resourcemanager mod adds a GCP > Cloud Resource Manager service resource with Discovery, CMDB, and API Enabled controls. Its controls read API state through the Service Usage API, so they work even while the Cloud Resource Manager API is still disabled in a project. Setting GCP > Cloud Resource Manager > API Enabled to Enforce: Enabled at the organization or a folder makes Guardrails enable the API in every project underneath, including projects created after the import.

  1. Install the @turbot/gcp-resourcemanager mod in your workspace. See Install a Mod.

  2. Grant the Guardrails service account permission to enable services. The recommended read-only role set does not include serviceusage.services.enable. The least-privilege addition is roles/serviceusage.serviceUsageAdmin at the organization level:

    gcloud organizations add-iam-policy-binding "<ORG_ID>" \
      --member="serviceAccount:<SA_EMAIL>" \
      --role="roles/serviceusage.serviceUsageAdmin"
    
  3. Set the policy at the organization (or a folder, or in a policy pack attached to them):

    # GCP > Cloud Resource Manager > API Enabled
    resource "turbot_policy_setting" "gcp_resourcemanager_api_enabled" {
      resource = "id-of-gcp-organization-or-folder"
      type     = "tmod:@turbot/gcp-resourcemanager#/policy/types/resourceManagerApiEnabled"
      value    = "Enforce: Enabled"
    }
    

The same pattern works for any service. For example, GCP > Logging > API Enabled (tmod:@turbot/gcp-logging#/policy/types/loggingApiEnabled) keeps the Cloud Logging API on for event pollers and event handlers.

[!IMPORTANT] A GCP > Project > CMDB control that failed because the API was disabled is marked as a non-retryable error. After the API is enabled, rerun it: open the control, or filter the Controls page to the GCP > Project > CMDB control type in Error state, and choose Run. To rerun many at once, use the run controls scripts in the Guardrails Samples repository.

[!WARNING] If your organization enforces domain-restricted sharing (constraints/iam.allowedPolicyMemberDomains), enabling some APIs can fail because Google cannot grant the service agent its default role. See Domain-restricted sharing.

Verify

After the import, confirm the baseline is in place:

Service resource controls in Skipped with an API is disabled reason are expected for services you have not enabled and do not indicate a problem with the import.

Troubleshooting

IssueSolution
Nothing under the organization is syncing. Organization, folder, and project controls all report errors mentioning organizationcredentials.The Cloud Resource Manager API is off in the service account's home project, so Guardrails cannot verify the External ID label. Enable the API there, give it a few minutes, and rerun GCP > Organization > CMDB.
A few projects show CMDB errors mentioning the Cloud Resource Manager API, while the rest of the organization looks fine.The API is off in those projects; each error names its project number. Enable the API there (Option A) or let Guardrails enable it (Option B), then rerun the control.
A project's CMDB errors mention the Service Usage API.The Service Usage API was turned off in that project. Enable serviceusage.googleapis.com and rerun the control.
An event poller reports errors mentioning the Cloud Logging API.Enable logging.googleapis.com in the project, or set GCP > Logging > API Enabled to Enforce: Enabled.
Service controls show Skipped with an API is disabled reason.Working as intended: Guardrails skips discovery for services whose API is off. To govern the service, enable its API or set the API Enabled policy. See Enabling GCP Services.
An API Enabled policy set to Enforce: Enabled stays in Alarm.The service account usually lacks serviceusage.services.enable. Grant roles/serviceusage.serviceUsageAdmin at the organization level. If permissions look right, check domain-restricted sharing.
Further assistanceOpen a Support Ticket

Next Steps