-
Notifications
You must be signed in to change notification settings - Fork 141
feat: new launcher using Apache Mina sshd library #570
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
kuisathaverat
wants to merge
24
commits into
jenkinsci:main
Choose a base branch
from
kuisathaverat:apache_mina
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 19 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 29267ed
fix: apply spotless formatting (#595)
kuisathaverat 9b0d756
feat: move to use Apache Mina SSHD
kuisathaverat 9a0dab4
fix: do not run on windows some test
kuisathaverat 750a02c
fix: test on windows
kuisathaverat d63b129
test: make 10min connections test instead 15min
kuisathaverat c6b837d
fix: cleanup pom
kuisathaverat aa76259
fix: licenses
kuisathaverat c947758
chore: suggestions
kuisathaverat f1a45b1
fix: copy file permissions
kuisathaverat 4015ec2
chore: suggestions
kuisathaverat 68eed5e
chore: remove docker agents files
kuisathaverat 0ecc904
chore: add WIP warning
kuisathaverat a224de7
chore: update Junit 5
kuisathaverat 70667e2
chore: add (alpha) to the name
kuisathaverat d90eff3
fix: tests
kuisathaverat ce4b6c3
chore: disable host verification selection
kuisathaverat 1239993
chore: remove eddsa-api dependency
kuisathaverat 3cc712a
feta: use SSHAuthenticator from mina-sshd-api plugin
kuisathaverat d17df70
Apply suggestions from code review
kuisathaverat 3d35221
Apply suggestions from code review
kuisathaverat da28716
chore: jnord suggestions
kuisathaverat 65f2bfe
chore: more suggestions
kuisathaverat 62ceadf
fix: sportbugs
kuisathaverat File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
144 changes: 144 additions & 0 deletions
144
src/main/java/io/jenkins/plugins/sshbuildagents/ssh/Connection.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,144 @@ | ||
| /* | ||
| * Copyright The Original Author or Authors | ||
kuisathaverat marked this conversation as resolved.
Show resolved
Hide 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 { | ||
kuisathaverat marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| /** | ||
| * Execute a command and return the error code returned when it finish. | ||
kuisathaverat marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * | ||
| * @param command Command to execute. | ||
| * @return The error code returned by the command. | ||
| * @throws IOException in case of error. | ||
kuisathaverat marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| */ | ||
| int execCommand(String command) throws IOException; | ||
|
|
||
| /** | ||
| * Create a {@link #shellChannel()} to execute non-interactive commands. | ||
kuisathaverat marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * | ||
| * @return Return a {@link #shellChannel()} | ||
kuisathaverat marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * @throws IOException | ||
kuisathaverat marked this conversation as resolved.
Show resolved
Hide 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(); | ||
|
|
||
| /** Close the connections and resources associated. */ | ||
| void close(); | ||
kuisathaverat marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
kuisathaverat marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| * Copy a file to the host by SCP. It does not create folders, so the folders of the path should | ||
| * exist. | ||
kuisathaverat marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * | ||
| * @param remoteFile Full path to the remote file. | ||
kuisathaverat marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| * @param bytes Array of bytes with the data to write. | ||
kuisathaverat marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * @param overwrite True to overwrite exit files. | ||
kuisathaverat marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * @param checkSameContent True to check the md5 of the file before write it and do not update the | ||
kuisathaverat marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * lie if it is the same. | ||
kuisathaverat marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * @throws IOException | ||
| */ | ||
| void copyFile(String remoteFile, byte[] bytes, boolean overwrite, boolean checkSameContent) throws IOException; | ||
kuisathaverat marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| * Set server host key Algorithms. | ||
| * | ||
| * @param algorithms Array of Host Key Algorithms. | ||
| */ | ||
| void setServerHostKeyAlgorithms(String[] algorithms); | ||
kuisathaverat marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| * Set the TCP_NODELAY flag on connections. | ||
| * | ||
| * @param tcpNoDelay True to set TCP_NODELAY. | ||
kuisathaverat marked this conversation as resolved.
Show resolved
Hide 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. | ||
kuisathaverat marked this conversation as resolved.
Show resolved
Hide 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(); | ||
| } | ||
19 changes: 19 additions & 0 deletions
19
src/main/java/io/jenkins/plugins/sshbuildagents/ssh/KeyAlgorithm.java
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
| 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 {} | ||
| } | ||
16 changes: 16 additions & 0 deletions
16
src/main/java/io/jenkins/plugins/sshbuildagents/ssh/KeyAlgorithmManager.java
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
| 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(); | ||
| } |
31 changes: 31 additions & 0 deletions
31
src/main/java/io/jenkins/plugins/sshbuildagents/ssh/KnownHosts.java
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
| 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. | ||
| * | ||
| */ | ||
| public class KnownHosts { | ||
| public static final int HOSTKEY_IS_OK = 0; | ||
| public static final int HOSTKEY_IS_NEW = 1; | ||
kuisathaverat marked this conversation as resolved.
Show resolved
Hide 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; | ||
| } | ||
kuisathaverat marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| public String[] getPreferredServerHostkeyAlgorithmOrder(String host) { | ||
| return new String[0]; | ||
| } | ||
| } | ||
12 changes: 12 additions & 0 deletions
12
src/main/java/io/jenkins/plugins/sshbuildagents/ssh/ServerHostKeyVerifier.java
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
| 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 | ||
| * verification mechanism. | ||
| * | ||
| */ | ||
| public interface ServerHostKeyVerifier {} | ||
50 changes: 50 additions & 0 deletions
50
src/main/java/io/jenkins/plugins/sshbuildagents/ssh/ShellChannel.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| /* | ||
| * 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. | ||
kuisathaverat marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| * | ||
| */ | ||
| public interface ShellChannel extends AutoCloseable { | ||
| /** | ||
| * Executed a command in a non-interactive session and exit, it does not wait for the result. | ||
kuisathaverat marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * | ||
| * @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 getLastHint(); | ||
kuisathaverat marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| * Closses the channel and resources associated. | ||
| * | ||
| * @throws IOException in case of error. | ||
| */ | ||
| void close() throws IOException; | ||
kuisathaverat marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.