Skip to content

Commit b6941a9

Browse files
committed
WIP: root squash nfs by default - fails b/c user homedir in wrong place
1 parent 8dc121a commit b6941a9

File tree

4 files changed

+86
-38
lines changed

4 files changed

+86
-38
lines changed

ansible/roles/basic_users/README.md

Lines changed: 74 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,62 +7,108 @@ without requiring LDAP etc. Features:
77
- UID/GID is consistent across cluster (and explicitly defined).
88
- SSH key generated and propagated to all nodes to allow login between cluster nodes.
99
- An "external" SSH key can be added to allow login from elsewhere.
10-
- Login to the control node is prevented (by default)
10+
- Login to the control node is prevented (by default).
1111
- When deleting users, systemd user sessions are terminated first.
1212

13-
Requirements
14-
------------
15-
- `$HOME` (for normal users, i.e. not `rocky`) is assumed to be on a shared
16-
filesystem. Actions affecting that shared filesystem are run on a single host,
17-
see `basic_users_manage_homedir` below.
13+
> [!IMPORTANT] This role assumes that `$HOME` for users managed by this role
14+
(e.g. not `rocky` and other system users) is on a shared filesystem. The export
15+
of this sharef filesystem may be root squashed if the server is in the
16+
`basic_user` group - see configuration advice below.
1817

1918
Role Variables
2019
--------------
2120

2221
- `basic_users_users`: Optional, default empty list. A list of mappings defining information for each user. In general, mapping keys/values are passed through as parameters to [ansible.builtin.user](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/user_module.html) and default values are as given there. However:
23-
- `create_home`, `generate_ssh_key` and `ssh_key_comment` are set automatically; this assumes home directories are on a cluster-shared filesystem.
24-
- `uid` should be set, so that the UID/GID is consistent across the cluster (which Slurm requires).
25-
- `shell` if *not* set will be `/sbin/nologin` on the `control` node and the default shell on other users. Explicitly setting this defines the shell for all nodes.
22+
- `create_home` and `generate_ssh_key`: Normally set automatically. Can be
23+
set `false` if necessary to disable home directory creation or cluster ssh
24+
key creation, should not be set `true`.
25+
- `ssh_key_comment`: Default is user name.
26+
- `home`: Normally set automatically.
27+
- `uid` should be set, so that the UID/GID is consistent across the cluster
28+
(which Slurm requires).
29+
- `shell` If *not* set will be `/sbin/nologin` on the `control` node and the
30+
default shell on other users. Explicitly setting this defines the shell for
31+
all nodes.
2632
- An additional key `public_key` may optionally be specified to define a key to log into the cluster.
2733
- An additional key `sudo` may optionally be specified giving a string (possibly multiline) defining sudo rules to be templated.
2834
- `ssh_key_type` defaults to `ed25519` instead of the `ansible.builtin.user` default of `rsa`.
2935
- Any other keys may present for other purposes (i.e. not used by this role).
3036
- `basic_users_groups`: Optional, default empty list. A list of mappings defining information for each group. Mapping keys/values are passed through as parameters to [ansible.builtin.group](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/group_module.html) and default values are as given there.
3137
- `basic_users_override_sssd`: Optional bool, default false. Whether to disable `sssd` when ensuring users/groups exist with this role. Permits creating local users/groups even if they clash with users provided via sssd (e.g. from LDAP). Ignored if host is not in group `sssd` as well. Note with this option active `sssd` will be stopped and restarted each time this role is run.
32-
- `basic_users_manage_homedir`: Optional bool, must be true on a single host to
33-
determine which host runs tasks affecting the shared filesystem. The default
34-
is to use the first play host which is not the control node, because the
35-
default NFS configuration does not have the shared `/home` directory mounted
36-
on the control node.
38+
- `basic_users_homedir_host`: Optional inventory hostname. Host to run actions
39+
which manipulate the home directories. If home directories are exported with
40+
root squash, this *must* specify that server. If root squash is not used it
41+
can be any node in the `basic_users` group. Default is the `control` node,
42+
which assumes the default appliance NFS-exported home directory configuration.
43+
- `basic_users_homedir_host_path`: Optional path prefix for home directories on
44+
the `basic_users_homedir_host`. Default is `/exports/home` which assumes the
45+
default appliance NFS-exported home directory configuration. **NB**: This may
46+
vary depending on whether
47+
`basic_users_homedir_host` is a server or a client for the home directories.
3748

3849
Dependencies
3950
------------
4051

4152
None.
4253

43-
Example Playbook
44-
----------------
54+
Example Configurations
55+
----------------------
4556

46-
```yaml
47-
- hosts: basic_users
48-
become: yes
49-
gather_facts: yes
50-
tasks:
51-
- import_role:
52-
name: basic_users
53-
```
54-
55-
Example variables, to create user `alice` and delete user `bob`:
57+
With default appliance NFS configuration, create user `alice` with access
58+
to all nodes except the control node, and delete user `bob`:
5659

5760
```yaml
5861
basic_users_users:
5962
- comment: Alice Aardvark
6063
name: alice
6164
uid: 2005
62-
public_key: ssh-rsa ...
65+
public_key: ssh-ed25519 ...
6366
- comment: Bob Badger
6467
name: bob
6568
uid: 2006
66-
public_key: ssh-rsa ...
69+
public_key: ssh-ed25519 ...
6770
state: absent
6871
```
72+
73+
Using an external share which does not root squash so this role can create
74+
directories on it, which is also mounted to the control node (so this role can
75+
set authorized keys there), create user `Carol`:
76+
77+
```yaml
78+
basic_users_homedir_host: "{{ ansible_play_hosts | first }}" # doesn't matter which host is used
79+
basic_users_homedir_host_path: /home # homedir_host is client not server
80+
basic_users_user:
81+
- comment: Carol Crane
82+
name: carol
83+
uid: 2007
84+
public_key: ssh-ed25519 ...
85+
```
86+
87+
Using an external share which *does* root squash, so home directories cannot be
88+
created by this role and must already exist, create user `Dan`:
89+
90+
```yaml
91+
basic_users_homedir_host: "{{ ansible_play_hosts | first }}"
92+
basic_users_homedir_host_path: /home
93+
basic_users_users:
94+
- comment: Dan Deer
95+
create_home: false
96+
name: dan
97+
uuid: 2009
98+
public_key: ssh-ed25519 ...
99+
```
100+
101+
Using NFS exported from the control node, but mounted to all nodes (so that
102+
authorized keys applies to all nodes), create user `Erin` with passwordless sudo:
103+
104+
```yaml
105+
basic_users_users:
106+
- comment: Erin Eagle
107+
name: dan
108+
uid: 2008
109+
shell: /bin/bash # override default nologin on control
110+
groups:
111+
- adm # enables ssh to compute nodes even without a job running
112+
sudo: dan ALL=(ALL) NOPASSWD:ALL
113+
public_key: ssh-ed25519 ...
114+
```

ansible/roles/basic_users/defaults/main.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
basic_users_manage_homedir: "{{ ansible_hostname == (ansible_play_hosts | difference(groups['control']) | first) }}"
1+
basic_users_homedir_host: "{{ groups['control'] | first }}" # no way, generally, to find the nfs_server
2+
basic_users_homedir_host_path: /exports/home
3+
_basic_users_manage_homedir: "{{ ansible_hostname == basic_users_homedir_host }}"
24
basic_users_userdefaults:
35
state: present
4-
create_home: "{{ basic_users_manage_homedir }}"
5-
generate_ssh_key: "{{ basic_users_manage_homedir }}"
6+
home: "{{ basic_users_homedir_host_path }}/{{ item.name }}"
7+
create_home: "{{ _basic_users_manage_homedir }}"
8+
generate_ssh_key: "{{ _basic_users_manage_homedir }}"
69
ssh_key_comment: "{{ item.name }}"
710
ssh_key_type: ed25519
811
shell: "{{'/sbin/nologin' if 'control' in group_names else omit }}"

ansible/roles/basic_users/tasks/main.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,28 +39,30 @@
3939
user: "{{ item.name }}"
4040
state: present
4141
key: "{{ item.public_key }}"
42+
become_user: "{{ item.name }}"
4243
loop: "{{ basic_users_users }}"
4344
loop_control:
4445
label: "{{ item.name }} [{{ item.state | default('present') }}]"
4546
when:
4647
- item.state | default('present') == 'present'
4748
- item.public_key is defined
48-
- basic_users_manage_homedir
49+
- _basic_users_manage_homedir
4950

5051
- name: Write generated public key as authorized for SSH access
51-
# this only runs on the basic_users_manage_homedir so has registered var
52+
# this only runs on the _basic_users_manage_homedir so has registered var
5253
# from that host too
5354
authorized_key:
5455
user: "{{ item.name }}"
5556
state: present
5657
manage_dir: no
5758
key: "{{ item.ssh_public_key }}"
59+
become_user: "{{ item.name }}"
5860
loop: "{{ basic_users_info.results }}"
5961
loop_control:
6062
label: "{{ item.name }}"
6163
when:
6264
- item.ssh_public_key is defined
63-
- basic_users_manage_homedir
65+
- _basic_users_manage_homedir
6466

6567
- name: Write sudo rules
6668
blockinfile:

environments/common/inventory/group_vars/all/nfs.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,4 @@ nfs_configurations:
1515
nfs_server: "{{ nfs_server_default }}"
1616
nfs_export: "/exports/home" # assumes skeleton TF is being used
1717
nfs_client_mnt_point: "/home"
18-
19-
# Set 'secure' to prevent tunneling nfs mounts
20-
# Cannot set 'root_squash' due to home directory creation
21-
nfs_export_options: 'rw,secure,no_root_squash'
18+
nfs_export_options: 'rw,secure,root_squash' # prevent tunnelling and setuid binaries

0 commit comments

Comments
 (0)