使用Chef访问另一个用户的注册表

前端之家收集整理的这篇文章主要介绍了使用Chef访问另一个用户的注册表前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
是否可以使用Chef访问另一个用户注册表?我有作为系统运行的chef-client,我想修改User1的注册表?有没有办法做到这一点?

registry_key资源提供了访问HKEY_Users的方法,但我看不到将用户名映射到SID的方法.

这最终变得有点曲折,看着它让我感到畏缩.但它似乎工作!

我想通过注册修改另一个用户的环境变量,如this Server Fault answer所述,但我也想用Chef创建用户.那么问题是Windows在用户登录之前不会为用户创建注册表配置单元.

如果相关用户肯定存在,您可以跳到修改用户注册表项.

强制Windows创建用户注册表配置单元

Chef内置的执行和批处理资源似乎不支持提供密码,因此看起来两者的用户属性似乎都不能在Windows上使用.但是the official Chef Windows cookbook包含一个windows_task资源,其中包含用于指定用户密码的属性.

现在的问题是授予相关用户“本地安全策略”权限以“作为批处理作业登录”.为此,我们可以使用SecEdit.

确保您的食谱取决于官方的厨师Windows食谱;在你的cookbook的Metadata.rb文件添加

depends "windows"

这是Chef食谱代码

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"

修改用户注册表项

确保您的食谱取决于官方的厨师Windows食谱;在你的cookbook的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

必须对关键属性进行延迟评估(即在运行配方的Chef的收敛阶段期间进行评估)以处理不存在的用户.

原文链接:https://www.f2er.com/windows/372068.html

猜你在找的Windows相关文章