如何为AWS Elastic Beans设置多行RSA私钥环境变量 [英] How to set multiline RSA private key environment variable for AWS Elastic Beans

查看:129
本文介绍了如何为AWS Elastic Beans设置多行RSA私钥环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Elastic Beanstalk将Ruby on Rails应用程序部署到AWS,并且必须将私钥设置为环境变量

I am deploying a Ruby on Rails application to AWS using Elastic Beanstalk and have to set a private key as an environment variable

例如

-----BEGIN RSA PRIVATE KEY----- SpvpksXQIBA65ICOgQxV2TvMIICAiMeV9prhdJSKjjsk2 tYdz8lhn/ibROQW71utuHLAyHGMBxz3kIaaIq1kjdkkk tYdz8lhn/ibROQW71utuHLAyHGMBxz3kIaaIq1kjdkkk tYdz8lhn/ibROQW71utuHLAyHGMBxz3kIaaIq1kjdkkk tYdz8lhn/ibROQW71utuHLAyHGMBxz3kIaaIq1kjdkkk -----END RSA PRIVATE KEY-----

-----BEGIN RSA PRIVATE KEY----- SpvpksXQIBA65ICOgQxV2TvMIICAiMeV9prhdJSKjjsk2 tYdz8lhn/ibROQW71utuHLAyHGMBxz3kIaaIq1kjdkkk tYdz8lhn/ibROQW71utuHLAyHGMBxz3kIaaIq1kjdkkk tYdz8lhn/ibROQW71utuHLAyHGMBxz3kIaaIq1kjdkkk tYdz8lhn/ibROQW71utuHLAyHGMBxz3kIaaIq1kjdkkk -----END RSA PRIVATE KEY-----

但是,这似乎在部署应用程序时不起作用,因为它总是会失败并显示

However this doesn't seem to work when deploying the app as it always fails with a

OpenSSL :: PKey :: RSAError:PUB密钥或PRIV密钥均未嵌套:asn1嵌套 错误

OpenSSL::PKey::RSAError: Neither PUB key nor PRIV key: nested asn1 error

我认为这是因为RSA密钥格式错误.

I think it's because the RSA Key is malformed.

但是,与Heroku不同,AWS EB不接受多行输入(请参阅下文),因此我必须使用\n来创建新行.

However unlike in Heroku, AWS EB does not accept multiline input (see below) so I have to use \n to create new lines.

我尝试了几种不同的样式,但是似乎没有一个样式能够正确地插入\n,并且我始终会遇到相同的错误.

I tried with few different styles but none of them seem to interpolate the \n properly and I always keep getting the same error.

我尝试过使用\n和每一行的结尾,然后使用\\n并尝试使用双引号\"来包装密钥,但是我仍然会遇到相同的错误.

I've tried with \n and the end of each line, then \\n and also tried tried double quotes \" to wrap the key but I still keep getting the same error.

如何在AWS Elastic Beanstalk中正确设置多行环境变量?

How do I properly set a multiline environment variable in AWS Elastic Beanstalk ?

推荐答案

您可以使用\n在EB中对其进行设置,然后在将其传递到config.key之前将'\ n'转换为换行符-类似于(请注意对gsub的调用中的单引号和双引号:

You could set it in EB using \n and then convert the '\n' to newlines before you pass it to config.key - something like this (note the single and double quotes in the call to gsub):

single_line_key = ENV.fetch('CLOUDFRONT_KEY')
multi_line_key = single_line_key.gsub('\n', "\n")
config.key = multi_line_key

这篇关于如何为AWS Elastic Beans设置多行RSA私钥环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