【问题标题】:How to encrypt a files in Jenkins如何在 Jenkins 中加密文件
【发布时间】:2020-09-14 13:29:12
【问题描述】:

我正在尝试从 jenkins 运行 Node.js 应用程序,该应用程序会备份我们的 API 管理平台。 当我们在詹金斯服务器上获得备份时,我们有以下目录 - 备份

├── apps
├── secretes
│   ├── abc
│   ├── pqr
│   └── xyz
└─ devs

秘密目录中有abcpqrxyz等目录,其中存储了一些包含机密数据的.txt文件。

我想在创建 zip 并将其放在备份存储位置之前加密 secretes 目录中存在的所有文件。任何加密方法都适合我。

【问题讨论】:

    标签: linux shell jenkins encryption


    【解决方案1】:

    使用 7zip 等外部工具创建高度加密的 zip 文件。

    使用此命令安装它sudo apt-get install p7zip-full -y

    使用以下命令加密 Jenkins 的 secretes 目录;

    7z a -mhe=on -t7z -mx=9 -pyour_custom_password output_encryped_backup_archive.7z secretes
    

    您可以在https://linux.die.net/man/1/7z阅读有关上述选项的更多信息

    您可以使用 crontab 自动执行此脚本。

    【讨论】:

      【解决方案2】:

      选项 1. Jenkins 凭据插件

      将所有凭据/秘密存储在一个地方。

      https://www.jenkins.io/doc/pipeline/steps/credentials-binding/

      例子

      node {
        ws {
          withCredentials([file(credentialsId: 'secret', variable: 'FILE')]) {
            sh 'use $FILE'
          }
        }
      }
      

      选项 2. git-crypt

      使用模块 git-crypt 直接存储到 git 中。在 Jenkins 凭据中,您已经存储了密钥

      https://github.com/AGWA/git-crypt

      要获取数据,只需使用额外的加密密钥检查 git

      选项 3. 将加密存档存储在 acrtifactory/S3 中,并将密码存储在 Jenkins 凭据中

      例如来自https://www.jenkins.io/doc/pipeline/steps/credentials-binding/

      node {
        withCredentials([usernameColonPassword(credentialsId: 'mylogin', variable: 'USERPASS')]) {
          sh '''
            set +x
            curl -u "$USERPASS" https://private.server/ > output
          '''
        }
      }
      

      【讨论】:

        猜你喜欢
        • 2011-01-27
        • 1970-01-01
        • 1970-01-01
        • 2013-03-01
        • 2011-05-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多