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.
Note: Cloud Audit Logs is separate from Cloud Storage usage logs. Both features provide information about who accesses your Cloud Storage resources, but Cloud Audit Logs is the recommended method for doing so. OverviewGoogle 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 logsThe following types of audit logs are available for Cloud Storage:
Admin Activity audit logs: Entries for operations that do the following:
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.
System Event audit logs: Entries for Google Cloud operations that modify configuration of Cloud Storage resources. These are generated by Google Cloud systems and not driven by user action.
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 operationsThe following table summarizes which Cloud Storage operations correspond to each audit log type:
Note: The following table provides an approximate mapping of Cloud Storage operations to Cloud Audit Logs logs. Cloud Audit Logs logs are generated based on the IAM permissions that get checked in the course of completing the Cloud Storage request. This means that some Cloud Storage requests can generate more than one Cloud Audit Logs log. Refer to the Cloud Storage page IAM permissions for JSON methods for a list of permissions that apply to different methods. Audit log type Sub-type Cloud Storage operations Admin ActivityADMIN_WRITE
ADMIN_READ
DATA_READ
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.
3 Bucket relocate might not start immediately after the initial request. The system event log gets written when the process actually begins.
RestrictionsThe following restrictions apply to Cloud Audit Logs with Cloud Storage:
principalEmail
and callerIp
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 formatAudit log entries include the following components:
The log entry itself, which is a LogEntry
object. Useful fields include the following:
logName
contains the resource ID and audit log type.resource
contains the target of the audited operation.timestamp
contains the time of the audited operation.protoPayload
contains the audited information.The audit logging data, which is an AuditLog
object held in the protoPayload
field of the log entry.
Within the protoPayload
field, the metadata
field includes information specific to Cloud Storage. For example, a rewrite operation's object GET request's log includes a destination
field in the metadata
field of its audit log to specify the bucket where the data has been copied to.
Within the protoPayload
field, additional audit information specific to Cloud Storage is included in the request and response fields when Detailed audit logging mode is enforced. Note that you don't 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 nameCloud 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_accessNote: The part of the log name following
/logs/
must be URL-encoded. The forward-slash character, /
, must be written as %2F
. 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 typesCloud 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 loggingAdmin 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 rolesIAM 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 in roles/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.
Note: Access Control Lists (ACLs) cannot be used to grant users access to view Admin Activity or Data Access audit logs. Viewing logsYou 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. For more information about querying your logs, see Build queries in the Logs Explorer
The Logs Explorer lets you view filter individual log entries. If you want to use SQL to analyze groups of log entries, then use the Log Analytics page. For more information, see:
Most audit logs can be viewed in Cloud Logging by using the Google Cloud console, the Google Cloud CLI, or the Logging API. However, for audit logs related to billing, you can only use the Google Cloud CLI or the Logging API.
ConsoleIn the Google Cloud console, you can use the Logs Explorer to retrieve your audit log entries for your Google Cloud project, folder, or organization:
Note: You can't view audit logs for Cloud Billing accounts in the Google Cloud console. You must use the API or the gcloud CLI.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:
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.
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
.
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.
You can attach custom information to requests for inclusion in audit logs 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
, with the inclusion of the x-goog-custom-audit-
prefix, can contain up to 64 characters, while each VALUE
can contain up to 1,200 characters.
Each request can contain up to 4 header or parameter entries combined.
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
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 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_userExample 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.
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:
For instructions about routing logs, see Configure and manage sinks .
PricingFor information about Cloud Logging pricing, see Google Cloud Observability pricing: Cloud Logging.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4