estesp / manifest-tool

Command line tool to create and query container image manifest list/indexes
Apache License 2.0
741 stars 92 forks source link

Panic when using the `--docker-cfg` flag #163

Closed jianzhangbjz closed 2 years ago

jianzhangbjz commented 2 years ago

manifest-tool version:

[cloud-user@preserve-olm-env2 manifest-tool]$ manifest-tool --version
manifest-tool version 2.0.4-dev (commit: ab59f071d40bc0bc98805adf9028e8caddc567c6)

help info:

[cloud-user@preserve-olm-env2 manifest-tool]$ ./manifest-tool --help
NAME:
   ./manifest-tool - registry client to inspect and push multi-platform OCI & Docker v2 images

USAGE:
   manifest-tool [global options] command [command options] [arguments...]

VERSION:
   2.0.4-dev (commit: ab59f071d40bc0bc98805adf9028e8caddc567c6)

COMMANDS:
   inspect  fetch image manifests in a container registry
   push     push a manifest list/OCI index entry to a registry with provided image details
   help, h  Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --debug             enable debug output
   --insecure          allow insecure registry communication
   --plain-http        allow registry communication over plain http
   --username value    registry username
   --password value    registry password
   --docker-cfg value  Docker's cli config for auth (default: "/home/cloud-user/.docker")
   --help, -h          show help
   --version, -v       print the version

It panics when I specify another auth file path.

[cloud-user@preserve-olm-env2 manifest-tool]$ manifest-tool --docker-cfg /run/user/1000/containers/auth.json inspect ec2-3-129-42-113.us-east-2.compute.amazonaws.com:5000/olmqe/learn-operator:3bc481c2
WARN[0000] Error loading auth file: /run/user/1000/containers/auth.json/config.json: stat /run/user/1000/containers/auth.json/config.json: not a directory 
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x28 pc=0x826a3c]

goroutine 1 [running]:
github.com/estesp/manifest-tool/v2/pkg/util.NewResolver({0x0, 0x0}, {0x0, 0x0}, 0xc0, 0x0, {0xc0001ff4b0, 0x0, 0xe6f79a8982779ad5})
    /data/jian/manifest-tool/v2/pkg/util/resolver.go:39 +0x2bc
main.glob..func1(0xc0000e82c0)
    /data/jian/manifest-tool/v2/cmd/manifest-tool/inspect.go:45 +0x40a
github.com/urfave/cli.HandleAction({0x8ea4e0, 0x9ccfa8}, 0x7)
    /data/jian/manifest-tool/v2/vendor/github.com/urfave/cli/app.go:525 +0x50
github.com/urfave/cli.Command.Run({{0x99f11f, 0x7}, {0x0, 0x0}, {0x0, 0x0, 0x0}, {0x9b8028, 0x2d}, {0x0, ...}, ...}, ...)
    /data/jian/manifest-tool/v2/vendor/github.com/urfave/cli/command.go:174 +0x63a
github.com/urfave/cli.(*App).Run(0xc0004081c0, {0xc0000200a0, 0x5, 0x5})
    /data/jian/manifest-tool/v2/vendor/github.com/urfave/cli/app.go:276 +0x80c
main.runApplication()
    /data/jian/manifest-tool/v2/cmd/manifest-tool/main.go:75 +0x5e5
main.main()
    /data/jian/manifest-tool/v2/cmd/manifest-tool/main.go:20 +0x19

Seems like the root cause is here, it adds a hard-code file name:config.json.

WARN[0000] Error loading auth file: /run/user/1000/containers/auth.json/config.json: stat /run/user/1000/containers/auth.json/config.json: not a directory` I specify the `/run/user/1000/containers/auth.json/`

Maybe we should update the help info: --docker-cfg value Docker's cli config for auth (default: "/home/cloud-user/.docker") Or update this flag to compatible with podman auth file.

estesp commented 2 years ago

Good catch; I didn't realize I was specifying the file config.json by appending it to whatever was passed via the --docker-cfg flag (which defaulted to the Docker directory). Creating a PR to handle passing a full explicit file OR a directory and will update the help text appropriately.

estesp commented 2 years ago

See #168 for a fix