- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
local_settings.py 反模式的原因之一是把 SECRET_KEY, AWS设置文件中的键等值有问题:
我的问题是如何将所有 key 保密?
最佳答案
最初的问题是关于如何在环境变量中保密。这在本书 Two Scoops of Django 中有广泛的讨论。 .下面是他们所说的摘要,然后是关于使用这种技术的警告。
从 1.11 版的第 48 页(第 5.3 节)开始:
Every operating system supported by Django (and Python) provides the easy capability to create environment variables.
Here are the benefits of using environment variables for secret keys:
- Keeping secrets out of settings allows you to store every settings file in version control without hesitation. All of your Python code really should be stored in version control, including your settings.
- Instead of each developer maintaining their own copy-and-pasted version of local_settings.py.example for development, everyone shares the same version-controlled settings/local.py .
- System administrators can rapidly deploy the project without having to modify files containing Python code.
- Most platforms-as-a-service recommend the use of environment variables for configuration and have built-in features for setting and managing them.
在下一页,本书继续:
Before you begin setting environment variables, you should have the following:
- A way to manage the secret information you are going to store.
- A good understanding of how bash settings work on servers, or a willingness to have your project hosted by a platform-as-a-service.
他们描述了如何在本地和生产环境中设置环境变量(以 Heroku 为例——您需要检查您是否使用不同的主机,这只是一种可能性):
How To Set Environment Variables Locally
export SOME_SECRET_KEY=1c3-cr3am-15-yummyHow To Set Environment Variables in Production
heroku config:set SOME_SECRET_KEY=1c3-cr3am-15-yummy
最后,在第 52 页,他们给出了如何访问 key 的说明。例如,您可以将下面的前两行放在您的设置文件中,以替换默认放置在那里的原始 key 字符串:
>>> import os
>>> os.environ['SOME_SECRET_KEY']
'1c3-cr3am-15-yummy'This snippet simply gets the value of the SOME_SECRET_KEY environment variable from the operating system and saves it to a Python variable called SOME_SECRET_KEY.
Following this pattern means all code can remain in version control, and all secrets remain safe.
请注意,这在某些情况下不起作用,例如,如果您使用的是 Apache 服务器。要处理这种模式不起作用的情况,您应该查看他们书中的第 5.4 节(“当您无法使用环境变量时”)。在这种情况下,他们建议使用 secret 文件。
截至 2017 年底,这种在环境变量中存储 secret 的技术是两勺和十二因素应用程序设计模式中推荐的最佳实践。在 Django 文档中也推荐使用它。但是,存在一些安全风险:如果某些开发人员或某些代码可以访问您的系统,他们将可以访问您的环境变量,并且可能会无意(或有意)将它们公开。 Michael Reinsch 在这里提出了这一点:
http://movingfast.io/articles/environment-variables-considered-harmful/
关于python - 保留 key ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14786072/
查看“mysqldump -d”并看到一个键是 KEY,而不是“PRIMARY KEY”或“FOREIGN KEY” 什么是关键? 示例: CREATE TABLE IF NOT EXISTS `TA
在我开始使用 Python 的过程中尝试找出最佳编码实践。我用 Pandas 写了一个 csv 到数据框阅读器。它使用格式: dataframe = read_csv(csv_input, useco
在 Flutter 中,用一个例子可以清楚地解释什么? 我的困惑是关于 key,如下面的代码所示。 MyHomepage({Key key, this.title}) : super(key: key
我在我的 Android 应用程序中使用 GCM。要使用 GCM 服务,我们需要创建 Google API key 。因此,我为 android、服务器和浏览器 key 创建了 API key 。似乎
我想在 azure key 保管库中创建一个 secret ,该 key 将具有多个 key (例如 JSON)。 例如- { "storageAccountKey":"XXXXX", "Co
尝试通过带有 encodeforURL() 的 url 发送 key 时,我不断收到错误消息和 decodefromUrl() .代码示例如下。 这是我的入口页面: key = generateSec
是否有检查雪花变体字段中是否存在键的函数? 最佳答案 您可以使用 IS_NULL_VALUE 来查看 key 是否存在。如果键不存在,则结果将为 NULL。如果键存在,如果值为 JSON null,则
我正在尝试运行此命令: sudo apt-key adv --keyserver keys.gnupg.net --recv-keys 1C4CBDCDCD2EFD2A 但我收到一个错误: Execu
我有一个 csv 文件,我正在尝试对 row[3] 进行计数,然后将其与 row[0] 连接 row[0] row[3] 'A01' 'a' 'B02'
如何编写具有这种形式的函数: A(key, B(key, C(key, ValFactory(key)))) 其中 A、B 和 C 具有此签名: TResult GetOrAdd(string key
审查 this method我很好奇为什么它使用 Object.keys(this).map(key => (this as any)[key])? 只调用 Object.keys(this).ind
我有一个奇怪的情况。我有一个字典,self.containing_dict。使用调试器,我看到了字典的内容,并且可以看到 self 是其中的一个键。但是看看这个: >>> self in self.c
我需要在我的 Google Apps 脚本中使用 RSA-SHA256 和公钥签署消息。 我正在尝试使用 Utilities.computeRsaSha256Signature(value, key)
我是 React 的初学者开发人员,几天前我看到了一些我不理解的有趣语法。 View组件上有{...{key}},我会写成 key={key} ,它完全一样吗?你有链接或解释吗? render()
代理 key 、合成 key 和人工 key 之间有什么区别吗? 我不清楚确切的区别。 最佳答案 代理键、合成键和人工键是同义词。技术关键是另一个。它们都表示“没有商业意义的主键”。它们不同于具有超出
问题陈述:在 Web/控制台 C# 应用程序中以编程方式检索并使用存储在 Azure Key Vault 中的敏感值(例如数据库连接字符串)。 据我所知,您可以在 AAD 中注册应用,并使用其客户端
问题陈述:在 Web/控制台 C# 应用程序中以编程方式检索并使用存储在 Azure Key Vault 中的敏感值(例如数据库连接字符串)。 据我所知,您可以在 AAD 中注册应用,并使用其客户端
我正在寻找 Perl 警告的解决方案 “引用键是实验性的” 我从这样的代码中得到这个: foreach my $f (keys($normal{$nuc}{$e})) {#x, y, and z 我在
我正在为 HSM 实现 JCE 提供程序 JCE中有没有机制指定 key 生成类型例如: session key 或永久 key KeyGenerator keygen = KeyGener
我在 Facebook 上创建了一个应用程序。我已经正确添加了 keyhash 并且应用程序运行良好但是当我今天来并尝试再次运行它时它给了我这个错误。 这已经是第二次了。 Previsouly 当我收
我是一名优秀的程序员,十分优秀!