Skip to content

Commit

Permalink
podman-remote does not support signature-policy
Browse files Browse the repository at this point in the history
Fixes: containers#12357

Signed-off-by: Daniel J Walsh <[email protected]>
  • Loading branch information
rhatdan committed Nov 19, 2021
1 parent 2755d02 commit 21629b0
Show file tree
Hide file tree
Showing 12 changed files with 70 additions and 33 deletions.
13 changes: 7 additions & 6 deletions cmd/podman/common/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -551,11 +551,6 @@ func DefineCreateFlags(cmd *cobra.Command, cf *entities.ContainerCreateOptions,
_ = cmd.RegisterFlagCompletionFunc(shmSizeFlagName, completion.AutocompleteNone)

stopSignalFlagName := "stop-signal"
createFlags.StringVar(
&cf.SignaturePolicy,
"signature-policy", "",
"`Pathname` of signature policy file (not usually used)",
)
createFlags.StringVar(
&cf.StopSignal,
stopSignalFlagName, "",
Expand Down Expand Up @@ -702,10 +697,16 @@ func DefineCreateFlags(cmd *cobra.Command, cf *entities.ContainerCreateOptions,
"Write the container process ID to the file")
_ = cmd.RegisterFlagCompletionFunc(pidFileFlagName, completion.AutocompleteDefault)

_ = createFlags.MarkHidden("signature-policy")
if registry.IsRemote() {
_ = createFlags.MarkHidden("env-host")
_ = createFlags.MarkHidden("http-proxy")
} else {
createFlags.StringVar(
&cf.SignaturePolicy,
"signature-policy", "",
"`Pathname` of signature policy file (not usually used)",
)
_ = createFlags.MarkHidden("signature-policy")
}

createFlags.BoolVar(
Expand Down
7 changes: 4 additions & 3 deletions cmd/podman/containers/runlabel.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,17 @@ func init() {
flags.BoolVarP(&runlabelOptions.Pull, "pull", "p", true, "Pull the image if it does not exist locally prior to executing the label contents")
flags.BoolVarP(&runlabelOptions.Quiet, "quiet", "q", false, "Suppress output information when installing images")
flags.BoolVar(&runlabelOptions.Replace, "replace", false, "Replace existing container with a new one from the image")
flags.StringVar(&runlabelOptions.SignaturePolicy, "signature-policy", "", "`Pathname` of signature policy file (not usually used)")
flags.BoolVar(&runlabelOptions.TLSVerifyCLI, "tls-verify", true, "Require HTTPS and verify certificates when contacting registries")

// Hide the optional flags.
_ = flags.MarkHidden("opt1")
_ = flags.MarkHidden("opt2")
_ = flags.MarkHidden("opt3")
_ = flags.MarkHidden("pull")
_ = flags.MarkHidden("signature-policy")

if !registry.IsRemote() {
flags.StringVar(&runlabelOptions.SignaturePolicy, "signature-policy", "", "`Pathname` of signature policy file (not usually used)")
_ = flags.MarkHidden("signature-policy")
}
if err := flags.MarkDeprecated("pull", "podman will pull if not found in local storage"); err != nil {
logrus.Error("unable to mark pull flag deprecated")
}
Expand Down
6 changes: 4 additions & 2 deletions cmd/podman/images/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,10 @@ func importFlags(cmd *cobra.Command) {
_ = cmd.RegisterFlagCompletionFunc(messageFlagName, completion.AutocompleteNone)

flags.BoolVarP(&importOpts.Quiet, "quiet", "q", false, "Suppress output")
flags.StringVar(&importOpts.SignaturePolicy, "signature-policy", "", "Path to a signature-policy file")
_ = flags.MarkHidden("signature-policy")
if !registry.IsRemote() {
flags.StringVar(&importOpts.SignaturePolicy, "signature-policy", "", "Path to a signature-policy file")
_ = flags.MarkHidden("signature-policy")
}
}

func importCon(cmd *cobra.Command, args []string) error {
Expand Down
6 changes: 4 additions & 2 deletions cmd/podman/images/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ func loadFlags(cmd *cobra.Command) {
_ = cmd.RegisterFlagCompletionFunc(inputFlagName, completion.AutocompleteDefault)

flags.BoolVarP(&loadOpts.Quiet, "quiet", "q", false, "Suppress the output")
flags.StringVar(&loadOpts.SignaturePolicy, "signature-policy", "", "Pathname of signature policy file")
_ = flags.MarkHidden("signature-policy")
if !registry.IsRemote() {
flags.StringVar(&loadOpts.SignaturePolicy, "signature-policy", "", "Pathname of signature policy file")
_ = flags.MarkHidden("signature-policy")
}
}

func load(cmd *cobra.Command, args []string) error {
Expand Down
6 changes: 4 additions & 2 deletions cmd/podman/images/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ func pullFlags(cmd *cobra.Command) {

flags.Bool("disable-content-trust", false, "This is a Docker specific option and is a NOOP")
flags.BoolVarP(&pullOptions.Quiet, "quiet", "q", false, "Suppress output information when pulling images")
flags.StringVar(&pullOptions.SignaturePolicy, "signature-policy", "", "`Pathname` of signature policy file (not usually used)")
flags.BoolVar(&pullOptions.TLSVerifyCLI, "tls-verify", true, "Require HTTPS and verify certificates when contacting registries")

authfileFlagName := "authfile"
Expand All @@ -113,7 +112,10 @@ func pullFlags(cmd *cobra.Command) {
flags.StringVar(&pullOptions.CertDir, certDirFlagName, "", "`Pathname` of a directory containing TLS certificates and keys")
_ = cmd.RegisterFlagCompletionFunc(certDirFlagName, completion.AutocompleteDefault)
}
_ = flags.MarkHidden("signature-policy")
if !registry.IsRemote() {
flags.StringVar(&pullOptions.SignaturePolicy, "signature-policy", "", "`Pathname` of signature policy file (not usually used)")
_ = flags.MarkHidden("signature-policy")
}
}

// imagePull is implement the command for pulling images.
Expand Down
6 changes: 4 additions & 2 deletions cmd/podman/images/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ func pushFlags(cmd *cobra.Command) {

flags.BoolVarP(&pushOptions.Quiet, "quiet", "q", false, "Suppress output information when pushing images")
flags.BoolVar(&pushOptions.RemoveSignatures, "remove-signatures", false, "Discard any pre-existing signatures in the image")
flags.StringVar(&pushOptions.SignaturePolicy, "signature-policy", "", "Path to a signature-policy file")

signByFlagName := "sign-by"
flags.StringVar(&pushOptions.SignBy, signByFlagName, "", "Add a signature at the destination using the specified key")
Expand All @@ -117,7 +116,10 @@ func pushFlags(cmd *cobra.Command) {
_ = flags.MarkHidden("remove-signatures")
_ = flags.MarkHidden("sign-by")
}
_ = flags.MarkHidden("signature-policy")
if !registry.IsRemote() {
flags.StringVar(&pushOptions.SignaturePolicy, "signature-policy", "", "Path to a signature-policy file")
_ = flags.MarkHidden("signature-policy")
}
}

// imagePush is implement the command for pushing images.
Expand Down
9 changes: 6 additions & 3 deletions cmd/podman/play/kube.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,6 @@ func init() {
flags.StringVar(&kubeOptions.CertDir, certDirFlagName, "", "`Pathname` of a directory containing TLS certificates and keys")
_ = kubeCmd.RegisterFlagCompletionFunc(certDirFlagName, completion.AutocompleteDefault)

flags.StringVar(&kubeOptions.SignaturePolicy, "signature-policy", "", "`Pathname` of signature policy file (not usually used)")

seccompProfileRootFlagName := "seccomp-profile-root"
flags.StringVar(&kubeOptions.SeccompProfileRoot, seccompProfileRootFlagName, defaultSeccompRoot, "Directory path for seccomp profiles")
_ = kubeCmd.RegisterFlagCompletionFunc(seccompProfileRootFlagName, completion.AutocompleteDefault)
Expand All @@ -121,7 +119,12 @@ func init() {
buildFlagName := "build"
flags.BoolVar(&kubeOptions.Build, buildFlagName, false, "Build all images in a YAML (given Containerfiles exist)")
}
_ = flags.MarkHidden("signature-policy")

if !registry.IsRemote() {
flags.StringVar(&kubeOptions.SignaturePolicy, "signature-policy", "", "`Pathname` of signature policy file (not usually used)")

_ = flags.MarkHidden("signature-policy")
}
}

func kube(cmd *cobra.Command, args []string) error {
Expand Down
8 changes: 6 additions & 2 deletions test/e2e/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,14 +363,18 @@ var _ = Describe("Podman create", func() {
})

It("podman create --signature-policy", func() {
SkipIfRemote("SigPolicy not handled by remote")
session := podmanTest.Podman([]string{"create", "--pull=always", "--signature-policy", "/no/such/file", ALPINE})
session.WaitWithDefaultTimeout()
Expect(session).To(ExitWithError())

session = podmanTest.Podman([]string{"create", "--pull=always", "--signature-policy", "/etc/containers/policy.json", ALPINE})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
if IsRemote() {
Expect(session).To(ExitWithError())
Expect(session.ErrorToString()).To(ContainSubstring("unknown flag"))
} else {
Expect(session).Should(Exit(0))
}
})

It("podman create with unset label", func() {
Expand Down
6 changes: 6 additions & 0 deletions test/e2e/import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,12 @@ var _ = Describe("Podman import", func() {

result := podmanTest.Podman([]string{"import", "--signature-policy", "/etc/containers/policy.json", outfile})
result.WaitWithDefaultTimeout()
if IsRemote() {
Expect(result).To(ExitWithError())
Expect(result.ErrorToString()).To(ContainSubstring("unknown flag"))
result := podmanTest.Podman([]string{"import", outfile})
result.WaitWithDefaultTimeout()
}
Expect(result).Should(Exit(0))
})
})
10 changes: 9 additions & 1 deletion test/e2e/load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,15 @@ var _ = Describe("Podman load", func() {

result := podmanTest.Podman([]string{"load", "--signature-policy", "/etc/containers/policy.json", "-i", outfile})
result.WaitWithDefaultTimeout()
Expect(result).Should(Exit(0))
if IsRemote() {
Expect(result).To(ExitWithError())
Expect(result.ErrorToString()).To(ContainSubstring("unknown flag"))
result = podmanTest.Podman([]string{"load", "-i", outfile})
result.WaitWithDefaultTimeout()
Expect(result).Should(Exit(0))
} else {
Expect(result).Should(Exit(0))
}
})

It("podman load with quiet flag", func() {
Expand Down
8 changes: 6 additions & 2 deletions test/e2e/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,18 @@ var _ = Describe("Podman run", func() {
})

It("podman run --signature-policy", func() {
SkipIfRemote("SigPolicy not handled by remote")
session := podmanTest.Podman([]string{"run", "--pull=always", "--signature-policy", "/no/such/file", ALPINE})
session.WaitWithDefaultTimeout()
Expect(session).To(ExitWithError())

session = podmanTest.Podman([]string{"run", "--pull=always", "--signature-policy", "/etc/containers/policy.json", ALPINE})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
if IsRemote() {
Expect(session).To(ExitWithError())
Expect(session.ErrorToString()).To(ContainSubstring("unknown flag"))
} else {
Expect(session).Should(Exit(0))
}
})

It("podman run --rm with --restart", func() {
Expand Down
18 changes: 10 additions & 8 deletions test/e2e/save_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,16 @@ default-docker:
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))

session = podmanTest.Podman([]string{"pull", "--tls-verify=false", "--signature-policy=sign/policy.json", "localhost:5000/alpine"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))

outfile := filepath.Join(podmanTest.TempDir, "temp.tar")
save := podmanTest.Podman([]string{"save", "remove-signatures=true", "-o", outfile, "localhost:5000/alpine"})
save.WaitWithDefaultTimeout()
Expect(save).To(ExitWithError())
if !IsRemote() {
session = podmanTest.Podman([]string{"pull", "--tls-verify=false", "--signature-policy=sign/policy.json", "localhost:5000/alpine"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))

outfile := filepath.Join(podmanTest.TempDir, "temp.tar")
save := podmanTest.Podman([]string{"save", "remove-signatures=true", "-o", outfile, "localhost:5000/alpine"})
save.WaitWithDefaultTimeout()
Expect(save).To(ExitWithError())
}
})

It("podman save image with digest reference", func() {
Expand Down

0 comments on commit 21629b0

Please sign in to comment.