Configure CMEK for log buckets

This document provides instructions for configuring customer-managed encryption keys (CMEK) for logs stored in log buckets. This document also describes how to manage those keys, and limitations associated with using CMEK.

You can configure CMEK as a default resource setting for an organization or a folder. When configured, Cloud Logging ensures that all new log buckets in the organization or folder are encrypted with a customer-managed key. If you don't supply a key when you create the log bucket, then the default key is used. For more information, see Configure CMEK for Cloud Logging.

Overview

By default, Cloud Logging encrypts customer content stored at rest. Data stored in log buckets by Logging is encrypted using key-encryption keys, a process known as envelope encryption. Access to your logging data requires access to those key-encryption keys. By default, these are Google-owned and Google-managed encryption keys and they don't require any actions on your part.

Your organization might have regulatory, compliance-related, or advanced encryption requirements that our default encryption at rest doesn't provide. To meet your organization's requirements, instead of using Google-owned and Google-managed encryption keys, you can manage your own keys.

For specific information about CMEK usage, including advantages, and limitations, see Customer-managed encryption keys.

For symmetric encryption, periodically and automatically rotating keys is a recommended security practice. For more information, see Key rotation.

Prerequisites

Complete the following steps:

  1. There are some limitations when using CMEK. Before you create a log bucket with CMEK enabled, review the Limitations.

  2. In the Google Cloud console, activate Cloud Shell.

    Activate Cloud Shell

    At the bottom of the Google Cloud console, a Cloud Shell session starts and displays a command-line prompt. Cloud Shell is a shell environment with the Google Cloud CLI already installed and with values already set for your current project. It can take a few seconds for the session to initialize.

  3. Configure the Google Cloud project where you plan to create your keys:

    1. To get the permissions that you need to create keys, ask your administrator to grant you the Cloud KMS Admin (roles/cloudkms.admin) IAM role on the project or a parent resource. For more information about granting roles, see Manage access to projects, folders, and organizations.

      You might also be able to get the required permissions through custom roles or other predefined roles.

    2. Enable the Cloud KMS API.

    3. Create a key ring and keys.

      Cloud Logging lets you use a key from any region. However, when you create a log bucket, the location of the log bucket must match the location of the key. For information about supported regions, see the following:

      You can't enable CMEK for log buckets created in the global region.

  4. Ensure that you have the following Cloud Logging permissions on the Google Cloud project where you plan to create log buckets:

    • logging.settings.get
    • logging.buckets.get
    • logging.buckets.list
    • logging.buckets.create
    • logging.buckets.update

Enable CMEK

After you've completed the prerequisite steps, follow these instructions to enable CMEK for an individual log bucket.

Determine the service account ID

To determine the service account ID associated with the Google Cloud resource for which CMEK will apply, do the following:

  1. Run the following gcloud logging settings describe command:

    gcloud logging settings describe --project=BUCKET_PROJECT_ID
    

    Before running the previous command, make the following replacement:

    • BUCKET_PROJECT_ID: Name of the Google Cloud project where you plan to create the log bucket.

    The previous command generates a service account for the specified resource, when one doesn't exist already, and it returns the ID of that service account in the kmsServiceAccountId field:

    kmsServiceAccountId: KMS_SERVICE_ACCT_NAME@gcp-sa-logging.iam.gserviceaccount.com
    loggingServiceAccountId: SERVICE_ACCT_NAME@gcp-sa-logging.iam.gserviceaccount.com
    name: projects/BUCKET_PROJECT_ID/settings
    

    The kmsServiceAccountId field lists the service account that is used by Cloud Logging to call Cloud Key Management Service.

  2. If the KMS_SERVICE_ACCT_NAME field has the format of cmek-pPROJECT_NUMBER, and if you are using VPC Service Controls or if you enable domain restricted sharing, then determine whether you need to migrate your CMEK service account. For information about when you need to migrate and the steps to perform the migration, see Troubleshoot VPC Service Controls and domain restricted sharing.

Assign the Encrypter/Decrypter role

When you're configuring CMEK at the log bucket level, give the service account permission to use your Cloud KMS by assigning the Cloud KMS CryptoKey Encrypter/Decrypter role to the service account identified by the kmsServiceAccountId field:

gcloud kms keys add-iam-policy-binding \
--project=KMS_PROJECT_ID \
--member serviceAccount:KMS_SERVICE_ACCT_NAME@gcp-sa-logging.iam.gserviceaccount.com \
--role roles/cloudkms.cryptoKeyEncrypterDecrypter \
--location=KMS_KEY_LOCATION \
--keyring=KMS_KEY_RING \
KMS_KEY_NAME

Before running the previous command, make the following replacements:

  • KMS_PROJECT_ID: The unique alphanumeric identifier, composed of your Google Cloud project name and a randomly assigned number, of the Google Cloud project running Cloud KMS. For information about getting this identifier, see Identifying projects.
  • KMS_SERVICE_ACCT_NAME: The name of the service account shown in the kmsServiceAccountId field of the response of the gcloud logging settings describe command.
  • KMS_KEY_LOCATION: The Cloud KMS key's region.
  • KMS_KEY_RING: The Cloud KMS key ring's name.
  • KMS_KEY_NAME: The Cloud KMS key's name. It is formatted like this: projects/KMS_PROJECT_ID/locations/LOCATION/keyRings/KMS_KEY_RING/cryptoKeys/KEY.

Create a log bucket and supply the Cloud KMS key

To create a log bucket and enable CMEK for the log bucket, run the following gcloud logging buckets create command:

gcloud logging buckets create BUCKET_ID \
--location=LOCATION \
--cmek-kms-key-name=KMS_KEY_NAME \
--project=BUCKET_PROJECT_ID

Before running the previous command, make the following replacements:

  • BUCKET_ID: The name or ID of the log bucket.
  • LOCATION: The location of the log bucket.
  • KMS_KEY_NAME: The Cloud KMS key's name. It is formatted like this: projects/KMS_PROJECT_ID/locations/LOCATION/keyRings/KMS_KEY_RING/cryptoKeys/KEY.
  • BUCKET_PROJECT_ID: Name of the Google Cloud project where the log bucket will be created.

Verify key enablement

To verify that you've successfully created a log bucket with CMEK enabled, run the following gcloud logging buckets list command:

gcloud logging buckets list --project=BUCKET_PROJECT_ID

Before running the previous command, make the following replacement:

  • BUCKET_PROJECT_ID: Name of the Google Cloud project that stores the log bucket.

In the tabular output, you see a column labeled CMEK. If the value of the CMEK column is TRUE, then CMEK is enabled for the log bucket.

To view the details for a specific log bucket, including the key's details, run this command:

gcloud logging buckets describe BUCKET_ID --location=LOCATION --project=BUCKET_PROJECT_ID

Manage your Cloud KMS key

The following sections describe how to update a log bucket to use the latest primary key version of a Cloud KMS key. They also describe how to change, revoke access for, and disable your Cloud KMS key.

Rotate your Cloud KMS key

When you create a Cloud KMS key, you can configure a rotation period. You can also rotate a Cloud KMS key manually. Each time a key is rotated, a new version for that key is created.

If you rotate a Cloud KMS key, then the new key version applies only to log buckets created after the key rotation. If the key is used by an existing log bucket, rotating the key doesn't change how the log bucket protects its data.

For example, suppose that you create a log bucket and enable CMEK, and then you rotate the Cloud KMS key. The log bucket that you created doesn't use the new key version, instead it continues to protect its data with the key version that was marked as primary when the log bucket was created.

To update a log bucket to use the most recent primary key version of a Cloud KMS key, do the following:

  1. Identify the current Cloud KMS key for the log bucket. For more information, see Verify key enablement.
  2. Identify another Cloud KMS key that you can use. If your key ring has only one key, then Create a key.
  3. Change the Cloud KMS key for the log bucket to the Cloud KMS key created in the previous step.
  4. Change the Cloud KMS key for the log bucket to the original Cloud KMS key.

Change your Cloud KMS key

To change the Cloud KMS key associated with your log bucket, create a key and update the CMEK settings for log bucket:

gcloud logging buckets update BUCKET_ID --location=LOCATION \
--cmek-kms-key-name=NEW_KMS_KEY_NAME --project=BUCKET_PROJECT_ID
  • BUCKET_ID: The name or ID of the log bucket.
  • LOCATION: The location of the log bucket.
  • NEW_KMS_KEY_NAME: Name of the new key.
  • BUCKET_PROJECT_ID: Name of the Google Cloud project that stores the log bucket.

Revoke access to the Cloud KMS key

To revoke Logging's access to the Cloud KMS key at any time, remove the configured service account's IAM permission for that key.

If you remove Logging's access to a key, it can take up to one hour for the change to take effect.

If you have a linked BigQuery dataset, BigQuery can't use this access to apply to key to a new BigQuery table. If you want to use a key on BigQuery table that aren't linked to Logging, follow BigQuery's documentation to do so. If you revoke Logging's access to a key and if you have a linked BigQuery dataset, then you also revoke BigQuery's access to the same key.

You can't revoke BigQuery's access to the linked dataset's key while preserving Logging's access.

For more information about the impact of revoking access, see Limitations.

To remove Logging's access to a key, run the following command:

gcloud kms keys remove-iam-policy-binding \
--project=KMS_PROJECT_ID \
--member serviceAccount:KMS_SERVICE_ACCT_NAME@gcp-sa-logging.iam.gserviceaccount.com \
--role roles/cloudkms.cryptoKeyEncrypterDecrypter \
--location=KMS_KEY_LOCATION \
--keyring=KMS_KEY_RING \
KMS_KEY_NAME

Before running the previous command, make the following replacements:

  • KMS_PROJECT_ID: The unique alphanumeric identifier, composed of your Google Cloud project name and a randomly assigned number, of the Google Cloud project running Cloud KMS. For information about getting this identifier, see Identifying projects.
  • KMS_SERVICE_ACCT_NAME: The name of the service account shown in the kmsServiceAccountId field of the response of the gcloud logging settings describe command.
  • KMS_KEY_LOCATION: The Cloud KMS key's region.
  • KMS_KEY_RING: The Cloud KMS key ring's name.
  • KMS_KEY_NAME: The Cloud KMS key's name. It is formatted like this: projects/KMS_PROJECT_ID/locations/LOCATION/keyRings/KMS_KEY_RING/cryptoKeys/KEY.

Limitations

The following are known limitations.

CMEK disables Error Reporting

If you want to use Error Reporting, then don't enable customer-managed encryption keys (CMEK) on your log buckets. For more information, see Troubleshooting.

CMEK can't be removed from log buckets

You can't reconfigure log buckets to change or remove CMEK.

Degradation due to Cloud KMS key unavailability

A Cloud KMS key is considered available and accessible by Logging if both of the following are true:

  • The key is enabled.
  • The Logging service account has encryption and decryption permissions on the key.

Logging strongly recommends ensuring that any keys are properly configured and always available.

Loss of disaster recovery

If there are critical failures in Cloud Logging primary storage, then Logging mirrors the logging data to disaster-recovery files. When CMEK is enabled for a resource, such as a Google Cloud organization, logs belonging to that resource are protected by the configured CMEK key. If the CMEK key isn't accessible, the disaster-recovery files can't be written for that resource.

Loss of disaster-recovery files doesn't affect normal logging operations. However, in the event of a storage disaster, Cloud Logging might be unable to recover logs from resources whose CMEK isn't properly configured.

Support constraints

Cloud Customer Care can't read your resource's logs if its key isn't properly configured or becomes unavailable.

Degraded query performance

When a customer-managed encryption key is inaccessible, Cloud Logging continues to encrypt your data and store data in log buckets. However, Cloud Logging can't perform background optimizations on this data. If key access is restored, the data becomes available; however, the data is initially be stored in an unoptimized state and query performance may suffer.

Degradation due to Cloud EKM key unavailability

When you use a Cloud EKM key, Google Cloud has no control over the availability of your externally managed key in the external key-management partner system. For bucket-level CMEK, if an externally managed key is unavailable, Cloud Logging continues to store logs in log buckets but users aren't able to access those logs.

For more considerations, and potential alternatives, when using external keys, see the Cloud External Key Manager documentation.

Regionality

When you create a log bucket and enable CMEK, you must use a key whose region matches the regional scope of your data. You can't configure CMEK for log buckets created in the global region.

Client library availability

Logging client libraries don't provide methods for configuring CMEK.

Quotas

For details on Logging usage limits, see Quotas and limits.

Troubleshoot configuration errors

For information about troubleshooting CMEK configuration errors, see Troubleshoot CMEK and organization setting errors.