How to set multiline RSA private key environment variable for AWS Elastic Beans

后端 未结 3 747
萌比男神i
萌比男神i 2021-01-17 12:31

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

E.g

-----BEGIN RSA

相关标签:
3条回答
  • 2021-01-17 12:35

    You need to 'export' your multiline string, e.g., your private or public key into the environment correctly.

    Enclose in your shell export statement $'.....' where ...... is your multiline string, e.g., your private or public key.

    Example: export KEY = $'-----BEGIN RSA PRIVATE KEY-----\nSpvpksXQIBA65ICOgQxV2TvMIICAiMeV9prhdJSKjjsk2tYdz8lhn/ibROQW71utuHLAyHGMBxz3kIaaIq1kjdkkktYdz8lhn/ibROQW71utuHLAyHGMBxz3kIaaIq1kjdkkktYdz8lhn/ibROQW71utuHLAyHGMBxz3kIaaIq1kjdkkktYdz8lhn/ibROQW71utuHLAyHGMBxz3kIaaIq1kjdkk\n-----END RSA PRIVATE KEY-----'

    0 讨论(0)
  • 2021-01-17 12:40

    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
    
    0 讨论(0)
  • 2021-01-17 12:55

    In I had the same problem with Golang and the elastic beanstalk, I did this went to AWS console and set the value like this:

    -----BEGIN RSA PRIVATE KEY-----\nSpvpksXQIBA65ICOgQxV2TvMIICAiMeV9prhdJSKjjsk2\ntYdz8lhn/ibROQW71utuHLAyHGMBxz3kIaaIq1kjdkkk\ntYdz8lhn/ibROQW71utuHLAyHGMBxz3kIaaIq1kjdkkk\ntYdz8lhn/ibROQW71utuHLAyHGMBxz3kIaaIq1kjdkkk\ntYdz8lhn/ibROQW71utuHLAyHGMBxz3kIaaIq1kjdkkk\n-----END RSA PRIVATE KEY-----  
    

    inside my code

    key := os.Getenv("PUSH_AUTH_KEY")
    key = strings.Replace(key, `\n`, "\n", 5)
    
    0 讨论(0)
提交回复
热议问题