You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Follow Jenkins handbook steps to setting up an SSH credential (add SSH username with private key under Manage Jenkins > Credentials, and paste the SSH private key under "Enter directly").
Also according to the same handbook steps, start up a docker-ssh-agent instance with the corresponding public key, add a node with "Launch agents via SSH" launch method in Jenkins, and select the credentials just added.
Save. The node connects without issues.
Go to Manage Jenkins > Configuration as Code and click "View configuration". Copy credentials settings that contains the privateKey value, and paste into the JCasC configuration file.
Wipe docker containers and volumes etc to start from a clean slate, then start everything up again to let JCasC configure the credentials from the YAML configuration.
After starting up Jenkins from a clean slate, add a node in the same way again using the same credential.
Expected Results
After SSH credential has been set up by JCasC, the SSH agent connects just like it did when the credentials were set up through the GUI .
Actual Results
The node cannot connect. Looking at log, it complains that the PEM for the private key is of an unknown type, which suggests to me that it has been corrupted. Full log:
SSHLauncher{host='jenkins-agent', port=22, credentialsId='jenkins', jvmOptions='', javaPath='', prefixStartSlaveCmd='', suffixStartSlaveCmd='', launchTimeoutSeconds=60, maxNumRetries=10, retryWaitTime=15, sshHostKeyVerificationStrategy=hudson.plugins.sshslaves.verifiers.ManuallyTrustedKeyVerificationStrategy, tcpNoDelay=true, trackCredentials=true}
[11/30/23 06:43:07] [SSH] Opening SSH connection to jenkins-agent:22.
[11/30/23 06:43:07] [SSH] SSH host key matches key seen previously for this host. Connection will be allowed.
ERROR: Server rejected the 1 private key(s) for jenkins (credentialId:jenkins/method:publickey)
ERROR: Failed to authenticate as jenkins with credential=jenkins
java.io.IOException: Publickey authentication failed.
at com.trilead.ssh2.auth.AuthenticationManager.authenticatePublicKey(AuthenticationManager.java:349)
at com.trilead.ssh2.Connection.authenticateWithPublicKey(Connection.java:472)
at com.cloudbees.jenkins.plugins.sshcredentials.impl.TrileadSSHPublicKeyAuthenticator.doAuthenticate(TrileadSSHPublicKeyAuthenticator.java:110)
at com.cloudbees.jenkins.plugins.sshcredentials.SSHAuthenticator.authenticate(SSHAuthenticator.java:431)
at com.cloudbees.jenkins.plugins.sshcredentials.SSHAuthenticator.authenticate(SSHAuthenticator.java:468)
at hudson.plugins.sshslaves.SSHLauncher.openConnection(SSHLauncher.java:878)
at hudson.plugins.sshslaves.SSHLauncher.lambda$launch$0(SSHLauncher.java:434)
at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.base/java.lang.Thread.run(Unknown Source)
Caused by: java.io.IOException: PEM problem: it is of unknown type. Supported algorithms are :[ssh-ed25519, ecdsa-sha2-nistp521, ecdsa-sha2-nistp384, ecdsa-sha2-nistp256, rsa-sha2-256, rsa-sha2-512, ssh-rsa, ssh-dss]
at com.trilead.ssh2.crypto.PEMDecoder.decodeKeyPair(PEMDecoder.java:482)
at com.trilead.ssh2.auth.AuthenticationManager.authenticatePublicKey(AuthenticationManager.java:290)
... 10 more
[11/30/23 06:43:07] [SSH] Authentication failed.
Authentication failed.
[11/30/23 06:43:07] Launch failed - cleaning up connection
[11/30/23 06:43:07] [SSH] Connection closed.
Anything else?
I'm aware that there is a warning in the GUI that the exported configuration is not intended to be directly usable. However, this is the only way I know of to find out how to actually configure an SSH private key, as I have not found any documentation on how to do it. As an alternative, I have tried reading the key from a file like so:
but this gives me the same error at connection. So if a non-working exported configuration is the intended behavior, please direct me to a description of how to set up an SSH private key credential using JCasC. I would actually very much prefer to read it from a separate file since I don't want to keep secrets in the YAML file.
The text was updated successfully, but these errors were encountered:
mattiasflodin
changed the title
SSH username with private key credential is corrupted by export + import
SSH private key credential is corrupted by export + import
Nov 30, 2023
Jenkins and plugins versions report
Environment
What Operating System are you using (both controller, and any agents involved in the problem)?
Controller: jenkins/jenkins:lts-alpine docker image (Alpine Linux 3.18)
Agent: jenkins/ssh-agent:latest-jdk17 docker image (Debian GNU/Linux 12)
Reproduction steps
Expected Results
After SSH credential has been set up by JCasC, the SSH agent connects just like it did when the credentials were set up through the GUI .
Actual Results
The node cannot connect. Looking at log, it complains that the PEM for the private key is of an unknown type, which suggests to me that it has been corrupted. Full log:
Anything else?
I'm aware that there is a warning in the GUI that the exported configuration is not intended to be directly usable. However, this is the only way I know of to find out how to actually configure an SSH private key, as I have not found any documentation on how to do it. As an alternative, I have tried reading the key from a file like so:
but this gives me the same error at connection. So if a non-working exported configuration is the intended behavior, please direct me to a description of how to set up an SSH private key credential using JCasC. I would actually very much prefer to read it from a separate file since I don't want to keep secrets in the YAML file.
The text was updated successfully, but these errors were encountered: