【发布时间】:2018-01-16 01:22:27
【问题描述】:
我想将 ssh 密钥存储到 HashiCorp Vault 中的 git,然后在我的 Jenkins 文件中,我想获取我的密钥并使用它来签出并提交到存储库,是否有可能或者我应该采用传统方式,在 Jenkins 中定义凭据然后使用它。提出此类问题的目的是因为我想将所有机密信息保存在 Vault 中
【问题讨论】:
标签: git jenkins hashicorp-vault
我想将 ssh 密钥存储到 HashiCorp Vault 中的 git,然后在我的 Jenkins 文件中,我想获取我的密钥并使用它来签出并提交到存储库,是否有可能或者我应该采用传统方式,在 Jenkins 中定义凭据然后使用它。提出此类问题的目的是因为我想将所有机密信息保存在 Vault 中
【问题讨论】:
标签: git jenkins hashicorp-vault
我相信您正在寻找 Hashicorp Vault Plugin - 它可以让您访问 Jenkinsfile 中的秘密 as shown here:
node {
// define the secrets and the env variables
def secrets = [
[$class: 'VaultSecret', path: 'secret/testing', secretValues: [
[$class: 'VaultSecretValue', envVar: 'testing', vaultKey: 'value_one'],
[$class: 'VaultSecretValue', envVar: 'testing_again', vaultKey: 'value_two']]],
[$class: 'VaultSecret', path: 'secret/another_test', secretValues: [
[$class: 'VaultSecretValue', envVar: 'another_test', vaultKey: 'value']]]
]
// optional configuration, if you do not provide this the next higher configuration
// (e.g. folder or global) will be used
def configuration = [$class: 'VaultConfiguration',
vaultUrl: 'http://my-very-other-vault-url.com',
vaultCredentialId: 'my-vault-cred-id']
// inside this block your credentials will be available as env variables
wrap([$class: 'VaultBuildWrapper', configuration: configuration, vaultSecrets: secrets]) {
sh 'echo $testing'
sh 'echo $testing_again'
sh 'echo $another_test'
}
}
【讨论】:
您可以使用相同的 vault jenkins 插件来完成。
withVault(configuration: [timeout: 60, vaultCredentialId: '<ur vault credential>', vaultUrl: '<ur vault URL>'], vaultSecrets: [[path: 'secret/<ur secret ssh path>', secretValues: [[vaultKey: '<ur key of ssh>']]]]) {
//use as env.<<ur key of ssh>>
}
【讨论】: