»Google Cloud KMS Secrets Engine
The Google Cloud KMS Vault secrets engine provides encryption and key management via Google Cloud KMS. It supports management of keys, including creation, rotation, and revocation, as well as encrypting and decrypting data with managed keys. This enables management of KMS keys through Vault's policies and IAM system.
»Setup
Most secrets engines must be configured in advance before they can perform their functions. These steps are usually completed by an operator or configuration management tool.
Enable the Google Cloud KMS secrets engine:
By default, the secrets engine will mount at the name of the engine. To enable the secrets engine at a different path, use the
-path
argument.Configure the secrets engine with account credentials and/or scopes:
If you are running Vault from inside Google Compute Engine or Google Kubernetes Engine, the instance or pod service account can be used in place of specifying the credentials JSON file. For more information on authentication, see the authentication section below.
Create a Google Cloud KMS key:
The
key_ring
parameter is specified in the following format:where:
<project>
- the name of the GCP project (e.g. "my-project")<location>
- the location of the KMS key ring (e.g. "us-east1", "global")<keyring>
- the name of the KMS key ring (e.g. "my-keyring")
»Usage
After the secrets engine is configured and a user/machine has a Vault token with the proper permission, it can be used to encrypt, decrypt, and manage keys. The following sections describe the different ways in which keys can be managed.
»Symmetric Encryption/Decryption
This section describes using a Cloud KMS key for symmetric encryption/decryption. This is one of the most common types of encryption. Google Cloud manages the key ring which is used to encrypt and decrypt data.
Purpose | Supported Algorithms |
---|---|
encrypt_decrypt | symmetric_encryption |
Create or use an existing key eligible for symmetric encryption/decryption:
Encrypt plaintext data using the
/encrypt
endpoint with a named key:Unlike Vault's transit backend, plaintext data does not need to be base64 encoded. The endpoint will automatically convert data.
Note that Vault is not storing this data. The caller is responsible for storing the resulting ciphertext.
Decrypt ciphertext using the
/decrypt
endpoint with a named key:For easier scripting, it is also possible to extract the plaintext directly:
Rotate the underlying encryption key. This will generate a new crypto key version on Google Cloud KMS and set that version as the active key.
As the message says, rotation is not immediate. Depending on a number of factors, the propagation of the new key can take quite some time. If you have a need to immediately encrypt data with this new key, query the API to wait for the key to become the primary. Alternatively, you can specify the
key_version
parameter to lock to the exact key for use with encryption.Re-encrypt already-encrypted ciphertext to be encrypted with a new version of the crypto key. Vault will decrypt the value using the appropriate key in the keyring and then encrypt the resulting plaintext with the newest key in the keyring.
This process does not reveal the plaintext data. As such, a Vault policy could grant an untrusted process the ability to re-encrypt ciphertext data, since the process would not be able to get access to the plaintext data.
Trim old key versions by deleting Cloud KMS crypto key versions that are older than the
min_version
allowed on the key.Then delete all keys older than version 10. This will make it impossible to encrypt, decrypt, or sign values with the older key by conventional means.
Delete the key to delete all key versions and Vault's record of the key.
This will make it impossible to encrypt, decrypt, or sign values by conventional means.
»Asymmetric Decryption
This section describes using a Cloud KMS key for asymmetric decryption. In this model Google Cloud manages the key ring and exposes the public key via an API endpoint. The public key is used to encrypt data offline and produce ciphertext. When the plaintext is desired, the user submits the ciphertext to Cloud KMS which decrypts the value using the corresponding private key.
Purpose | Supported Algorithms |
---|---|
asymmetric_decrypt | rsa_decrypt_oaep_2048_sha256 rsa_decrypt_oaep_3072_sha256 rsa_decrypt_oaep_4096_sha256 |
Create or use an existing key eligible for symmetric encryption/decryption:
Retrieve the public key from Cloud KMS:
Encrypt plaintext data with the public key. Note this varies widely between programming languages. The following example uses OpenSSL, but you can use your language's built-ins as well.
Note that this encryption happens offline (meaning outside of Vault), and the encryption is happening with a public key. Only Cloud KMS has the corresponding private key.
Decrypt ciphertext using the
/decrypt
endpoint with a named key:
»Asymmetric Signing
This section describes using a Cloud KMS key for asymmetric signing. In this model Google Cloud manages the key ring and exposes the public key via an API endpoint. A message or digest is signed with the corresponding private key, and can be verified by anyone with the corresponding public key.
Purpose | Supported Algorithms |
---|---|
asymmetric_sign | rsa_sign_pss_2048_sha256 rsa_sign_pss_3072_sha256 rsa_sign_pss_4096_sha256 rsa_sign_pkcs1_2048_sha256 rsa_sign_pkcs1_3072_sha256 rsa_sign_pkcs1_4096_sha256 ec_sign_p256_sha256 ec_sign_p384_sha384 |
Create or use an existing key eligible for symmetric encryption/decryption:
Calculate the base64-encoded binary digest. Use the hashing algorithm that corresponds to they key type:
Ask Cloud KMS to sign the digest:
Verify the signature of the digest:
Note: it is also possible to verify this signature without Vault. Download the public key from Cloud KMS, and use a tool like OpenSSL or your programming language primitives to verify the signature.
»Authentication
The Google Cloud KMS Vault secrets backend uses the official Google Cloud Golang
SDK. This means it supports the common ways of providing credentials to Google
Cloud. In addition to specifying credentials
directly via Vault
configuration, you can also get configuration from the following values on the
Vault server:
The environment variables
GOOGLE_APPLICATION_CREDENTIALS
. This is specified as the path to a Google Cloud credentials file, typically for a service account. If this environment variable is present, the resulting credentials are used. If the credentials are invalid, an error is returned.Default instance credentials. When no environment variable is present, the default service account credentials are used. This is useful when running Vault on Google Compute Engine or Google Kubernetes Engine
For more information on service accounts, please see the Google Cloud Service Accounts documentation.
To use this secrets engine, the service account must have the following minimum scope(s):
»Required Permissions
The credentials given to Vault must have the following role:
If Vault will not be creating keys, you can reduce the permissions. For example, to create keys out of band and have Vault manage the encryption/decryption, you only need the following permissions:
To sign and verify, you only need the following permissions:
For more information, please see the Google Cloud KMS IAM documentation.
»FAQ
How is this different than Vault's transit secrets engine?
Vault's transit secrets engine uses in-memory keys to
encrypt/decrypt keys. In general it will be faster and more performant. However,
users who need physical, off-site, or out-of-band key management can use the
Google Cloud KMS secrets engine to get those benefits while leveraging
Vault's policy and identity system.
Can Vault use an existing KMS key?
You can use the /register
endpoint to configure Vault to talk to an existing
Google Cloud KMS key. As long as the IAM permissions are correct, Vault will be
able to encrypt/decrypt data and rotate the key. See the api for more
information.
Can this be used with a hardware key like an HSM?
Yes! You can set protection_level
to "hsm" when creating a key, or use an
existing Cloud KMS key that is backed by an HSM.
How much does this cost?
The plugin is free and open source. KMS costs vary by key type and the number of
operations. Please see the Cloud KMS pricing page for more
details.
»Help & Support
The Google Cloud KMS Vault secrets engine is written as an external Vault plugin. The code lives outside the main Vault repository. It is automatically bundled with Vault releases, but the code is managed separately.
Please report issues, add feature requests, and submit contributions to the vault-plugin-secrets-gcpkms repo on GitHub.
»API
The Google Cloud KMS secrets engine has a full HTTP API. Please see the Google Cloud KMS secrets engine API docs for more details.