Skip to main content

Bring your own key (BYOK)

Register, list, update, or delete your customer managed keys (CMKs), associate CMKs with services, and view CMK usage across services in Aiven projects using the Aiven Provider for Terraform, Aiven API, or the Aiven CLI.

Availability​

Bring your own key (BYOK) is generally available for services running on Aiven-managed infrastructure and for services running in your own cloud account with bring your own cloud (BYOC). The way BYOK works, encryption scope, prerequisites, key setup, and key management operations for projects and services are the same for both deployments. The deployments differ in how you get access to BYOK and how BYOK is charged:

DeploymentAccess to BYOKPricing
Aiven-managed infrastructureAvailable for all projects. Register a CMK and associate it with your services at any time.Currently available at no additional cost
Custom cloud (BYOC)Enterprise feature. Enable BYOC for your organization, and then contact Aiven to request access to BYOK.Part of your BYOC agreement

How BYOK works​

Aiven encrypts all service data at rest. By default, Aiven creates and manages the encryption keys for you. With BYOK, you supply a customer managed key (CMK) from your own key management service (KMS) instead, and Aiven uses your CMK to encrypt the keys that protect your service data and backups.

Aiven never holds a copy of your CMK. It calls your KMS to wrap and unwrap the data encryption keys, so the key stays under your control: you decide which projects can use it, and you can revoke Aiven's access to it at any time.

  1. Set up the key in your KMS and grant Aiven access to it. See Set up customer managed keys.
  2. Register the key with Aiven and allocate it to the projects allowed to use it. See Register CMK resource identifier.
  3. Assign the key to services when you create them, or set it as the default key for the allocated projects. See Manage service CMK associations.
  4. Keep Aiven's access in place. Aiven checks access to each registered key periodically. If access is lost, see Troubleshooting.
warning

Losing access to your key can cause data loss. If Aiven can't use your key for about 15 to 20 minutes, for example because the key is disabled or scheduled for deletion, or a policy change or network restriction blocks access, Aiven powers off every service that uses it. This ensures Aiven has no way to access your data without your key.

Services don't power on automatically. After you restore access and power them on, they restore from the latest backup, and data written since that backup is lost. Aiven for Apache Kafka® topic data, including tiered storage, isn't backed up, so Kafka services lose all topic messages. If the key is destroyed, access can't be restored and backups can't be read.

To revoke access without data loss, move services to another key or to Aiven-managed keys first.

Encryption scope​

BYOK encrypts the following using your CMKs:

  • Backups: Your CMK encrypts the keys that encrypt the backups Aiven creates for your services. Aiven can read those backups only while it can use your CMK.
  • Service data at rest: CMKs protect all data stored by the service.
  • Data in transit between the service and backups: Encryption occurs on the service node before data leaves the cluster, so backup transfers use your CMK.

Prerequisites​

  • Key management service (KMS) that supports customer managed keys in one of the supported cloud providers:

    • Google Cloud KMS: asymmetric RSA 2048 or RSA 4096 keys
    • Oracle Cloud Infrastructure (OCI) Vault: AES keys
    • AWS KMS: symmetric encryption keys (ENCRYPT_DECRYPT)
    • Azure Key Vault: RSA keys (software-protected or HSM-backed)
  • Public internet access to your KMS or key vault: Aiven connects to your key management service over the public internet to perform wrap and unwrap operations, so the key management service must be reachable from the public internet. Key vaults that block public internet access aren't currently supported.

  • Authentication token to use the Aiven API

  • Aiven CLI installed and configured (for CLI instructions)

  • Aiven Provider for Terraform installed and configured (for Terraform instructions)

    • More information on the aiven_cmk resource and its configuration options are available in the Terraform documentation.

List CMK accessors​

List customer managed key (CMK) accessors - principals that need to be granted access to perform encrypt/decrypt operations on your behalf.

API endpoint​

GET /v1/project/PROJECT_ID/secrets/cmks/accessors

Reference: CMKAccessorsList API

Path parameters​

ParameterTypeRequiredDescription
PROJECT_IDStringTrueProject identifier

Sample request​

curl -X GET https://api.aiven.io/v1/project/PROJECT_ID/secrets/cmks/accessors \
-H "Authorization: Bearer AIVEN_API_TOKEN"

Sample response​

A successful request returns a 200 OK status code and a JSON object with the accessors for each provider, for example:

{
"accessors": {
"gcp": {
"access_group": "access.example.12345678-1234-1234-1234-123456789abc@aiven.io"
},
"oci": {
"access_group": "ocid1.group.oc1..abcdABCD....",
"access_tenant": "ocid1.tenancy.oc1..abcdABCD...."
},
"aws": {
"role_arn": "arn:aws:iam::123456789012:role/aiven-cmk-anchor"
},
"azure": {
"app_id": "12345678-1234-1234-1234-123456789abc"
}
}
}
note

Use the accessor values returned by this operation when granting Aiven access to your key:

  • Google Cloud KMS: Grant the access_group email address the roles/cloudkms.cryptoOperator role on your key.
  • OCI Vault: Use access_tenant and access_group OCIDs to create cross-tenancy IAM policies.
  • AWS KMS: Use the role_arn as the trusted principal in your KMS key policy (see AWS KMS setup).
  • Azure Key Vault: Use the app_id to create a service principal in your Azure AD tenant (see Azure Key Vault setup).

Set up customer managed keys on your cloud provider​

Before registering a CMK with Aiven, set up the key and grant Aiven access on your cloud provider.

Google Cloud KMS setup​

Create a key ring​

gcloud kms keyrings create <keyring-name> \
--location <region> \
--project <your-project>

Create a CryptoKey​

gcloud kms keys create <key-name> \
--location <region> \
--keyring <keyring-name> \
--purpose encryption \
--project <your-project>

For HSM-backed keys:

gcloud kms keys create <key-name> \
--location <region> \
--keyring <keyring-name> \
--purpose encryption \
--protection-level hsm \
--project <your-project>

Record the key resource name:

projects/<project>/locations/<location>/keyRings/<keyring>/cryptoKeys/<key-name>

Grant Aiven access to your key​

  1. Get Aiven's access group email using List CMK accessors.
  2. Grant the Cloud KMS CryptoKey Encrypter/Decrypter role to Aiven's group:
gcloud kms keys add-iam-policy-binding <key-name> \
--location <region> \
--keyring <keyring-name> \
--project <your-project> \
--member "group:<aiven-cmk-group>@aiven.io" \
--role "roles/cloudkms.cryptoKeyEncrypterDecrypter"
warning

To revoke Aiven's access, remove the IAM policy binding, or disable or schedule the destruction of the key. Revoking access powers off every service that uses the key, which can cause data loss. See How BYOK works.

Oracle Cloud Infrastructure (OCI) Vault setup​

OCI key validation can fail with a generic error when the key region is not available for BYOK. If key validation fails after you confirm the key OCID and IAM policy, contact Aiven support.

Create cross-tenancy IAM policies​

  1. Get Aiven's tenancy OCID and group OCID using List CMK accessors. Use OCI access_tenant for <aiven-tenancy-ocid> and OCI access_group for <aiven-cmk-group-ocid>.
  2. Create the policy in the root compartment of your tenancy.
  3. Create cross-tenancy IAM policies in your tenancy to grant Aiven access to the key:
oci iam policy create \
--compartment-id <customer-tenancy-ocid> \
--name aiven-cmk-access \
--statements '[
"define tenancy AT as <aiven-tenancy-ocid>",
"define group AG as <aiven-cmk-group-ocid>",
"admit group AG of tenancy AT to use keys in tenancy"
]'

All three statements are required. Do not remove the define group statement.

Optional: Restrict access to a specific key by adding a condition to the admit statement:

oci iam policy create \
--compartment-id <customer-tenancy-ocid> \
--name aiven-cmk-access \
--statements '[
"define tenancy AT as <aiven-tenancy-ocid>",
"define group AG as <aiven-cmk-group-ocid>",
"admit group AG of tenancy AT to use keys in tenancy where target.key.id = \"<key-ocid>\""
]'

Create a Vault​

oci kms management vault create \
--compartment-id <compartment-ocid> \
--display-name <vault-name> \
--vault-type DEFAULT

For HSM-backed vaults:

oci kms management vault create \
--compartment-id <compartment-ocid> \
--display-name <vault-name> \
--vault-type VIRTUAL_PRIVATE

Record the Vault's management endpoint and crypto endpoint.

Create a Master Encryption Key​

oci kms management key create \
--compartment-id <compartment-ocid> \
--display-name <key-name> \
--endpoint <vault-management-endpoint> \
--key-shape '{"algorithm": "AES", "length": 32}'

Record the key OCID:

ocid1.key.oc1.<region>.<hash>
warning

To revoke Aiven's access, remove the cross-tenancy IAM policies, or disable or schedule the deletion of the key. Revoking access powers off every service that uses the key, which can cause data loss. See How BYOK works.

AWS KMS setup​

Aiven authenticates to your AWS KMS key using cross-account IAM access. You grant access by adding Aiven's IAM role ARN as a trusted principal in your KMS key policy. No resources need to be created in Aiven's AWS account. Everything is controlled through your key policy.

Step 1: Create a KMS key​

Create a symmetric encryption key in the AWS region where your Aiven services will run:

aws kms create-key \
--description "Aiven CMK for data-at-rest encryption" \
--key-usage ENCRYPT_DECRYPT \
--origin AWS_KMS

Record the key ARN from the output:

arn:aws:kms:<region>:<account-id>:key/<key-id>
aws kms create-alias \
--alias-name alias/aiven-cmk \
--target-key-id <key-id>

Step 3: Grant Aiven access via the key policy​

Get Aiven's IAM role ARN using List CMK accessors (role_arn), then update your KMS key policy to allow Aiven to perform encrypt and decrypt operations.

The key policy must include the following statement:

{
"Sid": "Allow Aiven to use this key for CMK operations",
"Effect": "Allow",
"Principal": {
"AWS": "<aiven-role-arn>"
},
"Action": [
"kms:Encrypt",
"kms:Decrypt"
],
"Resource": "*"
}

The full key policy must also retain the root account statement so that your IAM policies can still manage the key:

{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "Enable IAM policies for key management",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::<your-account-id>:root"
},
"Action": "kms:*",
"Resource": "*"
},
{
"Sid": "Allow Aiven to use this key for CMK operations",
"Effect": "Allow",
"Principal": {
"AWS": "<aiven-role-arn>"
},
"Action": [
"kms:Encrypt",
"kms:Decrypt"
],
"Resource": "*"
}
]
}

Apply the key policy:

aws kms put-key-policy \
--key-id <key-id> \
--policy-name default \
--policy file://key-policy.json
note

All KMS operations performed by Aiven are logged in your AWS CloudTrail, giving you a full audit trail.

warning

To revoke Aiven's access, remove the Aiven principal from the key policy, or disable or delete the key. Revoking access powers off every service that uses the key, which can cause data loss. See How BYOK works.

Azure Key Vault setup​

Aiven authenticates to your Azure Key Vault using a multi-tenant application registered in Aiven's Azure AD tenant. You grant access by creating a service principal from Aiven's application in your tenant and assigning it the Key Vault Crypto User role on your key.

Step 1: Create a service principal for Aiven's application​

Get Aiven's app_id using List CMK accessors, then register Aiven's application as a service principal in your Azure AD tenant:

az ad sp create --id <aiven-application-id>

This allows Aiven to authenticate into your Azure AD tenant using its multi-tenant application.

Step 2: Create a Key Vault with Azure RBAC​

If this is the first Key Vault in your subscription, register the Microsoft.KeyVault resource provider first:

az provider register --namespace Microsoft.KeyVault --wait

The Key Vault must use Azure RBAC for its authorization model (not the legacy access policy model):

az keyvault create \
--name <vault-name> \
--resource-group <resource-group> \
--location <region> \
--enable-rbac-authorization true

To protect against accidental or malicious key deletion, enable purge protection by adding --enable-purge-protection true to the command.

If you are using an existing Key Vault, ensure RBAC authorization is enabled:

az keyvault update \
--name <vault-name> \
--enable-rbac-authorization true

For a newly created Key Vault, assign yourself the Key Vault Administrator role so you can create keys:

az role assignment create \
--role "Key Vault Administrator" \
--assignee $(az ad signed-in-user show --query id -o tsv) \
--scope $(az keyvault show \
--name <vault-name> --resource-group <resource-group> --query id -o tsv)

Step 3: Create an RSA key​

Create an RSA key with the wrapKey and unwrapKey operations enabled.

