Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add nerdctl image (encrypt|decrypt) SRC DST #484

Merged
merged 4 commits into from
Nov 2, 2021

Conversation

AkihiroSuda
Copy link
Member

@AkihiroSuda AkihiroSuda commented Nov 1, 2021

nerdctl run has been supporting decryption, but we didn't have the command to encrypt images.

This will be probably beneficial for IPFS (#465)

Encrypt:

openssl genrsa -out mykey.pem
openssl rsa -in mykey.pem -pubout -out mypubkey.pem
nerdctl image encrypt --recipient=jwe:mypubkey.pem --platform=linux/amd64,linux/arm64 foo example.com/foo:encrypted
nerdctl push example.com/foo:encrypted

Decrypt:

nerdctl pull --unpack=false example.com/foo:encrypted
nerdctl decrypt --key=mykey.pem example.com/foo:encrypted foo:decrypted

See also docs/ocicrypt.md

nerctl image encrypt

$ nerdctl image encrypt --help
Encrypt image layers.

Use '--recipient' to specify the recipients.
The following protocol prefixes are supported:
- pgp:<email-address>
- jwe:<public-key-file-path>
- pkcs7:<x509-file-path>

Use '--platform' to define the platforms to encrypt. Defaults to the host platform.
When '--all-platforms' is given all images in a manifest list must be available.
Unspecified platforms are omitted from the output image.

Example:
  openssl genrsa -out mykey.pem
  openssl rsa -in mykey.pem -pubout -out mypubkey.pem
  nerdctl image encrypt --recipient=jwe:mypubkey.pem --platform=linux/amd64,linux/arm64 foo example.com/foo:encrypted
  nerdctl push example.com/foo:encrypted

To run the encrypted image, put the private key file (mykey.pem) to /etc/containerd/ocicrypt/keys (rootful) or ~/.config/containerd/ocicrypt/keys (rootless).
containerd before v1.4 requires extra configuration steps, see https://github.com/containerd/nerdctl/blob/master/docs/ocicrypt.md

CAUTION: This command only encrypt image layers, but does NOT encrypt container config information such as 'Env' and 'Cmd'.
To see non-encrypted information, run 'nerdctl image inspect --mode=native --platform=PLATFORM example.com/foo:encrypted' .

Usage:
  nerdctl image encrypt [flags] <source_ref> <target_ref>...

Flags:
      --all-platforms           Convert content for all platforms
      --dec-recipient strings   Recipient of the image; used only for PKCS7 and must be an x509 certificate
      --gpg-homedir string      The GPG homedir to use; by default gpg uses ~/.gnupg
      --gpg-version string      The GPG version ("v1" or "v2"), default will make an educated guess
  -h, --help                    help for encrypt
      --key strings             A secret key's filename and an optional password separated by colon; this option may be provided multiple times
      --platform strings        Convert content for a specific platform
      --recipient strings       Recipient of the image is the person who can decrypt it in the form specified above (i.e. jwe:/path/to/pubkey)

Global Flags:
...

nerctl image decrypt

$ nerdctl image decrypt --help
Decrypt an image locally.

Use '--key' to specify the private keys.
Private keys in PEM format may be encrypted and the password may be passed
along in any of the following formats:
- <filename>:<password>
- <filename>:pass=<password>
- <filename>:fd=<file descriptor> (not available for rootless mode)
- <filename>:filename=<password file>

Use '--platform' to define the platforms to decrypt. Defaults to the host platform.
When '--all-platforms' is given all images in a manifest list must be available.
Unspecified platforms are omitted from the output image.

Example (encrypt):
  openssl genrsa -out mykey.pem
  openssl rsa -in mykey.pem -pubout -out mypubkey.pem
  nerdctl image encrypt --recipient=jwe:mypubkey.pem --platform=linux/amd64,linux/arm64 foo example.com/foo:encrypted
  nerdctl push example.com/foo:encrypted

Example (decrypt):
  nerdctl pull --unpack=false example.com/foo:encrypted
  nerdctl decrypt --key=mykey.pem example.com/foo:encrypted foo:decrypted

Usage:
  nerdctl image decrypt [flags] <source_ref> <target_ref>...

Flags:
      --all-platforms           Convert content for all platforms
      --dec-recipient strings   Recipient of the image; used only for PKCS7 and must be an x509 certificate
      --gpg-homedir string      The GPG homedir to use; by default gpg uses ~/.gnupg
      --gpg-version string      The GPG version ("v1" or "v2"), default will make an educated guess
  -h, --help                    help for decrypt
      --key strings             A secret key's filename and an optional password separated by colon; this option may be provided multiple times
      --platform strings        Convert content for a specific platform

Global Flags:
...

@AkihiroSuda AkihiroSuda added this to the v0.13.0 milestone Nov 1, 2021
@AkihiroSuda
Copy link
Member Author

I'd like to have this in v0.13, but can be postponed to v0.14.

@AkihiroSuda AkihiroSuda force-pushed the imgcrypt branch 2 times, most recently from 3aa522f to adc7160 Compare November 1, 2021 11:30
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
pkg/imgutil/imgutil.go Outdated Show resolved Hide resolved
docs/ocicrypt.md Outdated Show resolved Hide resolved
cmd/nerdctl/pull.go Outdated Show resolved Hide resolved
Copy link

@lumjjb lumjjb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks awesome! LGTM with Stefan's feedback

docs/ocicrypt.md Show resolved Hide resolved
@AkihiroSuda AkihiroSuda force-pushed the imgcrypt branch 5 times, most recently from b7faabb to d7cc941 Compare November 2, 2021 01:24
docs/ocicrypt.md Outdated Show resolved Hide resolved
Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
…bility

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
Copy link
Member

@ktock ktock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (except typo)

README.md Outdated Show resolved Hide resolved
@AkihiroSuda AkihiroSuda force-pushed the imgcrypt branch 2 times, most recently from f0d6e37 to 27dd90a Compare November 2, 2021 02:06
Encrypt:
  openssl genrsa -out mykey.pem
  openssl rsa -in mykey.pem -pubout -out mypubkey.pem
  nerdctl image encrypt --recipient=jwe:mypubkey.pem --platform=linux/amd64,linux/arm64 foo example.com/foo:encrypted
  nerdctl push example.com/foo:encrypted

Decrypt:
  nerdctl pull --unpack=false example.com/foo:encrypted
  nerdctl decrypt --key=mykey.pem example.com/foo:encrypted foo:decrypted

See also ./docs/ocicrypt.md

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants