Last active
December 21, 2015 11:18
-
-
Save erchn/6297717 to your computer and use it in GitHub Desktop.
salt user management
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
base: | |
'*': | |
# account details are available everywhere | |
- users.accounts | |
# ops group data | |
- users.ops | |
# individual users on a given machine | |
- users.nodeusers | |
'web*': | |
# server group data | |
- users.server |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
accounts: | |
joe: | |
id: 2100 | |
pwhash: 2sd0f8s9s0df89s. | |
key: l23kj4l2kj342l4kj24lk23j423l4kj234l2k3j42lk4j24l2k3j42l4kj2l42kj4lzkx,xmxlz | |
frank: | |
id: 3100 | |
pwhash: 2sd0f8s9s0df89s. | |
key: sldfkjsldkfjl2k3jl2k3j4l2k34jl2kjlkcjlxkxxljklkwdjdlskjdfdklj | |
mark: | |
id: 3101 | |
pwhash: 2sd0f8s9s0df89s. | |
key: sldfkjsldkfjl2k3jl2k3j4l2k34jl2kjlkcjlxkxxljklkwdjdlskjdfdklj | |
ethan: | |
id: 3102 | |
pwhash: 2sd0f8s9s0df89s. | |
key: sldfkjsldkfjl2k3jl2k3j4l2k34jl2kjlkcjlxkxxljklkwdjdlskjdfdklj | |
user2: | |
id: 3103 | |
pwhash: 2sd0f8s9s0df89s. | |
key: sldfkjsldkfjl2k3jl2k3j4l2k34jl2kjlkcjlxkxxljklkwdjdlskjdfdklj |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# machine to account mapping | |
user: | |
node: | |
# on host1 add ethan | |
host1.example.com | |
- ethan | |
# host2 add frank | |
host2.example.com: | |
- frank |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# file that ties accounts to a group for ops | |
group.ops: | |
- ethan | |
- frank |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# file that ties accounts to a group for server | |
group.server: | |
- joe | |
- frank |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
base: | |
'*': | |
# ops should be on all machines | |
- users.ops | |
# individual users on a given machine | |
- users.nodeusers | |
'web*': | |
# add users in server group to web* | |
- users.server |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# support creating individual user accounts (and ssh_auth) on a given machine | |
{% set node_user_list = 'user:node:{0}'.format(grains['id']) %} | |
{% if salt['config.get'](node_user_list, []) %} | |
{% for user in salt['config.get'](node_user_list, []) %} | |
{{ user }}: | |
user.present: | |
- uid: {{ salt['config.get']('accounts:{0}:id'.format(user), '-1') }} | |
- password: {{ salt['config.get']('accounts:{0}:pwhash'.format(user), '\'!!\'') }} | |
ssh_auth.present: | |
- user: {{ user }} | |
- name: {{ salt['config.get']('accounts:{0}:key'.format(user), 'key') }} | |
- enc: {{ salt['config.get']('accounts:{0}:enc'.format(user), 'rsa') }} | |
{% endfor %} | |
{% endif %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ops group state target | |
{% set group = 'ops' %} | |
{% include "users/templ.sls" %} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /srv/salt/users/server.sls | |
{% set group = 'server' %} | |
{% include "users/templ.sls" %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# main template for user creation and ssh_auth handing | |
{% for user in salt['config.get']('group.{0}'.format(group)) %} | |
{{ user }}: | |
user.present: | |
- uid: {{ salt['config.get']('accounts:{0}:id'.format(user), '-1') }} | |
- password: {{ salt['config.get']('accounts:{0}:pwhash'.format(user), '\'!!\'') }} | |
ssh_auth.present: | |
- user: {{ user }} | |
- name: {{ salt['config.get']('accounts:{0}:key'.format(user), 'key') }} | |
- enc: {{ salt['config.get']('accounts:{0}:enc'.format(user), 'rsa') }} | |
{% endfor %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The above files define an ops and server group, define the user's details, define the states that create users for ops and server, and the for loop processing of those datas.
The top two files tie data and state to the appropriate servers
Finally, support with nodeusers.sls under pillar and salt to map individual users to a given node, instead of a group to a target. See srv-salt-users-nodeusers.sls.yaml and srv-pillar-users-nodeusers.sls.yaml