Encrypt container images with ctr-enc
mainTo encrypt images, follow these steps:
Generate an RSA key pair using OpenSSL:
openssl genrsa -out mykey.pem openssl rsa -in mykey.pem -pubout -out mypubkey.pemIdentify the target image and its platform using
ctr-enc(linked to your containerd socket):# Set the CTR variable to point to your socket CTR="/usr/local/bin/ctr-enc -a /tmp/run/containerd/containerd.sock" $CTR images layerinfo --platform linux/amd64 docker.io/library/bash:latestEncrypt the image using the
--recipientflag with thejwe:prefix and your public key:$CTR images encrypt --recipient jwe:mypubkey.pem --platform linux/amd64 docker.io/library/bash:latest bash.enc:latestVerify encryption by checking the layer info of the new image. The
ENCRYPTIONcolumn should showjweandRECIPIENTSshould show[jwe].
# 1. Generate keys
openssl genrsa -out mykey.pem
openssl rsa -in mykey.pem -pubout -out mypubkey.pem
# 2. Encrypt image
CTR="/usr/local/bin/ctr-enc -a /tmp/run/containerd/containerd.sock"
$CTR images encrypt --recipient jwe:mypubkey.pem --platform linux/amd64 docker.io/library/bash:latest bash.enc:latest