Changing the database encryption key
Replace the value of the secret that is used for encrypting database fields in the management subsystem.
Before you begin
Take a backup of your existing management database encryption key. If you need to restore a management database backup, you must have the encryption key that was in use at the time the database backup was created.
- Identify the name of the management database encryption
secret:
kubectl get mgmt <mangement CR name> -o=jsonpath='{.status.encryptionSecret}'where <mangement CR name> can be determined by running:kubectl get mgmt - Copy the secret to a YAML
file:
kubectl get secret <management enc secret> -o yaml > management_enc_key_backup_<date>.yaml
Keep your backed up encryption secret with your management infrastructure configuration backup: Taking a management infrastructure configuration backup. If you want to restore a database backup that was taken when a previous encryption key was in use, then see restore backup.
About this task
This update does not require an outage; however some operations might take longer than usual due to database locking.
Procedure
What to do next
If you need to restore a management database backup that was taken before you updated the encryption key, then you must restore your previous encryption key from your backup.
- Edit your secret backup file:
management_enc_key_backup_<date>.yaml and change
metadata.nameto a unique name for your backup secret. Delete all othermetadatacontents. Your updated YAML file should look like this:apiVersion: v1 data: encryption_secret.bin: If7HlVzZeAgrYrwvcEhv1Ub0LVXNQsN0mGISy1GvYXKA4d1tSWLB80hB89sn+VvN0/vAVTU90AP6jPOsi5LpOaddfoqT85ugvjEwHLnEtSI6CbEr05NtMUwJGAr5/KWfjj6mwCn+EMp4VBsEDppU54yvycyb7iBLRtGyrPktTaw= kind: Secret metadata: name: backup_mgmt_encryption_secret type: Opaque - Restore the encryption secret from your updated backup
file:
kubectl create -f management_enc_key_backup_<date>.yaml - Verify that the backup secret was created:
You should see your restored backup secret in the output:kubectl get secretsNAME TYPE DATA AGE ... backup_mgmt_encryption_secret Opaque 3 10s ... - In your mgmtrestore_cr.yaml file, add the property
spec.mgmtEncKeyNameand set it to your newly created backup secret name:apiVersion: management.apiconnect.ibm.com/v1beta1 kind: ManagementRestore metadata: generateName: management- # this the prefix for the name of the restore CR that is created spec: backupName: <backup CR name> subsystemName: <management CR name> mgmtEncKeyName: backup_mgmt_encryption_secretThe encryption key that is contained in
backup_mgmt_encryption_secretis copied to your active encryption secret. After you restore the backup, you might want to update the encryption key again (for the same reason that you previously updated the secret).For more information about management database backup restore, see Restoring from a management database backup.
If you have a two data center disaster recovery deployment, you must copy the updated encryption secret to your warm-standby data center. Follow these steps:
- Extract the management database encryption secret from the active data
center:
kubectl get secret <mgmt encryption secret> --template='{{ index .data "encryption_secret.bin" }}' > mgmt-enc-secret.txt - Verify that the mgmt-enc-secret.txt file contains your
secret:
cat mgmt-enc-secret.txtExpected output should be a long string, for example:YSXft4YoApS+UJHpaXjdu8OUovFGhLT9YsBaWeRCI5sUigPdchY/cq18Z5UKaW5afZDXxQDWUcY6tx9xTXVGzEm9oZCDV1hmq4mu7qM015rBjZIJ7FPrA3gNgxflxim9SORSybnhW2JT6S41ZH9QJwfUtIUUpe981h8sraSEtOQ= - In your warm-standby data
center, identify the name of the management database encryption
secret:
kubectl get mgmt <mangement CR name> -o=jsonpath='{.status.encryptionSecret}' - Update the warm-standby
secret with the secret from the active that you obtained in step 1:
kubectl patch secret <warm-standby enc secret name> -p "{\"data\": {\"encryption_secret.bin\":\"$(<mgmt-enc-secret.txt)\"}}"