-
-
Notifications
You must be signed in to change notification settings - Fork 401
[JENKINS-71461] GIT_SSH_COMMAND diagnostics fail with some host key verification strategies #1713
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2,5 +2,9 @@ | |||||||||||||
| <j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form"> | ||||||||||||||
| <f:section title="Git Host Key Verification Configuration"> | ||||||||||||||
| <f:dropdownDescriptorSelector field="sshHostKeyVerificationStrategy" title="Host Key Verification Strategy"/> | ||||||||||||||
| <f:entry title="SSH Verbose Mode" field="sshVerbose"> | ||||||||||||||
| <f:checkbox title="Enable verbose SSH output for diagnostics" | ||||||||||||||
| help="When enabled, SSH commands will include -vvv flag for detailed diagnostic output. This helps troubleshoot SSH connection issues without requiring the GIT_SSH_COMMAND environment variable."/> | ||||||||||||||
|
||||||||||||||
| <f:entry title="SSH Verbose Mode" field="sshVerbose"> | |
| <f:checkbox title="Enable verbose SSH output for diagnostics" | |
| help="When enabled, SSH commands will include -vvv flag for detailed diagnostic output. This helps troubleshoot SSH connection issues without requiring the GIT_SSH_COMMAND environment variable."/> | |
| <f:entry title="SSH Verbose Mode" field="sshVerbose" | |
| help="When enabled, SSH commands will include -vvv flag for detailed diagnostic output. This helps troubleshoot SSH connection issues without requiring the GIT_SSH_COMMAND environment variable."> | |
| <f:checkbox title="Enable verbose SSH output for diagnostics"/> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,7 @@ | |
| import org.junit.jupiter.params.provider.Arguments; | ||
| import org.junit.jupiter.params.provider.MethodSource; | ||
| import org.jvnet.hudson.test.Issue; | ||
| import org.jvnet.hudson.test.junit.jupiter.WithJenkins; | ||
|
|
||
| /** | ||
| * Security test that proves the environment variable approach prevents | ||
|
|
@@ -35,6 +36,7 @@ | |
| * | ||
| * @author Mark Waite | ||
| */ | ||
| @WithJenkins | ||
| class CliGitAPISecurityTest { | ||
|
|
||
| @TempDir | ||
|
|
@@ -286,4 +288,178 @@ private void executeWrapper(Path wrapper, Path keyFile) throws Exception { | |
| // That's fine - we're just checking for injection | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Test that SSH verbose mode is disabled by default (no -vvv flag) | ||
| */ | ||
| @Test | ||
| @Issue("JENKINS-71461") | ||
| void testSshVerboseModeDisabledByDefault() throws Exception { | ||
| workspace = new File(tempDir, "test-default"); | ||
| workspace.mkdirs(); | ||
|
|
||
| Path keyFile = createMockSSHKey(workspace); | ||
| Path knownHosts = Files.createTempFile("known_hosts", ""); | ||
|
|
||
| try { | ||
| // When Jenkins is not available, SSH verbose should default to false | ||
| GitClient gitClient = Git.with(TaskListener.NULL, new EnvVars()) | ||
| .in(workspace) | ||
| .using("git") | ||
| .getClient(); | ||
|
||
| CliGitAPIImpl git = (CliGitAPIImpl) gitClient; | ||
|
|
||
| Path sshWrapper; | ||
| if (isWindows()) { | ||
| sshWrapper = git.createWindowsGitSSH(keyFile, "testuser", knownHosts); | ||
| } else { | ||
| sshWrapper = git.createUnixGitSSH(keyFile, "testuser", knownHosts); | ||
| } | ||
|
|
||
| String wrapperContent = Files.readString(sshWrapper, StandardCharsets.UTF_8); | ||
|
|
||
| // Verify -vvv flag is NOT present | ||
| assertFalse( | ||
| wrapperContent.contains("-vvv"), | ||
| "Wrapper should NOT contain -vvv flag when verbose mode is disabled"); | ||
|
|
||
| } finally { | ||
| Files.deleteIfExists(knownHosts); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Test that SSH verbose mode adds -vvv flag when enabled | ||
| */ | ||
| @Test | ||
| @Issue("JENKINS-71461") | ||
| void testSshVerboseModeEnabled() throws Exception { | ||
| // Skip if Jenkins instance is not available | ||
| if (jenkins.model.Jenkins.getInstanceOrNull() == null) { | ||
| return; | ||
| } | ||
|
|
||
| workspace = new File(tempDir, "test-verbose"); | ||
| workspace.mkdirs(); | ||
|
|
||
| Path keyFile = createMockSSHKey(workspace); | ||
| Path knownHosts = Files.createTempFile("known_hosts", ""); | ||
|
|
||
| try { | ||
| // Enable SSH verbose mode | ||
| GitHostKeyVerificationConfiguration.get().setSshVerbose(true); | ||
|
|
||
| GitClient gitClient = Git.with(TaskListener.NULL, new EnvVars()) | ||
| .in(workspace) | ||
| .using("git") | ||
| .getClient(); | ||
| CliGitAPIImpl git = (CliGitAPIImpl) gitClient; | ||
|
|
||
| Path sshWrapper; | ||
| if (isWindows()) { | ||
| sshWrapper = git.createWindowsGitSSH(keyFile, "testuser", knownHosts); | ||
| } else { | ||
| sshWrapper = git.createUnixGitSSH(keyFile, "testuser", knownHosts); | ||
| } | ||
|
|
||
| String wrapperContent = Files.readString(sshWrapper, StandardCharsets.UTF_8); | ||
|
|
||
| // Verify -vvv flag IS present | ||
| assertTrue( | ||
| wrapperContent.contains("-vvv"), "Wrapper should contain -vvv flag when verbose mode is enabled"); | ||
|
|
||
| } finally { | ||
| // Reset to default | ||
| GitHostKeyVerificationConfiguration.get().setSshVerbose(false); | ||
| Files.deleteIfExists(knownHosts); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Test that SSH verbose mode flag is placed correctly in Unix wrapper | ||
| */ | ||
| @Test | ||
| @Issue("JENKINS-71461") | ||
| void testUnixSshVerboseFlagPlacement() throws Exception { | ||
| // Skip if Jenkins instance is not available or on Windows | ||
| if (jenkins.model.Jenkins.getInstanceOrNull() == null || isWindows()) { | ||
| return; | ||
| } | ||
|
|
||
| workspace = new File(tempDir, "test-unix-verbose"); | ||
| workspace.mkdirs(); | ||
|
|
||
| Path keyFile = createMockSSHKey(workspace); | ||
| Path knownHosts = Files.createTempFile("known_hosts", ""); | ||
|
|
||
| try { | ||
| // Enable SSH verbose mode | ||
| GitHostKeyVerificationConfiguration.get().setSshVerbose(true); | ||
|
|
||
| GitClient gitClient = Git.with(TaskListener.NULL, new EnvVars()) | ||
| .in(workspace) | ||
| .using("git") | ||
| .getClient(); | ||
| CliGitAPIImpl git = (CliGitAPIImpl) gitClient; | ||
| Path sshWrapper = git.createUnixGitSSH(keyFile, "testuser", knownHosts); | ||
|
|
||
| String wrapperContent = Files.readString(sshWrapper, StandardCharsets.UTF_8); | ||
|
|
||
| // Verify -vvv appears before "$@" (which represents additional args) | ||
| int vvvIndex = wrapperContent.indexOf("-vvv"); | ||
| int argsIndex = wrapperContent.indexOf("\"$@\""); | ||
| assertTrue(vvvIndex > 0, "-vvv flag should be present"); | ||
| assertTrue(argsIndex > 0, "\"$@\" should be present"); | ||
| assertTrue(vvvIndex < argsIndex, "-vvv flag should appear before \"$@\""); | ||
|
|
||
| } finally { | ||
| // Reset to default | ||
| GitHostKeyVerificationConfiguration.get().setSshVerbose(false); | ||
| Files.deleteIfExists(knownHosts); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Test that SSH verbose mode flag is placed correctly in Windows wrapper | ||
| */ | ||
| @Test | ||
| @Issue("JENKINS-71461") | ||
| void testWindowsSshVerboseFlagPlacement() throws Exception { | ||
| // Skip if Jenkins instance is not available or on Unix | ||
| if (jenkins.model.Jenkins.getInstanceOrNull() == null || !isWindows()) { | ||
| return; // Skip on Unix | ||
| } | ||
|
|
||
| workspace = new File(tempDir, "test-windows-verbose"); | ||
| workspace.mkdirs(); | ||
|
|
||
| Path keyFile = createMockSSHKey(workspace); | ||
| Path knownHosts = Files.createTempFile("known_hosts", ""); | ||
|
|
||
| try { | ||
| // Enable SSH verbose mode | ||
| GitHostKeyVerificationConfiguration.get().setSshVerbose(true); | ||
|
|
||
| GitClient gitClient = Git.with(TaskListener.NULL, new EnvVars()) | ||
| .in(workspace) | ||
| .using("git") | ||
| .getClient(); | ||
| CliGitAPIImpl git = (CliGitAPIImpl) gitClient; | ||
| Path sshWrapper = git.createWindowsGitSSH(keyFile, "testuser", knownHosts); | ||
|
|
||
| String wrapperContent = Files.readString(sshWrapper, StandardCharsets.UTF_8); | ||
|
|
||
| // Verify -vvv appears before %* (which represents additional args) | ||
| int vvvIndex = wrapperContent.indexOf("-vvv"); | ||
| int argsIndex = wrapperContent.indexOf("%*"); | ||
| assertTrue(vvvIndex > 0, "-vvv flag should be present"); | ||
| assertTrue(argsIndex > 0, "%* should be present"); | ||
| assertTrue(vvvIndex < argsIndex, "-vvv flag should appear before %*"); | ||
|
|
||
| } finally { | ||
| // Reset to default | ||
| GitHostKeyVerificationConfiguration.get().setSshVerbose(false); | ||
| Files.deleteIfExists(knownHosts); | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isSshVerboseEnabled()checksJenkins.getInstanceOrNull()and returnsfalsewhen it is null.CliGitAPIImplmethods execute on agents (theGitClientis created viaMasterToSlaveFileCallableinGit#getClient), whereJenkins.getInstanceOrNull()is typically null. As a result, the-vvvflag will never be added for most real jobs running on agents, even when the global configuration enables it. Consider resolving thesshVerbosesetting on the controller (where theGlobalConfigurationis available) and passing it to the agent along withhostKeyFactory(e.g., add a boolean to the callable and store it in the remoteGitClient/CliGitAPIImplinstance).