简体   繁体   English

将屏蔽的Jenkins环境变量传递给Docker容器

[英]Passing Masked Jenkins Environment Variable to Docker container

I have a password parameter set in my Jenkins build containing some information I want kept secret. 我在Jenkins版本中设置了一个密码参数,其中包含一些我想保密的信息。 The Jenkins build will create a Docker container which needs access to this parameter. Jenkins构建将创建一个需要访问此参数的Docker容器。 Currently, my command looks like such: 目前,我的命令如下所示:

docker run -e PASSWORD=${PASSWORD} my_image my_command

This works as I expected it to--the PASSWORD parameter I have set in my build is passed as an environment variable to the Docker container which can then utilize it. 这可以按我预期的那样工作-我在构建中设置的PASSWORD参数作为环境变量传递给Docker容器,然后可以利用它。 This is part of my console output: 这是我的控制台输出的一部分:

+ docker run -e PASSWORD=abc123efg my_image my_command

The problem is that the raw password is shown in the output above. 问题是原始密码显示在上面的输出中。 Is there any workaround or alternative solution I can use to pass the masked parameter to my container without exposing it in the output? 是否可以使用任何变通方法或替代解决方案,以将被屏蔽的参数传递给我的容器而不在输出中暴露该参数?

有许多插件可以掩盖控制台输出中的特定参数,例如https://wiki.jenkins-ci.org/display/JENKINS/Mask+Passwords+Plugin

Passing sensitive information as plaintext imho is not a good choice even if masked. 即使将敏感信息屏蔽,也不能将其作为纯文本imho传递。 If you control the build pipeline then it might be a more robust option to go with a shared secret approach instead. 如果您控制构建管道,那么使用共享秘密方法可能是一个更可靠的选择。 It's relatively straightforward to implement and well documented. 实施起来相对简单,并且有据可查。 From a quick google search I'll pick http://bigthinkingapplied.com/key-based-encryption-using-openssl/ which explains it quite nicely. 从Google的快速搜索中,我将选择http://bigthinkingapplied.com/key-based-encryption-using-openssl/ ,它对此进行了很好的解释。 In a nutshell... 简而言之...

  • Create a random file ("shared secret") and make it available in your build system as well as in the docker container 创建一个随机文件(“共享机密”)并使其在构建系统以及Docker容器中可用
  • Encrypt the password using the shared secret 使用共享机密加密密码
  • Pass the encrypted password to the docker container 将加密的密码传递到Docker容器
  • In the docker container, use the shared secret to decrypt the password 在Docker容器中,使用共享密钥来解密密码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM