diff --git a/cmd/podman/root.go b/cmd/podman/root.go index 86f42d1c4b..a10ede54a9 100644 --- a/cmd/podman/root.go +++ b/cmd/podman/root.go @@ -400,7 +400,10 @@ func persistentPostRunE(cmd *cobra.Command, args []string) error { func configHook() { if dockerConfig != "" { - logrus.Warn("The --config flag is ignored by Podman. Exists for Docker compatibility") + if err := os.Setenv("DOCKER_CONFIG", dockerConfig); err != nil { + fmt.Fprintf(os.Stderr, "cannot set DOCKER_CONFIG=%s: %s", dockerConfig, err.Error()) + os.Exit(1) + } } } @@ -476,8 +479,10 @@ func rootFlags(cmd *cobra.Command, podmanConfig *entities.PodmanConfig) { lFlags.StringVarP(&podmanConfig.URI, "host", "H", podmanConfig.URI, "Used for Docker compatibility") _ = lFlags.MarkHidden("host") - lFlags.StringVar(&dockerConfig, "config", "", "Ignored for Docker compatibility") - _ = lFlags.MarkHidden("config") + configFlagName := "config" + lFlags.StringVar(&dockerConfig, "config", "", "Location of authentication config file") + _ = cmd.RegisterFlagCompletionFunc(configFlagName, completion.AutocompleteDefault) + // Context option added just for compatibility with DockerCLI. lFlags.String("context", "default", "Name of the context to use to connect to the daemon (This flag is a NOOP and provided solely for scripting compatibility.)") _ = lFlags.MarkHidden("context") diff --git a/docs/source/markdown/podman.1.md b/docs/source/markdown/podman.1.md index 151a7410d5..37480b3ac6 100644 --- a/docs/source/markdown/podman.1.md +++ b/docs/source/markdown/podman.1.md @@ -32,6 +32,9 @@ The CGroup manager to use for container cgroups. Supported values are __cgroupfs Note: Setting this flag can cause certain commands to break when called on containers previously created by the other CGroup manager type. Note: CGroup manager is not supported in rootless mode when using CGroups Version V1. +#### **--config** +Location of config file. Mainly for docker compatibility, only the authentication parts of the config are supported. + #### **--conmon** Path of the conmon binary (Default path is configured in `containers.conf`) diff --git a/pkg/domain/entities/engine.go b/pkg/domain/entities/engine.go index 6c7f0abb4c..3346110d60 100644 --- a/pkg/domain/entities/engine.go +++ b/pkg/domain/entities/engine.go @@ -35,7 +35,7 @@ type PodmanConfig struct { ContainersConf *config.Config ContainersConfDefaultsRO *config.Config // The read-only! defaults from containers.conf. DBBackend string // Hidden: change the database backend - DockerConfig string // Used for Docker compatibility + DockerConfig string // Location of authentication config file CgroupUsage string // rootless code determines Usage message ConmonPath string // --conmon flag will set Engine.ConmonPath CPUProfile string // Hidden: Should CPU profile be taken diff --git a/test/system/001-basic.bats b/test/system/001-basic.bats index 0512accba9..7b4cc58b3e 100644 --- a/test/system/001-basic.bats +++ b/test/system/001-basic.bats @@ -35,9 +35,6 @@ function setup() { run_podman -v is "$output" "podman.*version \+" "'Version line' in output" - - run_podman 0+w --config foobar version - require_warning "The --config flag is ignored by Podman. Exists for Docker compatibility" } # bats test_tags=distro-integration diff --git a/test/system/150-login.bats b/test/system/150-login.bats index f9c6b1394d..f8c2994d2c 100644 --- a/test/system/150-login.bats +++ b/test/system/150-login.bats @@ -91,6 +91,38 @@ function setup() { assert "$output" =~ "Error: options for paths to the credential file and to the Docker-compatible credential file can not be set simultaneously" } +@test "podman login - check with --config global option" { + dockerconfig=${PODMAN_LOGIN_WORKDIR}/docker + rm -rf $dockerconfig + + registry=localhost:${PODMAN_LOGIN_REGISTRY_PORT} + + run_podman --config $dockerconfig login \ + --tls-verify=false \ + --username ${PODMAN_LOGIN_USER} \ + --password ${PODMAN_LOGIN_PASS} \ + $registry + + # Confirm that config file now exists + test -e $dockerconfig/config.json || \ + die "podman login did not create config $dockerconfig/config.json" + + # Special bracket form needed because of colon in host:port + run jq -r ".[\"auths\"][\"$registry\"][\"auth\"]" <$dockerconfig/config.json + is "$status" "0" "jq from $dockerconfig/config.json" + + expect_userpass="${PODMAN_LOGIN_USER}:${PODMAN_LOGIN_PASS}" + actual_userpass=$(base64 -d <<<"$output") + is "$actual_userpass" "$expect_userpass" "credentials stored in $dockerconfig/config.json" + + # Now log out and make sure credentials are removed + run_podman --config $dockerconfig logout $registry + + run jq -r '.auths' <$dockerconfig/config.json + is "$status" "0" "jq from $dockerconfig/config.json" + is "$output" "{}" "credentials removed from $dockerconfig/config.json" +} + # Some push tests @test "podman push fail" {