获取所有秘密并将其放入 Jenkins 和 hashcorpVault 上的 env 文件中

Has*_*sha 5 jenkins jenkins-plugins hashicorp-vault

目前我们正在构建詹金斯部署管道。在这些构建中,我们使用 HachiCorp 金库进行秘密管理。为了获取秘密,我们使用hashcorp-vault-plugin。问题是我们想要声明管道脚本上的所有变量,就像这样-testing'、'testing_again'、secret/another_test(我们不希望这样)

node {
    // define the secrets and the env variables
    // engine version can be defined on secret, job, folder or global.
    // the default is engine version 2 unless otherwise specified globally.
    def secrets = [
        [path: 'secret/testing', engineVersion: 1, secretValues: [
            [envVar: 'testing', vaultKey: 'value_one'],
            [envVar: 'testing_again', vaultKey: 'value_two']]],
        [path: 'secret/another_test', engineVersion: 2, secretValues: [
            [vaultKey: 'another_test']]]
    ]

    // optional configuration, if you do not provide this the next higher configuration
    // (e.g. folder or global) will be used
    def configuration = [vaultUrl: 'http://my-very-other-vault-url.com',
                         vaultCredentialId: 'my-vault-cred-id',
                         engineVersion: 1]
    // inside this block your credentials will be available as env variables
    withVault([configuration: configuration, vaultSecrets: secrets]) {
        sh 'echo $testing'
        sh 'echo $testing_again'
        sh 'echo $another_test'
    }
} 
Run Code Online (Sandbox Code Playgroud)

但需要一些这样的东西 -

  1. 获取所有秘密作为键和值
  2. 在构建项目之前放置一个 env 文件
  3. 构建项目后,销毁 env 文件。

是否可以通过 jenkins hashicorp-vault-plugin 或通过curl从vault中获取这些秘密并通过shellcommand进行处理(示例很棒)。

小智 1

在保险库插件中不可能将秘密归档。仅立即放入环境变量。存储在 env 中后,您可以做任何您想做的事情:)您可以做类似的事情

sh 'echo $YOURVAR > .env'
Run Code Online (Sandbox Code Playgroud)

通过保险库概念获取所有秘密作为键和值,您应该知道秘密名称才能访问它。不确定你的情况应该如何

ps如果您需要文件凭据,您可以使用 jenkins 的凭据凭据绑定插件