2016-04-11 11 views
2

私は、1つのサーバーにsshとsudoアクセスを必要とし、他のサーバーにはアクセスできない請負業者がいるユースケースを持っています。私たちのサーバーはすべてシェフが管理しており、データバッグを使用して各ユーザーを設定しています。これにアプローチする最善の方法に関するヒントChefを使用して特定のサーバー/環境へのユーザーアクセスを制限する

答えて

2

いつもと同じように、 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を設定することができるノードレベルでのは:

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 

EDIT:

{ 
    "id": "a-user-to-remove", 
    ... 
    "nodes": { 
      "srv123.typo3.org": { 
        "action": "remove" 
      } 
    } 
} 

implementation of this(残念ながら、真実では非常にきれいではない)、単にnode[fqdn]に関連付けられているすべてのユーザーを検索し、任意のユーザーを持つことに注意してシェフのクライアント証明書にアクセスすると、クライアントが読み取れるものに基づいてデータを照会できます。これには、他のノードの属性に格納されているパスワードを含めることができます。 RBACまたはchef-vaultはこれを軽減できます。

関連する問題