Skip to content

Support SSSD and optionally LDAP #438

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 27 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
7413c08
support sssd configuration
sjpb Sep 11, 2024
7d1bd69
make sssd-ldap optional
sjpb Sep 12, 2024
be02780
SSSD PR review tweaks
sjpb Sep 12, 2024
70e630d
enable installing sssd in fatimage
sjpb Sep 13, 2024
ae16669
install sssd and sssd-ldap packages in stackhpc fatimage
sjpb Sep 13, 2024
7ea7709
fix sssd being enabled in fatimage
sjpb Sep 17, 2024
c451460
bump CI image
sjpb Sep 17, 2024
ab45c2a
simplify sssd-ldap package installation in fatimage
sjpb Sep 18, 2024
15373e1
Merge branch 'main' into feat/sssd-ldap-v2
sjpb Sep 18, 2024
243be0f
bump CI image
sjpb Sep 18, 2024
701da11
enable mkhomedir
sjpb Sep 18, 2024
e6db5fa
add sshd role
sjpb Sep 18, 2024
2ab2ada
auto enable ssh passwords if using ldap
sjpb Sep 20, 2024
793fa69
actually run sshd role
sjpb Sep 18, 2024
2ee20c7
make sshd config more flexible
sjpb Sep 19, 2024
7362b7b
add basic_users_override_sssd flag
sjpb Oct 4, 2024
cfe8def
port PR comment re. basic_users docs
sjpb Oct 11, 2024
354b444
Merge branch 'main' into feat/sssd-ldap-v2
sjpb Oct 11, 2024
60a8a2c
Merge branch 'main' into feat/sssd-ldap-v2
sjpb Oct 30, 2024
bcf593c
add sssd-ldap package during stackhpc build only
sjpb Oct 30, 2024
09e7bda
bump CI image
sjpb Oct 30, 2024
a1c8a77
add missing empty sssd group
sjpb Nov 1, 2024
73329ff
remove deprecated & empty block_devices group
sjpb Nov 1, 2024
ff40ff2
regularise common groups & everything groups template a bit
sjpb Nov 1, 2024
ecea821
Merge branch 'main' into feat/sssd-ldap-v2
sjpb Jan 9, 2025
fa1297e
bumb CI image
sjpb Jan 9, 2025
a3b7303
sssd review comments
sjpb Jan 9, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ansible/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ roles/*
!roles/squid/**
!roles/tuned/
!roles/tuned/**
!roles/sssd/
!roles/sssd/**
!roles/sshd/
!roles/sshd/**
!roles/compute_init/
!roles/compute_init/**
!roles/k3s/
Expand Down
9 changes: 9 additions & 0 deletions ansible/bootstrap.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,15 @@
policy: "{{ selinux_policy }}"
register: sestatus

- hosts: sshd
tags: sshd
gather_facts: no
become: yes
tasks:
- name: Configure sshd
import_role:
name: sshd

- hosts: dnf_repos
become: yes
tasks:
Expand Down
5 changes: 5 additions & 0 deletions ansible/fatimage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@
name: freeipa
tasks_from: client-install.yml
when: "'freeipa_client' in group_names"
- name: Install sssd
import_role:
name: sssd
tasks_from: install.yml
when: "'sssd' in group_names"

# - import_playbook: filesystems.yml:
- name: Install nfs packages
Expand Down
9 changes: 9 additions & 0 deletions ansible/iam.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,12 @@
import_role:
name: freeipa
tasks_from: users.yml

- hosts: sssd
become: yes
gather_facts: no
tags: sssd
tasks:
- name: Configure sssd
import_role:
name: sssd
1 change: 1 addition & 0 deletions ansible/roles/basic_users/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Role Variables
- An additional key `sudo` may optionally be specified giving a string (possibly multiline) defining sudo rules to be templated.
- Any other keys may present for other purposes (i.e. not used by this role).
- `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.
- `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.

Dependencies
------------
Expand Down
1 change: 1 addition & 0 deletions ansible/roles/basic_users/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ basic_users_userdefaults:
shell: "{{'/sbin/nologin' if 'control' in group_names else omit }}"
basic_users_users: []
basic_users_groups: []
basic_users_override_sssd: false
17 changes: 16 additions & 1 deletion ansible/roles/basic_users/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,16 @@
label: "{{ item.name }}"
when:
- "item.state | default('present') == 'absent'"


- name: Stop sssd if required
systemd:
name: sssd
state: stopped
register: _stop_sssd
when:
- "'sssd' in group_names"
- basic_users_override_sssd | bool

- name: Create groups
ansible.builtin.group: "{{ item }}"
loop: "{{ basic_users_groups }}"
Expand All @@ -19,6 +28,12 @@
label: "{{ item.name }} [{{ item.state | default('present') }}]"
register: basic_users_info

- name: Restart sssd if required
systemd:
name: sssd
state: started
when: _stop_sssd is changed

- name: Write supplied public key as authorized for SSH access
authorized_key:
user: "{{ item.name }}"
Expand Down
9 changes: 9 additions & 0 deletions ansible/roles/sshd/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# sshd

Configure sshd.

## Role variables

- `sshd_password_authentication`: Optional bool. Whether to enable password login. Default `false`.
- `sshd_conf_src`: Optional string. Path to sshd configuration template. Default is in-role template.
- `sshd_conf_dest`: Optional string. Path to destination for sshd configuration file. Default is `/etc/ssh/sshd_config.d/10-ansible.conf` which overides `50-{cloud-init,redhat}` files, if present.
3 changes: 3 additions & 0 deletions ansible/roles/sshd/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
sshd_password_authentication: false
sshd_conf_src: sshd.conf.j2
sshd_conf_dest: /etc/ssh/sshd_config.d/10-ansible.conf
4 changes: 4 additions & 0 deletions ansible/roles/sshd/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- name: Restart sshd
systemd:
name: sshd
state: restarted
15 changes: 15 additions & 0 deletions ansible/roles/sshd/tasks/configure.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
- name: Template sshd configuration
# NB: If parameters are defined multiple times the first value wins;
# The default /etc/ssh/sshd_config has
# Include /etc/ssh/sshd_config.d/*.conf
# early on, which is generally held to be the correct approach, so adding
# values to the end of that file won't work
template:
src: "{{ sshd_conf_src }}"
dest: "{{ sshd_conf_dest }}"
owner: root
group: root
mode: u=rw,go=
validate: sshd -t -f %s
notify:
- Restart sshd
1 change: 1 addition & 0 deletions ansible/roles/sshd/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- import_tasks: configure.yml
2 changes: 2 additions & 0 deletions ansible/roles/sshd/templates/sshd.conf.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# {{ ansible_managed }}
PasswordAuthentication {{ 'yes' if sshd_password_authentication | bool else 'no' }}
18 changes: 18 additions & 0 deletions ansible/roles/sssd/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# sssd

Install and configure [sssd](https://sssd.io/docs/introduction.html).


## Role variables

The only required configuration is to create a [sssd.conf](https://www.mankier.com/5/sssd.conf) template at the location specified by `sssd_conf_src`.

- `sssd_packages`: Optional list. Packages to install.
- `sssd_ldap_install`: Optional bool. Whether to install packages enabling SSSD to authenticate against LDAP. Default `false`.
- `sssd_ldap_packages`: Optional list. Packages to install when using `sssd_ldap_install`.
- `sssd_enable_mkhomedir`: Optional bool. Whether to enable creation of home directories on login. Default `false`.
- `sssd_mkhomedir_packages`: Optional list. Packages to install when using `sssd_enable_mkhomedir`.
- `sssd_conf_src`: Optional string. Path to `sssd.conf` template. Default (which must be created) is `{{ appliances_environment_root }}/files/sssd.conf.j2`.
- `sssd_conf_dest`: Optional string. Path to destination for `sssd.conf`. Default `/etc/sssd/sssd.conf`.
- `sssd_started`: Optional bool. Whether `sssd` service should be started.
- `sssd_enabled`: Optional bool. Whether `sssd` service should be enabled.
12 changes: 12 additions & 0 deletions ansible/roles/sssd/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
sssd_packages:
- sssd-common
sssd_install_ldap: false
sssd_ldap_packages:
- sssd-ldap
sssd_enable_mkhomedir: false
sssd_mkhomedir_packages:
- oddjob-mkhomedir
sssd_conf_src: "{{ appliances_environment_root }}/files/sssd.conf.j2"
sssd_conf_dest: /etc/sssd/sssd.conf
sssd_started: true
sssd_enabled: true
5 changes: 5 additions & 0 deletions ansible/roles/sssd/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- name: Restart sssd
systemd:
name: sssd
state: restarted
when: sssd_started | bool
28 changes: 28 additions & 0 deletions ansible/roles/sssd/tasks/configure.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
- name: Manage sssd.conf configuration
template:
src: "{{ sssd_conf_src }}"
dest: "{{ sssd_conf_dest }}"
owner: root
group: root
mode: u=rw,go=
notify: "Restart sssd"

- meta: flush_handlers

- name: Ensure sssd service state
systemd:
name: sssd
state: "{{ 'started' if sssd_started | bool else 'stopped' }}"
enabled: "{{ sssd_enabled | bool }}"

- name: Get current authselect configuration
command: authselect current --raw
changed_when: false
failed_when:
- _authselect_current.rc != 0
- "'No existing configuration detected' not in _authselect_current.stdout"
register: _authselect_current # stdout: sssd with-mkhomedir

- name: Configure nsswitch and PAM for SSSD
command: "authselect select sssd --force{% if sssd_enable_mkhomedir | bool %} with-mkhomedir{% endif %}"
when: "'sssd' not in _authselect_current.stdout"
13 changes: 13 additions & 0 deletions ansible/roles/sssd/tasks/install.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
- name: Ensure sssd packages are installed
dnf:
name: "{{ sssd_packages + sssd_ldap_packages if (sssd_install_ldap | bool) else [] }}"

- name: Control if sssd should start on boot
# Needs to be done here to prevent starting after image build, is enabled by default
systemd:
name: sssd
enabled: "{{ sssd_enabled | bool }}"

- name: Ensure mkhomedir packages are installed if required
dnf:
name: "{{ sssd_mkhomedir_packages }}"
2 changes: 2 additions & 0 deletions ansible/roles/sssd/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- import_tasks: install.yml
- import_tasks: configure.yml
4 changes: 4 additions & 0 deletions environments/.stackhpc/inventory/extra_groups
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,7 @@ compute
[squid:children]
# Install squid into fat image
builder

[sssd:children]
# Install sssd into fat image
builder
2 changes: 2 additions & 0 deletions environments/.stackhpc/inventory/group_vars/builder.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#update_enable: false # Can uncomment for speed debugging non-update related build issues
sssd_install_ldap: true # include sssd-ldap package in fatimage
# update_enable: false # Can uncomment for speed debugging non-update related build issues

# Uncomment below to use CI pulp servers
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"cluster_image": {
"RL8": "openhpc-RL8-250108-1703-e515b902",
"RL9": "openhpc-RL9-250108-1703-e515b902"
"RL8": "openhpc-RL8-250109-1444-ecea8219",
"RL9": "openhpc-RL9-250109-1444-ecea8219"
}
}
1 change: 1 addition & 0 deletions environments/common/inventory/group_vars/all/sshd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sshd_password_authentication: "{{ sssd_install_ldap | default(false) | bool }}"
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ squid_cache_disk: 0 # just needs to be defined
squid_cache_mem: 0
tuned_started: false
tuned_enabled: false
sssd_started: false
sssd_enabled: false
appliances_mode: build
18 changes: 12 additions & 6 deletions environments/common/inventory/groups
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ login
control
compute

[eessi:children]
# Hosts on which EESSI stack should be configured

[hpctests:children]
# Login group to use for running mpi-based testing.
login
Expand Down Expand Up @@ -79,9 +76,6 @@ cluster
# Hosts to install firewalld on - see ansible/roles/filewalld
fail2ban

[block_devices]
# Superset of hosts to configure filesystems on - see ansible/roles/block_devices/README.md

[basic_users]
# Add `openhpc` group to add slurm users via creation of users on each node.

Expand Down Expand Up @@ -118,12 +112,18 @@ freeipa_client
[cuda]
# Hosts to install NVIDIA CUDA on - see ansible/roles/cuda/README.md

[eessi]
# Hosts on which EESSI stack should be configured

[resolv_conf]
# Allows defining nameservers in /etc/resolv.conf - see ansible/roles/resolv_conf/README.md

[proxy]
# Hosts to configure http/s proxies - see ansible/roles/proxy/README.md

[manila]
# Hosts to configure for manila fileshares

[persist_hostkeys]
# Hosts to persist hostkeys for across reimaging. NB: Requires appliances_state_dir on hosts.

Expand All @@ -136,6 +136,12 @@ freeipa_client
[ansible_init]
# Hosts to run linux-anisble-init

[sssd]
# Hosts to configure sssd on

[sshd]
# Hosts where the OpenSSH server daemon should be configured

[compute_init]
# EXPERIMENTAL: Compute hosts to enable joining cluster on boot on

Expand Down
9 changes: 8 additions & 1 deletion environments/common/layouts/everything
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ cluster
# Hosts to install NVIDIA CUDA on - see ansible/roles/cuda/README.md

[eessi:children]
# Hosts on which EESSI stack should be configured
openhpc

[resolv_conf]
Expand All @@ -83,9 +84,15 @@ openondemand
# Hosts to run TuneD configuration

[ansible_init:children]
# Hosts to run ansible-init
# Hosts to run linux-anisble-init
cluster

[sssd]
# Hosts to configure sssd on

[sshd]
# Hosts where the OpenSSH server daemon should be configured

[compute_init:children]
# EXPERIMENTAL: Compute hosts to enable joining cluster on boot on
compute
Expand Down
Loading