Bring Your Own Key

This feature is currently available only to customers participating in a Private Preview. If you'd like to participate and be among the first to try this feature, ask our support or account team for details.

With bring your own key (BYOK), you generate the key material for Encryption as a Service yourself and import it into Workload Secrets Vault. Workload Secrets Vault never generates BYOK key material, not even when you rotate a key. Encrypting, decrypting, and rewrapping work the same way as with service-managed keys.

You import keys by encrypting ("wrapping") them with your tenant's public wrapping key, so the key material is never sent in the clear.

Before You Begin

  • Keys must be 256-bit AES keys (exactly 32 bytes).

  • Keep your own secure copy of every key you import. Workload Secrets Vault can't export keys.

  • You need OpenSSL 1.1.1 or later, or another tool that supports RSA-OAEP with SHA-256.

  • You need the permissions and policy actions in Permissions and Policy Actions.

Importing a Key

  1. Get the wrapping key and save its ID and public key:

    Copy
    delinea --json workload crypto manual wrapping-key get > wrapping-key.json
    WRAPPING_KEY_ID=$(jq -r '.keyId' wrapping-key.json)
    jq -r '.publicKeyPem' wrapping-key.json > wrapping-key.pem

    The wrapping key is a 3072-bit RSA key that belongs to your tenant. It's created the first time anyone in the tenant requests it, and every later request returns the same key.

  2. Generate a 256-bit key, or export one from your own key management system:

    Copy
    openssl rand 32 > aes.key
  3. Wrap the key with RSA-OAEP, using SHA-256 for both the OAEP hash and MGF1, and encode the result in Base64:

    Copy
    openssl pkeyutl -encrypt -pubin -inkey wrapping-key.pem \
      -pkeyopt rsa_padding_mode:oaep -pkeyopt rsa_oaep_md:sha256 -pkeyopt rsa_mgf1_md:sha256 \
      -in aes.key -out wrapped.bin
    WRAPPED_KEY=$(openssl base64 -A -in wrapped.bin)
  4. Import the wrapped key at a key path:

    Copy
    delinea --json workload crypto manual key create payments/card-tokens \
      --wrapping-key-id "$WRAPPING_KEY_ID" --wrapped-key "$WRAPPED_KEY"

    The response shows version 1 of the key. Key paths follow the same rules as for service-managed keys.

  5. Move aes.key to your own secure key storage and remove it, wrapped.bin, and the shell variables from the computer where you ran these commands.

Encrypting and Decrypting

Use the crypto manual commands with the same flags as for service-managed keys:

Copy
delinea --json workload crypto manual encrypt --path payments/card-tokens --plaintext tok_4242
delinea --json workload crypto manual decrypt --path payments/card-tokens --ciphertext <ciphertext>

The 64 KiB limit and the error behavior are the same as described in Encryption as a Service.

Rotating a Key

To rotate a BYOK key, generate and wrap a new key as in steps 2 and 3 of Importing a Key, and then add it as the next version:

Copy
delinea --json workload crypto manual key rotate payments/card-tokens \
  --wrapping-key-id "$WRAPPING_KEY_ID" --wrapped-key "$NEW_WRAPPED_KEY"

New encryptions use the new version, and earlier versions still decrypt. To move existing ciphertext to the new version, rewrap it:

Copy
delinea --json workload crypto manual rewrap payments/card-tokens --ciphertext <ciphertext>

The service doesn't check that new key material differs from earlier versions, and BYOK rotation has no startingVersion check. Always generate a fresh key for each rotation.

Replacing Key Material

You can also import new key material into an existing BYOK key with crypto manual key update, using the same flags as for importing a key. The earlier key material isn't removed. The imported key becomes the key's next version, exactly as with rotation: new encryptions use it, and earlier versions still decrypt. The key must exist and must not be deleted. As with rotation, generate a fresh key each time.

For example, with a new key that you wrapped as in steps 2 and 3 of Importing a Key:

Copy
delinea --json workload crypto manual key update payments/card-tokens \
  --wrapping-key-id "$WRAPPING_KEY_ID" --wrapped-key "$NEW_WRAPPED_KEY"

The response shows the key's new version. The REST equivalent is PUT crypto/manual/keys/{path}. Replacing key material needs the Update Key permission and the update policy action, not Manage Key and rotate.

Deleting and Restoring a Key

Copy
delinea workload crypto manual key delete payments/card-tokens
delinea workload crypto manual restore payments/card-tokens

You can restore a deleted BYOK key for 30 days. After that, you can't restore it or create a new key at the same path, so use a new path for a replacement key.

Limitations

  • Only 256-bit AES keys can be imported.

  • Your tenant's wrapping key isn't rotated.

  • The wrapping key response includes a signature field, but you can't verify it yourself. Get the wrapping key only over an authenticated connection to your own tenant, as the CLI and API do.

  • A policy for service-managed keys (cryptokey/) doesn't grant access to BYOK keys (manualcryptokey/), and the reverse is also true. A service-managed key and a BYOK key can have the same path.

Permissions and Policy Actions

Operation Permission Policy action and target
Get the wrapping key Read Key read-wrapping-key on manualcryptokey/_wrapping-key
Import a key Create Key create on manualcryptokey/<path>
View a key Read Key read
Encrypt Encrypt Data encrypt
Decrypt Decrypt Data decrypt
Rotate a key Manage Key rotate
Replace key material Update Key update
Rewrap ciphertext Manage Key rewrap
Delete a key Delete Key delete
Restore a key Update Key restore

Update Key together with the update action lets a caller replace a key's material, with the same effect as rotating the key. Grant them as carefully as Manage Key and rotate.

REST API Reference

Paths are relative to https://<your-tenant>/workload-secrets/api/v1/. BYOK keys use paths under crypto/manual/, and service-managed keys use paths under crypto/auto/, which are listed in REST API Reference.

Operation Request CLI (delinea workload crypto manual ...)
Get the wrapping key GET crypto/manual/wrapping-key wrapping-key get
Import POST crypto/manual/keys/{path} with {"wrappingKeyId", "wrappedKey"} key create <path> --wrapping-key-id <id> --wrapped-key <key>
View GET crypto/manual/keys/{path} key get <path>
Rotate POST crypto/manual/rotate/{path} with {"wrappingKeyId", "wrappedKey"} key rotate <path> --wrapping-key-id <id> --wrapped-key <key>
Replace key material PUT crypto/manual/keys/{path} with {"wrappingKeyId", "wrappedKey"} key update <path> --wrapping-key-id <id> --wrapped-key <key>
Delete DELETE crypto/manual/keys/{path} key delete <path>
Restore PUT crypto/manual/restore/{path} restore <path>
Encrypt POST crypto/manual/encrypt encrypt --path <path> --plaintext <text>
Decrypt POST crypto/manual/decrypt decrypt --path <path> --ciphertext <text>
Rewrap POST crypto/manual/rewrap/{path} rewrap <path> --ciphertext <text>

Import, rotate, and replace fail with 400 and the error code crypto_invalid_argument when the wrapping key ID is unknown, the wrapped key isn't valid Base64, the service can't unwrap the key (for example, because it was wrapped with a different public key or with the wrong padding), or the unwrapped key isn't exactly 32 bytes.