fix/mirror-gerrit: encode clone URL credentials and validate the creds file - #1145
Merged
Conversation
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.
addPasswordsplices the HTTP password into the clone URL as a raw string, so a password containing a character that URL syntax reserves corrupts the result. Roughly half of Gerrit-generated passwords contain a/, which failsurl.Parsein alog.Fatalfand aborts the mirror before anything is cloned, while#or?parse cleanly into a different host. Because the splice matches on a literal://<username>@, it also does nothing at all when the credentials file's username differs from the download scheme's, silently sending no credentials. The credentials file is separately split on every:, truncating passwords that contain a colon and panicking on a file with none.This sets
Useron the already-parsed per-project URL sonet/urlpercent-encodes it, and parses the credentials file withSplitN, reporting a malformed one instead of truncating or panicking. Scheme selection and URL assembly move intoselectProjectURLandbuildCloneURLso they can be tested. The credentials file now supplies the whole userinfo, so it wins when the two usernames disagree.One caveat for verifying this. If the Gerrit URL carries an explicit port, REST authentication still fails before any of the above runs: go-gerrit's
NewClientextracts credentials with a regex that only matches when a port is present and takes them as raw substrings, so it sends the percent-encoded password (andygrunwald/go-gerrit#224, fix open in #225). That path is untouched here —rootURLreachesNewClientexactly as before — but a ported instance needs the upstream fix as well.Closes #1144.