Skip to content

Commit

Permalink
[JENKINS-50573] Prefer URL username with ssh URL
Browse files Browse the repository at this point in the history
When using an ssh private key, the CliGitAPIImpl implementation previously
passed a "-l" command line argument from the username associated with
the ssh key.  OpenSSH implementations prior to OpenSSH 7.7 would only use
that command line argument if no username were included in the ssh URI.

OpenSSH 7.7 changes the ssh command line argument parsing rules.
Previously, the last user name specified would be used, including the
user name in the URL.  With OpenSSH 7.7, the first user name specified
is used, even if a user name is specified in the URL.

The command line:

    ssh -l jenkins git@github.com:jenkinsci/git-client-plugin.git

uses the username 'git' with OpenSSH versions before 7.7 and uses the
username 'jenkins' with OpenSSH 7.7.

OpenSSH 7.7 is included in Windows Git 2.17 and in OpenBSD 6.3.

The CredentialsTest class can test this case.
  • Loading branch information
MarkEWaite committed Apr 16, 2018
1 parent 7467507 commit e2520d9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions src/main/java/org/jenkinsci/plugins/gitclient/CliGitAPIImpl.java
Expand Up @@ -1647,11 +1647,17 @@ private String launchCommandWithCredentials(ArgumentListBuilder args, File workD
listener.getLogger().println("using GIT_SSH to set credentials " + sshUser.getDescription());

key = createSshKeyFile(sshUser);
// Prefer url username if set, OpenSSH 7.7 argument precedence change
// See JENKINS-50573 for details
String userName = url.getUser();
if (userName == null) {
userName = sshUser.getUsername();
}
if (launcher.isUnix()) {
ssh = createUnixGitSSH(key, sshUser.getUsername());
ssh = createUnixGitSSH(key, userName);
pass = createUnixSshAskpass(sshUser);
} else {
ssh = createWindowsGitSSH(key, sshUser.getUsername());
ssh = createWindowsGitSSH(key, userName);
pass = createWindowsSshAskpass(sshUser);
}

Expand Down
Expand Up @@ -325,7 +325,7 @@ public static Collection gitRepoUrls() throws MalformedURLException, FileNotFoun
}
}
Collections.shuffle(repos); // randomize test order
int toIndex = Math.min(repos.size(), TEST_ALL_CREDENTIALS ? 90 : 6); // Don't run more than 90 variations of test - about 3 minutes
int toIndex = Math.min(repos.size(), TEST_ALL_CREDENTIALS ? 120 : 6); // Don't run more than 120 variations of test - about 3 minutes
return repos.subList(0, toIndex);
}

Expand Down

0 comments on commit e2520d9

Please sign in to comment.