This page provides supplemental information for using Cloud Audit Logs with Cloud Storage. Use Cloud Audit Logs to generate logs for API operations performed in Cloud Storage.
Overview
Google Cloud services write audit logs to help you answer the questions, "Who did what, where, and when?" within your Google Cloud resources. You can also attach custom information to audit logs for more granular information about how your resources are accessed.
Your Google Cloud projects contain only the audit logs for resources that are directly within the Google Cloud project. Other Google Cloud resources, such as folders, organizations, and billing accounts, contain the audit logs for the entity itself.
For a general overview of Cloud Audit Logs, see Cloud Audit Logs overview. For a deeper understanding of the audit log format, see Understand audit logs.
Available audit logs
The following types of audit logs are available for Cloud Storage:
Admin Activity audit logs: Entries for operations that modify access to Cloud Storage resources and operations that restore buckets or create, delete, or modify buckets, managed folders, or inventory report configurations.
Data Access audit logs: Entries for operations that are not tracked in Admin Activity audit logs. There are several sub-types of Data Access audit logs:
ADMIN_READ
: Entries for operations that read access configurations, read bucket metadata, or list buckets within a project.DATA_READ
: Entries for operations that read or list Cloud Storage resources other than buckets.DATA_WRITE
: Entries for operations that create, modify, delete, or restore objects or that create, modify, or delete XML API multipart uploads or that create, delete or rename folders.
To receive Data Access audit logs, you must explicitly enable them.
In addition to audit logs for Cloud Storage, Cloud Audit Logs can create audit logs for Storage Insights. Storage Insights audit logs are generated whenever inventory report configurations are created, updated, and fetched, and when inventory reports are fetched.
For fuller descriptions of the audit log types, see Types of audit logs.
Audited operations
The following table summarizes which Cloud Storage operations correspond to each audit log type:
Audit log type | Sub-type | Cloud Storage operations |
---|---|---|
Admin Activity | ADMIN_WRITE |
|
Data Access | ADMIN_READ |
|
Data Access | DATA_READ |
|
Data Access | DATA_WRITE |
|
1 Admin Activity audit logs are not generated if/when ACLs are initially set at object creation. Additionally, if an object ACL is set to public, audit logs are not generated for reads or writes to that object or its ACL.
2 These operations involve both reading and writing data. As a result, these operations each generate two log entries.
Restrictions
The following restrictions apply to Cloud Audit Logs with Cloud Storage:
- Cloud Audit Logs does not track access to public objects.
- Cloud Audit Logs does not track changes made by the Object Lifecycle Management or Autoclass features.
- Data Access logs generated from authenticated browser downloads have
their
principalEmail
andcallerIp
fields redacted when the download occurs outside of the Google Cloud console.
If you need logging capabilities in one of these cases, consider using Cloud Storage usage logs.
Audit log format
Audit log entries include the following components:
The log entry itself, which is a
LogEntry
object. Useful fields include the following:- The
logName
contains the resource ID and audit log type. - The
resource
contains the target of the audited operation. - The
timestamp
contains the time of the audited operation. - The
protoPayload
contains the audited information.
- The
The audit logging data, which is an
AuditLog
object held in theprotoPayload
field of the log entry.Optional Cloud Storage-specific audit information, including detailed request and response information; for more information, see Detailed audit logging mode. Note that you do not need to enforce detailed audit logging to attach custom information to audit logs.
For other fields in these objects, and how to interpret them, see Understand audit logs.
Log name
Cloud Audit Logs log names include resource identifiers indicating the Google Cloud project or other Google Cloud entity that owns the audit logs, and whether the log contains Admin Activity or Data Access audit logging data.
The following are the audit log names, including variables for the resource identifiers:
projects/PROJECT_ID/logs/cloudaudit.googleapis.com%2Factivity projects/PROJECT_ID/logs/cloudaudit.googleapis.com%2Fdata_access folders/FOLDER_ID/logs/cloudaudit.googleapis.com%2Factivity folders/FOLDER_ID/logs/cloudaudit.googleapis.com%2Fdata_access billingAccounts/BILLING_ACCOUNT_ID/logs/cloudaudit.googleapis.com%2Factivity billingAccounts/BILLING_ACCOUNT_ID/logs/cloudaudit.googleapis.com%2Fdata_access organizations/ORGANIZATION_ID/logs/cloudaudit.googleapis.com%2Factivity organizations/ORGANIZATION_ID/logs/cloudaudit.googleapis.com%2Fdata_access
Service name
Cloud Storage audit logs use the service name
storage.googleapis.com
.
Storage Insights audit logs use the service name
storageinsights.googleapis.com
.
For a list of all the Cloud Logging API service names and their corresponding monitored resource type, see Map services to resources.
Resource types
Cloud Storage audit logs use the resource type gcs_bucket
.
For a list of all the Cloud Logging monitored resource types and descriptive information, see Monitored resource types.
Enable audit logging
Admin Activity audit logs are always enabled; you can't disable them.
Data Access audit logs are disabled by default and aren't written unless explicitly enabled.
For information about enabling some or all of your Data Access audit logs, see Configure Data Access audit logs.
Permissions and roles
IAM permissions and roles determine your ability to access audit logs data in Google Cloud resources.
When deciding which Logging-specific permissions and roles apply to your use case, consider the following:
The Logs Viewer role (
roles/logging.viewer
) gives you read-only access to Admin Activity, Policy Denied, and System Event audit logs. If you have just this role, you cannot view Data Access audit logs that are in the_Required
and_Default
buckets.The Private Logs Viewer role
(roles/logging.privateLogViewer
) includes the permissions contained inroles/logging.viewer
, plus the ability to read Data Access audit logs in the_Required
and_Default
buckets.Note that if these private logs are stored in user-defined buckets, then any user who has permissions to read logs in those buckets can read the private logs. For more information about log buckets, see Routing and storage overview.
For more information about the IAM permissions and roles that apply to audit logs data, see Access control with IAM.
Viewing logs
You can query for all audit logs or you can query for logs by their
audit log name. The audit log name includes the
resource identifier
of the Google Cloud project, folder, billing account, or
organization for which you want to view audit logging information.
Your queries can specify indexed LogEntry
fields, and if you use
the Log Analytics page, which supports SQL queries, then you can
view your query results as a chart.
For more information about querying your logs, see the following pages:
- Build queries in the Logs Explorer.
- Query and view logs in Log Analytics.
- Sample queries for security insights.
Console
In the Google Cloud console, you can use the Logs Explorer to retrieve your audit log entries for your Google Cloud project, folder, or organization:
-
In the Google Cloud console, go to the Logs Explorer page:
If you use the search bar to find this page, then select the result whose subheading is Logging.
Select an existing Google Cloud project, folder, or organization.
To display all audit logs, enter either of the following queries into the query-editor field, and then click Run query:
logName:"cloudaudit.googleapis.com"
protoPayload."@type"="type.googleapis.com/google.cloud.audit.AuditLog"
To display the audit logs for a specific resource and audit log type, in the Query builder pane, do the following:
In Resource type, select the Google Cloud resource whose audit logs you want to see.
In Log name, select the audit log type that you want to see:
- For Admin Activity audit logs, select activity.
- For Data Access audit logs, select data_access.
- For System Event audit logs, select system_event.
- For Policy Denied audit logs, select policy.
Click Run query.
If you don't see these options, then there aren't any audit logs of that type available in the Google Cloud project, folder, or organization.
If you're experiencing issues when trying to view logs in the Logs Explorer, see the troubleshooting information.
For more information about querying by using the Logs Explorer, see Build queries in the Logs Explorer. For information about summarizing log entries in the Logs Explorer by using Gemini, see Summarize log entries with Gemini assistance.
gcloud
The Google Cloud CLI provides a command-line interface to the Logging API. Supply a valid resource identifier in each of the log names. For example, if your query includes a PROJECT_ID, then the project identifier you supply must refer to the currently selected Google Cloud project.
To read your Google Cloud project-level audit log entries, run the following command:
gcloud logging read "logName : projects/PROJECT_ID/logs/cloudaudit.googleapis.com" \ --project=PROJECT_ID
To read your folder-level audit log entries, run the following command:
gcloud logging read "logName : folders/FOLDER_ID/logs/cloudaudit.googleapis.com" \ --folder=FOLDER_ID
To read your organization-level audit log entries, run the following command:
gcloud logging read "logName : organizations/ORGANIZATION_ID/logs/cloudaudit.googleapis.com" \ --organization=ORGANIZATION_ID
To read your Cloud Billing account-level audit log entries, run the following command:
gcloud logging read "logName : billingAccounts/BILLING_ACCOUNT_ID/logs/cloudaudit.googleapis.com" \ --billing-account=BILLING_ACCOUNT_ID
Add the --freshness
flag
to your command to read logs that are more than 1 day old.
For more information about using the gcloud CLI, see
gcloud logging read
.
API
When building your queries, supply a valid resource identifier in each of the log names. For example, if your query includes a PROJECT_ID, then the project identifier you supply must refer to the currently selected Google Cloud project.
For example, to use the Logging API to view your project-level audit log entries, do the following:
Go to the Try this API section in the documentation for the
entries.list
method.Put the following into the Request body part of the Try this API form. Clicking this prepopulated form automatically fills the request body, but you need to supply a valid PROJECT_ID in each of the log names.
{ "resourceNames": [ "projects/PROJECT_ID" ], "pageSize": 5, "filter": "logName : projects/PROJECT_ID/logs/cloudaudit.googleapis.com" }
Click Execute.
Add custom information to audit logs
You can attach custom information to audit logs to requests by
including the x-goog-custom-audit-KEY: VALUE
header in your request. XML API requests additionally support the usage of a
x-goog-custom-audit-KEY=VALUE
query
parameter. Custom information is added to the metadata
field of the
protoPayload
in the audit log entry.
When adding custom audit information, note the following considerations:
Each
KEY
can contain up to 64 characters, while eachVALUE
can contain up to 1,200 characters.Each request can contain up to 4 header or parameter entries combined.
Example header entries
The following list shows examples of key-value pairs you can include in header entries:
x-goog-custom-audit-job: test-job-id-here
x-goog-custom-audit-user: user ID test 1
x-goog-custom-audit-internal-user-id: MATR2022-11
x-goog-custom-audit-tracking-ticket: TT/1516512851
x-goog-custom-audit-justification: Removed customer identity record at customer request
x-goog-custom-audit-customer-id: USCU12315154
Example requests
Command line
gcloud storage hash gs://example_bucket/example_object.jpeg --additional-headers=x-goog-custom-audit-job="job name",x-goog-custom-audit-user="test user"
Client libraries
C++
To learn how to add custom headers to requests, see Add custom headers.
C#
To learn how to add custom headers to requests, see Add custom headers.
Go
To learn how to add custom headers to requests, see Add custom headers.
Java
To learn how to add custom headers to requests, see Add custom headers.
Node.js
To learn how to add custom headers to requests, see Add custom headers.
PHP
To learn how to add custom headers to requests, see Add custom headers.
Python
To learn how to add custom headers to requests, see Add custom headers.
Ruby
To learn how to add custom headers to requests, see Add custom headers.
REST APIs
JSON API
curl -X GET "https://storage.googleapis.com/storage/v1/b/example_bucket/o/example_object" \ -H "Authorization: Bearer ya29.AHES6ZRVmB7fkLtd1XTmq6mo0S1wqZZi3-Lh_s-6Uw7p8vtgSwg" \ -H "x-goog-custom-audit-job: job name" \ -H "x-goog-custom-audit-user: test user"
XML API
curl -X GET "https://storage.googleapis.com/example_bucket/example_object" \ -H "Authorization: Bearer ya29.AHES6ZRVmB7fkLtd1XTmq6mo0S1wqZZi3-Lh_s-6Uw7p8vtgSwg" \ -H "x-goog-custom-audit-job: job name" \ -H "x-goog-custom-audit-user: test user"
Signed URL requests
curl -X GET 'storage.googleapis.com/example_bucket?X-Goog-Algorithm=GOOG4-RSA-SHA256&X-Goog-Credential=example%40example-project.iam.gserviceaccount.com%2F20181026%2Fus-central1%2Fstorage%2Fgoog4_request&X-Goog-Date=20181026T181309Z&X-Goog-Expires=900&X-Goog-SignedHeaders=host,x-goog-custom-audit-job,x-goog-custom-audit-user&X-Goog-Signature=247a2aa45f169edf4d187d54e7cc46e4731b1e6273242c4f4c39a1d2507a0e58706e25e3a85a7dbb891d62afa8496def8e260c1db863d9ace85ff0a184b894b117fe46d1225c82f2aa19efd52cf21d3e2022b3b868dcc1aca2741951ed5bf3bb25a34f5e9316a2841e8ff4c530b22ceaa1c5ce09c7cbb5732631510c20580e61723f5594de3aea497f195456a2ff2bdd0d13bad47289d8611b6f9cfeef0c46c91a455b94e90a66924f722292d21e24d31dcfb38ce0c0f353ffa5a9756fc2a9f2b40bc2113206a81e324fc4fd6823a29163fa845c8ae7eca1fcf6e5bb48b3200983c56c5ca81fffb151cca7402beddfc4a76b133447032ea7abedc098d2eb14a7' \ -H "x-goog-custom-audit-job: job name" \ -H "x-goog-custom-audit-user: test user"
Note that the custom audit headers must also be included in
X-Goog-SignedHeaders
.
To create a signed URL request that supports the addition of custom audit headers, the custom audit headers you want to use in the request must also be included when you generate the signed URL. For example:
gcloud storage sign-url gs://example_bucket/example_object.jpeg --private-key-file=example-key.json --duration=10m --headers=x-goog-custom-audit-job:"job name",x-goog-custom-audit-user="test user"
You can also use client libraries to generate the signed URL when you set custom headers.
As an alternative to using signed headers, you can use query parameters to pass custom audit entries.
curl -X GET 'storage.googleapis.com/example_bucket?X-Goog-Custom-Audit-Key=Value&X-Goog-Algorithm=GOOG4-RSA-SHA256&X-Goog-Credential=example%40example-project.iam.gserviceaccount.com%2F20181026%2Fus-central1%2Fstorage%2Fgoog4_request&X-Goog-Date=20181026T181309Z&X-Goog-Expires=900&X-Goog-SignedHeaders=host&X-Goog-Signature=247a2aa45f169edf4d187d54e7cc46e4731b1e6273242c4f4c39a1d2507a0e58706e25e3a85a7dbb891d62afa8496def8e260c1db863d9ace85ff0a184b894b117fe46d1225c82f2aa19efd52cf21d3e2022b3b868dcc1aca2741951ed5bf3bb25a34f5e9316a2841e8ff4c530b22ceaa1c5ce09c7cbb5732631510c20580e61723f5594de3aea497f195456a2ff2bdd0d13bad47289d8611b6f9cfeef0c46c91a455b94e90a66924f722292d21e24d31dcfb38ce0c0f353ffa5a9756fc2a9f2b40bc2113206a81e324fc4fd6823a29163fa845c8ae7eca1fcf6e5bb48b3200983c56c5ca81fffb151cca7402beddfc4a76b133447032ea7abedc098d2eb14a7'
These query parameters must be included when you generate the signed URL. For example:
gcloud storage sign-url gs://example_bucket/example_object.jpeg --private-key-file=example-key.json --duration=10m --query-params=x-goog-custom-audit-job=job_name,x-goog-custom-audit-user=test_user
Example log entry
protoPayload: { @type: "type.googleapis.com/google.cloud.audit.Auditlog", ... metadata: { audit_context: { app_context: "EXTERNAL", audit_info: { x-goog-custom-audit-job: "job name", x-goog-custom-audit-user: "test user" } } } }
For more information on the fields included in the protoPayload
object with
the type type.googleapis.com/google.cloud.audit.Auditlog
, see the
AuditLog
reference documentation.
Route audit logs
You can route audit logs to supported destinations in the same way that you can route other kinds of logs. Here are some reasons you might want to route your audit logs:
- To keep audit logs for a longer period of time or to use more powerful search capabilities, you can route copies of your audit logs to Cloud Storage, BigQuery, or Pub/Sub. Using Pub/Sub, you can route to other applications, other repositories, and to third parties.
- To manage your audit logs across an entire organization, you can create aggregated sinks that can route logs from any or all Google Cloud projects in the organization.
- If your enabled Data Access audit logs are pushing your Google Cloud projects over your free allotment, you can create sinks that exclude the Data Access audit logs from Logging.
For instructions about routing logs, see Configure and manage sinks .
Pricing
For information about Cloud Logging pricing, see Google Cloud Observability pricing: Cloud Logging.