Last active
October 12, 2018 18:35
-
-
Save rtyler/cd3a3f759c46f308bf7151819f5538a0 to your computer and use it in GitHub Desktop.
Determine whether there are passphrase-protected ed25519 keys in a Jenkins instance
This file contains 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
import com.cloudbees.hudson.plugins.folder.* | |
import com.cloudbees.hudson.plugins.folder.properties.* | |
import com.cloudbees.hudson.plugins.folder.properties.FolderCredentialsProvider.FolderCredentialsProperty | |
import com.cloudbees.plugins.credentials.* | |
import com.cloudbees.jenkins.plugins.sshcredentials.SSHUserPrivateKey | |
/* Let's see if the key is ed25518 */ | |
boolean checkKey(def key) { | |
boolean found = false | |
if ((key instanceof SSHUserPrivateKey) && (key.passphrase)) { | |
key.privateKeys.each { privateKey -> | |
if (privateKey =~ '----BEGIN OPENSSH PRIVATE KEY-----') { | |
println "" | |
println "The SSH key (${CredentialsNameProvider.name(key)}) may cause failures with the 2.73.1 upgrade!" | |
found = true | |
} | |
} | |
} | |
return found | |
} | |
/* Find all globally defined SSH Keys with a passphrase */ | |
SystemCredentialsProvider.instance.store.domains.each { domain -> | |
SystemCredentialsProvider.instance.store.getCredentials(domain).each { key -> | |
if (checkKey(key)) { | |
println "(in the global scope, under the domain ${domain.name})" | |
} | |
} | |
} | |
/* Find all Folder-defined SSH keys with a passphrase */ | |
Jenkins.instance.getAllItems(AbstractFolder).each { folder -> | |
def p = folder.properties.get(FolderCredentialsProperty) | |
p?.store.domains.each { domain -> | |
p.store.getCredentials(domain).each { key -> | |
if (checkKey(key)) { | |
println "(in the folder ${folder.displayName}, under the domain ${domain})" | |
} | |
} | |
} | |
} | |
return null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
As this script is listed in the Upgrade Guide, I ll leave the comment here that it fails with the following error on Jenkins LTS 2.60.1.
Happens on a folder that does not seem to have any properties (println the folder.properties in line 35 outputs 'null').