File: _user_accounts.yml

package info (click to toggle)
python-mitogen 0.3.3-9%2Bdeb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 6,816 kB
  • sloc: python: 22,086; sh: 171; makefile: 74; perl: 19; ansic: 18; javascript: 5
file content (192 lines) | stat: -rw-r--r-- 5,778 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#
# Add users expected by tests. Assumes passwordless sudo to root.
#
# WARNING: this creates non-privilged accounts with pre-set passwords!
#

- hosts: all
  gather_facts: true
  strategy: mitogen_free
  become: true
  vars:
    distro: "{{ansible_distribution}}"
    special_users:
      - has_sudo
      - has_sudo_nopw
      - has_sudo_pubkey
      - pw_required
      - readonly_homedir
      - require_tty
      - require_tty_pw_required
      - permdenied
      - slow_user
      - webapp
      - sudo1
      - sudo2
      - sudo3
      - sudo4

    user_groups:
      has_sudo: ['mitogen__group', '{{sudo_group[distro]}}']
      has_sudo_pubkey: ['mitogen__group', '{{sudo_group[distro]}}']
      has_sudo_nopw: ['mitogen__group', 'mitogen__sudo_nopw']
      sudo1: ['mitogen__group', 'mitogen__sudo_nopw']
      sudo2: ['mitogen__group', '{{sudo_group[distro]}}']
      sudo3: ['mitogen__group', '{{sudo_group[distro]}}']
      sudo4: ['mitogen__group', '{{sudo_group[distro]}}']

    normal_users: "{{
      lookup('sequence', 'start=1 end=5 format=user%d', wantlist=True)
    }}"

    all_users: "{{
      special_users +
      normal_users
    }}"
  tasks:
    - name: Disable non-localhost SSH for Mitogen users
      when: false
      blockinfile:
        path: /etc/ssh/sshd_config
        block: |
          Match User mitogen__* Address !127.0.0.1
            DenyUsers *

    - name: Create Mitogen test groups
      group:
        name: "mitogen__{{item}}"
      with_items:
      - group
      - sudo_nopw

    - name: Create user accounts
      block:
      - user:
          name: "mitogen__{{item}}"
          shell: /bin/bash
          groups: "{{user_groups[item]|default(['mitogen__group'])}}"
          password: "{{ (item + '_password') | password_hash('sha256') }}"
        with_items: "{{all_users}}"
        when: ansible_system != 'Darwin'
      - user:
          name: "mitogen__{{item}}"
          shell: /bin/bash
          groups: |
            {{
                ['com.apple.access_ssh'] +
                (user_groups[item] | default(['mitogen__group']))
            }}
          password: "{{item}}_password"
        with_items: "{{all_users}}"
        when: ansible_system == 'Darwin'

    - name: Hide users from login window (Darwin).
      when: ansible_system == 'Darwin'
      with_items: "{{all_users}}"
      osx_defaults:
        array_add: true
        domain: /Library/Preferences/com.apple.loginwindow
        type: array
        key: HiddenUsersList
        value: ['mitogen_{{item}}']

    - name: Check if AccountsService is used
      stat:
        path: /var/lib/AccountsService/users
      register: out

    - name: Hide users from login window (Linux).
      when: ansible_system == 'Linux' and out.stat.exists
      with_items: "{{all_users}}"
      copy:
        dest: /var/lib/AccountsService/users/mitogen__{{item}}
        content: |
          [User]
          SystemAccount=true

    - name: Restart AccountsService (Linux).
      when: ansible_system == 'Linux' and out.stat.exists
      service:
        name: accounts-daemon
        restarted: true

    - name: Readonly homedir for one account
      shell: "chown -R root: ~mitogen__readonly_homedir"

    - name: Slow bash profile for one account
      copy:
        dest: ~mitogen__slow_user/.{{item}}
        src: ../data/docker/mitogen__slow_user.profile
      with_items:
      - bashrc
      - profile

    - name: "Login throws permission denied errors (issue #271)"
      copy:
        dest: ~mitogen__permdenied/.{{item}}
        src: ../data/docker/mitogen__permdenied.profile
      with_items:
      - bashrc
      - profile

    - name: Install pubkey for mitogen__has_sudo_pubkey
      block:
        - file:
            path: ~mitogen__has_sudo_pubkey/.ssh
            state: directory
            mode: go=
            owner: mitogen__has_sudo_pubkey
        - copy:
            dest: ~mitogen__has_sudo_pubkey/.ssh/authorized_keys
            src: ../data/docker/mitogen__has_sudo_pubkey.key.pub
            mode: go=
            owner: mitogen__has_sudo_pubkey

    - name: Install slow profile for one account
      block:
        - copy:
            dest: ~mitogen__slow_user/.profile
            src: ../data/docker/mitogen__slow_user.profile
        - copy:
            dest: ~mitogen__slow_user/.bashrc
            src: ../data/docker/mitogen__slow_user.profile

    - name: Require a TTY for two accounts
      lineinfile:
        path: /etc/sudoers
        line: "{{item}}"
      with_items:
        - Defaults>mitogen__pw_required targetpw
        - Defaults>mitogen__require_tty requiretty
        - Defaults>mitogen__require_tty_pw_required requiretty,targetpw

    - name: Require password for two accounts
      lineinfile:
        path: /etc/sudoers
        line: "{{lookup('pipe', 'whoami')}} ALL = ({{item}}:ALL) ALL"
        validate: '/usr/sbin/visudo -cf %s'
      with_items:
        - mitogen__pw_required
        - mitogen__require_tty_pw_required
      when:
        - ansible_virtualization_type != "docker"

    - name: Allow passwordless sudo for require_tty/readonly_homedir
      lineinfile:
        path: /etc/sudoers
        line: "{{lookup('pipe', 'whoami')}} ALL = ({{item}}:ALL) NOPASSWD:ALL"
        validate: '/usr/sbin/visudo -cf %s'
      with_items:
        - mitogen__require_tty
        - mitogen__readonly_homedir
      when:
        - ansible_virtualization_type != "docker"

    - name: Allow passwordless for many accounts
      lineinfile:
        path: /etc/sudoers
        line: "{{lookup('pipe', 'whoami')}} ALL = (mitogen__{{item}}:ALL) NOPASSWD:ALL"
        validate: '/usr/sbin/visudo -cf %s'
      with_items: "{{normal_users}}"
      when:
        - ansible_virtualization_type != "docker"