覆盖清单中的人偶类变量

问题描述

我目前正在使用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中的解密值-例如,这是由保管库后端完成的。

但是,即使您超过了第一个障碍,结果也取决于gitlab模块对包含Sensitive值的哈希进行的处理。如果它只是传递initial_root_password的值可能会起作用,但是如果它对该值进行任何操作(例如检查它是否为空字符串),则可能会失败。如果您不走运,它似乎可以正常工作,但是您最终可能会得到密码“已编辑” :-)。如果模块的维护人员无法使用,请与他们联系,并要求他们支持将密码作为Sensitive值而不是字符串。