【问题标题】:is it good practice to add nodes and client folder to chef server template将节点和客户端文件夹添加到厨师服务器模板是否是一种好习惯
【发布时间】:2025-12-14 20:10:02
【问题描述】:

我还在学习厨师。我已经引导并将我的服务器模板上传到远程存储库。但我想知道将nodes 目录添加到remote 存储库是否安全,因为它包含确切的服务器passwords

这是一个示例节点

{
  "environment":"production",
  "authorization": {
    "sudo": {
      // The password for the depliy user is set in data_bags/users/deploy.json
      // and should be generated using:
      // openssl passwd -1 "plaintextpassword"
      "users": ["deploy", "vagrant"]
    }
  },

  "vagrant" : {
    "exclusions" : [],
    "name" : "rails-postgres-redis1",
    "ip" : "192.168.50.4"
  },
  "rbenv":{
    "rubies": [
      "2.1.2"
    ],
    "global" : "2.1.2",
    "gems": {
      "2.1.2" : [
        {"name":"bundler"}
      ]
    }
  },
  "monit": {
    "notify_emails" : ["email@example.com"],
    "enable_emails" : false,
    "web_interface" : {
      // the plaintext monit username and password
      "allow" : ["your_username","your_password"]
    },
    "mailserver" : {
      "host" : "mailserver.example.com",
      "port" : "999",
      "username" : "your_username",
      "password" : "your_password",
      "hostname" : "the_hostname"
    }
  },
  "postgresql" : {
    "password" : {
      // this should be generated with:
      // openssl passwd -1 "plaintextpassword"
      // currently test
      "postgres" : "$1$mMK9HNoN$r42n7Q8fKsZabbknlT1Zt1"
    }
  },
  "run_list":
  [
    "role[server]",
    "role[nginx-server]",
    "role[postgres-server]",
    "role[rails-app]",
    "role[redis-server]",
  ]
}

由于密码是可见的,这样添加是否安全?

如果它应该在 gitignore 中,那么稍后如果我们从远程仓库克隆,那么我们需要从头开始引导服务器,因为不存在节点目录,对吗?

有更好的方法还是我在这里遗漏了什么?

【问题讨论】:

    标签: chef-infra chef-solo


    【解决方案1】:

    您不需要节点 json 文件的副本来引导节点。安全数据应来自 Chef Vault/Hashicorp Vault/任何其他安全存储。非机密数据可以是配方/包装配方/角​​色/环境/等的一部分,可以存储在存储库中。如果您确实有特定于单个节点的数据,您可以在引导过程中使用-j 传递它们。

    【讨论】:

    • 基于上述答案,我假设版本控制中不需要节点 json,并且可以轻松重新创建,因此可以放在 gitignore 上。但是在对现有服务器进行更新时会使用节点 json 文件,例如添加新角色/食谱.. 对吗?在这种情况下,如果我没有节点 json 文件,是否需要再次引导?如果是这样,可以在已经引导的节点上执行此操作吗?
    • 对不起,我做了一个假设(可能有点过头了),您使用的是 ChefZero 的 ChefServer 吗?如果是前者,您不应该关心节点 json 文件,只需定期备份您的 ChefServer。对于后者,您应该将引导所需的所有必需品保存在作为引导选项-j 传递的单独文件中。
    • 是的,我正在使用 chefzero。抱歉,我忘记在问题上提及这一点。谢谢
    • 你可以考虑使用某种加密的 git,比如 Keybase(我不确定它有多安全)。它可能与使用 ChefVault 一样好,您必须以某种方式传递/传输/存储私钥。或者也许只是避免公共 git 托管服务?在这种情况下没有灵丹妙药。
    • 将查看密钥库。谢谢。