Commit e0a9c0e6 by John Jarvis

adding type param to user role

parent f2e9307e
# Creates a single user on a server
# By default no super-user privileges
# Example: ansible-playbook -i "jarv.m.sandbox.edx.org," ./create_user.yml -e "user=jarv"
# Create a user with sudo privileges
# Example: ansible-playbook -i "jarv.m.sandbox.edx.org," ./create_user.yml -e "user=jarv" -e "give_sudo=true"
- name: Create all user types (test play)
hosts: all
sudo: True
gather_facts: False
vars_files:
- 'roles/edxapp/defaults/main.yml'
- 'roles/common/defaults/main.yml'
- 'roles/analytics-server/defaults/main.yml'
- 'roles/analytics/defaults/main.yml'
pre_tasks:
- fail: msg="You must pass a user into this play"
when: user is not defined
- name: give access with no sudo
set_fact:
user_info:
- name: "{{ user }}"
github: true
- name: test-admin-user
type: admin
- name: test-normal-user
- name: test-restricted-user-edxapp
type: restricted
sudoers_template: 99-edxapp-manage-cmds.j2
- name: test-restricted-user-anayltics
type: restricted
sudoers_template: 99-analytics-manage-cmds.j2
roles:
- user
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
set_fact: set_fact:
user_info: user_info:
- name: "{{ user }}" - name: "{{ user }}"
admin: true type: admin
github: true github: true
when: give_sudo is defined when: give_sudo is defined
roles: roles:
......
...@@ -12,25 +12,25 @@ ...@@ -12,25 +12,25 @@
user_data: user_data:
- name: sefk - name: sefk
github: true github: true
admin: true type: admin
- name: jbau - name: jbau
github: true github: true
admin: true type: admin
- name: jrbl - name: jrbl
github: true github: true
admin: true type: admin
- name: ali123 - name: ali123
github: true github: true
admin: true type: admin
- name: caesar2164 - name: caesar2164
github: true github: true
admin: true type: admin
- name: dcadams - name: dcadams
github: true github: true
admin: true type: admin
- name: nparlante - name: nparlante
github: true github: true
admin: true type: admin
- name: jinpa - name: jinpa
github: true github: true
- name: gbruhns - name: gbruhns
......
...@@ -3,6 +3,7 @@ dependencies: ...@@ -3,6 +3,7 @@ dependencies:
- role: user - role: user
user_info: user_info:
- name: automator - name: automator
type: restricted
sudoers_template: '99-automator-analytics.j2' sudoers_template: '99-automator-analytics.j2'
user_authorized_keys: "{{ AS_AUTOMATOR_AUTHORIZED_KEYS }}" user_authorized_keys: "{{ AS_AUTOMATOR_AUTHORIZED_KEYS }}"
user_rbash_links: user_rbash_links:
......
...@@ -9,6 +9,7 @@ dependencies: ...@@ -9,6 +9,7 @@ dependencies:
- role: user - role: user
user_info: user_info:
name: automator name: automator
type: restricted
sudoers_template: '99-edxapp-manage-cmds.j2' sudoers_template: '99-edxapp-manage-cmds.j2'
user_authorized_keys: "{{ EDXAPP_AUTOMATOR_AUTHORIZED_KEYS }}" user_authorized_keys: "{{ EDXAPP_AUTOMATOR_AUTHORIZED_KEYS }}"
when: EDXAPP_AUTOMATOR_AUTHORIZED_KEYS|length != 0 when: EDXAPP_AUTOMATOR_AUTHORIZED_KEYS|length != 0
...@@ -19,6 +19,11 @@ ...@@ -19,6 +19,11 @@
# (2) admin users with full sudo permissions # (2) admin users with full sudo permissions
# (3) restricted users that use rbash and are locked down to specific sudo commands # (3) restricted users that use rbash and are locked down to specific sudo commands
# #
# The parameter "type" sets the user in one of these three categories:
# (1) type not set
# (2) type=admin
# (3) type=restricted
#
# Dependencies: # Dependencies:
# #
# This role has no dependencies but requires parameters # This role has no dependencies but requires parameters
...@@ -39,7 +44,7 @@ ...@@ -39,7 +44,7 @@
# # for edxapp, it creates a user that can only # # for edxapp, it creates a user that can only
# # run manage.py commands # # run manage.py commands
# - name: automator # - name: automator
# restricted: true # type: restricted
# # The sudoers file is optional. # # The sudoers file is optional.
# sudoers_template: '99-edxapp-manage-cmds.j2' # sudoers_template: '99-edxapp-manage-cmds.j2'
# authorized_keys: # authorized_keys:
...@@ -50,7 +55,7 @@ ...@@ -50,7 +55,7 @@
# # with full sudo, key fetched from github # # with full sudo, key fetched from github
# - name: frank # - name: frank
# github: true # github: true
# admin: true # type: admin
# #
# # This user is a normal login user without sudo, with # # This user is a normal login user without sudo, with
# # a couple keys passed in as parameters # # a couple keys passed in as parameters
...@@ -92,7 +97,7 @@ ...@@ -92,7 +97,7 @@
user: user:
name={{ item.name }} name={{ item.name }}
groups=edxadmin groups=edxadmin
when: item.admin is defined when: item.type is defined and item.type == 'admin'
with_items: user_info with_items: user_info
# authorized_keys2 used here so that personal # authorized_keys2 used here so that personal
...@@ -119,7 +124,7 @@ ...@@ -119,7 +124,7 @@
src=default.bashrc.j2 src=default.bashrc.j2
dest=/home/{{ item.name }}/.bashrc mode=0640 dest=/home/{{ item.name }}/.bashrc mode=0640
owner={{ item.name }} owner={{ item.name }}
when: item.restricted is not defined when: not (item.type is defined and item.type == 'restricted')
with_items: user_info with_items: user_info
- name: create .profile for all users - name: create .profile for all users
...@@ -136,7 +141,7 @@ ...@@ -136,7 +141,7 @@
user: user:
name={{ item.name }} name={{ item.name }}
shell=/bin/rbash shell=/bin/rbash
when: item.restricted is defined when: item.type is defined and item.type == 'restricted'
with_items: user_info with_items: user_info
- name: create bashrc file for restricted users - name: create bashrc file for restricted users
...@@ -144,7 +149,7 @@ ...@@ -144,7 +149,7 @@
src=restricted.bashrc.j2 src=restricted.bashrc.j2
dest=/home/{{ item.name }}/.bashrc mode=0640 dest=/home/{{ item.name }}/.bashrc mode=0640
owner={{ item.name }} owner={{ item.name }}
when: item.restricted is defined when: item.type is defined and item.type == 'restricted'
with_items: user_info with_items: user_info
- name: create sudoers file from template - name: create sudoers file from template
...@@ -152,7 +157,7 @@ ...@@ -152,7 +157,7 @@
dest=/etc/sudoers.d/{{ item.sudoers_template|basename|replace('.j2','') }} dest=/etc/sudoers.d/{{ item.sudoers_template|basename|replace('.j2','') }}
src=etc/sudoers.d/{{ item.sudoers_template }} owner="root" src=etc/sudoers.d/{{ item.sudoers_template }} owner="root"
group="root" mode=0440 validate='visudo -cf %s' group="root" mode=0440 validate='visudo -cf %s'
when: item.restricted is defined and item.sudoers_template is defined when: item.type is defined and item.type == 'restricted' and item.sudoers_template is defined
with_items: user_info with_items: user_info
# Prevent restricted user from updating their PATH and # Prevent restricted user from updating their PATH and
...@@ -160,14 +165,14 @@ ...@@ -160,14 +165,14 @@
- name: change home directory ownership to root for restricted users - name: change home directory ownership to root for restricted users
shell: "chown -R root:{{ item.name }} /home/{{ item.name }}" shell: "chown -R root:{{ item.name }} /home/{{ item.name }}"
when: item.restricted is defined when: item.type is defined and item.type == 'restricted'
with_items: user_info with_items: user_info
- name: create ~/bin directory - name: create ~/bin directory
file: file:
path=/home/{{ item.name }}/bin state=directory mode=0750 path=/home/{{ item.name }}/bin state=directory mode=0750
owner="root" group={{ item.name }} owner="root" group={{ item.name }}
when: item.restricted is defined when: item.type is defined and item.type == 'restricted'
with_items: user_info with_items: user_info
- name: create allowed command links - name: create allowed command links
...@@ -175,7 +180,7 @@ ...@@ -175,7 +180,7 @@
src: "{{ item[1] }}" src: "{{ item[1] }}"
dest: "/home/{{ item[0].name }}/bin/{{ item[1]|basename }}" dest: "/home/{{ item[0].name }}/bin/{{ item[1]|basename }}"
state: link state: link
when: item[0].restricted is defined when: item[0].type is defined and item[0].type == 'restricted'
with_nested: with_nested:
- user_info - user_info
- user_rbash_links - user_rbash_links
{{ item.user }} ALL=({{ analytics_web_user }}) NOPASSWD:SETENV:{{ analytics_venv_dir }}/bin/django-admin.py run_all_queries * {{ item.name }} ALL=({{ analytics_web_user }}) NOPASSWD:SETENV:{{ analytics_venv_dir }}/bin/django-admin.py run_all_queries *
...@@ -175,7 +175,7 @@ name_tag: $name_tag ...@@ -175,7 +175,7 @@ name_tag: $name_tag
user_data: user_data:
- name: ${github_username} - name: ${github_username}
github: true github: true
admin: true type: admin
dns_zone: $dns_zone dns_zone: $dns_zone
rabbitmq_refresh: True rabbitmq_refresh: True
USER_CMD_PROMPT: '[$name_tag] ' USER_CMD_PROMPT: '[$name_tag] '
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment