npx skills add ...
npx skills add google/skills --skill cloud-logging-cross-project-configuration
Configure and troubleshoot Google Cloud cross-project centralized logging and read-time aggregation. Use when: - Setting up log routing from multiple projects/folders/organizations to a central log bucket. - Creating cross-project log sinks and configuring central log buckets. - Troubleshooting cross-project routing. Don't use for single-project basic configurations.
npx skills add google/skills --skill cloud-logging-cross-project-configuration
This skill describes how to use gcloud commands to configure Cloud Logging so
that you store log data in a central location, regardless of the point of
origin. The skill also describes how to query log data when that data is stored
in multiple projects.
[!IMPORTANT] Sandbox Network Limitation (CRITICAL for Agent Testing): During evaluation or in restricted sandboxed environments, network traffic to GCP APIs is blocked. Do NOT run network discovery commands to find resource names, project IDs, or organization IDs. Always use the exact project IDs or placeholders provided in the user prompt or instructions, for example,
{project_id},{source_project_id},{central_project_id}. Assume these resources exist and proceed directly with configuration commands. Running these discovery commands will cause the execution to hang and timeout.
Before executing any commands on behalf of the user, you MUST adhere to the following safety tiers based on the action requested:
gcloud logging readgcloud logging buckets listgcloud logging views creategcloud logging views updategcloud logging scopes creategcloud logging buckets creategcloud logging metrics creategcloud logging links creategcloud projects add-iam-policy-bindinggcloud logging buckets deletegcloud logging sinks update --add-exclusionUse this decision matrix to evaluate and choose between Centralized Storage and Read-Time Aggregation. With centralized storage, log data is routed to one log bucket, regardless of where the data originates. You write queries against the centralized log bucket. With read-time aggregation, log data is stored by the resource where it originates. However, a single query aggregates the data by querying all resources.
After you have determined the optimal architecture for handling cross-project logs, follow the corresponding configuration steps detailed below.
| Criterion | Centralized Storage | Read-Time Aggregation |
|---|---|---|
| GCP Project Scale | Scales to thousands of | Best for < 375 projects. |
| : : projects. : : | ||
| Log Storage | Consolidated in a single | Resides in originating |
| : : log bucket. : resources. : | ||
| SQL Analytics | Easy; unified querying | Hard; requires querying |
| : : via Observability : multiple log buckets. : | ||
| : : Analytics. : : | ||
| Access Control | Scoped access via log | Requires IAM access to |
| : : views on the centralized : all views on resources : | ||
| : : log bucket. : that store log data. : | ||
| Configuration | Options vary based on | Will not interfere with |
| : Complexity : Project, Folder, : bucket-based log-based : | ||
| : : Organization structure. : metrics. : | ||
| Cost | Potential for duplicate | Cost-effective; no data |
| : : storage of log buckets : replication. : | ||
| : : if exclusions aren't : : | ||
| : : set. : : |
Use these steps to route logs from one or more source projects to a central log bucket in a project. Create or select the Google Cloud project that you will use for storing your log data. This is the central project.
Create a custom log bucket with Log Analytics enabled.
[Tip] Use regional log buckets, for example, set the location to
us-central1. Don't use thegloballocation. This approach ensures compatibility with Observability Analytics and SQL querying.
Create a project-level sink in the central project pointing to the central log bucket. This sink will route logs that land in the central project's log router into the central log bucket.
To route logs to the central project, you must create a log sink in each source
organization, folder, or project. While you can configure a sink to route only a
subset of logs using the --log-filter argument, recommended practice is to
route all non-audit logs, and then restrict access or partition logs at the
destination using custom Log Views on the centralized log bucket.
For an organization-level log sink
For project-level log sinks
[!IMPORTANT] Security Action (Tier B): Granting IAM permissions changes access control policy and must be explicitly confirmed by the user before execution.
To allow the source sinks to route logs to the central project's router, and to allow the central sink to write logs to the central bucket:
Grant Logs Writer permission to the source sink: Retrieve the
writerIdentity of the source log sink and grant it
roles/logging.logWriter on the central project.
The output is the {source_writer_identity} value (for example
serviceAccount:...) for the following command:
Grant Bucket Writer permission to the central sink: Retrieve the
writerIdentity of the central log sink and grant it
roles/logging.bucketWriter on the central project.
The output is the {central_writer_identity} value for the following
command:
To partition logs or restrict access by log ID or project (since all logs were routed to the same central bucket), create custom Log Views on the central bucket.
Filter by log ID:
Filter by source project:
To verify that logs are being routed from the source projects to the central regional log bucket:
Write a test log in the source project:
Read the test log from the central log bucket: For regional log buckets,
you must specify the --view flag. Because the default view _Default
only contains logs matching the default filter, you should query the
_AllLogs view or your custom log view on the central bucket:
Create or select a Google Cloud project that you will use for querying your log data. This is the scoping project. Use these steps to configure a log scope. Log scopes let you issue a query for log data that is stored in multiple projects.
Create a Log View in the source project to restrict which logs are accessible.
[!IMPORTANT] Gotcha: Log View filters can only contain specific restrictions. Refer to https://docs.cloud.google.com/logging/docs/logs-views.md.txt#view-filter
{bucket_id}: for example, _Default{region}: for example, global{view_id}: for example, app-logs-view--log-filter flag.Create a log scope in the scoping project listing the source resources, which may be projects or specific log views.
{log_scope_id}: for example, central-query-scope{resource_names}: Comma-separated list of log views. For example,
projects/source-project-1/locations/global/buckets/_Default/views/app-logs-view,projects/source-project-2/locations/global/buckets/_Default/views/app-logs-view.
You can include up to 100 views in the scope.Link the log scope to the project's default observability scope so it is used by default in Logs Explorer.
Unlike centralized routing, permissions are checked at query time on all source projects. Users running queries must have:
roles/logging.viewAccessor granted on the specific Log View (with IAM
conditions) or roles/logging.viewer on the source projects.If logs are not appearing in a central project's bucket after configuring centralized logging:
Ensure that the log sink's filter matches the logs you expect to route.
[!IMPORTANT] Gotcha: Standard filter expressions like
logName:abcorlogName="projects/{project_id}/logs/abc"can fail to match in log sinks. Always useLOG_ID("abc")for precise matching in log sink filters.
Verify that you have not configured an exclusion filter that accidentally discards these logs.
The log sink's writer identity service account in the source project must be explicitly granted the necessary permissions on the central resource.
Step A: Get the Writer Identity
Step B: Grant the Permission in the Central Project (Tier B)
[!IMPORTANT] Security Action (Tier B): Granting IAM permissions changes access control policy and must be explicitly confirmed by the user before execution.
For Cloud Logging Buckets (standard): Grant
roles/logging.bucketWriter:
For GCS Buckets: Grant roles/storage.objectCreator on the GCS
bucket.
For Pub/Sub Topics: Grant roles/pubsub.publisher on the Pub/Sub
topic.
For BigQuery Datasets: Grant roles/bigquery.dataEditor on the
BigQuery dataset.
graph LR
subgraph "Source Project 1"
Log1[Resource Logs] --> Bucket1["Bucket: _Default"]
end
subgraph "Source Project 2"
Log2[Resource Logs] --> Bucket2["Bucket: _Default"]
end
subgraph "Scoping Project (No Log Storage)"
Scope["Log scope: central-query-scope"]
Scope -.-> View1["_AllLogs View on Bucket1"]
Scope -.-> View2["_AllLogs View on Bucket2"]
endgcloud logging buckets create {bucket_id} \
--project={central_project_id} \
--location={region} \
--retention-days={retention_days} \
--enable-analyticsgcloud logging sinks create {sink_name} \
logging.googleapis.com/projects/{central_project_id}/locations/{region}/buckets/{bucket_id} \
--project={central_project_id}