mirror of
https://github.com/containers/podman.git
synced 2025-10-25 02:04:43 +08:00
Adding encryption decryption feature
Signed-off-by: Tarun1 Gupta <gupttaru@deshaw.com>
This commit is contained in:
@ -571,9 +571,18 @@ func DefineCreateFlags(cmd *cobra.Command, cf *entities.ContainerCreateOptions,
|
||||
createFlags.StringVar(&cf.PasswdEntry, passwdEntryName, "", "Entry to write to /etc/passwd")
|
||||
_ = cmd.RegisterFlagCompletionFunc(passwdEntryName, completion.AutocompleteNone)
|
||||
|
||||
decryptionKeysFlagName := "decryption-key"
|
||||
createFlags.StringSliceVar(
|
||||
&cf.DecryptionKeys,
|
||||
decryptionKeysFlagName, []string{},
|
||||
"Key needed to decrypt the image (e.g. /path/to/key.pem)",
|
||||
)
|
||||
_ = cmd.RegisterFlagCompletionFunc(decryptionKeysFlagName, completion.AutocompleteNone)
|
||||
|
||||
if registry.IsRemote() {
|
||||
_ = createFlags.MarkHidden("env-host")
|
||||
_ = createFlags.MarkHidden("http-proxy")
|
||||
_ = createFlags.MarkHidden(decryptionKeysFlagName)
|
||||
} else {
|
||||
createFlags.StringVar(
|
||||
&cf.SignaturePolicy,
|
||||
|
||||
@ -334,15 +334,21 @@ func PullImage(imageName string, cliVals *entities.ContainerCreateOptions) (stri
|
||||
skipTLSVerify = types.NewOptionalBool(!cliVals.TLSVerify.Value())
|
||||
}
|
||||
|
||||
decConfig, err := util.DecryptConfig(cliVals.DecryptionKeys)
|
||||
if err != nil {
|
||||
return "unable to obtain decryption config", err
|
||||
}
|
||||
|
||||
pullReport, pullErr := registry.ImageEngine().Pull(registry.GetContext(), imageName, entities.ImagePullOptions{
|
||||
Authfile: cliVals.Authfile,
|
||||
Quiet: cliVals.Quiet,
|
||||
Arch: cliVals.Arch,
|
||||
OS: cliVals.OS,
|
||||
Variant: cliVals.Variant,
|
||||
SignaturePolicy: cliVals.SignaturePolicy,
|
||||
PullPolicy: pullPolicy,
|
||||
SkipTLSVerify: skipTLSVerify,
|
||||
Authfile: cliVals.Authfile,
|
||||
Quiet: cliVals.Quiet,
|
||||
Arch: cliVals.Arch,
|
||||
OS: cliVals.OS,
|
||||
Variant: cliVals.Variant,
|
||||
SignaturePolicy: cliVals.SignaturePolicy,
|
||||
PullPolicy: pullPolicy,
|
||||
SkipTLSVerify: skipTLSVerify,
|
||||
OciDecryptConfig: decConfig,
|
||||
})
|
||||
if pullErr != nil {
|
||||
return "", pullErr
|
||||
|
||||
@ -23,6 +23,7 @@ type pullOptionsWrapper struct {
|
||||
entities.ImagePullOptions
|
||||
TLSVerifyCLI bool // CLI only
|
||||
CredentialsCLI string
|
||||
DecryptionKeys []string
|
||||
}
|
||||
|
||||
var (
|
||||
@ -107,6 +108,13 @@ func pullFlags(cmd *cobra.Command) {
|
||||
flags.StringVar(&pullOptions.Authfile, authfileFlagName, auth.GetDefaultAuthFile(), "Path of the authentication file. Use REGISTRY_AUTH_FILE environment variable to override")
|
||||
_ = cmd.RegisterFlagCompletionFunc(authfileFlagName, completion.AutocompleteDefault)
|
||||
|
||||
decryptionKeysFlagName := "decryption-key"
|
||||
flags.StringSliceVar(&pullOptions.DecryptionKeys, decryptionKeysFlagName, nil, "Key needed to decrypt the image (e.g. /path/to/key.pem)")
|
||||
_ = cmd.RegisterFlagCompletionFunc(decryptionKeysFlagName, completion.AutocompleteDefault)
|
||||
|
||||
if registry.IsRemote() {
|
||||
_ = flags.MarkHidden(decryptionKeysFlagName)
|
||||
}
|
||||
if !registry.IsRemote() {
|
||||
certDirFlagName := "cert-dir"
|
||||
flags.StringVar(&pullOptions.CertDir, certDirFlagName, "", "`Pathname` of a directory containing TLS certificates and keys")
|
||||
@ -156,6 +164,12 @@ func imagePull(cmd *cobra.Command, args []string) error {
|
||||
pullOptions.Password = creds.Password
|
||||
}
|
||||
|
||||
decConfig, err := util.DecryptConfig(pullOptions.DecryptionKeys)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to obtain decryption config: %w", err)
|
||||
}
|
||||
pullOptions.OciDecryptConfig = decConfig
|
||||
|
||||
if !pullOptions.Quiet {
|
||||
pullOptions.Writer = os.Stderr
|
||||
}
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package images
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/containers/common/pkg/auth"
|
||||
@ -20,6 +21,8 @@ type pushOptionsWrapper struct {
|
||||
TLSVerifyCLI bool // CLI only
|
||||
CredentialsCLI string
|
||||
SignPassphraseFileCLI string
|
||||
EncryptionKeys []string
|
||||
EncryptLayers []int
|
||||
}
|
||||
|
||||
var (
|
||||
@ -121,6 +124,14 @@ func pushFlags(cmd *cobra.Command) {
|
||||
flags.StringVar(&pushOptions.CompressionFormat, compressionFormat, "", "compression format to use")
|
||||
_ = cmd.RegisterFlagCompletionFunc(compressionFormat, common.AutocompleteCompressionFormat)
|
||||
|
||||
encryptionKeysFlagName := "encryption-key"
|
||||
flags.StringSliceVar(&pushOptions.EncryptionKeys, encryptionKeysFlagName, nil, "Key with the encryption protocol to use to encrypt the image (e.g. jwe:/path/to/key.pem)")
|
||||
_ = cmd.RegisterFlagCompletionFunc(encryptionKeysFlagName, completion.AutocompleteDefault)
|
||||
|
||||
encryptLayersFlagName := "encrypt-layer"
|
||||
flags.IntSliceVar(&pushOptions.EncryptLayers, encryptLayersFlagName, nil, "Layers to encrypt, 0-indexed layer indices with support for negative indexing (e.g. 0 is the first layer, -1 is the last layer). If not defined, will encrypt all layers if encryption-key flag is specified")
|
||||
_ = cmd.RegisterFlagCompletionFunc(encryptLayersFlagName, completion.AutocompleteDefault)
|
||||
|
||||
if registry.IsRemote() {
|
||||
_ = flags.MarkHidden("cert-dir")
|
||||
_ = flags.MarkHidden("compress")
|
||||
@ -129,6 +140,8 @@ func pushFlags(cmd *cobra.Command) {
|
||||
_ = flags.MarkHidden(signByFlagName)
|
||||
_ = flags.MarkHidden(signBySigstorePrivateKeyFlagName)
|
||||
_ = flags.MarkHidden(signPassphraseFileFlagName)
|
||||
_ = flags.MarkHidden(encryptionKeysFlagName)
|
||||
_ = flags.MarkHidden(encryptLayersFlagName)
|
||||
}
|
||||
if !registry.IsRemote() {
|
||||
flags.StringVar(&pushOptions.SignaturePolicy, "signature-policy", "", "Path to a signature-policy file")
|
||||
@ -172,6 +185,13 @@ func imagePush(cmd *cobra.Command, args []string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
encConfig, encLayers, err := util.EncryptConfig(pushOptions.EncryptionKeys, pushOptions.EncryptLayers)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to obtain encryption config: %w", err)
|
||||
}
|
||||
pushOptions.OciEncryptConfig = encConfig
|
||||
pushOptions.OciEncryptLayers = encLayers
|
||||
|
||||
// Let's do all the remaining Yoga in the API to prevent us from scattering
|
||||
// logic across (too) many parts of the code.
|
||||
return registry.ImageEngine().Push(registry.GetContext(), source, destination, pushOptions.ImagePushOptions)
|
||||
|
||||
Reference in New Issue
Block a user