-
Notifications
You must be signed in to change notification settings - Fork 45
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
Better built-in secure field support #64
Comments
Here's how it can be supported. Based on using jenkins:
secrets_id: "<Jenkins RSA key identifier>"
secrets:
- key: MY_ENVIRONMENT_VAR
secret: <rsa encrypted string>
- key: ANOTHER_ENVIRON_VAR
secret: <rsa encypted string> Job DSL to obtain the private key from Jenkins. import jenkins.model.Jenkins
public String getFolderRSAKeyCredentials(String folder, String credentials_id) {
def credentials
def properties = Jenkins.getInstance().getJob(folder).getProperties()
for(int i=0; i < properties.size(); i++) {
if(properties.get(i).getClass().getSimpleName() == 'FolderCredentialsProperty') {
credentials = properties.get(i)
}
}
String found_credentials = ''
if(credentials != null ) {
credentials.getDomainCredentials().each { domain ->
domain.getCredentials().each { credential ->
if(credential != null && credential.getClass().getSimpleName() == 'BasicSSHUserPrivateKey') {
if(credential.getId() == credentials_id) {
found_credentials = credential.getPrivateKey()
}
}
}
}
}
return found_credentials
}
println getFolderRSAKeyCredentials('folder', 'cred-id') |
Created a test repo. https://github.com/samrocketman/jervis-secrets-test |
https://wiki.jenkins-ci.org/display/JENKINS/Mask+Passwords+Plugin can be used to set the secret vars. |
File priv_key = File.createTempFile('temp', '.txt')
//delete file if JVM is shut down
priv_key.deleteOnExit()
try {
priv_key.write(getFolderRSAKeyCredentials('folder', 'cred-id'))
//do some stuff with secrets
//use the absolute path when referencing
//priv_key.getAbsolutePath()
}
catch(Throwable t) {
//clean up temp file
priv_key.delete()
//rethrow caught exception
throw t
} |
https://issues.jenkins-ci.org/browse/JENKINS-31674 for Job DSL implementation. |
Right now a lot of the work for secure field support is offloaded to the user. I want this to be made even easier by offloading most of this work into the library. See also #22.
The text was updated successfully, but these errors were encountered: