Rotating gossip encryption keys in your Consul cluster helps maintain strong security posture. In this tutorial, we’ll walk through:Documentation Index
Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
Use this file to discover all available pages before exploring further.
- Reviewing the current configuration
- Generating a new encryption key
- Distributing the key across the cluster
- Promoting the new key to primary
- Removing the old key
1. Review Current Configuration
Inspect your existing gossip encryption key inconsul.d/config.hcl:
Before you begin, back up your Consul configuration and data directory. This ensures you can recover quickly if something goes wrong.
2. Generate a New Gossip Encryption Key
Run the following command on any Consul server or client to create a fresh base64-encoded key:3. Distribute the New Key Across the Cluster
Install the newly generated key into the cluster keyring:3.1. Verify Key Distribution
On another node, list installed keys:4. Promote the New Key to Primary
Switch the cluster’s primary gossip encryption key:5. Remove the Old Encryption Key
Once every node is using the new key, remove the old one:Do not remove the old key until all nodes report the new key as primary. Premature removal can lead to cluster partitions and service disruptions.
Command Reference
| Command | Description |
|---|---|
consul keygen | Generates a new base64-encoded key |
consul keyring -install <key> | Installs a key into the cluster keyring |
consul keyring -list | Lists installed keys and their usage counts |
consul keyring -use <key> | Promotes a key to be the primary encryption key |
consul keyring -remove <key> | Deletes an old key from the keyring |