首页 > 解决方案 > 为什么在部署后找不到我的数字海洋空间的 Rails 凭据?

问题描述

我在使用空间将我的 rails 6 应用程序部署到 Digital Ocean 时遇到问题。部署后,网络服务器失败。在 Puma 日志中,我发现:

Unable to load application: Aws::Sigv4::Errors::MissingCredentialsError: missing credentials, provide credentials with one of the following options:
Feb 05 03:33:25:   - :access_key_id and :secret_access_key
Feb 05 03:33:25:   - :credentials
Feb 05 03:33:25:   - :credentials_provider

这是我的相关导轨设置:

宝石文件

gem 'aws-sdk-s3'

配置/存储.yml

digitalocean_spaces:
  service: S3
  access_key_id: <%= Rails.application.credentials.dig(:digitalocean_spaces, :access_key_id) %>
  secret_access_key: <%= Rails.application.credentials.dig(:digitalocean_spaces, :secret_access_key) %>
  region: nyc3
  endpoint: 'https://nyc3.digitaloceanspaces.com'
  bucket: foobar-bucket

环境/生产.rb

config.active_storage.service = :digitalocean_spaces

凭证.yml.enc

digitalocean_spaces:
  access_key_id: foobar
  secret_access_key: secretfoobar

标签: pumarails-activestorageruby-on-rails-6.1digital-ocean-spaces

解决方案


当您通过执行生成凭证文件时EDITOR="nano -w" rails credentials:edit --environment production,在保存类似这样的内容后会打印到控制台:

Adding config/credentials/production.key to store the encryption key: c1463bd04a5521e81cbe2a496a91af52

Save this in a password manager your team can access.

If you lose the key, no one, including you, can access anything encrypted with it.

      create  config/credentials/production.key

Ignoring config/credentials/production.key so it won't end up in Git history:

      append  .gitignore

服务器必须知道密钥才能解密凭据。

我正在使用 DO 应用程序,必须转到我的应用程序 -> 设置 -> 应用程序级环境变量 -> 编辑并添加RAILS_MASTER_KEY其中包含生成的密钥


推荐阅读