Commit Graph

22 Commits

Author SHA1 Message Date
Valentin Rothberg c9914e52de pkg/auth: re-allow http{s} prefixes
Until version v3.2, `podman login` trimmed http{s} prefixes along with
everything else but the host[:port] parts.  Starting with v3.3, `login`
supports storing credentials for namespaces and dropped support for
trimming prefixes due to ambiguities in registry URLs.

The aforementioned changes caused a regression (see BZ below) as some
users depend on the prefix trimming.  Fix that regression by enabling
the http{s} prefix trimming.  If present, everything but the host[:port]
parts will be stripped as well.

 * `login quay.io/repo` uses `quay.io/repo`
 * `login https://quay.io/repo` uses `quay.io`

Fixes: bugzilla.redhat.com/show_bug.cgi?id=2062072
Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2022-03-17 10:11:26 +01:00
Jason T. Greene c50f702af7 Fix console password reading on Windows
The windows handle is not on fd 0 (it's -10), so access through os.Stdin

Signed-off-by: Jason T. Greene <jason.greene@redhat.com>
2022-02-03 16:49:18 -06:00
Miloslav Trmač 620331697f Stop returning a reference.Named from parseRegistryArgument
... and instead primarily use the string key.  This allows
using a docker.io/vendor namespace.

Also rename parseRegistryArgument to parseCredentialsKey,
the argument is not just a registry.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2021-12-02 15:48:44 +01:00
Miloslav Trmač b53b2ebfbe Don't use ref from parserRegistryArgument
We can now call GetCredentials with namespaced keys,
so simplify.

The ref value is still computed, we'll remove that momentarily.

Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2021-12-02 15:48:44 +01:00
Miloslav Trmač db22f1cbfa Use a switch for parsing arguments in Logout
This avoids duplication and non-obvious interactions (where "!= 0"
means "== 1"), and is more similar to Login.

Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2021-12-02 15:42:56 +01:00
Miloslav Trmač 42c4bdc016 Handle logout --all first
Only test opts.All once instead of three times.

Don't even start worrying about key/registry with --all.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2021-12-02 15:42:56 +01:00
Miloslav Trmač e0b05e152e Remove a single-use variable in Login
Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2021-12-02 15:42:56 +01:00
Miloslav Trmač 2db91a8d01 Don't return irrelevant values on error paths of parseRegistryArgument
The caller shouldn't care anyway.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2021-12-02 15:42:56 +01:00
dependabot[bot] 55204ee364 build(deps): bump github.com/containers/image/v5 from 5.14.0 to 5.15.0
Bumps [github.com/containers/image/v5](https://github.com/containers/image) from 5.14.0 to 5.15.0.
- [Release notes](https://github.com/containers/image/releases)
- [Commits](https://github.com/containers/image/compare/v5.14.0...v5.15.0)

---
updated-dependencies:
- dependency-name: github.com/containers/image/v5
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2021-08-02 16:02:52 +02:00
Sascha Grunert 9f3d6b6bdd Add support for path based registry in login/logout
We now add a new configuration option to opt-in for path based registry
authentication in containers-auth.json. This affects login and logout,
which means if the option is enabled we can now use
`my-registry.local/path/to/image` to save or remove the credentials from
the auth.json.

If the option is enabled, then we enforce a stricter validation of the
input. For example it is not allowed input `http[s]://` prefixed keys.

Signed-off-by: Sascha Grunert <sgrunert@redhat.com>
2021-07-23 09:41:19 +02:00
flouthoc 71eec0674b Use SetCredentials and add verbose to loginopts
Signed-off-by: flouthoc <flouthoc.git@gmail.com>
2021-06-16 13:56:07 +05:30
Valentin Rothberg 32a28aee73 new libimage package
The new `libimage` package is an attempt to consolidate the code for
managing container images and performing operations on them such as
pulling, pushing, saving, searching, local lookups, removing etc.

Over time, Buildah, CRI-O and Podman diverged with respect to managing
container images resulting in a high amount of code duplication
rendering the tools harder to maintain (e.g., bug fixes) and harder to
extend (e.g., adding new features) than necessary.

The desire to share all that code in a common library grew and this is
an attempt to address the it.

The changes as they are now pass Buildah CI [1].  Once merged into
Buildah, I expect follow up changes when migrating Podman over to
`libimage`.

Miscellaneous changes:

* Copy `podman/pkg/signal` to `pkg/signal`.

* Copy `buildah/manifests` to `image/manifests`. Note that the unit
  tests require root privileges. Skip()'s are added when running
  rootless.  Currently excluded from linting.

* Copy `buildah/pkg/manifests` to `pkg/manifests`.  Currently excluded
  from linting.

* Copy `buildah/pkg/supplemented` to `pkg/supplemented`.  Currently
  excluded from linting.

[1] github.com/containers/buildah/pull/3148

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2021-04-21 11:17:47 +02:00
Morten Linderud 0356183170 pkg/auth: Ensure DOCKER_CONFIG refers to config.json
`REGISTRY_AUTH_FILE` expects a complete path to the authentication file,
however `DOCKER_CONFIG` only refers to a configuration directory. The
function would only return the directory itself and cause confusing
errors when passed onwards to `container/image`.

    $ DOCKER_CONFIG="/home/fox/.config/docker" podman pull docker.io/alpine
    Trying to pull docker.io/library/alpine:latest...
      read /home/fox/.config/docker: is a directory
    [...]
    $ DOCKER_CONFIG="/home/fox/.config/docker/config.json" podman pull docker.io/alpine
    Trying to pull docker.io/library/alpine:latest...
      open /home/fox/.config/docker/config.json/config.json: not a directory
    [...]

Signed-off-by: Morten Linderud <morten@linderud.pw>
2021-04-07 16:02:58 +02:00
Daniel J Walsh 417d17cba5 [NO TESTS NEEDED] Remove some stuttering on return errors
golang builtin OS functions, include the path to the object being used,
no reason for us to wrap these errors with an object for a second time.

This just causes stuttering, and looks bad at the CLI level.

Existing tests should catch any errors.

Also stop adding "error" to something that is obviusly an error when it
shows up to the user.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-03-29 10:33:18 -04:00
Daniel J Walsh a6447704e3 Stop logging messages about using DOCKER_CONFIG
Since the GetDefaultAuthFile() is caused during podman init
it ends up logging the same info line multiple times, with
no way for the user to quiet the output.

Fixes https://github.com/containers/podman/issues/9473

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-02-22 17:00:05 -05:00
Daniel J Walsh 6172fd7db6 Add support for DOCKER_CONFIG
DOCKER_CONFIG environment variable is sometimes used to point
to the config.json.  The container engines use REGISTRY_AUTH_FILE
for similar functionality.  This PR causes programs that use
GetAuthFile to use DOCKER_CONFIG if it set and REGISTRY_AUTH_FILE
is not.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-12-21 17:07:24 -05:00
Sascha Grunert 89b399d4cf Fix all gocritic lints
This enables the missing gocritic checks and fixes all of the lints.

Signed-off-by: Sascha Grunert <sgrunert@suse.com>
2020-08-25 20:58:15 +02:00
Daniel J Walsh 276ce73e39 Fix duplicated code found by codeverity.
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-08-12 10:55:46 -04:00
Qi Wang cdc87dc2bd logout suggests logout with docker
logout suggests logout with docker if credential exists in ~/.docker/config,json

Signed-off-by: Qi Wang <qiwan@redhat.com>
2020-06-09 20:49:43 -04:00
Miloslav Trmač 1eb5ce9b5b Implement *.AuthFile and LoginOptions.CertDir
... so that the callers don't have to implement options they
haven't defined.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2020-05-07 22:50:21 +02:00
Qi Wang 1d57954f2c auth pkg supports login empty argument
Signed-off-by: Qi Wang <qiwan@redhat.com>
2020-05-06 12:16:50 -04:00
Qi Wang 6b9441182d Add pkg/auth common code for login/logout
pkg/auth includes CLI options definitions and implementatoin of login/logout.

Signed-off-by: Qi Wang <qiwan@redhat.com>
2020-04-09 13:38:57 -04:00