manifest inspect: support authentication

Previous tests have worked by pure chance since the client and server
ran on the same host; the server picked up the credentials created by
the client login.

Extend the gating tests and add a new integration test which is further
capable of exercising the remote code.

Note that fixing authentication support requires adding a new
`--authfile` CLi flag to `manifest inspect`.  This will at least allow
for passing an authfile to be bindings.  Username and password are not
yet supported.

Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
This commit is contained in:
Valentin Rothberg
2023-07-10 10:52:01 +02:00
parent 7cd1fb77f9
commit a69194b02f
13 changed files with 135 additions and 41 deletions

View File

@ -3,6 +3,8 @@ package manifest
import (
"fmt"
"github.com/containers/common/pkg/auth"
"github.com/containers/common/pkg/completion"
"github.com/containers/image/v5/types"
"github.com/containers/podman/v4/cmd/podman/common"
"github.com/containers/podman/v4/cmd/podman/registry"
@ -11,8 +13,9 @@ import (
)
var (
tlsVerifyCLI bool
inspectCmd = &cobra.Command{
inspectOptions entities.ManifestInspectOptions
tlsVerifyCLI bool
inspectCmd = &cobra.Command{
Use: "inspect [options] IMAGE",
Short: "Display the contents of a manifest list or image index",
Long: "Display the contents of a manifest list or image index.",
@ -30,6 +33,9 @@ func init() {
})
flags := inspectCmd.Flags()
authfileFlagName := "authfile"
flags.StringVar(&inspectOptions.Authfile, authfileFlagName, auth.GetDefaultAuthFile(), "path of the authentication file. Use REGISTRY_AUTH_FILE environment variable to override")
_ = inspectCmd.RegisterFlagCompletionFunc(authfileFlagName, completion.AutocompleteDefault)
flags.BoolP("verbose", "v", false, "Added for Docker compatibility")
_ = flags.MarkHidden("verbose")
flags.BoolVar(&tlsVerifyCLI, "tls-verify", true, "require HTTPS and verify certificates when accessing the registry")
@ -38,14 +44,13 @@ func init() {
}
func inspect(cmd *cobra.Command, args []string) error {
opts := entities.ManifestInspectOptions{}
if cmd.Flags().Changed("tls-verify") {
opts.SkipTLSVerify = types.NewOptionalBool(!tlsVerifyCLI)
inspectOptions.SkipTLSVerify = types.NewOptionalBool(!tlsVerifyCLI)
} else if cmd.Flags().Changed("insecure") {
insecure, _ := cmd.Flags().GetBool("insecure")
opts.SkipTLSVerify = types.NewOptionalBool(insecure)
inspectOptions.SkipTLSVerify = types.NewOptionalBool(insecure)
}
buf, err := registry.ImageEngine().ManifestInspect(registry.Context(), args[0], opts)
buf, err := registry.ImageEngine().ManifestInspect(registry.Context(), args[0], inspectOptions)
if err != nil {
return err
}