Software-protected key:

az keyvault key create \
--vault-name <vault-name> \
--name <key-name> \
--kty RSA \
--size 2048 \
--ops wrapKey unwrapKey

Dedicated HSM-backed key (for higher security requirements):

note

HSM-backed (Hardware Security Module) keys require an Azure Managed HSM, which must be provisioned separately before creating keys. Provisioning takes a few minutes and incurs an hourly cost. See the Azure Managed HSM quickstart for single-tenant (dedicated) HSM setup instructions.

az keyvault key create \
--hsm-name <hsm-name> \
--name <key-name> \
--kty RSA-HSM \
--size 2048 \
--ops wrapKey unwrapKey

Supported key sizes are 2048, 3072, and 4096.

Record the key URL, which becomes the resource identifier you register with Aiven:

  • Software-protected key: https://<vault-name>.vault.azure.net/keys/<key-name>
  • HSM-backed key: https://<hsm-name>.vault.azure.net/keys/<key-name>

If you include a specific version in the URL, Aiven uses that version exclusively. Omitting the version means Aiven always uses the latest active version.

Step 4: Grant Aiven access to the key​

Find the object ID of the Aiven service principal in your tenant:

az ad sp show --id <aiven-application-id> --query id -o tsv

Software-protected key: assign the Key Vault Crypto User built-in role to the Aiven service principal. This role grants only key wrapping permissions, so Aiven cannot manage, rotate, or delete your key.

Scope to the specific key (recommended):

az role assignment create \
--assignee <aiven-service-principal-object-id> \
--role "Key Vault Crypto User" \
--scope "/subscriptions/<subscription-id>/resourceGroups/<resource-group>/providers/Microsoft.KeyVault/vaults/<vault-name>/keys/<key-name>"

Or scope to the entire vault:

az role assignment create \
--assignee <aiven-service-principal-object-id> \
--role "Key Vault Crypto User" \
--scope "/subscriptions/<subscription-id>/resourceGroups/<resource-group>/providers/Microsoft.KeyVault/vaults/<vault-name>"

HSM-backed key: use the Managed HSM CLI command and assign the Managed HSM Crypto User role instead:

Scope to the specific key (recommended):

az keyvault role assignment create \
--hsm-name <hsm-name> \
--role "Managed HSM Crypto User" \
--assignee-object-id <aiven-service-principal-object-id> \
--scope /keys/<key-name>

Or scope to all keys in the HSM:

az keyvault role assignment create \
--hsm-name <hsm-name> \
--role "Managed HSM Crypto User" \
--assignee-object-id <aiven-service-principal-object-id> \
--scope /keys
warning

To revoke Aiven's access, remove the role assignment or delete the service principal from your tenant. This immediately stops all cryptographic operations by Aiven. Revoking access powers off every service that uses the key, which can cause data loss. See How BYOK works.

Manage a project CMK​

Use the Aiven Provider for Terraform, Aiven API, or Aiven CLI to manage customer managed keys (CMKs) for encrypting service data.

For per-service CMK assignment and rotation, see Manage service CMK associations.

Register CMK resource identifier​

Register a customer managed key resource identifier for an Aiven project.

API endpoint​

POST /v1/project/PROJECT_ID/secrets/cmks

Path parameters​

ParameterTypeRequiredDescription
PROJECT_IDStringTrueProject identifier

Request body parameters​

ParameterTypeRequiredDescription
providerStringTrueCloud provider hosting the KMS: gcp, oci, aws, or azure
resourceStringTrueCMK reference (key identifier of max 512 characters). Format depends on provider: GCP resource name, OCI OCID, AWS KMS key ARN, or Azure Key Vault key URL
default_cmkBooleanFalseMark this key as default for new service creation

Sample request (Google Cloud)​

curl -X POST https://api.aiven.io/v1/project/PROJECT_ID/secrets/cmks \
-H "Content-Type: application/json" \
-H "Authorization: Bearer AIVEN_API_TOKEN" \
-d '{
"provider": "gcp",
"resource": "projects/aiven-example/locations/us-central1/keyRings/example-keyring/cryptoKeys/example-key",
"default_cmk": true
}'

Sample response (Google Cloud)​

A successful request returns a 201 CREATED status code and a JSON object representing the newly registered CMK configuration, for example:

