Skip to content

[JENKINS-70093] Add Windows SSH agent implementation #1056

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

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

rdysart
Copy link
Contributor

@rdysart rdysart commented Mar 11, 2025

Adding support for launching Windows agents using SSH https://issues.jenkins.io/browse/JENKINS-70093

Testing done

mvn clean verify

Tested on Jenkins controller 2.500 launching and connecting to Windows Server 2019 agent via SSH.
Tested with init script

Mar 11, 2025 11:17:29 AM hudson.plugins.ec2.EC2Cloud
INFO: Launching instance: i-XXXXXXXXXXXXXXXXX
Mar 11, 2025 11:17:29 AM hudson.plugins.ec2.EC2Cloud
INFO: bootstrap()
Mar 11, 2025 11:17:29 AM hudson.plugins.ec2.EC2Cloud
INFO: Getting keypair...
Mar 11, 2025 11:17:29 AM hudson.plugins.ec2.EC2Cloud
INFO: Using private key XXXXX (SHA-1 fingerprint XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX)
Mar 11, 2025 11:17:29 AM hudson.plugins.ec2.EC2Cloud
INFO: Authenticating as Administrator
Mar 11, 2025 11:17:29 AM hudson.plugins.ec2.EC2Cloud
INFO: Connecting to X.X.X.X on port 22, with timeout 10000.
Mar 11, 2025 11:18:29 AM hudson.plugins.ec2.EC2Cloud
INFO: Failed to connect via ssh: DefaultConnectFuture[Administrator@/X.X.X.X:22]: Failed (ConnectException) to execute: Connection timed out.
Mar 11, 2025 11:18:29 AM hudson.plugins.ec2.EC2Cloud
INFO: Waiting for SSH to come up. Sleeping 5.
Mar 11, 2025 11:18:34 AM hudson.plugins.ec2.EC2Cloud
INFO: Connecting to X.X.X.X on port 22, with timeout 10000.
Mar 11, 2025 11:18:50 AM hudson.plugins.ec2.EC2Cloud
INFO: Connected via SSH.
Mar 11, 2025 11:18:51 AM hudson.plugins.ec2.EC2Cloud
INFO: The instance EC2 (XXXXXXXX) - win (i-XXXXXXXXXXXXXXXXX) didn't print the host key. Expected a line starting with: "ecdsa-sha2-nistp256"
Mar 11, 2025 11:18:51 AM hudson.plugins.ec2.EC2Cloud
INFO: The SSH key (ecdsa-sha2-nistp256 XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX) presented by the instance has not been found on the instance console. Cannot check the key but the connection to EC2 (XXXXXXXX) - win (i-XXXXXXXXXXXXXXXXX) is allowed
Mar 11, 2025 11:18:51 AM hudson.plugins.ec2.EC2Cloud
INFO: connect fresh as Administrator
Mar 11, 2025 11:18:51 AM hudson.plugins.ec2.EC2Cloud
INFO: Connecting to X.X.X.X on port 22, with timeout 10000.
Mar 11, 2025 11:18:51 AM hudson.plugins.ec2.EC2Cloud
INFO: Connected via SSH.
Mar 11, 2025 11:18:51 AM hudson.plugins.ec2.EC2Cloud
INFO: Connection allowed after the host key has been verified
Mar 11, 2025 11:18:51 AM hudson.plugins.ec2.EC2Cloud
INFO: Creating tmp directory (C:\Windows\Temp\) if it does not exist
Mar 11, 2025 11:18:53 AM hudson.plugins.ec2.EC2Cloud
INFO: Upload init script
Mar 11, 2025 11:18:54 AM hudson.plugins.ec2.EC2Cloud
INFO: Executing init script

administrator@XXXXXXX-XXXXXXX C:\Users\Administrator>ECHO INIT SCRIPT HELLO WORLD
INIT SCRIPT HELLO WORLD
Mar 11, 2025 11:18:54 AM hudson.plugins.ec2.EC2Cloud
INFO: Creating %USERPROFILE%\.hudson-run-init
        1 file(s) copied.
Mar 11, 2025 11:18:54 AM hudson.plugins.ec2.EC2Cloud
INFO: Copying remoting.jar to: C:\Windows\Temp\
Mar 11, 2025 11:18:55 AM hudson.plugins.ec2.EC2Cloud
INFO: Launching remoting agent (via SSH2 Connection):  java  -jar C:\Windows\Temp\remoting.jar -workDir C:\jenkins
Mar 11, 2025 11:18:55 AM hudson.plugins.ec2.EC2Cloud
INFO: Connecting to X.X.X.X on port 22, with timeout 10000.
Mar 11, 2025 11:18:55 AM hudson.plugins.ec2.EC2Cloud
INFO: Connected via SSH.
Mar 11, 2025 11:18:55 AM hudson.plugins.ec2.EC2Cloud
INFO: Connection allowed after the host key has been verified
<===[JENKINS REMOTING CAPACITY]===>Remoting version: 3283.v92c105e0f819
Launcher: EC2WindowsSSHLauncher
Communication Protocol: Standard in/out
This is a Windows agent
Agent successfully connected and online

Submitter checklist

  • Make sure you are opening from a topic/feature/bugfix branch (right side) and not your main branch!
  • Ensure that the pull request title represents the desired changelog entry
  • Please describe what you did
  • Link to relevant issues in GitHub or Jira
  • Link to relevant pull requests, esp. upstream and downstream changes
  • Ensure you have provided tests - that demonstrates feature works or fixes the issue

@Dohbedoh
Copy link
Contributor

Should be linked to https://issues.jenkins.io/browse/JENKINS-70093.


@Override
public boolean isWindows() {
return false;
Copy link
Contributor

@Dohbedoh Dohbedoh Mar 28, 2025

Choose a reason for hiding this comment

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

I find this misleading.. It is a windows AMI. But describe Windows SSH attributes. Shouldn't this be true. And condition that were using it should be updated.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see now that for each implementation we add a boolean isNewImplementation method.. so maybe this is just following the design I guess.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added isSSHAgent/isWinRMAgent for checking the agent connection type and refactored isWindows/isMac/isUnix to only be used for checking the agent OS

@@ -1490,19 +1493,25 @@ public String getRemoteAdmin() {
public String getRootCommandPrefix() {
return (amiType.isUnix()
? ((UnixData) amiType).getRootCommandPrefix()
: (amiType.isMac() ? ((MacData) amiType).getRootCommandPrefix() : ""));
: (amiType.isMac()
Copy link
Contributor

@Dohbedoh Dohbedoh Mar 28, 2025

Choose a reason for hiding this comment

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

Those could be simplified with maybe an abstract SSHData ? WindowsSSHData, MacData and UnixData all have the same attributes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed and done

@rdysart rdysart changed the title Add Windows SSH agent implementation [JENKINS-70093] Add Windows SSH agent implementation Mar 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants