【问题标题】:Jenkins: How to get an encrypted credentials password from shell script?Jenkins:如何从 shell 脚本中获取加密的凭据密码?
【发布时间】:2017-03-13 15:17:22
【问题描述】:

当密码被加密并存储到 credentials.xml 时,我使用的是 secrets/master.key。但是在新的 jenkins 设置中恢复同一组 credentials.xml 和 master.key 不起作用。我什至尝试恢复 secret.key 但这也不起作用。

我还注意到 iscredentials.xml 中的加密字符串对于相同的字符串也不相同。 我正在尝试自动化詹金斯设置。有没有办法获得詹金斯从 bash 生成的加密密码?

【问题讨论】:

    标签: bash encryption jenkins


    【解决方案1】:

    Jenkins 及其插件通常使用 Secret 类加密字符串,该类 (AFAICT) 将密钥存储在 ${JENKINS_HOME}/secrets/hudson.util.Secret 下。

    我不知道任何简单的独立解决方案,但您可以使用 Jenkins Script Console(或 groovy CLI 命令)尝试解密您拥有的秘密值:

    import hudson.util.Secret
    
    Secret a = Secret.fromString('my secret value')
    String ciphertext = a.getEncryptedValue()
    println ciphertext
    // '{AQAAABAAAAAQdIQUuG2AhKoV7mCIcd3PXBdw8ItgchIrvQrQ=}'
    // or similar; will change with each new secret object
    
    Secret b = Secret.decrypt(ciphertext)
    String plaintext = b.getPlainText()
    println plaintext
    // 'my secret value'
    

    【讨论】:

    • 你能告诉我们怎么做吗?
    【解决方案2】:
      host=http://$JENKINS_USERNAME:$JENKINS_PASSWORD@localhost:8080
     CRUMB=$(curl -s "$host"'/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,":",//crumb)')
     encrypted_passphrase=$(curl  -H "$CRUMB" -d "script=println(hudson.util.Secret.fromString('password').getEncryptedValue())" -X POST $host/scriptText)
    

    【讨论】:

      猜你喜欢
      • 2018-07-20
      • 2018-07-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-28
      • 1970-01-01
      • 2017-02-04
      相关资源
      最近更新 更多