首页 > 解决方案 > 覆盖 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 定义类参数时编辑所有敏感值的最佳方法是什么?

标签: puppethiera

解决方案


您需要将密码作为单独的密钥,以便自动转换生效。查找的键绑定到一个散列,并且不可能用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值而不是字符串。


推荐阅读