使用 Chef,限制用户访问某些 servers/environments
Using Chef, limiting user access to certain servers/environments
我有一个用例,我有一个承包商需要 ssh 和 sudo 访问一台服务器,但不需要访问我们的其他服务器。我们所有的服务器都由 Chef 管理,我们使用数据包来配置每个用户。关于处理此问题的最佳方法的任何提示?
一如既往,有多种可能性:-)
Here is,我们如何根据 users
数据包配置每个节点的用户访问权限。
- 所有具有
group: sysadmin
的用户都会自动分配给具有 sudo 权限的所有节点。
- 所有其他用户都是根据他们对特定主机的分配添加的。
users
数据包是
在数据包的 "nodes"
键中搜索了包含 node['fqdn']
条目的项目:
{
"id": "a-srv123-admin",
...
"nodes": {
"srv123.typo3.org": {
"sudo": "true"
}
}
}
为了从所有节点中删除一个用户,可以设置action: remove
在最高级别:
{
"id": "a-user-to-remove",
"action": "remove"
}
为了从某个节点删除用户,可以设置action: remove
在节点级别:
{
"id": "a-user-to-remove",
...
"nodes": {
"srv123.typo3.org": {
"action": "remove"
}
}
}
implementation of this(不幸的是,事实上不是很干净),只搜索与 node[fqdn]
:
关联的所有用户
node_attribute = "fqdn"
log "Searching for users associated with node #{node[node_attribute]}"
begin
users = search(users_databag_name, "nodes:#{node[node_attribute]}")
rescue Net::HTTPServerException
Chef::Log.warn "Searching for users in the 'users' databag failed, search for users associated with node '#{node[node_attribute]}'"
users = {}
end
users.each do |u|
node_options = u['nodes'][node[node_attribute]]
Chef::Log.info "Got node options: #{node_options}"
if u['action'] == "remove" || node_options['action'] == "remove"
user u['username'] ||= u['id'] do
action :remove
end
else
# snip...
# Create user object.
user u['username'] do
uid u['uid'] if u['uid']
gid u['gid'] if u['gid']
shell u['shell']
comment u['comment']
password u['password'] if u['password']
supports manage_home: true
home home_dir
action u['action'] if u['action']
end
# sudo management
if node_options['sudo'] == "true"
sudo u['username'] do
nopasswd true
user u['username']
end
else
sudo u['username'] do
action :remove
end
end
end
end
编辑:请注意,任何有权访问 Chef 客户端证书的用户都可以根据客户端可读取的内容查询数据。这可以包括存储在其他节点属性中的密码。 RBAC 或 chef-vault 可以缓解这种情况。
我有一个用例,我有一个承包商需要 ssh 和 sudo 访问一台服务器,但不需要访问我们的其他服务器。我们所有的服务器都由 Chef 管理,我们使用数据包来配置每个用户。关于处理此问题的最佳方法的任何提示?
一如既往,有多种可能性:-)
Here is,我们如何根据 users
数据包配置每个节点的用户访问权限。
- 所有具有
group: sysadmin
的用户都会自动分配给具有 sudo 权限的所有节点。 - 所有其他用户都是根据他们对特定主机的分配添加的。
users
数据包是 在数据包的"nodes"
键中搜索了包含node['fqdn']
条目的项目:
{
"id": "a-srv123-admin",
...
"nodes": {
"srv123.typo3.org": {
"sudo": "true"
}
}
}
为了从所有节点中删除一个用户,可以设置action: remove
在最高级别:
{
"id": "a-user-to-remove",
"action": "remove"
}
为了从某个节点删除用户,可以设置action: remove
在节点级别:
{
"id": "a-user-to-remove",
...
"nodes": {
"srv123.typo3.org": {
"action": "remove"
}
}
}
implementation of this(不幸的是,事实上不是很干净),只搜索与 node[fqdn]
:
node_attribute = "fqdn"
log "Searching for users associated with node #{node[node_attribute]}"
begin
users = search(users_databag_name, "nodes:#{node[node_attribute]}")
rescue Net::HTTPServerException
Chef::Log.warn "Searching for users in the 'users' databag failed, search for users associated with node '#{node[node_attribute]}'"
users = {}
end
users.each do |u|
node_options = u['nodes'][node[node_attribute]]
Chef::Log.info "Got node options: #{node_options}"
if u['action'] == "remove" || node_options['action'] == "remove"
user u['username'] ||= u['id'] do
action :remove
end
else
# snip...
# Create user object.
user u['username'] do
uid u['uid'] if u['uid']
gid u['gid'] if u['gid']
shell u['shell']
comment u['comment']
password u['password'] if u['password']
supports manage_home: true
home home_dir
action u['action'] if u['action']
end
# sudo management
if node_options['sudo'] == "true"
sudo u['username'] do
nopasswd true
user u['username']
end
else
sudo u['username'] do
action :remove
end
end
end
end
编辑:请注意,任何有权访问 Chef 客户端证书的用户都可以根据客户端可读取的内容查询数据。这可以包括存储在其他节点属性中的密码。 RBAC 或 chef-vault 可以缓解这种情况。