【问题标题】:Generate reusable non-random but strong password with Ansible from a seed使用 Ansible 从种子生成可重用的非随机但强密码
【发布时间】:2021-10-13 09:56:10
【问题描述】:

我对我的 Ansible 清单有这样的想法:我只想拥有一个保管库值,一个种子,它可以生成我在清单中需要的所有密码。

类似这样的:

---

# I only have this to generate randomly, and vault
inventory_seed: "a strong random string" 

# Then all my other password are derived from this seed. 
# I feed the salted seed to a filter that creates a password directly sourced from the string I give him.

# will output, say, `wgSqz$@+SU^nw2;I` everytime I invoke ansible for the same inventory_hostname
machine_root_password: "{{ inventory_hostname + inventory_seed + 'root password' | to_strong_password }}"

# same: dp_password will be the same strong password everytime I invoke ansible
db_password:  "{{ inventory_seed + 'db password' | to_strong_password }}" 

# ... etc. All my inventory-specific passwords (and other keys) are derived from the same seed

这种方法有助于解决以下问题:

  • 我有很多库存,但只有一组角色。
  • 每次在角色中引入新密码时,我都必须为每个库存保存一个新密码。

我还将扩展它以生成密钥对、证书等。启动一个新的库存将减少到只指定一个或两个变量而不是几十个。

这是否存在于(综合)Jinja / Ansible 过滤器中?

我知道lookup( 'password', xxx) 方法,但这是不可重现的:如果提供了相同的种子,它不会将种子作为输入来输出相同的密码。我也知道这是一个经常被问到的问题,但是每次密码都保存在本地我不想要。

我必须自己实现吗?

您将如何扩展以生成其他合理但需要的数据(X509 证书、密钥对等)

【问题讨论】:

    标签: ansible passwords


    【解决方案1】:

    解决方案是使用password_hash,它也可以与盐和种子结合使用。

    这里有一些例子:

    # uses a random salt
    # -> output changes on each run
    {{ 'rootpassword' | password_hash('sha512') }}
    
    # uses a user defined salt
    # -> output always stays the same
    {{ 'rootpassword' | password_hash('sha512', 'secretsalt') }}
    
    # creates a random numeric salt by using the inventory_hostname as a seed
    # -> output is unique for every host and stays the same on each run
    {{ 'rootpassword' | password_hash('sha512', 12345 | random(seed=inventory_hostname) | string) }}
    

    【讨论】:

      【解决方案2】:

      阅读您的要求对我来说听起来像是老式的密码本或一次性密码本 (OTP)。您可以找到更多信息@https://crypto.stackexchange.com/

      我只想拥有一个拱顶价值...

      您的一个保管库值将是密码本,例如,它可能是一个非常长的随机字符串或文件 (How do I create a 1GB random file?)。您可以定义一个字符集,并根据需要将其设置为数百千字节。它也可以是一个巨大的文本文件或只是一个视频。

      产生所有密码的种子

      种子是指向该密码本或文件中某个位置的指针,通过定义长度,您可以读出您喜欢的密码。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-09-13
        • 1970-01-01
        • 2012-08-07
        • 2014-12-27
        • 2010-09-08
        • 2012-08-09
        相关资源
        最近更新 更多