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

Fix HTTP credentials passing #11538

Merged
merged 27 commits into from
Jan 6, 2022

Conversation

mtrmac
Copy link
Collaborator

@mtrmac mtrmac commented Sep 11, 2021

This primarily fixes the incorrect normalization added in #11430 .

That requires UNMERGED containers/image#1373

Separately I abuse this PR for testing UNMERGED and mostly unrelated containers/common#763 .

Also, this adds a lot of unit tests to the HTTP credential passing code, and proposes a fairly significant WIP refactoring. Still outstanding:

  • Remove unnecessary/redundant parameters to auth.Make…Header (at the very least don’t modify caller’s SystemContext)
  • Split auth.MakeXRegistryAuthHeader yet further into two, to emphasize the exclusive sets of parameters instead of pretending to handle both.

See individual commit messages for details.

@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Sep 11, 2021
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Sep 11, 2021

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: mtrmac

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 Sep 11, 2021
@mtrmac mtrmac changed the title Fix HTTP credentials passing WIP: Fix HTTP credentials passing Sep 11, 2021
@mtrmac
Copy link
Collaborator Author

mtrmac commented Sep 11, 2021

NOTE: The comments in the pkg/auth package talk about the AuthHeader using multiple values and ConfigHeader using a map, but the actual code supports multiple header values the other way around. Which one is correct? I’ve been assuming it’s the code.

@openshift-ci openshift-ci bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 13, 2021
@openshift-ci openshift-ci bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 13, 2021
@openshift-ci openshift-ci bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 19, 2021
@github-actions
Copy link

A friendly reminder that this PR had no activity for 30 days.

@rhatdan
Copy link
Member

rhatdan commented Oct 21, 2021

@mtrmac any progress on this?

@openshift-ci openshift-ci bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 21, 2021
@mtrmac
Copy link
Collaborator Author

mtrmac commented Oct 21, 2021

OK, rebased and enough with the refactoring.

The PR now contains a fairly extensive refactoring of pkg/auth:

  • Restructure to make it easier to unit-test, and add those tests
  • (Actually fix the credential passing)
  • Refactor the external API to simplify and avoid surprising aspects.

Some parts of the above, especially of the refactor, might not be ideal, or might be actively unwanted based on concerns I’m not aware of. Please don’t hesitate to say so, I’d be happy to split this into multiple PRs, drop parts entirely, or change in any other way requested.

@github-actions github-actions bot removed the stale-pr label Oct 22, 2021
@mtrmac mtrmac changed the title WIP: Fix HTTP credentials passing Fix HTTP credentials passing Oct 22, 2021
@openshift-ci openshift-ci bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 28, 2021
@github-actions
Copy link

A friendly reminder that this PR had no activity for 30 days.

@openshift-ci openshift-ci bot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Nov 29, 2021
Almost every caller is using it only to wrap an error
in exactly the same way, so move that error context into GetCredentials
and simplify the users.

(The one other caller, build, was even wrapping the error incorrectly
talking about query parameters; so let it use the same text as the others.)

Signed-off-by: Miloslav Trmač <[email protected]>
Don't create a single-element map only for the only caller
to laboriously extract an element of that map; just return
a single entry.

Should not change behavior.

Signed-off-by: Miloslav Trmač <[email protected]>
In the "no input" case, return a constant instead of
continuing with the decode/convert path, converting empty data.

Should not change behavior.

Signed-off-by: Miloslav Trmač <[email protected]>
…uthHeader

Both have a single caller, so there's no point in looking up
the header value twice.

Should not change behavior.

Signed-off-by: Miloslav Trmač <[email protected]>
Use separate lines, and use the provided .String() API.

Should not change behaivor.

Signed-off-by: Miloslav Trmač <[email protected]>
It's possibly a bit more expensive, but semantically safer
because it does header normalization.

And we'll regain the cost by not looking up the value repeatedly.

Signed-off-by: Miloslav Trmač <[email protected]>
... and have GetCredentials pass the values down to
getConfigCredentials and getAuthCredentials.

Should not change behavior.

Signed-off-by: Miloslav Trmač <[email protected]>
We'll share even more code here in the future.

Should not change behavior.

Signed-off-by: Miloslav Trmač <[email protected]>
This shares the code, and makes getConfigCredentials
and getAuthCredentials side-effect free and possibly easier to test.

Should not change behavior.

Signed-off-by: Miloslav Trmač <[email protected]>
... which can be called independently.

For now, there are no new callers, to test that the behavior
has not changed.

Should not change behavior.

Signed-off-by: Miloslav Trmač <[email protected]>
…Header)

All callers hard-code a header value, so this is actually shorter.

Should not change behavior.

Signed-off-by: Miloslav Trmač <[email protected]>
... which can be called independently.

For now, there are no new callers, to test that the behavior
has not changed.

Should not change behavior.

Signed-off-by: Miloslav Trmač <[email protected]>
All callers hard-code a header value, so this is actually shorter.

Should not change behavior.

Signed-off-by: Miloslav Trmač <[email protected]>
It is no longer used.

Split the existing tests into MakeXRegistryConfigHeader
and MakeXRegistryAuthHeader variants. For now we don't modify
the implementations at all, to make review simpler; cleanups
will follow.

Should not change behavior.

Signed-off-by: Miloslav Trmač <[email protected]>
Should not change (test) behavior.

Signed-off-by: Miloslav Trmač <[email protected]>
which used to contain more context, but now are just
a pointless copy.

Should not change (test) behavior.

Signed-off-by: Miloslav Trmač <[email protected]>
Having a parameter that modifies the provides types.SystemContext
seems rather unexpected and risky to have around - and the only
user of that is actually a no-op; so, remove that option and simplify.

Should not change behavior.

Signed-off-by: Miloslav Trmač <[email protected]>
... now that two of the three cases are the same.

Should not change behavior.

Signed-off-by: Miloslav Trmač <[email protected]>
Having a parameter that modifies the provides types.SystemContext
seems rather unexpected and risky to have around - and the only
user of that is actually a no-op, others only provide a nil
SystemContext; so, remove that option and simplify (well, somewhat;
many callers now have extra &types.SystemContext{AuthFilePath}
boilerplate; at least that's consistent with that code carrying
a TODO to create a larger-scope SystemContext).

Should not change behavior.

Signed-off-by: Miloslav Trmač <[email protected]>
... now that they have no public users.

Also remove the HeaderAuthName type, we don't need the type-safety
so much for private constants, and using plain strings results in
less visual noise.

Should not change behavior.

Signed-off-by: Miloslav Trmač <[email protected]>
@openshift-ci openshift-ci bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 10, 2021
@rhatdan
Copy link
Member

rhatdan commented Jan 5, 2022

LGTM

@mheon
Copy link
Member

mheon commented Jan 6, 2022

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Jan 6, 2022
@openshift-merge-robot openshift-merge-robot merged commit 2fd6c2e into containers:main Jan 6, 2022
@mtrmac mtrmac deleted the http-credentials branch January 6, 2022 16:00
@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 Sep 22, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 22, 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants