Retrieving secret from HashiCorp Vault in jenkins pipeline

2.6k Views Asked by At

I am trying to retreive hashicorp vault secret and use it in jenkins pipeline. I managed to connect to hashicorp vault, but pipeline fails to retreive the secret saved in vault.

Pipeline output:

Started by user admin
[Pipeline] Start of Pipeline
[Pipeline] node
Running on Jenkins in /var/lib/jenkins/workspace/test_pipeline
[Pipeline] {
[Pipeline] withVault
Retrieving secret: my.secrets/data/dev
Access denied to Vault Secrets at 'my.secrets/data/dev'
[Pipeline] {
[Pipeline] sh
+ echo

[Pipeline] }
[Pipeline] // withVault
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS

Pipeline: key heslo exists in my.secrets/data/dev path

node {

    def secrets = [
        [path: 'my.secrets/data/dev', engineVersion: 2, secretValues: [
            [envVar: 'value', vaultKey: 'heslo']
      ]]     
    ]

    def configuration = [vaultUrl: 'http://10.47.0.235:8200/',
                         vaultCredentialId: 'b0467c75-24e4-4307-9a35-f7da364f6285',
                         engineVersion: 2]
  
    withVault([configuration: configuration, vaultSecrets: secrets]) {
        sh 'echo $value'
    
    }
}

my jenkins-policy.hcl file for approle method to access vault from jenkins:

path "my.secrets/data/dev" {
    capabilities = [ "read" ]
  }

Thank you in advance

1

There are 1 best solutions below

5
On

Remove the "data" from the "path" definition:

path: 'my.secrets/dev'

You must use the "data" in the policy path but not when retrieving the secret.