Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
3d2dfbc
feat: move to use Apache Mina SSHD
kuisathaverat Jun 9, 2025
29267ed
fix: apply spotless formatting (#595)
kuisathaverat Jun 22, 2025
9b0d756
feat: move to use Apache Mina SSHD
kuisathaverat Jun 9, 2025
9a0dab4
fix: do not run on windows some test
kuisathaverat Jun 22, 2025
750a02c
fix: test on windows
kuisathaverat Jun 22, 2025
d63b129
test: make 10min connections test instead 15min
kuisathaverat Jun 22, 2025
c6b837d
fix: cleanup pom
kuisathaverat Jun 23, 2025
aa76259
fix: licenses
kuisathaverat Jun 28, 2025
c947758
chore: suggestions
kuisathaverat Jun 28, 2025
f1a45b1
fix: copy file permissions
kuisathaverat Jun 28, 2025
4015ec2
chore: suggestions
kuisathaverat Jun 28, 2025
68eed5e
chore: remove docker agents files
kuisathaverat Jun 28, 2025
0ecc904
chore: add WIP warning
kuisathaverat Jun 28, 2025
a224de7
chore: update Junit 5
kuisathaverat Jun 28, 2025
70667e2
chore: add (alpha) to the name
kuisathaverat Jun 28, 2025
d90eff3
fix: tests
kuisathaverat Jun 28, 2025
ce4b6c3
chore: disable host verification selection
kuisathaverat Jun 28, 2025
1239993
chore: remove eddsa-api dependency
kuisathaverat Jun 28, 2025
3cc712a
feta: use SSHAuthenticator from mina-sshd-api plugin
kuisathaverat Jun 28, 2025
d17df70
Apply suggestions from code review
kuisathaverat Jul 9, 2025
3d35221
Apply suggestions from code review
kuisathaverat Jul 9, 2025
da28716
chore: jnord suggestions
kuisathaverat Jul 9, 2025
65f2bfe
chore: more suggestions
kuisathaverat Jul 9, 2025
62ceadf
fix: sportbugs
kuisathaverat Jul 9, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,18 @@
</dependencyManagement>

<dependencies>
<dependency>
<groupId>io.jenkins.plugins.mina-sshd-api</groupId>
<artifactId>mina-sshd-api-common</artifactId>
</dependency>
<dependency>
<groupId>io.jenkins.plugins.mina-sshd-api</groupId>
Comment thread
kuisathaverat marked this conversation as resolved.
<artifactId>mina-sshd-api-core</artifactId>
</dependency>
<dependency>
<groupId>io.jenkins.plugins.mina-sshd-api</groupId>
<artifactId>mina-sshd-api-scp</artifactId>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>credentials</artifactId>
Expand All @@ -106,6 +118,7 @@
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>ssh-credentials</artifactId>
</dependency>
<!-- TODO remove in future versions -->
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>trilead-api</artifactId>
Expand Down
134 changes: 134 additions & 0 deletions src/main/java/io/jenkins/plugins/sshbuildagents/ssh/Connection.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
/*
* Copyright The Original Author or Authors
Comment thread
kuisathaverat marked this conversation as resolved.
* SPDX-License-Identifier: MIT
*/
package io.jenkins.plugins.sshbuildagents.ssh;

import com.cloudbees.plugins.credentials.common.StandardUsernameCredentials;
import java.io.IOException;
import java.io.OutputStream;
import org.apache.sshd.client.session.ClientSession;

/**
* Interface to manage an SSH connection.
*
*/
public interface Connection extends AutoCloseable {
Comment thread
kuisathaverat marked this conversation as resolved.
/**
* Execute a command and return the exit code returned when it finish.
*
* @param command Command to execute.
* @return The exit code of the command (if the command ran).
* @throws IOException in case of an error launching the command.
*/
int execCommand(String command) throws IOException;

/**
* Create a {@link ShellChannel} to execute non-interactive commands.
*
* @return Return a {@link ShellChannel}
* @throws IOException
Comment thread
kuisathaverat marked this conversation as resolved.
*/
ShellChannel shellChannel() throws IOException;

/**
* @return Return the host configured to connect by SSH.
*/
String getHostname();

/**
* @return Return the port configured to connect by SSH.
*/
int getPort();

/**
* Copy a file to the host by SCP. It does not create folders, so the folders of the path must
* exist prior to calling this.
* FIXME The remote file should be relative to the working directory.

Check warning on line 47 in src/main/java/io/jenkins/plugins/sshbuildagents/ssh/Connection.java

View check run for this annotation

ci.jenkins.io / Open Tasks Scanner

FIXME

HIGH: The remote file should be relative to the working directory.
* FIXME use SHA instead of MD5 to check the content of the file, it is no longer in the JDK.

Check warning on line 48 in src/main/java/io/jenkins/plugins/sshbuildagents/ssh/Connection.java

View check run for this annotation

ci.jenkins.io / Open Tasks Scanner

FIXME

HIGH: use SHA instead of MD5 to check the content of the file, it is no longer in the JDK.
* @param remoteFile Full path to the remote file.
Comment thread
kuisathaverat marked this conversation as resolved.
* @param data Array of bytes with the data to write.
* @param overwrite @{code true} to overwrite the file if it already exists. If @{false} and the file exists an @{code IOException} will be thrown.
* @param checkSameContent if true will calculate and compare the checksum of the remote file and data and if identical will skip writing the file.
* @throws IOException
*/
void copyFile(String remoteFile, byte[] data, boolean overwrite, boolean checkSameContent) throws IOException;

/**
* Set the TCP_NODELAY flag on connections.
*
* @param tcpNoDelay True to set TCP_NODELAY.
Comment thread
kuisathaverat marked this conversation as resolved.
*/
void setTCPNoDelay(boolean tcpNoDelay);

/**
* Establishes an SSH connection with the configuration set in the class.
*
* @return Return a {@link ClientSession} to interact with the SSH connection.
* @throws IOException
*/
ClientSession connect() throws IOException;

/**
* Set Server host verifier.
*
* @param verifier The Server host verifier to use.
*/
void setServerHostKeyVerifier(ServerHostKeyVerifier verifier);

/**
* Set the connection timeout.
*
* @param timeout Timeout in milliseconds.
*/
void setTimeout(long timeout);

/**
* Set the credential to use to authenticate in the SSH service.
*
* @param credentials Credentials used to authenticate.
*/
void setCredentials(StandardUsernameCredentials credentials);

/**
* Set the time to wait between retries.
*
* @param time Time to wait in seconds.
*/
void setRetryWaitTime(int time);

/**
* Set the number of times we will retry the SSH connection.
Comment thread
kuisathaverat marked this conversation as resolved.
*
* @param retries Number of retries.
*/
void setRetries(int retries);

/**
* Set the absolute path to the working directory.
*
* @param path absolute path to the working directory.
*/
void setWorkingDirectory(String path);

/**
* Set the standard error output.
*
* @param stderr Value of the new standard error output.
*/
void setStdErr(OutputStream stderr);

/**
* Set the standard output.
*
* @param stdout Value of the new standard output.
*/
void setStdOut(OutputStream stdout);

/**
* Check if the connection is open.
*
* @return True if the connection is open, false otherwise.
*/
boolean isOpen();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright The Original Author or Authors
* SPDX-License-Identifier: MIT
*/
package io.jenkins.plugins.sshbuildagents.ssh;

import java.io.IOException;

/**
* Class to manage key algorithms for SSH connections.
*
*/
public class KeyAlgorithm {
public String getKeyFormat() {
return "";
}

public void decodePublicKey(byte[] keyValue) throws IOException {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright The Original Author or Authors
* SPDX-License-Identifier: MIT
*/
package io.jenkins.plugins.sshbuildagents.ssh;

import java.util.List;

/**
* Interface to manage supported key algorithms for SSH connections.
*
*/
public interface KeyAlgorithmManager {

List<KeyAlgorithm> getSupportedAlgorithms();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright The Original Author or Authors
* SPDX-License-Identifier: MIT
*/
package io.jenkins.plugins.sshbuildagents.ssh;

import java.io.File;

/**
* Class to manage known hosts for SSH connections. It provides methods to verify host keys and
* manage known hosts files. TODO Implement a proper host key verification mechanism.

Check warning on line 11 in src/main/java/io/jenkins/plugins/sshbuildagents/ssh/KnownHosts.java

View check run for this annotation

ci.jenkins.io / Open Tasks Scanner

TODO

NORMAL: Implement a proper host key verification mechanism.
*
*/
public class KnownHosts {
public static final int HOSTKEY_IS_OK = 0;
public static final int HOSTKEY_IS_NEW = 1;
Comment thread
kuisathaverat marked this conversation as resolved.

public KnownHosts(File knownHostsFile) {}

public static String createHexFingerprint(String algorithm, byte[] key) {
return "";
}

public int verifyHostkey(String host, String algorithm, byte[] key) {
return 1;
}
Comment thread
kuisathaverat marked this conversation as resolved.

public String[] getPreferredServerHostkeyAlgorithmOrder(String host) {
return new String[0];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* Copyright The Original Author or Authors
* SPDX-License-Identifier: MIT
*/
package io.jenkins.plugins.sshbuildagents.ssh;

/**
* Interface to verify the server host key during SSH connections. TODO Implement a proper host key

Check warning on line 8 in src/main/java/io/jenkins/plugins/sshbuildagents/ssh/ServerHostKeyVerifier.java

View check run for this annotation

ci.jenkins.io / Open Tasks Scanner

TODO

NORMAL: Implement a proper host key
* verification mechanism.
*
*/
public interface ServerHostKeyVerifier {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright The Original Author or Authors
* SPDX-License-Identifier: MIT
*/
package io.jenkins.plugins.sshbuildagents.ssh;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

/**
* Interface to manage non-interactive sessions.
Comment thread
kuisathaverat marked this conversation as resolved.
* TODO review names for interactive and non-interactive sessions. Mina uses ShellChannel for interactive and ExecChannel for non-interactive.

Check warning on line 13 in src/main/java/io/jenkins/plugins/sshbuildagents/ssh/ShellChannel.java

View check run for this annotation

ci.jenkins.io / Open Tasks Scanner

TODO

NORMAL: review names for interactive and non-interactive sessions. Mina uses ShellChannel for interactive and ExecChannel for non-interactive.
*
*/
public interface ShellChannel extends AutoCloseable {
/**
* Execute a command in a non-interactive session and return without waiting for the command to complete.
*
* @param cmd
* @throws IOException
*/
void execCommand(String cmd) throws IOException;

/**
* @return The standard output of the process launched in a InputStream for reading.
*/
InputStream getInvertedStdout();

/**
* @return The standard input of the process launched in a OutputStream for writting.
*/
OutputStream getInvertedStdin();

/**
* @return the last error in the channel.
*/
Throwable getLastError();

/**
* @return the last command received in the SSH channel.
*/
String getLastAttemptedCommand();
}
Loading
Loading