Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug 1982498: default to podman credential configs #893

Merged
merged 3 commits into from Nov 30, 2021

Conversation

atiratree
Copy link
Member

we should first try podman location for detecting credentials and then check the docker ones

relevant docs:
https://man.archlinux.org/man/community/containers-common/containers-auth.json.5.en
http://docs.podman.io/en/latest/markdown/podman-login.1.html

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Aug 9, 2021

@atiratree: An error was encountered searching for bug 1982498 on the Bugzilla server at https://bugzilla.redhat.com. No known errors were detected, please see the full error message for details.

Full error message. could not unmarshal response body: invalid character '<' looking for beginning of value

Please contact an administrator to resolve this issue, then request a bug refresh with /bugzilla refresh.

In response to this:

Bug 1982498: default to podman credential configs

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@openshift-ci openshift-ci bot added bugzilla/severity-medium Referenced Bugzilla bug's severity is medium for the branch this PR is targeting. bugzilla/invalid-bug Indicates that a referenced Bugzilla bug is invalid for the branch this PR is targeting. labels Aug 9, 2021
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Aug 9, 2021

@atiratree: This pull request references Bugzilla bug 1982498, which is invalid:

  • expected the bug to target the "4.9.0" release, but it targets "---" instead

Comment /bugzilla refresh to re-evaluate validity if changes to the Bugzilla bug are made, or edit the title of this pull request to link to a different bug.

In response to this:

/bugzilla refresh

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Aug 9, 2021

@atiratree: An error was encountered querying GitHub for users with public email (wzheng@redhat.com) for bug 1982498 on the Bugzilla server at https://bugzilla.redhat.com. No known errors were detected, please see the full error message for details.

Full error message. Post "http://ghproxy/graphql": dial tcp 172.30.229.2:80: connect: connection refused

Please contact an administrator to resolve this issue, then request a bug refresh with /bugzilla refresh.

In response to this:

/bugzilla refresh

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@atiratree
Copy link
Member Author

/bugzilla refresh

@openshift-ci openshift-ci bot added the bugzilla/valid-bug Indicates that a referenced Bugzilla bug is valid for the branch this PR is targeting. label Aug 9, 2021
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Aug 9, 2021

@atiratree: This pull request references Bugzilla bug 1982498, which is valid. The bug has been moved to the POST state.

3 validation(s) were run on this bug
  • bug is open, matching expected state (open)
  • bug target release (4.9.0) matches configured target release for branch (4.9.0)
  • bug is in the state NEW, which is one of the valid states (NEW, ASSIGNED, ON_DEV, POST, POST)

Requesting review from QA contact:
/cc @wzheng1

In response to this:

/bugzilla refresh

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@openshift-ci openshift-ci bot removed the bugzilla/invalid-bug Indicates that a referenced Bugzilla bug is invalid for the branch this PR is targeting. label Aug 9, 2021
@openshift-ci openshift-ci bot requested a review from wzheng1 August 9, 2021 17:25
@atiratree
Copy link
Member Author

/assign @soltysh

@xiuwang
Copy link

xiuwang commented Aug 10, 2021

/bugzilla refresh

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Aug 10, 2021

@xiuwang: This pull request references Bugzilla bug 1982498, which is valid.

3 validation(s) were run on this bug
  • bug is open, matching expected state (open)
  • bug target release (4.9.0) matches configured target release for branch (4.9.0)
  • bug is in the state POST, which is one of the valid states (NEW, ASSIGNED, ON_DEV, POST, POST)

Requesting review from QA contact:
/cc @xiuwang

In response to this:

/bugzilla refresh

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@openshift-ci openshift-ci bot requested a review from xiuwang August 10, 2021 02:07
@atiratree
Copy link
Member Author

/retest

1 similar comment
@atiratree
Copy link
Member Author

/retest

@xiuwang
Copy link

xiuwang commented Aug 11, 2021

Build oc from this pr, and report two premerged bugs,
https://bugzilla.redhat.com/show_bug.cgi?id=1992474
https://bugzilla.redhat.com/show_bug.cgi?id=1992468

This pr didn't account the situation when ${XDG_RUNTIME_DIR} and ${XDG_CONFIG_HOME} not set in host. Then the podman login auth will located to a replacement directory with similar capabilities . Like this:
DEBU[0000] Returning credentials from /run/containers/0/auth.json

@atiratree
Copy link
Member Author

atiratree commented Aug 11, 2021

@xiuwang Thanks for the feedback. I have reassessed the logic we have in oc and decided to use the same logic as podman uses. The logic itself is quite complex and is fortunately shared via github.com/containers/image library.

Although bear in mind that even podman doesn't fallback to other locations when ${REGISTRY_AUTH_FILE} or --authfile is specified. So the oc is using the same convention.

Regarding the oc login I think it is not feasible without breaking backwards compatibility (please see the BZ for more details).

@atiratree atiratree force-pushed the podman-credentials branch 2 times, most recently from 56abe09 to ebadfd8 Compare August 11, 2021 18:45
@atiratree
Copy link
Member Author

/retest

1 similar comment
@atiratree
Copy link
Member Author

/retest

@xiuwang
Copy link

xiuwang commented Aug 17, 2021

Hi @atiratree Thanks for update.
I check the oc cmd with new commits.
the option has included ~/.dockercfg file, but oc doesn't query this file when other target files not existing.

-a, --registry-config='': Path to your registry credentials. Alternatively env variable ${REGISTRY_AUTH_FILE} can be
also specified. Defaults to ${XDG_RUNTIME_DIR}/containers/auth.json, ${XDG_CONFIG_HOME}/containers/auth.json,
/run/containers/${UID}/auth.json, ${DOCKER_CONFIG}, ~/.docker/config.json, ~/.dockercfg

@xiuwang
Copy link

xiuwang commented Aug 17, 2021

This issue https://bugzilla.redhat.com/show_bug.cgi?id=1992474 doesn't be fixed yet.

@atiratree
Copy link
Member Author

Hi @atiratree Thanks for update.
I check the oc cmd with new commits.
the option has included ~/.dockercfg file, but oc doesn't query this file when other target files not existing.

@xiuwang
I cannot reproduce this. Both options are working fine for me - when other configs exist or not exist. Are you sure you are using the right format? kubernetes/kubernetes#12626 (comment)

Can you please share how are you reproducing this and what errors you are getting?

@@ -51,7 +51,7 @@ type SecurityOptions struct {
}

func (o *SecurityOptions) Bind(flags *pflag.FlagSet) {
flags.StringVarP(&o.RegistryConfig, "registry-config", "a", o.RegistryConfig, "Path to your registry credentials (defaults to ~/.docker/config.json)")
flags.StringVarP(&o.RegistryConfig, "registry-config", "a", o.RegistryConfig, "Path to your registry credentials. Alternatively env variable ${REGISTRY_AUTH_FILE} can be also specified. Defaults to ${XDG_RUNTIME_DIR}/containers/auth.json, ${XDG_CONFIG_HOME}/containers/auth.json, /run/containers/${UID}/auth.json, ${DOCKER_CONFIG}, ~/.docker/config.json, ~/.dockercfg")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't change the order, since that might break current users. We'll have to do it gradually:

  1. Add podman locations after .docker/config.json, we talked with @atiratree about it, it'll be done by re-using the current logic to read .docker/config.json and add everything else using github.com/containers/image library. We just need to ensure that the former has higher precedence than the latter.
  2. Add a warning when using the old loading order.
  3. Add support for the new order, but behind an env var, CONTAINERS_AUTH_ORDER or something like that. This would basically drop the legacy support we currently have for .docker/config.json and just use github.com/containers/image/. This would apply both to reading and writing as well.

Don't forget:

  1. Add release notes about the loading order changes including the env var to enable it - CONTAINERS_AUTH_ORDER. Mention supporting REGISTRY_AUTH_FILE as well.
    Call out that in 2 release, we'll flip CONTAINERS_AUTH_ORDER to on by default.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@soltysh I think I have resolved all of the issues. Can you please rereview?

regarding the release notes, I will write them just after we confirm the name of the env variable

@xiuwang
Copy link

xiuwang commented Aug 31, 2021

@atiratree After I used the previous format for .dockercfg, the cmd could get the auth.
Validate ~/.docker/config.json (deprecated),${XDG_RUNTIME_DIR}/containers/auth.json, ${XDG_CONFIG_HOME}/containers/auth.json, /run/containers/${UID}/auth.json, ${DOCKER_CONFIG}, ~/.dockercfg . And Defaults can be changed via REGISTRY_AUTH_PREFERENCE env variable.

/label qe-approved

@openshift-ci openshift-ci bot added the qe-approved Signifies that QE has signed off on this PR label Aug 31, 2021
@atiratree
Copy link
Member Author

/bugzilla refresh

@openshift-ci openshift-ci bot removed the bugzilla/valid-bug Indicates that a referenced Bugzilla bug is valid for the branch this PR is targeting. label Sep 2, 2021
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Sep 2, 2021

@atiratree: This pull request references Bugzilla bug 1982498, which is invalid:

  • expected the bug to target the "4.9.0" release, but it targets "4.10.0" instead

Comment /bugzilla refresh to re-evaluate validity if changes to the Bugzilla bug are made, or edit the title of this pull request to link to a different bug.

In response to this:

/bugzilla refresh

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@openshift-ci openshift-ci bot added the bugzilla/invalid-bug Indicates that a referenced Bugzilla bug is invalid for the branch this PR is targeting. label Sep 2, 2021
@atiratree
Copy link
Member Author

/retest

@atiratree
Copy link
Member Author

/bugzilla refresh
/retest

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Oct 1, 2021

@atiratree: This pull request references Bugzilla bug 1982498, which is valid.

3 validation(s) were run on this bug
  • bug is open, matching expected state (open)
  • bug target release (4.10.0) matches configured target release for branch (4.10.0)
  • bug is in the state POST, which is one of the valid states (NEW, ASSIGNED, ON_DEV, POST, POST)

Requesting review from QA contact:
/cc @xiuwang

In response to this:

/bugzilla refresh
/retest

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@openshift-ci openshift-ci bot added bugzilla/valid-bug Indicates that a referenced Bugzilla bug is valid for the branch this PR is targeting. and removed bugzilla/invalid-bug Indicates that a referenced Bugzilla bug is invalid for the branch this PR is targeting. labels Oct 1, 2021
@atiratree
Copy link
Member Author

/retest

@atiratree
Copy link
Member Author

rebased

@atiratree
Copy link
Member Author

/retest

- introduce REGISTRY_AUTH_FILE env variable as an alternative to  --registry-config
- introduce REGISTRY_AUTH_PREFERENCE env variable for switching
  preference for default auth config location (podman, docker)
…tials

- introduce REGISTRY_AUTH_FILE env variable as an alternative to  --registry-config
- introduce REGISTRY_AUTH_PREFERENCE env variable for switching
  preference for default auth config location (podman, docker)
Copy link
Member

@soltysh soltysh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm
/approve
nits can be addressed in followup

@@ -50,7 +50,8 @@ type SecurityOptions struct {
}

func (o *SecurityOptions) Bind(flags *pflag.FlagSet) {
flags.StringVarP(&o.RegistryConfig, "registry-config", "a", o.RegistryConfig, "Path to your registry credentials (defaults to ~/.docker/config.json)")
// TODO: fix priority and deprecation notice in 4.12
flags.StringVarP(&o.RegistryConfig, "registry-config", "a", o.RegistryConfig, "Path to your registry credentials. Alternatively REGISTRY_AUTH_FILE env variable can be also specified. Defaults to ~/.docker/config.json (order deprecated), ${XDG_RUNTIME_DIR}/containers/auth.json, ${XDG_CONFIG_HOME}/containers/auth.json, /run/containers/${UID}/auth.json, ${DOCKER_CONFIG}, ~/.dockercfg. Defaults can be changed via REGISTRY_AUTH_PREFERENCE env variable to docker or podman.")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion:

Path to your registry credentials. Alternatively REGISTRY_AUTH_FILE env variable can be specified.
Defaults to ~/.docker/config.json, ${XDG_RUNTIME_DIR}/containers/auth.json, ${XDG_CONFIG_HOME}/containers/auth.json, /run/containers/${UID}/auth.json, ${DOCKER_CONFIG}, ~/.dockercfg. The order can be changed via REGISTRY_AUTH_PREFERENCE env variable to docker (current default - deprecated) or podman (prioritizes podman credentials over docker) .

result = RegistryAuthConfigPreference(authPreference)
} else {
// TODO: remove once deprecated in 4.12
klog.Warningln("Defaulting of registry auth file to \"${HOME}/.docker/config.json\" is deprecated. The default will be switched to podman config locations in 4.12")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: in the future version

we don't specify exact version in these messages, in case we forget 😉

"net/http"
"net/url"
"os"
"path/filepath"
"strings"

"github.com/containers/image/v5/pkg/docker/config"
imageTypes "github.com/containers/image/v5/types"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: most import aliases are lowercase to differentiate that from variables.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we maybe make these imports be:
dockerconfig and containerstypes so it's explicit where these are coming while reading the code

flag.StringVarP(&o.ConfigFile, "registry-config", "a", o.ConfigFile, "The location of the file your credentials will be stored in. Default is Docker config.json")
flag.StringVar(&o.ConfigFile, "to", o.ConfigFile, "The location of the file your credentials will be stored in. Default is Docker config.json")
flag.StringVarP(&o.ConfigFile, "registry-config", "a", o.ConfigFile, "The location of the file your credentials will be stored in. Alternatively REGISTRY_AUTH_FILE env variable can be also specified. Default is Docker config.json (deprecated). Default can be changed via REGISTRY_AUTH_PREFERENCE env variable to docker or podman.")
flag.StringVar(&o.ConfigFile, "to", o.ConfigFile, "The location of the file your credentials will be stored in. Alternatively REGISTRY_AUTH_FILE env variable can be also specified. Default is Docker config.json (deprecated). Default can be changed via REGISTRY_AUTH_PREFERENCE env variable to docker or podman.")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion:

The location of the file your credentials will be stored in. Alternatively REGISTRY_AUTH_FILE env variable can be specified. Defaults to ~/.docker/config.json. Default can be changed via REGISTRY_AUTH_PREFERENCE env variable to docker (current default - deprecated) or podman (prioritizes podman credentials over docker) .

This will be inline with that other place where I left similar comment.

contents, err := json.MarshalIndent(cfg, "", " ")
if err != nil {
ctx := &imageTypes.SystemContext{AuthFilePath: o.ConfigFile}
if err := config.SetAuthentication(ctx, o.HostPort, o.Credentials.Username, o.Credentials.Password); err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes the code so much easier 😅 we should've done that long time ago.

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Nov 30, 2021
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Nov 30, 2021

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: atiratree, soltysh

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 30, 2021
@openshift-merge-robot openshift-merge-robot merged commit 94c8c68 into openshift:master Nov 30, 2021
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Nov 30, 2021

@atiratree: All pull requests linked via external trackers have merged:

Bugzilla bug 1982498 has been moved to the MODIFIED state.

In response to this:

Bug 1982498: default to podman credential configs

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. bugzilla/severity-medium Referenced Bugzilla bug's severity is medium for the branch this PR is targeting. bugzilla/valid-bug Indicates that a referenced Bugzilla bug is valid for the branch this PR is targeting. lgtm Indicates that a PR is ready to be merged. qe-approved Signifies that QE has signed off on this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants