Rotate the Encryption Key
On this page
Use this procedure to rotate an existing FLOW_ used by Flow to encrypt secrets stored in config/config. after Ingest or XL Ingest is installed and configured.
SingleStore recommends rotating FLOW_ every 90 to 180 days, and immediately after any suspected compromise.loadConfig() after restart, Flow decrypts each secret with the old key, re-encrypts it with the new key, and rewrites config/config..config/config. are required.
Refer to Install SingleStore Flow for information on initial key setup and installation.
Prepare for Key Rotation
Before rotating the key, complete the following tasks:
-
Make a copy of
config/config.so the configuration can be restored if needed.xml -
Choose a maintenance window because Flow restarts during the rotation.
Note that active extracts resume from the last checkpoint after the service starts again. -
Generate the new Base64 encoded key using the same method used for the original key.
Rotate the Encryption Key
Perform the following steps on every Flow host, including both Ingest and XL Ingest when applicable.
-
Generate a new key using the same command used during the initial setup.
Refer to Set Up the Encryption Key for more information. -
Set the following variables in the launcher:
-
FLOW_must contain the new key.ENCRYPTION_ KEY -
OLD_must contain the previous key.FLOW_ ENCRYPTION_ KEY
Linux launcher (
ingest.orsh xlingest.):sh export FLOW_ENCRYPTION_KEY=<NEW_BASE64_KEY>export OLD_FLOW_ENCRYPTION_KEY=<PREVIOUS_BASE64_KEY>java -cp ingest.jar:lib/*:. org.sirus.RunWindows service wrapper (
ingest.orxml xlingest.) :xml <env name="FLOW_ENCRYPTION_KEY" value="<NEW_BASE64_KEY>"/><env name="OLD_FLOW_ENCRYPTION_KEY" value="<PREVIOUS_BASE64_KEY>"/>Windows batch launcher (
singlestore-ingest./bat SingleStore-XL-Ingest.):bat set FLOW_ENCRYPTION_KEY=<NEW_BASE64_KEY>set OLD_FLOW_ENCRYPTION_KEY=<PREVIOUS_BASE64_KEY>java -jar ingest.jar -
-
Restart the Flow service so the JVM picks up the new environment.
Use services.on Windows, your service manager on Linux/macOS, or stop and restart the Java process manually for non-service deployments.msc -
Confirm that the rotation completed.
Check the most recent log file under log/for the following markers in order.Info(CMG500): Resolved AES-256 encryption key from FLOW_ENCRYPTION_KEY env var (fingerprint <NEW_FP>)Info(CMG503): Old encryption key configured from OLD_FLOW_ENCRYPTION_KEY env var (fingerprint <OLD_FP>); rotation enabledInfo(CMG502): Encryption key rotation detected; re-encrypting secrets under current keyCMG502is the success signal confirming that every secret inconfig/config.was re-encrypted with the new key and persisted.xml If CMG502does not appear after a normal startup, either no secrets were stored under the old key, or every secret was already encrypted with the new key. -
After confirming successful rotation on ALL hosts (
CMG502in logs), removeOLD_from the configuration before the next restart.FLOW_ ENCRYPTION_ KEY The old key is no longer needed once all secrets are re-encrypted. Keep FLOW_set.ENCRYPTION_ KEY
Understand Key Rotation Behavior
The following behavior is expected during key rotation.
-
If
OLD_is set withoutFLOW_ ENCRYPTION_ KEY FLOW_, Flow does not start.ENCRYPTION_ KEY This prevents Flow from treating the previous key as the current key. -
If
OLD_is set to the same value asFLOW_ ENCRYPTION_ KEY FLOW_, Flow logs a warning and rotation does not occur.ENCRYPTION_ KEY -
If a secret cannot be decrypted with either the current key or the old key, Flow raises an error and stops.
This indicates the secret was encrypted with a different key. To resolve: Stop Flow, restore config/config.from backup, setxml FLOW_to the correct original key, restart Flow, and retry rotation with the correctENCRYPTION_ KEY OLD_value.FLOW_ ENCRYPTION_ KEY -
The
CMG500andCMG503log entries include a short fingerprint of the encryption key.If two processes show the same fingerprint, they are using the same key. This helps confirm which key was active without exposing the key itself. -
Rotation is applied per host.
Roll out the new key to every Flow instance and confirm CMG502on each instance before removingOLD_.FLOW_ ENCRYPTION_ KEY
Roll Back the Rotation
If the new key is incorrect and Flow does not start, remove FLOW_ and, optionally, OLD_ from the launcher, and then restart Flow.
If Flow has already started with the new key and config/config. was rewritten, restore the pre-rotation backup of config/config. before retrying.
Last modified: