Skip to content

Instantly share code, notes, and snippets.

@kisztof
Last active April 14, 2021 09:07
Show Gist options
  • Save kisztof/700a2151faf4432433424aaea45e846d to your computer and use it in GitHub Desktop.
Save kisztof/700a2151faf4432433424aaea45e846d to your computer and use it in GitHub Desktop.
Jenkins + Hashicorp Vault
vault secrets enable -path=secret_storage kv
vault kv put secret_storage/test1 ke1="val1"
vault policy write jenkins policy.hcl
vault auth enable approle
vault write auth/approle/role/jenkins \
secret_id_ttl=48h \
token_num_uses=10 \
token_ttl=96h \
token_max_ttl=96h \
secret_id_num_uses=1 \
policies=jenkins
vault read -format=json auth/approle/role/jenkins/role-id > role.json
vault write -format=json -f auth/approle/role/jenkins/secret-id > secretid.json
path "auth/approle/role/jenkins/secret-id" {
capabilities = ["create","update"]
}
path "secret_storage/*" {
capabilities = ["read","create","update"]
}
node('master') {
stage('Test Vault Connection') {
withVault(
configuration: [
engineVersion: 2,
timeout: 60,
vaultCredentialId: 'VAULT_CREDENTIALS', //Jenkins credential approle key (role-id, secret-id pair) https://plugins.jenkins.io/hashicorp-vault-plugin/
vaultUrl: 'http://127.0.0.1:8200'
],
vaultSecrets: [
[
path: 'secret_storage/test1', secretValues: [[envVar: 'test1', vaultKey: 'key1']]
]
]
) {
sh 'echo $test1'
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment