Skip to content
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

save vault secret to file #136

Closed
danielraq opened this issue Oct 19, 2020 · 8 comments
Closed

save vault secret to file #136

danielraq opened this issue Oct 19, 2020 · 8 comments

Comments

@danielraq
Copy link

Hello,

configuration-as-code:1.44
hashicorp-vault:3.6.1

I've a 'special' case. Gerrit plugins looks for a ssh key in a file system. Is there a way to extract it from the vault and save to file when jenkins starts in jcasc mode?

@jetersen
Copy link
Member

jetersen commented Oct 19, 2020

Can you link to gerrit plugin cause there many.

Gerrit plugins should be using credentials plugin? Than yes JCasC can create a credential ssh key.

@danielraq
Copy link
Author

https://plugins.jenkins.io/gerrit-trigger/

at the moment i don't see an option to use credentials plugin with gerrit trigger :(

@jetersen
Copy link
Member

Sounds like a lack on their part not JCasC or this plugin.

@danielraq
Copy link
Author

Agree in 100%. I'm looking for a work around for this problem.

@jetersen
Copy link
Member

Ah your missing: jenkinsci/configuration-as-code-groovy-plugin#3 😓

@danielraq
Copy link
Author

i know about that plugin ;) just wanted to know if there is something more sophisticated. unfortunately i've ended with groovy initial script:

import jenkins.*
import jenkins.model.* 
import hudson.*
import hudson.model.*
import  java.lang.System;

key_path=System.getenv("JENKINS_HOME" + "./ssh")
new File(key_path).mkdir() 
File file = new File(key_path+ '/id_rsa')


def jenkinsCredentials = com.cloudbees.plugins.credentials.CredentialsProvider.lookupCredentials(
        com.cloudbees.plugins.credentials.Credentials.class,
        Jenkins.instance,
        null,
        null
);


for (creds in jenkinsCredentials) {
  if(creds.id == System.getenv('GERRIT_USER')+"-ssh_key"){
    key = creds.privateKey
    }
}

file.write(key)

@jetersen
Copy link
Member

Ah yes, you can just use groovy to extract the credential, good point 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants