Google Cloud Security Command Center

1.44.0 · active · verified Thu Apr 16

Google Cloud Security Command Center (SCC) is a security and data risk platform that helps you prevent, detect, and respond to threats across your Google Cloud assets. It identifies security misconfigurations, surfaces suspicious activity, and provides actionable recommendations. The `google-cloud-securitycenter` client library for Python, currently at version 1.44.0, provides programmatic access to the SCC API and is frequently updated to support new features and API versions.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart initializes the Security Command Center client and lists all available security sources within a specified Google Cloud organization. Ensure your environment is authenticated (e.g., via `GOOGLE_APPLICATION_CREDENTIALS` or `gcloud auth application-default login`) and the `GOOGLE_CLOUD_ORGANIZATION_ID` environment variable is set.

import os
from google.cloud import securitycenter_v1
from google.api_core.exceptions import GoogleAPIError

# Ensure GOOGLE_APPLICATION_CREDENTIALS points to a service account key file
# or use `gcloud auth application-default login`.
# Set your Google Cloud Organization ID as an environment variable or replace the placeholder.
organization_id = os.environ.get('GOOGLE_CLOUD_ORGANIZATION_ID', 'YOUR_ORGANIZATION_ID')

def list_scc_sources(org_id: str):
    """Lists all Security Command Center sources for an organization."""
    if org_id == 'YOUR_ORGANIZATION_ID':
        print("Please set the GOOGLE_CLOUD_ORGANIZATION_ID environment variable or replace 'YOUR_ORGANIZATION_ID'.")
        return

    client = securitycenter_v1.SecurityCenterClient()
    parent = f"organizations/{org_id}"

    print(f"Listing SCC sources for organization: {parent}")
    try:
        # Paging through all results
        for source in client.list_sources(parent=parent):
            print(f"  Source: {source.display_name} (Name: {source.name})")
    except GoogleAPIError as e:
        print(f"An API error occurred: {e}")
    except Exception as e:
        print(f"An unexpected error occurred: {e}")

if __name__ == "__main__":
    list_scc_sources(organization_id)

view raw JSON →