To enforce organization-wide encryption requirements on AlloyDB for PostgreSQL
clusters and backups, you can apply predefined organization policy constraints
at the project, folder, or organization level.

## Customer-managed encryption keys (CMEK) organization policy

You can use the CMEK organization policy to control the CMEK settings of your
AlloyDB clusters and backups. This policy lets you control the
[Cloud Key Management Service (Cloud KMS) keys](https://docs.cloud.google.com/kms/docs/resource-hierarchy.md.txt#keys) that
you use to protect your data.

AlloyDB supports two organization policy constraints that help
enforce CMEK protection across an organization:

- `constraints/gcp.restrictNonCmekServices`: requires CMEK protection for the
  `alloydb.googleapis.com` service. When you add this constraint and add
  `alloydb.googleapis.com` to the `Deny` policy list of services,
  AlloyDB refuses to create a new cluster or a backup unless they
  are enabled with CMEK.

- `constraints/gcp.restrictCmekCryptoKeyProjects`: limits which
  Cloud KMS CryptoKeys you can use for CMEK protection in
  AlloyDB clusters and backups. With this constraint, when
  AlloyDB creates a new cluster or a backup with CMEK, the
  CryptoKey must come from an allowed project, folder, or organization.

These constraints are only enforced on newly created AlloyDB
clusters and backups.

For more overview information, see
[CMEK organization policies](https://docs.cloud.google.com/kms/docs/cmek-org-policy.md.txt).
For information about CMEK organization policy constraints, see
[Organization policy constraints](https://docs.cloud.google.com/resource-manager/docs/organization-policy/org-policy-constraints).

## Before you begin

1. Add the **Organization Policy Administrator** role ([`roles/orgpolicy.policyAdmin`](https://docs.cloud.google.com/iam/docs/roles-permissions/orgpolicy.md.txt)) to your user or service account from the **IAM \& Admin** page.


   [Go to the IAM accounts page](https://console.cloud.google.com/iam-admin/iam)

<br />

## Add the CMEK organization policy

To add a CMEK organization policy, follow these steps:

1. Go to the **Organization policies** page.

   [Go to the Organization policies page](https://console.cloud.google.com/iam-admin/orgpolicies)
2. Click the drop-down in the Google Cloud console menu bar, and then select the project, folder,
   or organization that requires the organization policy. The
   **Organization policies** page displays a list of available organization policy
   constraints.

3. To set `constraints/gcp.restrictNonCmekServices`, follow these steps:

   1. Filter for the constraint using the `ID`: `constraints/gcp.restrictNonCmekServices` or the `Name`: `Restrict which services may create resources without CMEK`.
   2. Click the constraint **Name**.
   3. Click **Edit**.
   4. Click **Customize**.
   5. Click **Add rule**.
   6. Under **Policy values** , click **Custom**.
   7. Under **Policy types** , select **Deny**.
   8. Under **Custom values** , enter `alloydb.googleapis.com`. This configuration enforces CMEK while creating AlloyDB clusters and backups.
4. To set `constraints/gcp.restrictCmekCryptoKeyProjects`, follow these steps:

   1. Filter for the constraint `ID`: `constraints/gcp.restrictCmekCryptoKeyProjects` or `Name`: `Restrict which projects may supply KMS CryptoKeys for CMEK`.
   2. Click the constraint **Name**.
   3. Click **Edit**.
   4. Click **Customize**.
   5. Click **Add rule**.
   6. Under **Policy values** , click **Custom**.
   7. Under **Policy types** , select **Allow**.
   8. Under **Custom values** , enter the resource using the following format:
      `under:organizations/ORGANIZATION_ID`,
      `under:folders/FOLDER_ID`, or
      `projects/PROJECT_ID`.

      This configuration restricts your AlloyDB clusters and
      backups to using Cloud KMS keys only from the allowed project,
      folder, or organization.
5. Click **Done** and then click **Save**.

## What's next

- Learn more about [customer-managed encryption keys (CMEK) for AlloyDB for PostgreSQL](https://docs.cloud.google.com/alloydb/docs/cmek.md.txt).
- See [Introduction to the Organization Policy Service](https://docs.cloud.google.com/resource-manager/docs/organization-policy/overview) to learn more about organization policies.
- Learn more about how to [create and manage organization policies](https://docs.cloud.google.com/resource-manager/docs/organization-policy/using-constraints).
- See the full list of predefined [Organization policy constraints](https://docs.cloud.google.com/resource-manager/docs/organization-policy/org-policy-constraints).
- [Connect using a public IP](https://docs.cloud.google.com/alloydb/docs/connect-public-ip.md.txt).
- [Create a primary instance](https://docs.cloud.google.com/alloydb/docs/instance-primary-create.md.txt).