简体   繁体   English

openssl 无法在 AWS ECS 容器上创建或写入 p12 文件

[英]openssl Cannot Create or Write to p12 File on AWS ECS Container

I have two docker images, one is a base image and the other uses the base image to create a more specific image for a Java microservice.我有两个 docker 图像,一个是基础图像,另一个使用基础图像为 Java 微服务创建更具体的图像。

The base image calls an entrypoint bash script, which in turn calls a Python script.基础映像调用入口点 bash 脚本,该脚本又调用 Python 脚本。 I wasn't involved in the initial setup of this so can't comment on why it is done this way, but it spins up the microservice fine so there is no issue with it as it is.我没有参与这个的初始设置,所以不能评论为什么这样做,但它可以很好地启动微服务,所以它没有问题。

However in the Python script I am now trying to add some extra Java SSL parameters to support HTTPS traffic.然而,在 Python 脚本中,我现在尝试添加一些额外的 Java SSL 参数以支持 HTTPS 流量。 I'm quite new to this but others in my company have done a similar thing which has worked.我对此很陌生,但我公司的其他人也做过类似的事情,而且效果很好。

In my Python script I'm running openssl to create cert files, using AWS SSM parameters for the content.在我的 Python 脚本中,我运行 openssl 来创建证书文件,使用内容的 AWS SSM 参数。 openssl should then output a "bundle.p12" file, collection of the certs. openssl 应该是 output 一个“bundle.p12”文件,证书的集合。

What I'm finding is that the script cannot create this bundle.p12 file.我发现脚本无法创建此 bundle.p12 文件。 I have since tried having a blank bundle.p12 file already on the container, but then it cannot write to it, ie it remains blank.从那以后,我尝试在容器上已有一个空白的 bundle.p12 文件,但是它无法写入它,即它仍然是空白的。

subprocess.run(['sudo', 'openssl', 'pkcs12', '-export', '-password', 'env:PASSWORD', '-in', './microservice/cloudwild.crt', '-certfile', './microservice/cloudchain.pem', '-inkey' ,'./microservice/cloudwild.key', '-name', 'bundle', '-out', './microservice/bundle.p12'])
subprocess.run(['ls','-la','./microservice'])
subprocess.run(['keytool', '-importkeystore', '-noprompt', '-deststorepass', '$PASSWORD', '-srcstorepass', '$KEYSTORE_PASSWORD', '-destkeystore', './microservice/keystore.p12', '-deststoretype', 'pkcs12', '-srckeystore', './microservice/bundle.p12', '-srcstoretype', 'PKCS12'])

The ls -la command after openssl shows that bundle.p12 is still 0 bytes. openssl 之后的 ls -la 命令显示 bundle.p12 仍然是 0 字节。 keytool then throws an error saying the p12 file exists, but is blank.然后 keytool 抛出一个错误,指出 p12 文件存在,但是是空白的。

So the issue appears to be openssl and what looks like permissions.所以问题似乎是 openssl 和权限。 However in the base image dockerfile I am setting the whole folder the p12 file is in, and the p12 file itself, to a user "bob" and switching to that user prior to calling the entrypoint bash script (which calls the python script).然而,在基本图像 dockerfile 中,我将 p12 文件所在的整个文件夹以及 p12 文件本身设置为用户“bob”,并在调用入口点 bash 脚本(调用 python 脚本)之前切换到该用户。

I'm not sure what the issue could be here, whether it's to do with having two images involved, it being on a container, or something around the p12 file permissions.我不确定这里可能有什么问题,是否与涉及两个图像有关,它在容器上,还是与 p12 文件权限有关。

If I run the same openssl and keytool commands locally, it works fine and puts the bundle of certs in the keystore.如果我在本地运行相同的 openssl 和 keytool 命令,它可以正常工作并将证书包放入密钥库中。

I appreciate I have left some other specifics of code out (dockerfile for example) so can share these if needed, but hoping someone has a broader opinion on what could be the problem with editing the p12 file.感谢我遗漏了一些其他代码细节(例如 dockerfile),因此可以在需要时共享这些代码,但希望有人对编辑 p12 文件可能出现的问题有更广泛的看法。

My issue here was the paths for the cert files and p12 file.我的问题是证书文件和 p12 文件的路径。 I had to use os.path.join to pass the paths in that way.我不得不使用 os.path.join 以这种方式传递路径。

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

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