Rails 加密凭证功能的 Python 世界模拟(安全存储 secret )

标签 python security encryption credentials

encrypted credentials Rails feature 的 Python 类似物吗? ?

引自Rails Guides on subject :

Rails stores secrets in config/credentials.yml.enc, which is encrypted and hence cannot be edited directly. Rails uses config/master.key or alternatively looks for the environment variable ENV["RAILS_MASTER_KEY"] to encrypt the credentials file. Because the credentials file is encrypted, it can be stored in version control, as long as the master key is kept safe.

To edit the credentials file, run bin/rails credentials:edit. This command will create the credentials file if it does not exist. Additionally, this command will create config/master.key if no master key is defined.

Secrets kept in the credentials file are accessible via Rails.application.credentials.

我的想法是:

  • 在存储库中对所有 secret 进行加密;
  • 仅在本地拥有 master.key(或仅一个环境变量);
  • 手动传递到生产服务器master.key
  • 然后通过 git 通过自动部署过程传递其他 secret 。

最佳答案

https://github.com/nzaillian/django-encrypted-secrets它的工作原理类似于 Rail 的加密凭证,但我还没有看到它在我从事过的任何项目中使用。

通常我会看到使用os.environ使用和访问环境变量:

import os

os.environ['API_USER']

django-environ package 也很流行,经常与 .env 文件一起使用。

我自己没用过,但是dynaconf似乎也很受欢迎。

关于Rails 加密凭证功能的 Python 世界模拟(安全存储 secret ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72287422/

相关文章:

python - 有没有比 `except: pass` 更简洁的替代品?

Python Mechanize Browser.links() - 奇怪的行为

C#河豚加密/解密

php - 公共(public)页面上的 ID 散列与加密

encryption - 创建不可修改的文件

python - PDF 后端目前不支持所选字体

python项目特定模块安装方法

sql-server - SQL Server 2005 : How Secure is SQL Server Authentication?

security - 强制 wsimport (Java 10/11) 容忍 TLSv1 和弱密码

security - 有计费系统经验