Skip to content

Conversation

@zuoxuesong-worker
Copy link
Contributor

@zuoxuesong-worker zuoxuesong-worker commented Dec 18, 2025

What type of PR is this?

/kind bug

What this PR does / why we need it:

fix a bug that image auth selector select an empty auth
for example, when user use auth like
{"repo":"somehub","username":"aaa","password":"bbb"},
{"repo":"somehub/someproj","username":"ccc","password":"ddd"},
{"repo":"somehub/otherproj"","username":"eee","password":"fff"}
and then push image :
"somehub/someproj/sub.proj/name:tag",
"somehub/otherproj/image:latest",
"somehub/myimage:v1.0",
"somehub/someproj/another:tag",
"otherhub/image:latest",
which auth should selected for each image?
according to the old func ,they would all select aaa/bbb
but when image should push to someproj ,acturaly we should choose ccc/ddd
so add a func to select the currect auth

Which issue(s) this PR fixes:

Fixes #
#2898

Special notes for reviewers:

fix image auth bug

Does this PR introduced a user-facing change?

fix image auth bug

Additional documentation, usage docs, etc.:


@kubesphere-prow kubesphere-prow bot added release-note kind/bug Categorizes issue or PR as related to a bug. labels Dec 18, 2025
@kubesphere-prow
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: zuoxuesong-worker

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

The pull request process is described here

Details 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

@kubesphere-prow kubesphere-prow bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Dec 18, 2025
@gemini-code-assist
Copy link

Summary of Changes

Hello @zuoxuesong-worker, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical bug in the image authentication mechanism where the system would incorrectly select authentication credentials, particularly when multiple authentication entries existed for different levels of a repository path. By introducing a new function to intelligently select the most specific authentication based on the image's full path, this change ensures that image pull and push operations use the correct credentials and TLS verification settings, thereby improving the reliability and security of image handling.

Highlights

  • Improved Image Authentication Selection: A new selectAuth function has been introduced to correctly identify the most specific authentication credentials for an image based on its repository path, resolving a bug where a less specific or incorrect authentication might be used.
  • Refactored Authentication Logic: The authFunc and skipTLSVerifyFunc have been updated to utilize the newly selected authentication, simplifying their internal logic and ensuring consistent credential and TLS verification application.
  • Application to Pull and Push Operations: The enhanced authentication selection mechanism is now applied consistently to both image pulling (imagePullArgs.pull) and image pushing (imagePushArgs.push) operations.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@kubesphere-prow kubesphere-prow bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Dec 18, 2025
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly addresses a bug in image credential selection by introducing a longest-prefix match logic in the new selectAuth function. The changes to use this function for Credential and InsecureSkipVerify are well-implemented. However, I've identified a few areas for improvement. The plainHTTP setting is still determined using the old, incorrect logic and should be updated to use the newly selected auth. Additionally, the tag-stripping logic within selectAuth has a bug when image names include a port, and there's a potential issue with how duplicate auth entries are handled. I've left specific comments with suggestions to address these points.

if err != nil {
return errors.Wrapf(err, "failed to get remote image %s", img)
}
selectedAuth := selectAuth(img, i.auths)

Choose a reason for hiding this comment

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

high

While Credential and InsecureSkipVerify are now correctly configured using selectedAuth, the plainHTTP setting is determined later on line 208 using plainHTTPFunc(img, i.auths, false), which still contains the old logic that doesn't respect longest-prefix matching. For consistency and correctness, plainHTTPFunc should be refactored to accept selectedAuth (similar to the change made for skipTLSVerifyFunc), and then used to set src.PlainHTTP.


func selectAuth(image string, authList []imageAuth) imageAuth {
repoPart := image
if colonIdx := strings.LastIndex(image, ":"); colonIdx != -1 {

Choose a reason for hiding this comment

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

high

The current logic for stripping the image tag is not robust. It will incorrectly handle image names that include a port in the registry name, for example, my.registry:5000/my/image. In this case, it would strip from the port colon, resulting in my.registry. A better approach is to check if the colon appears after the last slash.

Suggested change
if colonIdx := strings.LastIndex(image, ":"); colonIdx != -1 {
if colonIdx := strings.LastIndex(image, ":"); colonIdx > strings.LastIndex(image, "/") {

if err != nil {
return errors.Wrapf(err, "failed to get remote repository %q", dest)
}
selectedAuth := selectAuth(dest, i.auths)

Choose a reason for hiding this comment

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

high

Similar to the pull function, while Credential and InsecureSkipVerify are now correctly configured using selectedAuth, the plainHTTP setting is determined later on line 356 using plainHTTPFunc(dest, i.auths, false), which still contains the old logic. For consistency and correctness, plainHTTPFunc should be refactored to accept selectedAuth and be used to set dst.PlainHTTP.

Comment on lines 246 to 249
authMap := make(map[string]imageAuth)
for _, a := range authList {
authMap[a.Repo] = a
}

Choose a reason for hiding this comment

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

medium

When building authMap, if authList contains multiple entries for the same repository, the last one will silently overwrite the previous ones. This could lead to unexpected behavior if a user accidentally provides duplicate configurations. It would be good to either document this behavior or log a warning when an entry is overwritten.

Signed-off-by: [email protected] <[email protected]>

bugfix : fix image auth bug

Signed-off-by: [email protected] <[email protected]>
@kubesphere-prow kubesphere-prow bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Dec 18, 2025
@sonarqubecloud
Copy link

Signed-off-by: [email protected] <[email protected]>

bugfix : fix image auth bug

Signed-off-by: [email protected] <[email protected]>
@kubesphere-prow
Copy link

This PR has multiple commits, and the default merge method is: squash.
You can request commits to be merged using the label: tide/merge-method-merge

Details

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-sigs/prow repository.

@redscholar
Copy link
Contributor

/lgtm

@kubesphere-prow kubesphere-prow bot added the lgtm Indicates that a PR is ready to be merged. label Dec 18, 2025
@kubesphere-prow
Copy link

LGTM label has been added.

DetailsGit tree hash: 227eb7fd9392dfaf913e1c28e739dc4b770017d8

@kubesphere-prow kubesphere-prow bot merged commit 782575f into kubesphere:main Dec 18, 2025
5 checks passed
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. kind/bug Categorizes issue or PR as related to a bug. lgtm Indicates that a PR is ready to be merged. release-note size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants