Cloud Audit Logs with Cloud Storage

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.

Your Google Cloud projects contain only the audit logs for resources that are directly within the 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 ADMIN_WRITE operations that modify the configuration or metadata of a Cloud project, bucket, or object. You can't disable Admin Activity audit logs.

  • Data Access audit logs: Entries for operations that modify objects or read a Cloud project, bucket, or object. There are several sub-types of Data Access audit logs:

    • ADMIN_READ: Entries for operations that read the configuration or metadata of a Cloud project, bucket, or object.

    • DATA_READ: Entries for operations that read an object.

    • DATA_WRITE: Entries for operations that create or modify an object.

    To receive Data Access audit logs, you must explicitly enable them.

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
  • Creating buckets
  • Deleting buckets
  • Setting/changing IAM policies
  • Changing object ACLs3
  • Updating bucket metadata
Data Access ADMIN_READ
  • Getting bucket metadata
  • Getting IAM policies
  • Getting object ACLs
  • Listing buckets
DATA_READ
  • Getting object data
  • Getting object metadata
  • Listing objects
  • Copying objects1
  • Composing objects1
  • Listing ongoing XML API multipart uploads
  • Listing XML API multipart upload parts
DATA_WRITE
  • Creating objects
  • Deleting objects2
  • Updating non-ACL object metadata2
  • Copying objects1
  • Composing objects1
  • Initiating XML API multipart uploads
  • Creating parts in an XML API multipart upload
  • Aborting XML API multipart uploads2
  • Completing XML API multipart uploads

1 These operations involve both reading and writing data. As a result, these operations each generate two log entries.

2 Cloud Audit Logs does not log actions taken by the Object Lifecycle Management feature. For alternatives that track these actions, see Options for tracking Lifecycle actions.

3 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.

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 audit logging data, which is an AuditLog object held in the protoPayload 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.

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 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.

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 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.

Viewing logs

To query for audit logs, you need to know the audit log name, which includes the resource identifier of the Cloud project, folder, billing account, or organization for which you want to view audit logging information. In your query, you can further specify other indexed LogEntry fields, such as resource.type. For more information on querying, see Build queries in the Logs Explorer.

You can view audit logs in Cloud Logging by using the console, the Google Cloud CLI, or the Logging API.

Console

In the console, you can use the Logs Explorer to retrieve your audit log entries for your Cloud project, folder, or organization:

  1. In the console, go to the Logging> Logs Explorer page.

    Go to Logs Explorer

  2. Select an existing Cloud project, folder, or organization.

  3. 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.

    If you don't see these options, then there aren't any audit logs of that type available in the 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.

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 Cloud project.

To read your 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 Cloud project.

For example, to use the Logging API to view your project-level audit log entries, do the following:

  1. Go to the Try this API section in the documentation for the entries.list method.

  2. 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"
    }
    
  3. Click Execute.

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 Cloud projects in the organization.

  • If your enabled Data Access audit logs are pushing your 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's operations suite pricing: Cloud Logging.

Restrictions

The following restrictions apply to Cloud Audit Logs with Cloud Storage:

What's next