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

Add secret support to podman login #19200

Merged
merged 2 commits into from
Jul 13, 2023

Conversation

rhatdan
Copy link
Member

@rhatdan rhatdan commented Jul 11, 2023

Does this PR introduce a user-facing change?

Podman login can now read the secret for a registry from its secret database created with podman secret create.

Fixes: #18667

@openshift-ci openshift-ci bot added release-note approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Jul 11, 2023
@rhatdan
Copy link
Member Author

rhatdan commented Jul 11, 2023

@kriansa PTAL

@rhatdan
Copy link
Member Author

rhatdan commented Jul 11, 2023

@ashley-cui @vrothberg PTAL

@rhatdan
Copy link
Member Author

rhatdan commented Jul 11, 2023

@alexlarsson @ygalblum This is my idea for how quadlet could handle registry secrets, In pre section of the quadlet, do a ExecStartPre=podman login --secret secret registryfor.image.in.quadlet
ExecStopPost=podman logout registryfor.image.in.quadlet

"output from podman logout"
run_podman secret rm $secret

# test using secred id as --username
Copy link
Member

Choose a reason for hiding this comment

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

nit of a nit

Suggested change
# test using secred id as --username
# test using secret id as --username


run_podman login --tls-verify=false \
--username ${PODMAN_LOGIN_USER} \
--secret ${output} \
Copy link
Member

Choose a reason for hiding this comment

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

This squicks me out a little: first, it's not immediately obvious what $output is, second, it would be so easy to accidentally insert a run_podman load or run or something. Suggestion: add secretid=$output immediately after the secret create. Otherwise LGTM. with @TomSweeneyRedHat's suggestions.

@@ -48,7 +51,8 @@ func init() {
completion.CompleteCommandFlags(loginCommand, auth.GetLoginFlagsCompletions())

// Podman flags.
flags.BoolVarP(&loginOptions.tlsVerify, "tls-verify", "", false, "Require HTTPS and verify certificates when contacting registries")
flags.BoolVar(&loginOptions.tlsVerify, "tls-verify", false, "Require HTTPS and verify certificates when contacting registries")
flags.String("secret", "", "retrieve passwd from secret file")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
flags.String("secret", "", "retrieve passwd from secret file")
flags.String("secret", "", "Retrieve password from podman secret")

cmd/podman/login.go Show resolved Hide resolved
@@ -18,6 +18,8 @@ TLS certificates and keys, SSH keys or other important generic strings or binary

Secrets are not committed to an image with `podman commit`, and does not get committed in the archive created by a `podman export` command.

You can also use secrets to store secret data whcih can be used by `podman login` to authenticate to container registries.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
You can also use secrets to store secret data whcih can be used by `podman login` to authenticate to container registries.
You can also use secrets to store passwords for `podman login` to authenticate against container registries.

test/system/150-login.bats Show resolved Hide resolved
@@ -48,7 +51,8 @@ func init() {
completion.CompleteCommandFlags(loginCommand, auth.GetLoginFlagsCompletions())

// Podman flags.
flags.BoolVarP(&loginOptions.tlsVerify, "tls-verify", "", false, "Require HTTPS and verify certificates when contacting registries")
flags.BoolVar(&loginOptions.tlsVerify, "tls-verify", false, "Require HTTPS and verify certificates when contacting registries")
flags.String("secret", "", "retrieve passwd from secret file")
Copy link
Member

Choose a reason for hiding this comment

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

missing autocompletion function, this should complete secrets AutocompleteSecrets()

@ygalblum
Copy link
Contributor

@alexlarsson @ygalblum This is my idea for how quadlet could handle registry secrets, In pre section of the quadlet, do a ExecStartPre=podman login --secret secret registryfor.image.in.quadlet ExecStopPost=podman logout registryfor.image.in.quadlet

About the Quadlet integration, not sure I like it because the login and logout operations are not specific to the quadlet. As a result, if you have two services logging in to the same registry it can become a mess. I see two possible issues. First, different credentials to the same registry. Second, while both services are running, stopping one of them will logout from the registry.

So, for Quadlet, I think it's better to support a new unit type e.g. .registry. This unit will produce a service that does what you intended to do in the ExecStartPre and ExecStopPost, just in its ExecStart and ExecStop (maybe still ExecStopPost which I think handles error case better). Then support a new key in .container and .kube (e.g. Registry) that will create a dependency between the service units.

@rhatdan
Copy link
Member Author

rhatdan commented Jul 12, 2023

Sure, I was just giving an example of how you could use it. Probably would be fine to just do the ExecPreStart and never remove the secret, since on reboot the secret will be removed, and the secret is already stored on disk in a simple base64 encoding so there is no additional security risk to leaving it around.

Copy link
Member

@ashley-cui ashley-cui left a comment

Choose a reason for hiding this comment

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

One nit, otherwise LGTM

cmd/podman/login.go Outdated Show resolved Hide resolved
cmd/podman/login.go Outdated Show resolved Hide resolved
Co-authored-by: Ashley Cui <[email protected]>
Signed-off-by: Daniel J Walsh <[email protected]>
@rhatdan
Copy link
Member Author

rhatdan commented Jul 12, 2023

@vrothberg @giuseppe @Luap99 @TomSweeneyRedHat @containers/podman-maintainers PTAL

@TomSweeneyRedHat
Copy link
Member

LGTM
and happy green test buttons

Copy link
Member

@vrothberg vrothberg left a comment

Choose a reason for hiding this comment

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

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Jul 13, 2023
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Jul 13, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: rhatdan, vrothberg

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-merge-robot openshift-merge-robot merged commit 69f112a into containers:main Jul 13, 2023
@github-actions github-actions bot added the locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. label Oct 12, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. release-note
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add view/update to secrets
8 participants