Review Cloud Storage usage logging

Collect logs for the audit purpose and manage their access and retention.

Description

Use Cloud Audit Logs for most Cloud Storage API auditing. A log bucket also receives usage logs for requests, including public-object reads, and storage logs for capacity. Delivery can be late or incomplete.

Potential impact

Missing request records can slow an investigation. Log files can expose request details and incur storage costs if kept longer than needed.

Remediation

When you need usage logs, set logging.log_bucket to a separate bucket in the same location and organization as the source. If there is no organization, use the same project. Grant cloud-storage-analytics@google.com the roles/storage.objectCreator role on the destination. Limit log access and retention, then check that files arrive.

Examples

Supply your bucket name, project ID, and path to a service account JSON file.

Before

yaml
- name: 버킷 생성
  google.cloud.gcp_storage_bucket:
    name: ansible-storage-module
    project: test_project
    auth_kind: serviceaccount
    service_account_file: /tmp/auth.pem
    state: present

After

yaml
- name: 버킷 생성
  google.cloud.gcp_storage_bucket:
    name: ansible-storage-module
    project: test_project
    auth_kind: serviceaccount
    service_account_file: /tmp/auth.pem
    state: present
    logging:
      log_bucket: a_bucket_for_logs
      log_object_prefix: log

The second task sets the destination to a_bucket_for_logs and the object prefix to log.

References