etcd is the only stateful component of an OpenShift control plane, and it is the one most teams never test until the day they have to. Two problems compound each other: by default, Secret objects are stored in etcd in plaintext (base64 is not encryption), and most clusters rely on a backup procedure that exists only as a wiki page nobody has executed since installation day.
This article covers the complete loop: enabling at-rest encryption on the API server, automating cluster-backup.sh snapshots with a CronJob scheduled on control plane nodes, rehearsing a full restore in a lab, and understanding how encryption keys rotate — because a snapshot you cannot decrypt is not a backup.
Context: what an etcd snapshot actually contains
cluster-backup.sh produces two artifacts:
-
snapshot_<datetime>.db— a consistent etcd snapshot (every object in the cluster) -
static_kuberesources_<datetime>.tar.gz— the static pod resources from/etc/kubernetes/static-pod-resources, including the etcd encryption keys when encryption is enabled
That second point is the one people miss. If you enable encryption at rest and then store the backup bundle on an unprotected NFS share, you have changed nothing from a threat-model standpoint: the key travels with the ciphertext. Conversely, if you restore a snapshot_*.db with a mismatched static_kuberesources_*.tar.gz, the kube-apiserver will come up with the wrong EncryptionConfiguration and will fail to decrypt secrets. The two files are a unit. Always treat them as one atomic bundle.
The other recurring failure mode is procedural: an etcd restore on OpenShift is not etcdctl snapshot restore. It is a cluster-wide, ordered operation that stops static pods on surviving control plane nodes, rolls etcd back on a single recovery host, and then forces new revisions of the four control plane operators. Improvising this at 3 a.m. does not end well.
Enabling etcd encryption at rest
Encryption is driven by the APIServer cluster config. Two providers are available: aescbc (AES-CBC with PKCS#7 padding, 32-byte key) and aesgcm (AES-GCM, 32-byte key, available from OCP 4.13). Prefer aesgcm on recent clusters.
oc patch apiserver cluster \ --type=merge \ -p '{"spec":{"encryption":{"type":"aesgcm"}}}' Equivalent manifest if you manage the cluster with GitOps:
apiVersion: config.openshift.io/v1 kind: APIServer metadata: name: cluster spec: encryption: type: aesgcm audit: profile: Default Enabling encryption triggers a rollout of the kube-apiserver and openshift-apiserver static pods, then a background migration that rewrites every affected object so it is stored encrypted. Encrypted resource types are:
- kube-apiserver:
secrets,configmaps - openshift-apiserver:
routes.route.openshift.io,oauthaccesstokens.oauth.openshift.io,oauthauthorizetokens.oauth.openshift.io
On a large cluster, expect 10–30 minutes and several control plane revisions. Do not run it during a maintenance window with other changes.
Verifying the migration completed
oc get kubeapiserver cluster \ -o jsonpath='{range .status.conditions[?(@.type=="Encrypted")]}{.reason}: {.message}{"\n"}{end}' oc get openshiftapiserver cluster \ -o jsonpath='{range .status.conditions[?(@.type=="Encrypted")]}{.reason}: {.message}{"\n"}{end}' You are looking for EncryptionCompleted: All resources encrypted: .... While it runs you will see EncryptionInProgress.
Proving it on the wire
Operator conditions are nice; reading the raw bytes out of etcd is better. Create a canary secret and dump it directly from the etcd member:
oc -n default create secret generic canary --from-literal=probe=hello ETCD_POD=$(oc -n openshift-etcd get pods -l app=etcd \ -o jsonpath='{.items[0].metadata.name}') oc -n openshift-etcd rsh -c etcdctl "$ETCD_POD" \ etcdctl get /kubernetes.io/secrets/default/canary | head -c 80 | hexdump -C | head With encryption enabled, the value starts with k8s:enc:aesgcm:v1:<key-name>: followed by ciphertext. Without encryption, you can read probe and hello in the clear. Run this check after every control plane upgrade — it costs five seconds and catches silent regressions.
Automating snapshots with a CronJob
cluster-backup.sh only exists on control plane nodes (/usr/local/bin/cluster-backup.sh) and must run with host access. Two supported-ish approaches:
- A privileged CronJob that
chroots into the host filesystem (works on every 4.x release). - The
Backup/EtcdBackupAPI (config.openshift.io/v1alpha1) behind theAutomatedEtcdBackupfeature gate on 4.14+. It is Tech Preview and requires enabling a feature set on the cluster, which is irreversible — evaluate carefully before using it in production.
Here is the CronJob approach, which I still recommend for most clusters.
Namespace, service account and SCC
apiVersion: v1 kind: Namespace metadata: name: ocp-etcd-backup labels: openshift.io/cluster-monitoring: "true" --- apiVersion: v1 kind: ServiceAccount metadata: name: etcd-backup namespace: ocp-etcd-backup --- apiVersion: rbac.authorization.k8s.io/v1 kind: RoleBinding metadata: name: etcd-backup-privileged namespace: ocp-etcd-backup roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: system:openshift:scc:privileged subjects: - kind: ServiceAccount name: etcd-backup namespace: ocp-etcd-backup The CronJob
apiVersion: batch/v1 kind: CronJob metadata: name: etcd-backup namespace: ocp-etcd-backup spec: schedule: "0 */6 * * *" concurrencyPolicy: Forbid startingDeadlineSeconds: 900 successfulJobsHistoryLimit: 5 failedJobsHistoryLimit: 5 jobTemplate: spec: backoffLimit: 1 activeDeadlineSeconds: 1800 template: spec: serviceAccountName: etcd-backup restartPolicy: Never hostNetwork: true hostPID: true nodeSelector: node-role.kubernetes.io/master: "" tolerations: - key: node-role.kubernetes.io/master operator: Exists effect: NoSchedule containers: - name: backup image: registry.redhat.io/rhel9/support-tools:latest securityContext: privileged: true runAsUser: 0 command: ["/bin/bash", "-c"] args: - | set -euo pipefail BACKUP_DIR=/var/home/core/etcd-backup RETENTION_DAYS=3 chroot /host /bin/bash -c " mkdir -p ${BACKUP_DIR} /usr/local/bin/cluster-backup.sh ${BACKUP_DIR} find ${BACKUP_DIR} -type f -mtime +${RETENTION_DAYS} -delete ls -lh ${BACKUP_DIR} " volumeMounts: - name: host mountPath: /host volumes: - name: host hostPath: path: / type: Directory Notes that matter in production:
-
cluster-backup.shwrites into the directory you pass and refuses to overwrite; thefind -deletestep is your retention policy. Keep at least 48 hours locally. - Scheduling is not pinned to one specific master, which is intentional: if one node dies you still get backups. The downside is that snapshots scatter across nodes — hence the offload step below.
-
concurrencyPolicy: ForbidplusactiveDeadlineSecondsprevents overlapping snapshots that would thrash etcd I/O. - A snapshot is a point-in-time copy of the full keyspace. On a busy cluster it causes measurable disk and fsync pressure. Six-hour intervals are a sane default; one hour is only reasonable on fast NVMe.
Offloading off-cluster
A backup living on the node whose disk just failed is not a backup. Add a second step that pushes the bundle to object storage with server-side encryption and object lock:
# inside the same chroot block, after cluster-backup.sh LATEST_DB=$(ls -t ${BACKUP_DIR}/snapshot_*.db | head -1) LATEST_TAR=$(ls -t ${BACKUP_DIR}/static_kuberesources_*.tar.gz | head -1) tar czf /tmp/etcd-bundle-$(date +%Y%m%d%H%M).tar.gz "$LATEST_DB" "$LATEST_TAR" aws s3 cp /tmp/etcd-bundle-*.tar.gz "s3://${BUCKET}/${CLUSTER_ID}/" --sse aws:kms Mount the credentials from a Secret, never bake them in the image, and use a bucket policy that allows PutObject only — a compromised cluster must not be able to delete its own backups.
Finally, alert on absence. A CronJob that silently stops firing is the classic failure:
apiVersion: monitoring.coreos.com/v1 kind: PrometheusRule metadata: name: etcd-backup-staleness namespace: ocp-etcd-backup spec: groups: - name: etcd-backup rules: - alert: EtcdBackupMissing expr: | time() - max(kube_job_status_completion_time{namespace="ocp-etcd-backup"}) > 28800 for: 15m labels: severity: critical annotations: summary: "No successful etcd backup in the last 8 hours" Rehearsing a full restore
Do this in a lab cluster with the same topology and the same OCP minor version. Steps differ between releases (4.15 introduced quorum-restore.sh), so always cross-check your exact version's documentation; the flow below matches 4.14–4.17 for a 3-node control plane.
Step 0 — know which script to use
- Quorum lost, no data rollback wanted (two of three masters dead, etcd data intact on the survivor):
/usr/local/bin/quorum-restore.sh(4.15+). Faster, no snapshot needed. - Rollback to a previous cluster state (bad upgrade, mass deletion, corrupted etcd):
/usr/local/bin/cluster-restore.sh <backup-dir>, often referred to simply asrestore.sh.
Step 1 — stage the backup on the recovery host
Pick one healthy control plane node as the recovery host and copy the matching pair of files to it:
RECOVERY=master-0 oc debug node/${RECOVERY} -- chroot /host mkdir -p /home/core/assets/backup scp snapshot_20240518_030112.db \ static_kuberesources_20240518_030112.tar.gz \ core@${RECOVERY}:/home/core/assets/backup/ Step 2 — stop static pods on the other control plane nodes
On each non-recovery master:
sudo mv /etc/kubernetes/manifests/etcd-pod.yaml /tmp/ sudo crictl ps | grep -w etcd | grep -v operator # must return nothing sudo mv /etc/kubernetes/manifests/kube-apiserver-pod.yaml /tmp/ sudo crictl ps | grep -w kube-apiserver | grep -v operator # must return nothing sudo mv /var/lib/etcd/ /tmp/ If the API is still reachable you can drive this through oc debug node/<name> -- chroot /host ...; in a real outage you will be on the serial console or SSH.
Step 3 — run the restore on the recovery host
sudo -E /usr/local/bin/cluster-restore.sh /home/core/assets/backup The script stops the local etcd and API server static pods, moves the current data directory aside, restores the snapshot into a single-member etcd, restores the static pod manifests and secrets from the tarball (this is where the encryption keys come back), and restarts the control plane.
Watch it converge:
sudo crictl ps | grep etcd oc get nodes oc -n openshift-etcd get pods -l app=etcd -o wide Step 4 — bring back the other members and force new revisions
Restart the kubelet on all control plane nodes, then let the etcd operator re-add members. Once a single-member cluster is healthy, force a redeployment of the four control plane operators so every component picks up the restored state:
for res in etcd kubeapiserver kubecontrollermanager kubescheduler; do oc patch ${res} cluster --type=merge \ -p "{\"spec\":{\"forceRedeploymentReason\":\"recovery-$(date --rfc-3339=ns)\"}}" done # follow revisions until NodeInstallerProgressing clears oc get ${res} -o=jsonpath='{range .items[0].status.conditions[?(@.type=="NodeInstallerProgressing")]}{.reason} {.message}{"\n"}{end}' Step 5 — post-restore checks
oc get csr -o name | xargs -r oc adm certificate approve # pending kubelet CSRs oc get co # all Available=True, Degraded=False oc -n openshift-etcd rsh -c etcdctl $(oc -n openshift-etcd get pod -l app=etcd -o name | head -1 | cut -d/ -f2) \ etcdctl endpoint health --cluster oc -n default get secret canary -o jsonpath='{.data.probe}' | base64 -d # decryption works That last line is the real acceptance test: if the canary secret decrypts, the restored encryption keys match the restored snapshot. Objects created after the snapshot are gone — rebuild them from GitOps, which is why etcd backup never replaces declarative config management.
Time the whole drill and write down the numbers. "RTO is about 45 minutes on a 3-node cluster" is an engineering statement; "we have backups" is not.
Key rotation
OpenShift rotates etcd encryption keys automatically — roughly weekly — and migrates existing data to the new key in the background. You do not schedule it, but you should observe it:
oc get secrets -n openshift-config-managed \ -l encryption.apiserver.operator.openshift.io/component \ --sort-by=.metadata.creationTimestamp \ -o custom-columns='NAME:.metadata.name,CREATED:.metadata.creationTimestamp' Key secrets are named encryption-key-openshift-kube-apiserver-<N> and encryption-key-openshift-apiserver-<N>, and carry a migrated-timestamp annotation once all data has been rewritten with them. Old keys are retained for a while so previously written data stays readable, then pruned.
You can force a new key and a full re-encryption by changing the provider:
oc patch apiserver cluster --type=merge -p '{"spec":{"encryption":{"type":"aescbc"}}}' # ...wait for EncryptionCompleted, then switch back oc patch apiserver cluster --type=merge -p '{"spec":{"encryption":{"type":"aesgcm"}}}' Use this only when you have reason to believe a key was exposed (for example a leaked static_kuberesources tarball), and never while a backup job is running. Disabling encryption entirely is type: identity, which triggers a full decrypting rewrite.
Operational consequence of rotation: a backup older than the current key set is still restorable, because cluster-restore.sh restores the key material from its own tarball — but only if you kept the pair together. Splitting the bundle across two storage locations is how teams discover, during an incident, that they have ciphertext and no key.
Security best practices
- Encrypt the backup bundle itself. The
static_kuberesourcestarball holds the etcd encryption keys and the control plane certificates. Treat the pair as equivalent to cluster-admin credentials:age/gpgor SSE-KMS at minimum, plus bucket versioning and object lock. - Separate the credential domains. The IAM principal used by the backup CronJob should have
s3:PutObjectonly. Restore credentials live with the break-glass team, not on the cluster. - Restrict the privileged CronJob. It is a
privileged: truepod withhostPath: /. Keep it in its own namespace, bind the SCC to a dedicated ServiceAccount, and audit who can create workloads there — that namespace is a root-on-every-master foothold. - Never store a snapshot on the node's root volume only. Offload within minutes of creation.
- Rotate and verify. Enable encryption, then prove it by reading raw etcd bytes. Rotate keys when a bundle is suspected to have leaked, and re-run the raw read check after control plane upgrades.
- Protect the Kubernetes API path too. At-rest encryption does nothing against a compromised cluster-admin token; pair it with short-lived OIDC auth, audit logging at
WriteRequestBodiesfor sensitive namespaces, and RBAC that blocks blanketget secretsat cluster scope. - Test restores on a schedule, not on incident. Quarterly, in a lab, with a stopwatch and a written runbook updated for the running OCP minor version.
Conclusion
Encryption and backup are often treated as two separate checkboxes. On OpenShift they are the same subject: the etcd snapshot is the asset you are protecting, and the key that makes it readable ships in the companion tarball.
Key takeaways:
- Enable
aesgcmthrough theAPIServerCR, wait forEncryptionCompleted, and verify with a rawetcdctl getthat returnsk8s:enc:aesgcm:v1:. - Automate
cluster-backup.shwith a privileged CronJob on masters, apply local retention, offload to encrypted object storage immediately, and alert on backup staleness rather than on backup failure. - Keep
snapshot_*.dbandstatic_kuberesources_*.tar.gztogether, always — they are one restorable unit. - Know which script you need before you need it:
quorum-restore.shfor quorum loss,cluster-restore.shfor a point-in-time rollback, with static pods stopped on the non-recovery masters first and a forced redeployment of the four control plane operators afterwards. - Key rotation happens automatically; your job is to observe it and to keep old bundles matched with their keys.
Run the drill once in a lab and the procedure stops being a wiki page. That is the whole point.