Enabling customer-managed encryption keys

This page describes how to encrypt content stored in repositories with customer-managed encryption keys (CMEK).

Overview

By default, Google Cloud automatically encrypts data when it is at rest using encryption keys managed by Google. If you have specific compliance or regulatory requirements related to the keys that protect your data, you can create repositories encrypted with CMEK keys. Metadata about a repository, such as the repository name, is encrypted with Google default encryption.

When you enable CMEK, data at rest in repositories is encrypted using a key that you manage within Cloud Key Management Service. You can control access to the CMEK key using Identity and Access Management. If you temporarily disable or permanently destroy the CMEK key, data encrypted with that key cannot be accessed.

CMEK gives you control over more aspects of the lifecycle and management of your keys, but also incurs additional costs for the Cloud KMS service. CMEK-encrypted repositories also consume Cloud Key Management Service cryptographic request quota for each upload or download.

Cloud KMS can run in the same Google Cloud project as Artifact Registry or in a separate project where you centrally manage keys for multiple projects.

You assign a Cloud KMS key when you create a repository.

You cannot change the encryption mechanism of an existing repository. If you have a CMEK-encrypted repository, you cannot change the encryption mechanism to Google default encryption or assign a different Cloud KMS key for encryption.

For more information about CMEK in general, including when and why to enable it, see the Cloud KMS documentation.

Creating a key and granting permissions

To create a key for the repository and grant permissions to encrypt and decrypt repository data with the key:

  1. In the Google Cloud project where you want to manage your keys:

    1. Enable the Cloud KMS API.
    2. Create a key ring and a key. The key location must match the repository location of the repository you will encrypt.
  2. If you have not created a repository in the Artifact Registry project, the Artifact Registry service account does not yet exist. To create the service account, run the following command:

    gcloud beta services identity create --service=artifactregistry.googleapis.com --project=PROJECT
    

    Replace PROJECT with the ID of the project where Artifact Registry is running.

  3. Grant the CryptoKey Encrypter/Decrypter IAM role (roles/cloudkms.cryptoKeyEncrypterDecrypter) to the Artifact Registry service account. Grant this permission on the key you created.

    Console

    1. Go to the Cryptographic keys page.

      Open the Cloud KMS page

    2. Select the key you created.

    3. Select SHOW INFO PANEL.

    4. Click ADD MEMBER.

    5. Add the Artifact Registry service account. The service account is service-PROJECT-NUMBER@gcp-sa-artifactregistry.iam.gserviceaccount.com, where PROJECT-NUMBER is the project number of the Google Cloud project where Artifact Registry is running.

    6. In Select a role, select Cloud KMS > Cloud KMS CryptoKey Encrypter/Decrypter.

    7. Click SAVE.

    8. Return to the Cryptographic keys page and select the key again.

    9. Select the SHOW INFO PANEL. You should see roles on the Role/Member column.

    gcloud

    Run the following command:

    gcloud kms keys add-iam-policy-binding [--project=PROJECT] \
           KEY --location LOCATION --keyring=KEYRING \
           --member serviceAccount:service-PROJECT-NUMBER@gcp-sa-artifactregistry.iam.gserviceaccount.com \
           --role roles/cloudkms.cryptoKeyEncrypterDecrypter
    
    • PROJECT is the ID of the project that contains the key.
    • KEY is the key name.
    • LOCATION is the key location. The key location must matche the repository location of the repository you will encrypt.
    • KEYRING is the key ring name.
    • PROJECT-NUMBER is the project number of the Google Cloud project that is running Artifact Registry.

    For more information about this command see the gcloud kms keys add-iam-policy-binding documentation.

You can now create a repository and specify the key to use for encryption.

Removing access

There are several ways to remove access to a CMEK-encrypted repository:

We recommend that you revoke the permissions from the Artifact Registry service account before disabling or destroying a key. Changes to permissions are consistent within seconds, so you can observe the impacts of disabling or destroying a key.

When you disable or destroy the encryption key for a repository, you lose the ability to view or retrieve artifact data. All artifact data stored in the repository becomes inaccessible, including built artifacts, arbitrary binary data (blobs), and manifests such as a Docker manifest or an npm packument file. Users with the Artifact Registry Reader role or Viewer role can still view artifact metadata such as the artifact name, version, or tag.

Users with the Artifact Registry Administrator role or Owner role can delete the repository.

What's next?