github.com/containerd/nerdctl@v1.7.7/cmd/nerdctl/image_encrypt.go (about) 1 /* 2 Copyright The containerd Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package main 18 19 import ( 20 "github.com/spf13/cobra" 21 ) 22 23 const imageEncryptHelp = `Encrypt image layers. 24 25 Use '--recipient' to specify the recipients. 26 The following protocol prefixes are supported: 27 - pgp:<email-address> 28 - jwe:<public-key-file-path> 29 - pkcs7:<x509-file-path> 30 31 Use '--platform' to define the platforms to encrypt. Defaults to the host platform. 32 When '--all-platforms' is given all images in a manifest list must be available. 33 Unspecified platforms are omitted from the output image. 34 35 Example: 36 openssl genrsa -out mykey.pem 37 openssl rsa -in mykey.pem -pubout -out mypubkey.pem 38 nerdctl image encrypt --recipient=jwe:mypubkey.pem --platform=linux/amd64,linux/arm64 foo example.com/foo:encrypted 39 nerdctl push example.com/foo:encrypted 40 41 To run the encrypted image, put the private key file (mykey.pem) to /etc/containerd/ocicrypt/keys (rootful) or ~/.config/containerd/ocicrypt/keys (rootless). 42 containerd before v1.4 requires extra configuration steps, see https://github.com/containerd/nerdctl/blob/main/docs/ocicrypt.md 43 44 CAUTION: This command only encrypts image layers, but does NOT encrypt container configuration such as 'Env' and 'Cmd'. 45 To see non-encrypted information, run 'nerdctl image inspect --mode=native --platform=PLATFORM example.com/foo:encrypted' . 46 ` 47 48 func newImageEncryptCommand() *cobra.Command { 49 cmd := &cobra.Command{ 50 Use: "encrypt [flags] <source_ref> <target_ref>...", 51 Short: "encrypt image layers", 52 Long: imageEncryptHelp, 53 Args: cobra.MinimumNArgs(2), 54 RunE: getImgcryptAction(true), 55 ValidArgsFunction: imgcryptShellComplete, 56 SilenceUsage: true, 57 SilenceErrors: true, 58 } 59 registerImgcryptFlags(cmd, true) 60 return cmd 61 }