{
"cmk": {
"id": "12345678-1234-1234-1234-12345678abcd",
"provider": "gcp",
"default_cmk": true,
"resource": "projects/aiven-example/locations/us-central1/keyRings/example-keyring/cryptoKeys/example-key",
"status": "current",
"created_at": "YYYY-MM-DDTHH:MM:SSZ",
"updated_at": "YYYY-MM-DDTHH:MM:SSZ"
}
}

Sample request (AWS)​

curl -X POST https://api.aiven.io/v1/project/PROJECT_ID/secrets/cmks \
-H "Content-Type: application/json" \
-H "Authorization: Bearer AIVEN_API_TOKEN" \
-d '{
"provider": "aws",
"resource": "arn:aws:kms:us-east-1:123456789012:key/mrk-1234abcd12ab34cd56ef1234567890ab",
"default_cmk": true
}'

Sample response (AWS)​

{
"cmk": {
"id": "12345678-1234-1234-1234-12345678abcd",
"provider": "aws",
"default_cmk": true,
"resource": "arn:aws:kms:us-east-1:123456789012:key/mrk-1234abcd12ab34cd56ef1234567890ab",
"status": "current",
"created_at": "YYYY-MM-DDTHH:MM:SSZ",
"updated_at": "YYYY-MM-DDTHH:MM:SSZ"
}
}

Sample request (Azure)​

curl -X POST https://api.aiven.io/v1/project/PROJECT_ID/secrets/cmks \
-H "Content-Type: application/json" \
-H "Authorization: Bearer AIVEN_API_TOKEN" \
-d '{
"provider": "azure",
"resource": "https://my-vault.vault.azure.net/keys/my-cmk-key",
"default_cmk": true
}'

Sample response (Azure)​

{
"cmk": {
"id": "12345678-1234-1234-1234-12345678abcd",
"provider": "azure",
"default_cmk": true,
"resource": "https://my-vault.vault.azure.net/keys/my-cmk-key",
"status": "current",
"created_at": "YYYY-MM-DDTHH:MM:SSZ",
"updated_at": "YYYY-MM-DDTHH:MM:SSZ"
}
}

Response fields​

ParameterDescription
idIdentifier of the specific key
providerProvider type: gcp, oci, aws, or azure
resourceCMK reference
statusOne of current, old, or deleted
default_cmkWhether this CMK has been marked default for new services
created_atCMK creation timestamp
updated_atCMK update timestamp

Update CMK​

Update attributes or parameters on an existing customer managed key configuration.

API endpoint​

POST /v1/project/PROJECT_ID/secrets/cmks/CMK_ID

Path parameters​

ParameterTypeRequiredDescription
PROJECT_IDStringTrueProject identifier
CMK_IDStringTrueCMK identifier

Request body parameters​

ParameterTypeRequiredDescription
default_cmkBooleanFalseMark a specific key as default for new service creation

Sample request​

curl -X POST https://api.aiven.io/v1/project/PROJECT_ID/secrets/cmks/CMK_ID \
-H "Content-Type: application/json" \
-H "Authorization: Bearer AIVEN_API_TOKEN" \
-d '{
"default_cmk": false
}'

Sample response​

A successful request returns a 200 OK status code and a JSON object representing the updated CMK configuration, for example:

{
"cmk": {
"id": "12345678-1234-1234-1234-12345678abcd",
"provider": "gcp",
"default_cmk": false,
"resource": "projects/aiven-example/locations/us-central1/keyRings/example-keyring/cryptoKeys/example-key",
"status": "current",
"created_at": "YYYY-MM-DDTHH:MM:SSZ",
"updated_at": "YYYY-MM-DDTHH:MM:SSZ"
}
}

Response fields​

ParameterDescription
idIdentifier of the specific key
providerProvider type: gcp, oci, aws, or azure
resourceCMK reference
statusOne of current, old, or deleted
default_cmkWhether this CMK has been marked default for new services
created_atCMK creation timestamp
updated_atCMK update timestamp

Get CMK details​

Get the details of a customer managed key configuration.

API endpoint​

GET /v1/project/PROJECT_ID/secrets/cmks/CMK_ID

Path parameters​

ParameterTypeRequiredDescription
PROJECT_IDStringTrueProject identifier
CMK_IDStringTrueCMK identifier

Sample request​

curl -X GET https://api.aiven.io/v1/project/PROJECT_ID/secrets/cmks/CMK_ID \
-H "Authorization: Bearer AIVEN_API_TOKEN"

Sample response (OCI)​

A successful request returns a 200 OK status code and a JSON object representing the specified CMK configuration, for example:

{
"cmk": {
"id": "a1b2c3d4-e5f6-4789-a0b1-c2d3e4f5a6b7",
"provider": "oci",
"default_cmk": false,
"resource": "ocid1.key.oc1.iad.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"status": "current",
"created_at": "YYYY-MM-DDTHH:MM:SSZ",
"updated_at": "YYYY-MM-DDTHH:MM:SSZ"
}
}

Sample response (AWS)​

{
"cmk": {
"id": "a1b2c3d4-e5f6-4789-a0b1-c2d3e4f5a6b7",
"provider": "aws",
"default_cmk": false,
"resource": "arn:aws:kms:us-east-1:123456789012:key/mrk-1234abcd12ab34cd56ef1234567890ab",
"status": "current",
"created_at": "YYYY-MM-DDTHH:MM:SSZ",
"updated_at": "YYYY-MM-DDTHH:MM:SSZ"
}
}

Sample response (Azure)​

{
"cmk": {
"id": "a1b2c3d4-e5f6-4789-a0b1-c2d3e4f5a6b7",
"provider": "azure",
"default_cmk": false,
"resource": "https://my-vault.vault.azure.net/keys/my-cmk-key",
"status": "current",
"created_at": "YYYY-MM-DDTHH:MM:SSZ",
"updated_at": "YYYY-MM-DDTHH:MM:SSZ"
}
}

Key statuses​

A CMK has a status of its own, separate from the association status of each service that uses it. The key status appears in the API, CLI, and Terraform responses.

StatusDescription
currentThe key is registered and available for new and existing service associations.
oldThe key is superseded and is no longer offered for new associations.
deletedThe key configuration is deleted from the Aiven project.

List CMKs​

List all customer managed key configurations for a project.

API endpoint​

GET /v1/project/PROJECT_ID/secrets/cmks

Path parameters​

ParameterTypeRequiredDescription
PROJECT_IDStringTrueProject identifier

Sample request​

curl -X GET https://api.aiven.io/v1/project/PROJECT_ID/secrets/cmks \
-H "Authorization: Bearer AIVEN_API_TOKEN"

Sample response (OCI)​

A successful request returns a 200 OK status code and a JSON object containing a list of all CMK configurations for a project, for example:

{
"cmks": [
{
"id": "a1b2c3d4-e5f6-4789-a0b1-c2d3e4f5a6b7",
"provider": "oci",
"default_cmk": false,
"resource": "ocid1.key.oc1.iad.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"status": "current",
"created_at": "YYYY-MM-DDTHH:MM:SSZ",
"updated_at": "YYYY-MM-DDTHH:MM:SSZ"
},
{
"id": "8c9d0e1f-2a3b-4c5d-6e7f-8a9b0c1d2e3f",
"provider": "oci",
"default_cmk": false,
"resource": "ocid1.key.oc1.phx.yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy",
"status": "old",
"created_at": "YYYY-MM-DDTHH:MM:SSZ",
"updated_at": "YYYY-MM-DDTHH:MM:SSZ"
}
]
}

Remove CMK​

Delete a customer managed key configuration.

note

You can delete a CMK only when it has no service associations in active, activating, or deactivating status. Move each linked service to another CMK or remove the CMK association before deletion.

API endpoint​

DELETE /v1/project/PROJECT_ID/secrets/cmks/CMK_ID

Path parameters​

ParameterTypeRequiredDescription
PROJECT_IDStringTrueProject identifier
CMK_IDStringTrueCMK identifier

Sample request​

curl -X DELETE https://api.aiven.io/v1/project/PROJECT_ID/secrets/cmks/CMK_ID \
-H "Authorization: Bearer AIVEN_API_TOKEN"

Sample response (OCI)​

A successful request returns a 200 OK status code and a JSON object representing the deleted CMK configuration, for example:

{
"cmk": {
"id": "a1b2c3d4-e5f6-4789-a0b1-c2d3e4f5a6b7",
"provider": "oci",
"default_cmk": false,
"resource": "ocid1.key.oc1.iad.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"status": "current",
"created_at": "YYYY-MM-DDTHH:MM:SSZ",
"updated_at": "YYYY-MM-DDTHH:MM:SSZ"
}
}

If the CMK is still associated with one or more services, the request returns 409 Conflict.

{
"message": "CMK cannot be deleted because it is still associated with one or more services"
}

Manage service CMK associations​

Associate a specific customer managed key (CMK) with individual services during creation or update. This allows you to use different CMKs for different services, change CMKs for existing services, or remove CMK associations altogether.

Associate a CMK when creating a service​

Create a service with a specific CMK by providing the CMK ID in the service creation request.

Set cloud to control the cloud region for the new service.

API endpoint​

POST /v1/project/PROJECT_ID/service

Request body parameters​

ParameterTypeRequiredDescription
service_nameStringTrueName of the service
service_typeStringTrueType of service (for example, pg, mysql, redis)
planStringTrueService plan
cloudStringFalseCloud region for the service, for example google-europe-west3
cmk_idStringFalseCustomer managed key (CMK) identifier. If omitted, the
project's default CMK is used, or Aiven-managed keys if no default is set.

Sample request​

curl -X POST https://api.aiven.io/v1/project/PROJECT_ID/service \
-H "Content-Type: application/json" \
-H "Authorization: Bearer AIVEN_API_TOKEN" \
-d '{
"service_name": "my-pg-service",
"service_type": "pg",
"plan": "startup-4",
"cloud": "google-europe-west3",
"cmk_id": "12345678-1234-1234-1234-12345678abcd"
}'

Sample response​

A successful request returns a 201 CREATED status code and a JSON object representing the newly created service with the CMK association:

{
"service": {
"service_name": "my-pg-service",
"service_type": "pg",
"plan": "startup-4",
"cloud_name": "google-europe-west3",
"state": "REBUILDING",
"cmk_id": "12345678-1234-1234-1234-12345678abcd"
}
}

Change or remove the CMK for an existing service​

Update a service to use a different CMK or remove its CMK association.

What happens when you change a service's CMK​

When you assign a different CMK to a service, or move the service back to Aiven-managed keys, Aiven re-encrypts the service's data encryption keys with the new key. The service data and the backups themselves are not re-encrypted or re-uploaded.

  1. The new association enters activating status and the previous one enters deactivating status.
  2. Aiven decrypts each data encryption key with the previous CMK and encrypts it again with the new CMK.
  3. The new association moves to active status, and the previous association is removed.

Existing backups stay usable after the change, because Aiven re-encrypts the keys that protect them instead of the backup contents. Keep the previous key available until the new association reaches active status. If you revoke access to the previous key while the change is still in progress, Aiven cannot complete it.

API endpoint​

PUT /v1/project/PROJECT_ID/service/SERVICE_NAME

Path parameters​

ParameterTypeRequiredDescription
PROJECT_IDStringTrueProject identifier
SERVICE_NAMEStringTrueService name

Request body parameters​

ParameterTypeRequiredDescription
cmk_idStringFalseCustomer managed key (CMK) identifier to use for this service. Pass an empty UUID (00000000-0000-0000-0000-000000000000) to remove the CMK association and use Aiven-managed keys instead.

Sample request (change CMK)​

curl -X PUT https://api.aiven.io/v1/project/PROJECT_ID/service/SERVICE_NAME \
-H "Content-Type: application/json" \
-H "Authorization: Bearer AIVEN_API_TOKEN" \
-d '{
"cmk_id": "87654321-4321-4321-4321-87654321dcba"
}'

Sample request (remove CMK association)​

curl -X PUT https://api.aiven.io/v1/project/PROJECT_ID/service/SERVICE_NAME \
-H "Content-Type: application/json" \
-H "Authorization: Bearer AIVEN_API_TOKEN" \
-d '{
"cmk_id": "00000000-0000-0000-0000-000000000000"
}'

Sample response​

A successful request returns a 200 OK status code and a JSON object representing the updated service:

{
"service": {
"service_name": "my-pg-service",
"service_type": "pg",
"cloud_name": "google-europe-west3",
"state": "REBALANCING",
"cmk_id": "87654321-4321-4321-4321-87654321dcba"
}
}

View CMK details in service information​

When you retrieve service information, the response now includes the cmk_id field showing which CMK is actively protecting that service's data. This allows you to verify encryption key usage and track which services are using which CMKs.

API endpoint​

GET /v1/project/PROJECT_ID/service/SERVICE_NAME

Sample request​

curl -X GET https://api.aiven.io/v1/project/PROJECT_ID/service/SERVICE_NAME \
-H "Authorization: Bearer AIVEN_API_TOKEN"

Sample response​

The service details now include the cmk_id field:

{
"service": {
"service_name": "my-pg-service",
"service_type": "pg",
"plan": "startup-4",
"cloud_name": "google-europe-west3",
"state": "RUNNING",
"cmk_id": "12345678-1234-1234-1234-12345678abcd"
}
}

If the service is not using a CMK, the cmk_id field is null:

{
"service": {
"service_name": "my-mysql-service",
"service_type": "mysql",
"plan": "startup-4",
"cloud_name": "google-europe-west3",
"state": "RUNNING",
"cmk_id": null
}
}

List services associated with a CMK​

Find all services in a project that are using a specific customer managed key. This is useful for auditing, capacity planning, or managing CMK usage across your infrastructure.

API endpoint​

GET /v1/project/PROJECT_ID/secrets/cmks/CMK_ID/service_associations

Path parameters​

ParameterTypeRequiredDescription
PROJECT_IDStringTrueProject identifier
CMK_IDStringTrueCMK identifier

Sample request​

curl -X GET https://api.aiven.io/v1/project/PROJECT_ID/secrets/cmks/CMK_ID/service_associations \
-H "Authorization: Bearer AIVEN_API_TOKEN"

Sample response​

A successful request returns a 200 OK status code and a JSON object containing a list of services associated with the CMK:

{
"service_associations": [
{
"service_name": "my-pg-service",
"status": "active"
},
{
"service_name": "my-kafka-cluster",
"status": "activating"
}
]
}

Response fields​

FieldDescription
service_nameName of the service using this CMK
statusAssociation status: activating, active, deactivating, or deleted. See Service association statuses.

The response includes services currently associated with the CMK, including services still transitioning onto or off the key. Services not associated with the specified CMK are not included.

note

If a CMK has no associated services, the service_associations array is empty.

Service association statuses​

Each service that uses a CMK has its own association status, separate from the status of the key itself.

StatusDescription
activatingAiven is re-encrypting the service's data encryption keys with this CMK. The association is not complete yet.
activeThe service's data encryption keys are encrypted with this CMK.
deactivatingThe service is moving to another CMK or to Aiven-managed keys. The association is removed when the move completes.
deletedThe association is removed. The CMK no longer protects this service.

Troubleshooting​

Services are powered off after a key becomes unavailable​

Aiven checks access to each registered CMK periodically. After repeated failures to encrypt and decrypt with the key over about 15 to 20 minutes, Aiven powers off every service associated with that key to protect your data. A single failed check does not power off your services.

If you revoked Aiven's access deliberately, no further action is needed.

If the loss of access was not intentional, check the following in your cloud provider:

  • The key is not disabled, scheduled for deletion, or destroyed.
  • The permissions or access policy that grants Aiven access to the key has not been modified or removed. For the access each provider requires, see Set up customer managed keys.
  • No network restriction, such as a firewall rule or a service control, blocks access to your key management service. It must be reachable from the public internet.

After you restore access, power on each affected service. Services do not power on automatically. See Power on/off a service for what powering a service off and on involves.

Validation fails when you register a key​

Registration fails when Aiven cannot perform a test encryption and decryption with your key. Check the following:

  • The accessor value Aiven returned for your cloud, such as an access group, principal, or application ID, is the one you granted on the key.
  • The granted role allows encrypt and decrypt operations, and no other policy denies them.
  • The key resource path matches the key exactly, including the region.
  • The key is enabled and its key management service is reachable from the public internet.

Then register the key again.

A key cannot be deleted​

Deletion fails while the key still has service associations in activating, active, or deactivating status. Move each of those services to another CMK or to Aiven-managed keys, wait until the associations are removed, then delete the key. See Service association statuses.

Related pages