Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I download a jenkins secret file from the credential store?

I can only upload an existing jenkins secret file not download the existing one.

How do I download an existing secret file I uploaded to confirm its contents?

like image 240
red888 Avatar asked Jul 25 '18 17:07

red888


People also ask

Where are Jenkins secret files stored?

Encryption of Secrets and Credentials. Jenkins uses AES to encrypt and protect secrets, credentials, and their respective encryption keys. These encryption keys are stored in $JENKINS_HOME/secrets/ along with the master key used to protect said keys.

How use Jenkins credentials secret file?

Secret file - click the Choose file button next to the File field to select the secret file to upload to Jenkins. SSH Username with private key - specify the credentials Username, Private Key and optional Passphrase into their respective fields.

How do I unmask credentials in Jenkins?

Go to the jenkins workspace and look inside the file. The token will be present in plain text there. Further easy way will be to print the base64 encoded value of the credential and then decode it.


2 Answers

If you have shell access to and sudo/root/Jenkins Unix user permissions on the machine running Jenkins, you can retrieve the secret file by doing the following:

  • In some Jenkins job that has permissions to access the secret file, select Configure.
  • On the Configuration interface, under Build Environment, select Use secret text(s) or file(s).
  • Click Add -> Secret file. This creates a new Secret file binding.
  • Select Specific credentials, then from the drop-down menu below it select the secret file you would like to retrieve. Let's assume your secret file is stored under the filename my-secret-file.txt.
  • Assign to this secret file a variable e.g. MY_SECRET_FILE_TXT.
  • Now, under Pre Steps, click Add pre-build step -> Execute shell.
  • In the Command text area, add the following shell script:

    echo "executing user is $(whoami)"
    
    # remove my-secret-file.txt before possibly getting an overwriting error
    rm -f $WORKSPACE/my-secret-file.txt
    
    echo "Jenkins project workspace: $WORKSPACE"
    cp $MY_SECRET_FILE_TXT $WORKSPACE
    
  • Click Save to save this configuration.

The next time a build is triggered for this project, the secret file should appear in this project's workspace, i.e. at location $WORKSPACE/my-secret-file.txt. As an example, on my Ubuntu 14.04.5 LTS installation with installed package and daemonjenkins, that location is /var/lib/jenkins/workspace/$JENKINS_PROJECT_NAME/my-secret-file.txt

like image 73
Abdull Avatar answered Oct 18 '22 01:10

Abdull


I usually extract secrets from jenkins by creating a job like this:

enter image description here

Jenkins masks all the keys in the output, so just replace one character when you print it out. If it turns out there is another 0 in your key, it'll appear as ******* and you can try replacing a different character, or splitting it in two and printing the two halfs on different lines, or another similar trick.

You can also just stick it straight into a file like this.

echo $HELLO > slack-key.txt
like image 1
Alex028502 Avatar answered Oct 18 '22 00:10

Alex028502