如何将秘密文件推送到EC2(在AWS上)Ruby on Rails应用程序?

秘密文件应该如何通过弹性beanstalk使用amazon web services推送到EC2 Ruby on Rails应用程序?

我将这些文件添加到一个git仓库中,然后推送给github,但是我想把我的秘密文件保存在git仓库中。 我正在部署到aws使用:

git aws.push 

以下文件位于.gitignore中:

 /config/database.yml /config/initializers/omniauth.rb /config/initializers/secret_token.rb 

在此链接之后,我尝试将S3文件添加到我的部署中: http : //docs.amazonwebservices.com/elasticbeanstalk/latest/dg/customize-containers.html

从这个链接引用:

示例片段

以下示例从Amazon S3存储桶下载压缩文件,并将其解压缩到/ etc / myapp中:

 sources: /etc/myapp: http://s3.amazonaws.com/mybucket/myobject 

遵循这些说明,我将file upload到S3存储桶,并将以下内容添加到.elasticbeanstalk .ebextensions目录中的private.config文件中:

 sources: /var/app/current/: https://s3.amazonaws.com/mybucket/config.tar.gz 

该config.tar.gz文件将提取到:

 /config/database.yml /config/initializers/omniauth.rb /config/initializers/secret_token.rb 

但是,在部署应用程序时,S3主机上的config.tar.gz文件不会被复制或提取。 我仍然收到错误,无法finddatabase.yml和EC2日志没有configuration文件的logging,这里是错误消息:

 Error message: No such file or directory - /var/app/current/config/database.yml Exception class: Errno::ENOENT Application root: /var/app/current 

闻起来像一个错字。

你链接的说明在相关部分说:

在部署应用程序时自定义AWS Elastic Beanstalk环境需要两个步骤:

  1. 创build扩展名为.config的configuration文件,并将其放在源包的.ebextensions顶级目录中。 您可以在.ebextensions目录中拥有多个configuration文件。 这些文件按字母顺序执行。 例如,.ebextensions / 01run.config在.ebextensions / 02do.config之前执行。

但是,您说过将.config文件放在.elasticbeanstalk目录中。 尝试修复目录名称。

在S3中存储敏感文件是可能的(也是容易的),并且自动将它们复制到Beanstalk实例中。

当您创build一个Beanstalk应用程序时,会自动创build一个S3存储桶。 此存储区用于存储应用版本,日志,元数据等

分配给您的Beanstalk环境的默认aws-elasticbeanstalk-ec2-role具有对此存储桶的读取访问权限。

因此,您只需将敏感文件放在该存储桶中(存储桶的根目录或所需的任何目录结构),然后创build一个.ebextensionconfiguration文件,将其复制到您的EC2实例中。

这里是一个例子:

 # .ebextensions/sensitive_files.config Resources: AWSEBAutoScalingGroup: Metadata: AWS::CloudFormation::Authentication: S3Auth: type: "s3" buckets: ["elasticbeanstalk-us-east-1-XXX"] # Replace with your bucket name roleName: "Fn::GetOptionSetting": Namespace: "aws:autoscaling:launchconfiguration" OptionName: "IamInstanceProfile" DefaultValue: "aws-elasticbeanstalk-ec2-role" # This is the default role created for you when creating a new Beanstalk environment. Change it if you are using a custom role files: /etc/pki/tls/certs/server.key: # This is where the file will be copied on the EC2 instances mode: "000400" # Apply restrictive permissions to the file owner: root # Or nodejs, or whatever suits your needs group: root # Or nodejs, or whatever suits your needs authentication: "S3Auth" source: https://s3-us-west-2.amazonaws.com/elasticbeanstalk-us-east-1-XXX/server.key # URL to the file in S3 

这是logging在这里: http : //docs.aws.amazon.com/elasticbeanstalk/latest/dg/https-storingprivatekeys.html

您可以运行bash脚本,并使用命令行实用程序(如s3cmd)从S3下载所需的所有文件。

我撰写了一系列关于AWS Elastic Beanstalk定制的文章。

有关从S3下载文件的详细信息,请参阅http://www.hudku.com/blog/security-credentials-setup-customizing/#aws-credentials-setup.sh

尝试将源代码的源设置为/var/app/ondeck 。 IIRC,脚本在那里运行,一旦完成了一切,文件夹被重命名为/var/app/current所以你可能会解压到即将被replace的版本。