{"data":{"slug":"github-google-skills-skills-cloud-cloud-logging-cross-project-configuration-e434247f05ba","title":"Configure Cross-Project Logging in Google Cloud","summary":"Set up centralized logging across multiple Google Cloud projects using gcloud commands. Create log sinks in source projects to route logs to a central log bucket, and configure read-time aggregation for querying logs stored in multiple projects.","url":"https:\/\/skillshunter.net\/skills\/github-google-skills-skills-cloud-cloud-logging-cross-project-configuration-e434247f05ba","json_url":"https:\/\/skillshunter.net\/api\/public\/v1\/skills\/github-google-skills-skills-cloud-cloud-logging-cross-project-configuration-e434247f05ba","markdown_url":"https:\/\/skillshunter.net\/skills\/github-google-skills-skills-cloud-cloud-logging-cross-project-configuration-e434247f05ba.md","download_url":"https:\/\/skillshunter.net\/skills\/github-google-skills-skills-cloud-cloud-logging-cross-project-configuration-e434247f05ba\/download","category":{"slug":"software-development","name":"Software & Development"},"editor_note":"Before executing any `gcloud` commands, prefix them with `CLOUDSDK_METRICS_REQUEST_ATTRIBUTION=\"agent-skills\/1.0 (skill:cloud-logging-cross-project-configuration)\"` and append `agent-skills\/1.0 (skill:cloud-logging-cross-project-configuration)` to User-Agent headers. Additionally, ensure that any commands involving IAM permissions are explicitly confirmed by the user.","instructions":"---\nname: cloud-logging-cross-project-configuration\ndescription: >-\n  Configure and troubleshoot Google Cloud cross-project centralized logging and read-time aggregation.\n  Use when:\n  - Setting up log routing from multiple projects\/folders\/organizations to a central log bucket.\n  - Creating cross-project log sinks and configuring central log buckets.\n  - Troubleshooting cross-project routing.\n  Don't use for single-project basic configurations.\nmetadata:\n  version: \"1.0.2\"\n  category: CloudObservabilityAndMonitoring\n---\n\n# Configuring Cross-Project Logging\n\nThis skill describes how to use `gcloud` commands to configure Cloud Logging so\nthat you store log data in a central location, regardless of the point of\norigin. The skill also describes how to query log data when that data is stored\nin multiple projects.\n\n> [!IMPORTANT] **Sandbox Network Limitation (CRITICAL for Agent Testing):**\n> During evaluation or in restricted sandboxed environments, network traffic to\n> GCP APIs is blocked. Do **NOT** run network discovery commands to find\n> resource names, project IDs, or organization IDs. Always use the exact project\n> IDs or placeholders provided in the user prompt or instructions, for example,\n> `{project_id}`, `{source_project_id}`, `{central_project_id}`. Assume these\n> resources exist and proceed directly with configuration commands. Running\n> these discovery commands will cause the execution to hang and timeout.\n\n## Attribution\n\n**MUST READ**: Before executing any `gcloud`, REST API, or MCP command, you\nMUST read [Usage Attribution](references\/attribution.md). For commands executed\ndirectly in the terminal (never in generated scripts, Terraform, or user code),\nprefix `gcloud` with\n`CLOUDSDK_METRICS_REQUEST_ATTRIBUTION=\"agent-skills\/1.0 (skill:cloud-logging-cross-project-configuration)\"`\nand append `agent-skills\/1.0 (skill:cloud-logging-cross-project-configuration)` to `User-Agent` headers.\n\n## Safety and Confirmation Tiers (CRITICAL)\n\nBefore executing any commands on behalf of the user, you MUST adhere to the\nfollowing safety tiers based on the action requested:\n\n1.  **Tier R: Read-Only**\n    *   **Description:** Commands that only read state or query logs.\n    *   **Example commands:**\n        *   `gcloud logging read`\n        *   `gcloud logging buckets list`\n    *   **Rule:** No confirmation needed. You may execute these commands\n        immediately to gather information.\n2.  **Tier M: Mutation (Non-Billing)**\n    *   **Description:** Configuration modifications or free metadata creations\n        that do not incur direct storage or billing costs and do not affect\n        resource security\/access policies.\n    *   **Example commands:**\n        *   `gcloud logging views create`\n        *   `gcloud logging views update`\n        *   `gcloud logging scopes create`\n        *   `gcloud logging buckets create`\n    *   **Rule:** No confirmation needed. You may execute these commands\n        immediately to apply configurations.\n3.  **Tier B: Billing and Security-Sensitive Mutations (High-Risk)**\n    *   **Description:** Operations that create billing-inducing resources or\n        integrations, or modify security and IAM access control policies\n        (presenting a risk of privilege escalation).\n    *   **Example commands:**\n        *   `gcloud logging metrics create`\n        *   `gcloud logging links create`\n        *   `gcloud projects add-iam-policy-binding`\n    *   **Rule:** **Interactive confirmation required.** These commands create\n        resources that incur billing costs or alter security access. You MUST\n        present the exact, literal command and receive user confirmation before\n        executing. NEVER execute in the same turn as asking.\n4.  **Tier D: Causes irreversible data loss**\n    *   **Description:** Actions that permanently discard or delete logs, for\n        example sink exclusions.\n    *   **Example commands:**\n        *   `gcloud logging buckets delete`\n        *   `gcloud logging sinks update --add-exclusion`\n    *   **Rule:** **Explicit typed confirmation required.** These commands\n        discard or delete logs immediately and irreversibly, or they may result\n        in log data not being stored. You MUST ask for explicit typed\n        confirmation, for example, \"Yes, discard logs\", and halt execution until\n        the user replies.\n\n## Decision Matrix: Centralized Storage vs. Distributed Storage with Read-Time Aggregation\n\nUse this decision matrix to evaluate and choose between **Centralized Storage**\nand **Read-Time Aggregation**. With centralized storage, log data is routed to\none log bucket, regardless of where the data originates. You write queries\nagainst the centralized log bucket. With read-time aggregation, log data is\nstored by the resource where it originates. However, a single query aggregates\nthe data by querying all resources.\n\nAfter you have determined the optimal architecture for handling cross-project\nlogs, follow the corresponding configuration steps detailed below.\n\n| Criterion             | Centralized Storage      | Read-Time Aggregation    |\n| :-------------------- | :----------------------- | :----------------------- |\n| **GCP Project Scale** | Scales to thousands of   | Best for < 375 projects. |\n:                       : projects.                :                          :\n| **Log Storage**       | Consolidated in a single | Resides in originating   |\n:                       : log bucket.              : resources.               :\n| **SQL Analytics**     | Easy; unified querying   | Hard; requires querying  |\n:                       : via Observability        : multiple log buckets.    :\n:                       : Analytics.               :                          :\n| **Access Control**    | Scoped access via log    | Requires IAM access to   |\n:                       : views on the centralized : all views on resources   :\n:                       : log bucket.              : that store log data.     :\n| **Configuration**     | Options vary based on    | Will not interfere with  |\n: **Complexity**        : Project, Folder,         : bucket-based log-based   :\n:                       : Organization structure.  : metrics.                 :\n| **Cost**              | Potential for duplicate  | Cost-effective; no data  |\n:                       : storage of log buckets   : replication.             :\n:                       : if exclusions aren't     :                          :\n:                       : set.                     :                          :\n\n## Architecture\n\n### Centralized Storage (Log Routing)\n\n```mermaid\ngraph LR\n    subgraph \"Source Project(s)\"\n        Log[Resource Logs] --> Sink[\"Sink: route-to-central-project\"]\n    end\n\n    subgraph \"Central Project\"\n        Sink --> Bucket[\"Bucket: central-logs-bucket (us-central1)\"]\n    end\n```\n\n### Read-Time Aggregation (Log Scopes)\n\n```mermaid\ngraph LR\n    subgraph \"Source Project 1\"\n        Log1[Resource Logs] --> Bucket1[\"Bucket: _Default\"]\n    end\n\n    subgraph \"Source Project 2\"\n        Log2[Resource Logs] --> Bucket2[\"Bucket: _Default\"]\n    end\n\n    subgraph \"Scoping Project (No Log Storage)\"\n        Scope[\"Log scope: central-query-scope\"]\n        Scope -.-> View1[\"_AllLogs View on Bucket1\"]\n        Scope -.-> View2[\"_AllLogs View on Bucket2\"]\n    end\n```\n\n## Setup Steps: Centralized Storage (Log Routing)\n\nUse these steps to route logs from one or more source projects to a central log\nbucket in a project. Create or select the Google Cloud project that you will use\nfor storing your log data. This is the central project.\n\n### 1. Create log bucket in central project (Tier M)\n\nCreate a custom log bucket with Log Analytics enabled.\n\n> [Tip] Use regional log buckets, for example, set the location to\n> `us-central1`. Don't use the `global` location. This approach ensures\n> compatibility with Observability Analytics and SQL querying.\n\n```bash\ngcloud logging buckets create {bucket_id} \\\n    --project={central_project_id} \\\n    --location={region} \\\n    --retention-days={retention_days} \\\n    --enable-analytics\n```\n\n### 2. Create log sink in central project (Tier M)\n\nCreate a project-level sink in the central project pointing to the central log\nbucket. This sink routes logs that land in the central project's Log Router into\nthe central log bucket.\n\nAssuming the newly created bucket is specifically for centralizing data from\nother projects (and the central project is not one of the source projects), the\ncentral sink should exclude the central project's own logs. Include the\n`_Required` audit log exclusions on this central sink to avoid redundancy\nbetween `{bucket_id}` and the `_Required` bucket.\n\n```bash\ngcloud logging sinks create {sink_name} \\\n    logging.googleapis.com\/projects\/{central_project_id}\/locations\/{region}\/buckets\/{bucket_id} \\\n    --project={central_project_id} \\\n    --exclusion=filter='logName:\"projects\/{central_project_id}\/\"' \\\n    --exclusion=filter='LOG_ID(\"cloudaudit.googleapis.com\/activity\")' \\\n    --exclusion=filter='LOG_ID(\"externalaudit.googleapis.com\/activity\")' \\\n    --exclusion=filter='LOG_ID(\"cloudaudit.googleapis.com\/system_event\")' \\\n    --exclusion=filter='LOG_ID(\"externalaudit.googleapis.com\/system_event\")' \\\n    --exclusion=filter='LOG_ID(\"cloudaudit.googleapis.com\/access_transparency\")' \\\n    --exclusion=filter='LOG_ID(\"externalaudit.googleapis.com\/access_transparency\")'\n```\n\n### 3. Create log sink in source resource (Tier M)\n\nTo route logs to the central project, you must create a log sink in each source\norganization, folder, or project. While you can configure a sink to route only a\nsubset of logs using the `--log-filter` argument, recommended practice is to\nroute all non-audit logs, and then restrict access or partition logs at the\ndestination using custom Log Views on the centralized log bucket.\n\n*   **For an organization-level log sink**\n\n    ```bash\n    gcloud logging sinks create {sink_name} \\\n        logging.googleapis.com\/projects\/{central_project_id} \\\n        --organization={source_organization_id} \\\n        --include-children \\\n        --exclusion=filter='LOG_ID(\"cloudaudit.googleapis.com\/activity\")' \\\n        --exclusion=filter='LOG_ID(\"externalaudit.googleapis.com\/activity\")' \\\n        --exclusion=filter='LOG_ID(\"cloudaudit.googleapis.com\/system_event\")' \\\n        --exclusion=filter='LOG_ID(\"externalaudit.googleapis.com\/system_event\")' \\\n        --exclusion=filter='LOG_ID(\"cloudaudit.googleapis.com\/access_transparency\")' \\\n        --exclusion=filter='LOG_ID(\"externalaudit.googleapis.com\/access_transparency\")'\n    ```\n\n*   **For project-level log sinks**\n\n    ```bash\n    gcloud logging sinks create {sink_name} \\\n        logging.googleapis.com\/projects\/{central_project_id} \\\n        --project={source_project_id} \\\n        --exclusion=filter='LOG_ID(\"cloudaudit.googleapis.com\/activity\")' \\\n        --exclusion=filter='LOG_ID(\"externalaudit.googleapis.com\/activity\")' \\\n        --exclusion=filter='LOG_ID(\"cloudaudit.googleapis.com\/system_event\")' \\\n        --exclusion=filter='LOG_ID(\"externalaudit.googleapis.com\/system_event\")' \\\n        --exclusion=filter='LOG_ID(\"cloudaudit.googleapis.com\/access_transparency\")' \\\n        --exclusion=filter='LOG_ID(\"externalaudit.googleapis.com\/access_transparency\")'\n    ```\n\n### 4. Grant IAM permissions to sink writers (Tier B)\n\n> [!IMPORTANT] **Security Action (Tier B):** Granting IAM permissions changes\n> access control policy and must be explicitly confirmed by the user before\n> execution.\n\nTo allow the source sinks to route logs to the central project's router, and to\nallow the central sink to write logs to the central bucket:\n\n1.  **Grant Logs Writer permission to the source sink:** Retrieve the\n    `writerIdentity` of the source log sink and grant it\n    `roles\/logging.logWriter` on the central project.\n\n    ```bash\n    # Get the writer identity of the source sink\n    gcloud logging sinks describe {sink_name} \\\n        --project={source_project_id} \\\n        --format=\"value(writerIdentity)\"\n    ```\n\n    The output is the `{source_writer_identity}` value (for example\n    `serviceAccount:...`) for the following command:\n\n    ```bash\n    # Grant Logs Writer permissions on the central project\n    gcloud projects add-iam-policy-binding {central_project_id} \\\n        --member={source_writer_identity} \\\n        --role=roles\/logging.logWriter\n    ```\n\n2.  **Grant Bucket Writer permission to the central sink:** Retrieve the\n    `writerIdentity` of the central log sink and grant it\n    `roles\/logging.bucketWriter` on the central project.\n\n    ```bash\n    # Get the writer identity of the central sink\n    gcloud logging sinks describe {central_sink_name} \\\n        --project={central_project_id} \\\n        --format=\"value(writerIdentity)\"\n    ```\n\n    The output is the `{central_writer_identity}` value for the following\n    command:\n\n    ```bash\n    # Grant Bucket Writer permissions on the central project\n    gcloud projects add-iam-policy-binding {central_project_id} \\\n        --member={central_writer_identity} \\\n        --role=roles\/logging.bucketWriter\n    ```\n\n### 5. Create custom Log Views on the central bucket (Tier M)\n\nTo partition logs or restrict access by log ID or project (since all logs were\nrouted to the same central bucket), create custom Log Views on the central\nbucket.\n\n*   **Filter by log ID:**\n\n    ```bash\n    gcloud logging views create {view_id} \\\n        --bucket={bucket_id} \\\n        --location={region} \\\n        --project={central_project_id} \\\n        --log-filter='LOG_ID(\"{log_id}\")'\n    ```\n\n*   **Filter by source project:**\n\n    ```bash\n    gcloud logging views create {view_id} \\\n        --bucket={bucket_id} \\\n        --location={region} \\\n        --project={central_project_id} \\\n        --log-filter='project_id=\"{source_project_id}\"'\n    ```\n\n### Verify Centralized Log Routing (Tier R)\n\nTo verify that logs are being routed from the source projects to the central\nregional log bucket:\n\n1.  **Write a test log in the source project:**\n\n    ```bash\n    gcloud logging write {test_log_id} \"Test log entry for verification\" \\\n        --severity=WARNING \\\n        --project={source_project_id}\n    ```\n\n2.  **Read the test log from the central log bucket:** For regional log buckets,\n    you **must** specify the `--view` flag. Because the default view `_Default`\n    only contains logs matching the default filter, you should query the\n    **`_AllLogs`** view or your custom log view on the central bucket:\n\n    ```bash\n    gcloud logging read 'logName:\"projects\/{source_project_id}\/logs\/{test_log_id}\"' \\\n        --bucket={bucket_id} \\\n        --location={region} \\\n        --view=_AllLogs \\\n        --project={central_project_id}\n    ```\n\n--------------------------------------------------------------------------------\n\n## Setup Steps: Read-Time Aggregation (Log Scopes)\n\nCreate or select a Google Cloud project that you will use for querying your log\ndata. This is the scoping project. Use these steps to configure a log scope. Log\nscopes let you issue a query for log data that is stored in multiple projects.\n\n### 1. Create a custom Log View (Optional but recommended) (Tier M)\n\nCreate a Log View in the source project to restrict which logs are accessible.\n\n> [!IMPORTANT] **Gotcha:** Log View filters can only contain specific\n> restrictions. Refer to\n> https:\/\/docs.cloud.google.com\/logging\/docs\/logs-views.md.txt#view-filter\n\n```bash\ngcloud logging views create {view_id} \\\n    --bucket={bucket_id} \\\n    --location={region} \\\n    --project={source_project_id} \\\n    --log-filter='LOG_ID(\"{log_id}\")'\n```\n\n*   `{bucket_id}`: for example, `_Default`\n*   `{region}`: for example, `global`\n*   `{view_id}`: for example, `app-logs-view`\n*   If you want to allow access to all logs in the log bucket, omit the\n    `--log-filter` flag.\n\n### 2. Create a log scope in the scoping project (Tier M)\n\nCreate a log scope in the scoping project listing the source resources, which\nmay be projects or specific log views.\n\n```bash\ngcloud logging scopes create {log_scope_id} \\\n    --project={scoping_project_id} \\\n    --resource-names={resource_names}\n```\n\n*   `{log_scope_id}`: for example, `central-query-scope`\n*   `{resource_names}`: Comma-separated list of log views. For example,\n    `projects\/source-project-1\/locations\/global\/buckets\/_Default\/views\/app-logs-view,projects\/source-project-2\/locations\/global\/buckets\/_Default\/views\/app-logs-view`.\n    You can include up to 100 views in the scope.\n\n### 3. Update Default Observability Scope (Optional) (Tier M)\n\nLink the log scope to the project's default observability scope so it is used by\ndefault in Logs Explorer.\n\n```bash\ngcloud observability scopes update _Default \\\n    --project={scoping_project_id} \\\n    --location=global \\\n    --log-scope=\/\/logging.googleapis.com\/projects\/{scoping_project_id}\/locations\/global\/logScopes\/{log_scope_id}\n```\n\n### 4. Grant IAM permissions to users (Tier B)\n\nUnlike centralized routing, permissions are checked at query time on all source\nprojects. Users running queries must have:\n\n*   `roles\/logging.viewAccessor` granted on the specific Log View (with IAM\n    conditions) or `roles\/logging.viewer` on the source projects.\n*   Access to the scoping project.\n\n## Troubleshooting Cross-Project Log Routing and Sink Permission Failures\n\nIf logs are not appearing in a central project's bucket after configuring\ncentralized logging:\n\n### 1. Verify Log Router Sink Filters in Source Resource\n\n*   Ensure that the log sink's filter matches the logs you expect to route.\n\n    > [!IMPORTANT] **Gotcha:** Standard filter expressions like `logName:abc` or\n    > `logName=\"projects\/{project_id}\/logs\/abc\"` can fail to match in log sinks.\n    > **Always** use `LOG_ID(\"abc\")` for precise matching in log sink filters.\n\n*   Verify that you have not configured an exclusion filter that accidentally\n    discards these logs.\n\n### 2. Verify and Grant Writer Identity Permissions (Most Common Cause)\n\nThe log sink's writer identity service account in the source project must be\nexplicitly granted the necessary permissions on the central resource.\n\n*   **Step A: Get the Writer Identity**\n\n    ```bash\n    gcloud logging sinks describe {sink_name} \\\n        --project={source_project_id} \\\n        --format=\"value(writerIdentity)\"\n    ```\n\n*   **Step B: Grant the Permission in the Central Project (Tier B)**\n\n    > [!IMPORTANT] **Security Action (Tier B):** Granting IAM permissions\n    > changes access control policy and must be explicitly confirmed by the user\n    > before execution.\n\n    *   **For Cloud Logging Buckets (standard):** Grant\n        `roles\/logging.bucketWriter`:\n\n        ```bash\n        gcloud projects add-iam-policy-binding {central_project_id} \\\n            --member={writer_identity} \\\n            --role=roles\/logging.bucketWriter\n        ```\n\n    *   **For GCS Buckets:** Grant `roles\/storage.objectCreator` on the GCS\n        bucket.\n\n    *   **For Pub\/Sub Topics:** Grant `roles\/pubsub.publisher` on the Pub\/Sub\n        topic.\n\n    *   **For BigQuery Datasets:** Grant `roles\/bigquery.dataEditor` on the\n        BigQuery dataset.\n\n--------------------------------------------------------------------------------\n\n## References and Supporting Links\n\n*   [GCP Cloud Logging - Routing and Storage Overview](https:\/\/docs.cloud.google.com\/logging\/docs\/routing\/overview.md.txt)\n*   [GCP Cloud Logging - Log Scopes](https:\/\/docs.cloud.google.com\/logging\/docs\/log-scope\/create-and-manage.md.txt)\n*   [GCP Cloud Logging - Custom Log Views](https:\/\/docs.cloud.google.com\/logging\/docs\/logs-views.md.txt)\n","use_cases":["Route logs from multiple projects to a central log bucket.","Troubleshoot cross-project log routing issues.","Query log data stored in multiple projects using read-time aggregation."],"limitations":[],"compatibility":[],"setup_tip":null,"sample_input":null,"sample_output":null,"source_url":"https:\/\/github.com\/google\/skills\/blob\/e3c591afe426ea585e4c21799e5199d6d47cd1be\/skills\/cloud\/cloud-logging-cross-project-configuration\/SKILL.md","source_commit":"e3c591afe426ea585e4c21799e5199d6d47cd1be","license":null,"version":null,"listing_approved_at":"2026-11-17","created_at":"2026-11-16T12:58:36.000000Z","updated_at":"2026-11-17T05:10:16.000000Z","seo_title":"Configure Cross-Project Logging in Google Cloud","seo_description":"Configure centralized logging across multiple projects using gcloud commands for Google Cloud. Learn how to route logs and query data efficiently.","seo_keywords":["configure cross-project logging","centralized logging in Google Cloud","cross-project log routing","read-time aggregation logs","Google Cloud log aggregation"]}}