是否可以使用 Chef 访问另一个用户的注册表?我有厨师客户端作为系统运行,我想修改 User1 的注册表?有没有办法做到这一点?
registry_key资源提供了一种访问 HKEY_Users的方法,但我看不到将用户名映射到 SID 的方法。
是否可以使用 Chef 访问另一个用户的注册表?我有厨师客户端作为系统运行,我想修改 User1 的注册表?有没有办法做到这一点?
registry_key资源提供了一种访问 HKEY_Users的方法,但我看不到将用户名映射到 SID 的方法。
这最终有点令人费解,看着它让我畏缩。但它似乎工作!
我想通过注册表修改另一个用户的环境变量,如服务器故障答案中所述,但我也想用 Chef 创建用户。那么问题是Windows在用户登录之前不会为用户创建注册表配置单元。
如果相关用户确实存在,您可以跳到Modifying a User's Registry Keys。
Chef 内置execute和batch资源似乎不支持提供密码,因此两者的user属性似乎都不能在 Windows 上使用。但是官方的 Chef Windows 食谱包含一个windows_task资源,其中包含用于指定用户密码的属性。
现在的问题是授予相关用户“作为批处理作业登录”的本地安全策略权限。为此,我们可以使用SecEdit。
确保你的食谱依赖于官方的 Chef windows 食谱;在食谱的metadata.rb文件中添加:
depends "windows"
这是厨师食谱代码:
group "BatchJobUsers" do
append true
members ["AnotherUser"]
action :create
end
cookbook_file "BatchJobUsers-AddBatchLogonRight.inf" do
path "#{ENV['TEMP']}\\BatchJobUsers-AddBatchLogonRight.inf"
action :create_if_missing
end
execute "secedit" do
cwd "#{ENV['TEMP']}"
command "secedit /configure /db secedit.sdb /cfg BatchJobUsers-AddBatchLogonRight.inf"
end
windows_task "force-creation-of-AnotherUser-user-registry-hive" do
command "echo Force creation of AnotherUser user registry hive"
user "AnotherUser"
password "password-for-another-user"
action [:create, :run]
end
windows_task "force-creation-of-AnotherUser-user-registry-hive" do
action :delete
end
您需要将文件添加到名为BatchJobUsers- AddBatchLogonRight.inf 的COOKBOOK/files/default目录;它应包含以下内容:
[Unicode]
Unicode=yes
[Version]
signature="$CHICAGO$"
Revision=1
[Privilege Rights]
SeBatchLogonRight = "BatchJobUsers"
确保你的食谱依赖于官方的 Chef windows 食谱;在食谱的metadata.rb文件中添加:
depends "windows"
在您的食谱中,添加以下行:
::Chef::Recipe.send(:include, Windows::RegistryHelper)
然后你可以resolve_user_to_sid像这样在你的食谱中使用这个函数:
get_user_sid = lambda { resolve_user_to_sid("USER_NAME") }
registry_key "Create environment variable registry keys" do
key lazy { "HKEY_USERS\\#{ get_user_sid.call }\\Environment"
values [{
:name => "Variable",
:type => :string,
:data => "variable_data"
}]
recursive true
action :create
end
该key属性必须被延迟评估(即在 Chef 运行配方的收敛阶段评估)以处理不存在的用户。