Improved Usernames / Organization / Groups Path Matching in credentials - #4
Closed
macmonac wants to merge 2 commits into
Closed
Improved Usernames / Organization / Groups Path Matching in credentials#4macmonac wants to merge 2 commits into
macmonac wants to merge 2 commits into
Conversation
The old version only supported host verification. When combined with useHttpPath, it could only check a single-level path for usernames, organizations, or groups, not the full path.
If the first line matched the host or the first-level path, those credentials were returned, even if a later line specified a more precise path.
Example:
https://USERNAME:TOKEN1@gitlab.com/group/subgroup1/project.git
https://USERNAME:TOKEN2@gitlab.com/group/subgroup2/project2.git
https://USERNAME:TOKEN3@gitlab.com/group/subgroup2/
https://USERNAME:TOKEN4@gitlab.com/group/
For the repository:
https://USERNAME:TOKEN2@gitlab.com/group/subgroup2/project2.git
Without useHttpPath: Only the host, protocol, and HTTP username (if specified) are checked. It returns TOKEN1.
With useHttpPath (old version), only the first-level path was checked, even though the rest of the path did not match. In this case, it’s the same as above, so it returns TOKEN1.
Now, The system checks if the path configured in the credentials is the beginning of the requested path.
For the same repository:
https://USERNAME:TOKEN2@gitlab.com/group/subgroup2/project2.git
Without useHttpPath: Behavior remains unchanged (returns TOKEN1).
With useHttpPath (new version): It can now match the full path or a partial path, regardless of the number of username/organization/group levels. Since the full path of the first line doesn’t match the request, it continues to the second line, which does match. It returns TOKEN2.
Notes:
The third line provides global credentials for other projects under /group/subgroup2/.
The fourth line provides global credentials for other projects under /group/.
Important:
The order of lines in the credentials file matters. More specific paths should be listed before broader ones.
Owner
|
Thank you for the detailed report and the concrete GitLab examples. The underlying diagnosis is correct: the previous matcher considered only one path component, so nested group/subgroup paths could select an earlier, broader credential instead of the intended one. After reviewing the patch against the documented Git credential behavior, I did not merge it as-is for two reasons:
I implemented the nested-path correction separately in #6. The replacement implementation:
The replacement has been merged and released in v1.1.3. Relevant Git documentation:
Thanks again. This PR identified a real limitation, and the nested GitLab examples were valuable when designing the corrected behavior and its test coverage. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
User description
The old version only supported host verification. When combined with useHttpPath, it could only check a single-level path for usernames, organizations, or groups, not the full path.
If the first line matched the host or the first-level path, those credentials were returned, even if a later line specified a more precise path.
Example:
https://USERNAME:TOKEN1@gitlab.com/group/subgroup1/project.git
https://USERNAME:TOKEN2@gitlab.com/group/subgroup2/project2.git
https://USERNAME:TOKEN3@gitlab.com/group/subgroup2/
https://USERNAME:TOKEN4@gitlab.com/group/
For the repository:
https://USERNAME:TOKEN2@gitlab.com/group/subgroup2/project2.git
Now, The system checks if the path configured in the credentials is the beginning of the requested path.
For the same repository:
https://USERNAME:TOKEN2@gitlab.com/group/subgroup2/project2.git
Notes:
The third line provides global credentials for other projects under /group/subgroup2/.
The fourth line provides global credentials for other projects under /group/.
Important:
The order of lines in the credentials file matters. More specific paths should be listed before broader ones.
I hope this doesn’t alter the originally intended behavior.
If the pull request is accepted, I think we’ll need to update the end of the documentation.
PR Type
Enhancement, Bug fix
Description
Improved path matching to support full paths instead of single-level
Now checks if configured path is prefix of requested path
Added support for ignoring comments in credentials file
Simplified path matching logic with
strings.HasPrefixDiagram Walkthrough
File Walkthrough
main.go
Simplify path matching and add comment filteringmain.go
strings.HasPrefixfor fullpath comparison
strings.Cutand separatehandling branches
#or//incredentials file