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

libimage: Fix getDockerAuthConfig() for authentication #1342

Merged
merged 1 commit into from
Feb 28, 2023

Conversation

sstosh
Copy link
Contributor

@sstosh sstosh commented Feb 22, 2023

  • We need to set DockerAuthConfig even if we use of
    non-IdentityToken credentials.

  • This function should be failed when there are multiple
    credential sources, not only Username + Credentials.

Signed-off-by: Toshiki Sonoda sonoda.toshiki@fujitsu.com

@sstosh
Copy link
Contributor Author

sstosh commented Feb 22, 2023

common/libimage/search.go

Lines 241 to 245 in d6cedd5

// We should set the authConf unless a token was set. That's especially
// useful for Podman's remote API.
if options.IdentityToken != "" {
sys.DockerAuthConfig = authConf
}

Added in #1328.
This operation is not appropriate.
We need to set DockerAuthConfig even if we use of non-IdentityToken credentials.

@sstosh
Copy link
Contributor Author

sstosh commented Feb 22, 2023

I'm waiting to pass the podman CI tests which include this commit.
containers/podman/pull/17600

@sstosh sstosh marked this pull request as ready for review February 22, 2023 09:36
@sstosh
Copy link
Contributor Author

sstosh commented Feb 22, 2023

This is ready for review.

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.

@mtrmac PTAL

@@ -348,6 +331,41 @@ func searchRepositoryTags(ctx context.Context, sys *types.SystemContext, registr
return paramsArr, nil
}

// getDockerAuthConfig extracts a docker auth config from the CopyOptions. Returns
// nil if no credentials are set.
func (options *SearchOptions) getDockerAuthConfig() (*types.DockerAuthConfig, error) {
Copy link
Member

Choose a reason for hiding this comment

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

This is a code clone of https://github.com/containers/common/blob/main/libimage/copier.go#L172.

It.s probably worth refactoring the two functions into one that would username, credetials and ID token as arguments? The getDockerAuthConfig() methods could call this function.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes please.

libimage/search.go Outdated Show resolved Hide resolved
libimage/search.go Outdated Show resolved Hide resolved
@sstosh sstosh force-pushed the search-fix branch 3 times, most recently from 32703e1 to 585e07e Compare February 27, 2023 08:29
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, thank you!

@mtrmac PTAL

@sstosh
Copy link
Contributor Author

sstosh commented Feb 27, 2023

The podman CI tests are passed and ready for review.

@sstosh sstosh changed the title libimage: search: Add getDockerAuthConfig() for authentication libimage: Fix getDockerAuthConfig() for authentication Feb 27, 2023
Copy link
Contributor

@mtrmac mtrmac left a comment

Choose a reason for hiding this comment

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

LGTM overall.

I think The (creds + passwd) case is worth preventing, but I don’t feel strongly about it – others, feel free to merge as is.

libimage/copier.go Outdated Show resolved Hide resolved
libimage/copier.go Outdated Show resolved Hide resolved
}

return nil, nil
// Return nil if there is no credential source.
if numCredsSources == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

(Absolutely non-blocking: Alternatively, move the numCredsSources checks before creating authConf, so that we don’t create an authConf with invalid data at all.

Then this can be

switch numCredsSources {
case 0: return nil, nil
case 1: return &types.DockerAuthConfig{…}, nil
default: /* error */

)

- We need to set DockerAuthConfig even if we use of
non-IdentityToken credentials.

- This function should be failed when there are multiple
  credential sources, not only `Username` + `Credentials`.

Signed-off-by: Toshiki Sonoda <sonoda.toshiki@fujitsu.com>
@sstosh
Copy link
Contributor Author

sstosh commented Feb 28, 2023

Thank you for your review. I fixed it.
The podman CI tests are passed and ready for review.

Copy link
Contributor

@mtrmac mtrmac 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
Copy link
Contributor

openshift-ci bot commented Feb 28, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: mtrmac, sstosh, 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 911199c into containers:main Feb 28, 2023
@sstosh sstosh deleted the search-fix branch March 1, 2023 00:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants