puppet - 覆盖 Manifest 中的 Puppet 类变量
问题描述
我目前正在使用 hiera 为 Puppet forge Gitlab 模块设置我的所有类参数。
cat hieradata/nodes/example.yaml
---
gitlab::backup_cron_enable: true
gitlab::gitlab_rails:
backup_keep_time: 604800
backup_path: /opt/gitlab_backup
gitlab_default_can_create_group: false
initial_root_password: foobar
...
cat site/profiles/manifests/gitlab.rb
class profile::gitlab {
include gitlab
}
此代码按预期工作,但我想编辑日志输出和报告中的密码值。我尝试使用 hiera_options 转换敏感值,但 Puppet 仍然显示未编辑的值。
cat hieradata/nodes/example.yaml
---
lookup_options:
gitlab::gitlab_rails::initial_root_password:
convert_to: "Sensitive"
gitlab::backup_cron_enable: true
gitlab::gitlab_rails:
backup_keep_time: 604800
backup_path: /opt/gitlab_backup
gitlab_default_can_create_group: false
initial_root_password: foobar
...
在使用 hiera 定义类参数时编辑所有敏感值的最佳方法是什么?
解决方案
您需要将密码作为单独的密钥,以便自动转换生效。查找的键绑定到一个散列,并且不可能用lookup_options
(查找的是整个散列)来处理散列中的单个值。
您可以Sensitive
通过使用别名并将明文密码绑定到单独的密钥来创建单个值 - 如下所示:
cat hieradata/nodes/example.yaml
---
lookup_options:
gitlab::gitlab_rails::initial_root_password:
convert_to: "Sensitive"
gitlab::backup_cron_enable: true
gitlab::gitlab_rails:
backup_keep_time: 604800
backup_path: /opt/gitlab_backup
gitlab_default_can_create_group: false
initial_root_password: '%{alias("gitlab::gitlab_rails::initial_root_password")}'
gitlab::gitlab_rails::initial_root_password: 'foobar'
...
使用这种方法,您还可以使用 EYAML 或其他一些安全的 hiera 后端以加密形式存储密码。这样的后端可能已经返回封装的解密值Sensitive
- 例如,这是由 Vault 后端完成的。
但是,即使您通过了第一个障碍,结果也取决于gitlab
模块对现在包含Sensitive
值的哈希所做的操作。如果它只是传递 on 的值,initial_root_password
它可能会起作用,但如果它对该值执行任何操作(例如检查它是否为空字符串),它可能会失败。如果您不走运,它似乎可以工作,但您最终可能会得到“已编辑”的密码 :-)。如果模块不起作用,请联系模块的维护人员,并请求他们支持将密码作为Sensitive
值而不是字符串。
推荐阅读
- julia - How can I read text file with converting in Julia?
- android - React Native 添加谷歌广告
- c# - 如何制作上标变量的字符串?
- spring - 关于 @ConditionalOnProperty 和 @ImportResource 的快速基本 Spring 问题
- c# - Moq 测试 - 模拟服务调用总是返回 Null
- asp.net - 无法在 asp.net 核心中绑定 int 类型的字段
- r - 基于数据/类类型的 if 语句映射
- amazon-web-services - CloudFormation:重复/现有的 Route53 记录集
- php - “警告:session_start():无法发送会话cookie - 标头已发送”的原因是什么?
- tensorflow - SageMaker 上的 TensorFlow 参数服务器