Introducing a new way to review your PRs.

Read the announcement

prowler-cloud / prowler

This repo hosts Prowler OSS (CLI and Local Server). Prowler is the world’s most widely used open-source cloud security platform that automates security and compliance across any cloud environment for Humans and AI Agents.

View on GitHub

13 documents · Updated Nov 16, 2026

docs / gcp-provider

GCP Provider

Overview

The GCP provider lives under prowler/providers/gcp/**; tests for this area live under tests/providers/gcp/**. There is currently no permissions/gcp/** tree in this checkout, so reviewers looking for GCP IAM policy templates should not expect a generated permissions artifact there.

prowler/…/gcp_provider.py is the provider lifecycle entry point. GcpProvider.__init__ sets the retry override from --gcp-retries-max-attempts, records --skip-api-check, builds a Google credentials session, discovers auditable projects, filters active/included/excluded project IDs, enriches projects with organization display names when possible, loads audit/fixer config, loads GCPMutelist, and finally registers itself through Provider.set_global_provider(self). The provider state used by services is mostly session, project_ids, projects, default_project_id, audit_config, fixer_config, and skip_api_check.

Authentication and connection setup are centralized in GcpProvider.setup_session in prowler/…/gcp_provider.py. It supports, in order: static authorized-user credentials built from client_id, client_secret, and refresh_token; in-memory service account keys; a credentials file by setting GOOGLE_APPLICATION_CREDENTIALS; a raw CLOUDSDK_AUTH_ACCESS_TOKEN plus GOOGLE_CLOUD_PROJECT; otherwise Application Default Credentials from google.auth.default. All regular credentials use the https://www.googleapis.com/auth/cloud-platform scope. If impersonate_service_account is supplied, setup_session wraps the source credentials with google.auth.impersonated_credentials.Credentials. test_connection requires a GCP project provider ID, reuses setup_session, validates that the provider ID is accessible when it differs from the default project, and then calls the OAuth2 tokeninfo API.

Project and organization scope is also in prowler/…/gcp_provider.py. Without --organization-id, get_projects lists projects through Cloud Resource Manager (cloudresourcemanager v1), converts each response into GCPProject from prowler/…/models.py, and preserves an organization parent when present. With --organization-id, it uses Cloud Asset Inventory (cloudasset v1) scoped to organizations/{id} to recursively list project assets and attach GCPOrganization. Only ACTIVE projects are scanned. --project-id/--project-ids and --excluded-project-id/--excluded-project-ids accept exact IDs or simple * wildcard matching through is_project_matching; if no project IDs are supplied, all accessible active projects are scanned. --list-project-ids prints the selected project IDs and exits. If API listing returns no projects, explicit project_ids are treated as active fallback projects; a credentials-file project fallback is allowed only when no organization scan was requested.

The provider CLI arguments are registered by prowler/…/arguments.py: GCP-specific auth flags, organization/project selection, retry configuration, and --skip-api-check. Provider output naming and resource identity models are in prowler/…/models.py; GCPOutputOptions defaults output files to prowler-output-{identity.profile}-{timestamp}.

All GCP services inherit GCPService in prowler/…/service.py. The base service lowercases the discovery service name, builds a googleapiclient.discovery.build client with DEFAULT_RETRY_ATTEMPTS, copies provider config, and filters project_ids by checking serviceusage.services.get for {service}.googleapis.com unless provider.skip_api_check is true. It tracks definite disabled APIs in api_disabled_project_ids and unknown activation state in api_state_unknown_project_ids. Many resource collectors call __threading_call__ for per-location fetches and use __get_AuthorizedHttp_client__ for discovery calls that need an authorized httplib2 transport.

Each service package follows the Prowler singleton pattern: a *_service.py file defines a GCPService subclass plus pydantic resource models, and a small *_client.py instantiates it with Provider.get_global_provider(). For example, prowler/…/compute_client.py creates compute_client = Compute(Provider.get_global_provider()), and checks import that singleton. Service classes eagerly populate resource caches during construction: Compute gathers regions, zones, VM instances, networks, subnets, addresses, firewalls, load balancers, managed instance groups, images, and snapshots in prowler/…/compute_service.py; CloudStorage gathers buckets and bucket IAM/public-access state in prowler/…/cloudstorage_service.py; IAM gathers service accounts, keys, and Workload Identity Federation providers in prowler/…/iam_service.py; ServiceUsage lists enabled APIs per project in prowler/…/serviceusage_service.py.

Checks live in prowler/…/{check_name}.py and generally iterate over the service singleton's cached resources, creating Check_Report_GCP findings. Check_Report_GCP itself is defined outside this doc's owned paths, but GCP checks rely on its convention of deriving resource_id, resource_name, project_id, and location from resource attributes unless explicitly supplied. Examples: compute_instance_public_ip reads compute_client.instances; cloudstorage_bucket_public_access treats a bucket whose IAM policy could not be read as MANUAL; iam_account_access_approval_enabled emits project-level findings for configured, missing, disabled-API, and unknown-API states; gemini_api_disabled uses serviceusage_client.active_services and the GEMINI_SERVICE_NAME constant from prowler/…/constants.py.

Tests use tests/…/gcp_fixtures.py as the shared fixture and mock client catalog. set_mocked_gcp_provider returns a provider-shaped MagicMock with one active GCPProject, audit config values such as mig_min_zones, and empty fixer config. mock_api_client wires many discovery resource chains used by service tests; mock_is_api_active bypasses the base Service Usage precheck. Service tests usually patch GCPService.__generate_client__ and GCPService.__is_api_active__, while check tests patch Provider.get_global_provider and replace the imported service singleton with a MagicMock. Provider tests in tests/…/gcp_provider_test.py cover credential modes, project matching, organization scans, provider ID validation, service account key validation, and fallback behavior.

Coupling

  • If a service's discovery API name changes, update both the super().__init__ argument in its *_service.py and the API activation behavior in prowler/…/service.py; the base class probes projects/{project_id}/services/{self.service}.googleapis.com, so aliases such as Cloud Storage using "storage" and Cloud SQL using "sqladmin" must match the actual Service Usage name.
  • If a check needs to report on projects whose service API is disabled or whose activation state cannot be determined, do not only iterate client.project_ids: GCPService removes those projects from project_ids and records them in api_disabled_project_ids / api_state_unknown_project_ids. prowler/…/iam_account_access_approval_enabled.py is the model for adding explicit FAIL/MANUAL findings for filtered projects.
  • If GCPProject or resource model fields in prowler/…/models.py or a service *_service.py change, update checks and tests that rely on Check_Report_GCP implicit field extraction. Empty project/resource names collapse to "GCP Project", and check tests assert this behavior in GCP-specific paths.
  • If organization handling changes in prowler/…/gcp_provider.py, verify services that consume organization data indirectly: prowler/…/logging_service.py credits organization-level sinks using project.organization.id; prowler/…/iam_service.py EssentialContacts reads cloudresourcemanager_client.organizations; prowler/…/accesscontextmanager_service.py walks access policies from the same organization list.
  • If DEFAULT_RETRY_ATTEMPTS in prowler/…/config.py or --gcp-retries-max-attempts handling changes, check all service collectors. Most discovery calls pass this value to execute(num_retries=...), while a few files import the module rather than the constant to pick up runtime mutation.
  • If adding a new GCP service or check, include the service singleton file and tests under tests/providers/gcp/services/{service}/; the existing tests assume import-time singleton creation and commonly patch Provider.get_global_provider before importing the check under test.

Risks

  • prowler/…/gcp_provider.py service account key handling is security-sensitive. validate_service_account_key only accepts keys with type == "service_account" and token URIs in Google's allowlist because google-auth can otherwise read local files or fetch arbitrary URLs during refresh; history includes fix(api): harden social login and GCP service account keys (#13263). If this validation is loosened, attacker-supplied credential JSON can turn scanning into SSRF or local file access.
  • Organization scans in prowler/…/gcp_provider.py deliberately raise GCPGetOrganizationProjectsError when Cloud Asset Inventory listing fails instead of silently falling back to the credentials file project; history includes fix(gcp): surface organization-scan failures instead of silently scanning the home project (#11280). If that fallback returns for organization_id, Prowler may report a narrow project scan as an organization scan.
  • API-activation filtering in prowler/…/service.py can hide projects from checks that should still produce a finding for disabled APIs. iam_account_access_approval_enabled has extra loops for disabled/unknown projects because a disabled Access Approval API is itself evidence of failure; checks with similar semantics will under-report if they only iterate project_ids.
  • Cloud Storage IAM policy reads in prowler/…/cloudstorage_service.py distinguish ordinary IAM-denied buckets from VPC Service Controls blocks. History includes fix(gcp): keep evaluating buckets when one bucket's IAM policy is denied (#13333) and fix(gcp-cloudstorage): handle VPC-blocked API calls as PASS (#9478). If all HttpErrors are handled the same way, one denied bucket can suppress unrelated bucket findings or turn an evidence gap into a false PASS/FAIL.
  • Logging aggregation logic in prowler/…/logging_service.py is intentionally conservative when crediting org-level sinks and bucket-scoped metrics; history includes multiple fixes for aggregated sinks (#11355, #11488, #11575). If _sink_delivers_activity_logs or get_projects_covered_by_aggregated_metric is broadened without tests, child projects can be falsely passed for CIS logging metric checks.