Skip to content

Add freeipa (not containerised) #241

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 74 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from 70 commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
7a95581
use inventory_hostname.cluster.tld for hostnames
sjpb Nov 30, 2022
86dd61b
disable etc_hosts in arcus
sjpb Nov 30, 2022
03f0381
get freeipa-server working with ssh tunneled web GUI
sjpb Nov 30, 2022
f353472
add freeipa hosts and enrole them
sjpb Dec 1, 2022
a34e42d
don't use basic_users for IAM on arcus
sjpb Dec 2, 2022
9407ee9
add freeipa user handling
sjpb Dec 2, 2022
26d0d7f
use freeipa for arcus/ci users
sjpb Dec 2, 2022
e5d501a
add validation for freeipa
sjpb Dec 2, 2022
1cd2709
don't use 'fat' image for freeipa
sjpb Dec 2, 2022
6ee0c12
move freeipa before filesystems so nfs clients can find server
sjpb Dec 2, 2022
398e4ae
enable freeipa reverse DNS to fix slurm
sjpb Dec 2, 2022
5ca2a9c
make inventory_hostname == short hostname so slurm works
sjpb Dec 6, 2022
ab3817a
enable short inventory_hostnames to work for etc_hosts too
sjpb Dec 6, 2022
9db701c
validate TLD exists for freeipa
sjpb Dec 13, 2022
b3cd98f
increase control node size on arcus/CI
sjpb Dec 13, 2022
3722450
tidy OOD auth defaults
sjpb Dec 13, 2022
244d1e6
handle tld in rebuild adhoc
sjpb Dec 13, 2022
ba47527
don't force enrole freeipa clients - needs separate work
sjpb Dec 13, 2022
a540243
make provision of DNS from freeipa optional
sjpb Jan 5, 2023
ef99509
separate freeipa server & client (using random password) and add reso…
sjpb Jan 10, 2023
f04bafa
use ansible to save/restore client freeipa keytab from control's stat…
sjpb Jan 10, 2023
fa067ac
auto-set freeipa_setup_dns
sjpb Jan 10, 2023
6396291
add freeipa README
sjpb Jan 10, 2023
093bc3a
Merge branch 'main' into feat/freeipa-nocontainer
sjpb Jan 10, 2023
2a59df0
Revert "tidy OOD auth defaults"
sjpb Jan 10, 2023
24d9cd1
Merge branch 'main' into feat/freeipa-nocontainer
sjpb Jan 17, 2023
97955af
tweak freeipa README
sjpb Jan 17, 2023
ec41e8b
improve validation output when hostname is not fqdn
sjpb Jan 19, 2023
c5bf1dd
define hostname as fqdn reliably (using userdata) and set fqdn hostvar
sjpb Jan 25, 2023
a6cd6f5
add resolv_conf and proxy roles
sjpb Jan 25, 2023
05dc954
add missing gitignore changes for proxy/resolv_conf
sjpb Jan 25, 2023
bd5868a
fix dnf proxy
sjpb Jan 25, 2023
0f98726
move freeipa host and user tasks to iam.yml
sjpb Jan 24, 2023
4614cb3
rewrite freeipa role
sjpb Jan 25, 2023
585823a
use new resolv_conf role on arcus to set nameservers
sjpb Jan 31, 2023
b9766e3
fix freeipa client fail when enroled but no keytab persisted
sjpb Feb 1, 2023
05f5c96
change fqdn->node_fqnd and tld->cluster_domain_suffix
sjpb Feb 1, 2023
9c4a037
make freeipa_server_ip safe to template
sjpb Feb 7, 2023
9d5051d
fix /etc/hosts and realm when using cluster_domain_suffix
sjpb Feb 8, 2023
9759202
add adhoc to backup/restore keytabs to/from environment
sjpb Apr 11, 2023
64817d2
Merge branch 'main' into feat/freeipa-nocontainer
sjpb Jun 28, 2023
029ef11
move testuser setup to correct location
sjpb Jun 29, 2023
e034413
fix definition of control node for freeipa
sjpb Jun 29, 2023
6314134
still use clustername-each.key with FQDN hosts (for freeipa)
sjpb Jul 4, 2023
ca45ee2
fix etc_hosts template when using cluster_domain_suffix
sjpb Jul 4, 2023
c086c9e
revert rebuild adhoc now inventory_hostname isn't changed with fqdn h…
sjpb Jul 4, 2023
78b069c
Revert "move freeipa before filesystems so nfs clients can find server"
sjpb Jul 4, 2023
78a213e
move basic_users to after filesystems.yml so templating is done onto …
sjpb Jul 4, 2023
eba82fd
move EEESI to extras
sjpb Jul 4, 2023
0880610
remove duplicate resolv_conf role file
sjpb Jul 4, 2023
7aa6230
Revert "Revert "move freeipa before filesystems so nfs clients can fi…
sjpb Jul 4, 2023
dc926f2
update freeipa readme
sjpb Jul 4, 2023
8e511e6
fix freeipa client task inventory names
sjpb Jul 4, 2023
e3d8a60
disable freeipa in CI, just provide examples
sjpb Jul 4, 2023
52f062f
move node_fqdn to terraform inventory
sjpb Jul 4, 2023
d6fe264
document stackhpc env freeipa setup
sjpb Jul 4, 2023
69c34c0
Merge branch 'main' into feat/freeipa-nocontainer
sjpb Jul 21, 2023
cca7389
enable NFS PRC security service for freeipa clients
sjpb May 19, 2023
96bec2a
Merge branch 'main' into feat/freeipa-nocontainer
sjpb Aug 8, 2023
32ff5c1
Merge branch 'main' into feat/freeipa-nocontainer
sjpb Oct 12, 2023
46ef0c2
fix basic_users not working in CI
sjpb Oct 12, 2023
c2bdb57
install freeipa client packages in fatimage build
sjpb Oct 12, 2023
ddcff02
Merge branch 'main' into feat/freeipa-nocontainer
sjpb Oct 25, 2023
87af20c
Merge branch 'main' into feat/freeipa-nocontainer
sjpb Oct 27, 2023
89d282d
move freeipa_server validation so it runs
sjpb Nov 1, 2023
014c70d
add check for virtual servers in freeipa_server
sjpb Nov 1, 2023
40b6cff
move freeipa validation back to validate task
sjpb Nov 1, 2023
676de7c
don't log freeipa server passwords
sjpb Nov 1, 2023
5618d4e
fix freeipa testuser password to match normal CI/basic_users_users usage
sjpb Nov 1, 2023
3708a5c
add note re freeipa server incompatibility with other virtual servers
sjpb Nov 1, 2023
4febcc6
tweak freeipa names
sjpb Nov 2, 2023
6c07eca
freeipa README nits
sjpb Nov 2, 2023
a35ea26
freeipa editorial comments
sjpb Nov 2, 2023
966d350
remove argsplat from FreeIPA users task
sjpb Nov 2, 2023
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
11 changes: 11 additions & 0 deletions ansible/adhoc/backup-keytabs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Use ONE of the following tags on this playbook:
# - retrieve: copies keytabs out of the state volume to the environment
# - deploy: copies keytabs from the environment to the state volume

- hosts: freeipa_client
become: yes
gather_facts: no
tasks:
- import_role:
name: freeipa
tasks_from: backup-keytabs.yml
15 changes: 15 additions & 0 deletions ansible/bootstrap.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,21 @@
policy: "{{ selinux_policy }}"
register: sestatus

- hosts: freeipa_server
# Done here as it might be providing DNS
tags:
- freeipa
- freeipa_server
gather_facts: yes
become: yes
tasks:
- name: Install freeipa server
import_role:
name: freeipa
tasks_from: server.yml

# --- tasks after here require access to package repos ---

- hosts: firewalld
gather_facts: false
become: yes
Expand Down
10 changes: 10 additions & 0 deletions ansible/extras.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
- hosts: basic_users
become: yes
tags:
- basic_users
- users
gather_facts: yes
tasks:
- import_role:
name: basic_users

- name: Setup EESSI
hosts: eessi
tags: eessi
Expand Down
9 changes: 7 additions & 2 deletions ansible/fatimage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@
state: stopped
enabled: false

# - import_playbook: iam.yml
- name: Install freeipa client
import_role:
name: freeipa
tasks_from: client-install.yml
when: "'freeipa_client' in group_names"

# - import_playbook: filesystems.yml
- name: nfs
dnf:
Expand Down Expand Up @@ -149,8 +156,6 @@
name: cloudalchemy.grafana
tasks_from: install.yml

# - import_playbook: iam.yml - nothing to do

- name: Run post.yml hook
vars:
appliances_environment_root: "{{ lookup('env', 'APPLIANCES_ENVIRONMENT_ROOT') }}"
Expand Down
42 changes: 38 additions & 4 deletions ansible/iam.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,42 @@
- hosts: basic_users
- hosts: freeipa_client
tags:
- freeipa
- freeipa_server # as this is only relevant if using freeipa_server
- freeipa_host
gather_facts: no
become: yes
tasks:
- name: Add freeipa hosts
import_role:
name: freeipa
tasks_from: addhost.yml
when: groups['freeipa_server'] | length > 0

- hosts: freeipa_client
tags:
- basic_users
- freeipa
- freeipa_client
gather_facts: yes
become: yes
tasks:
- name: Install freeipa client
import_role:
name: freeipa
tasks_from: client-install.yml
- name: Enrole freeipa clients
import_role:
name: freeipa
tasks_from: enrole.yml

- hosts: freeipa_server
tags:
- freeipa
- freeipa_server
- users
gather_facts: yes
become: yes
tasks:
- import_role:
name: basic_users
- name: Add freeipa users
import_role:
name: freeipa
tasks_from: users.yml
7 changes: 5 additions & 2 deletions ansible/roles/etc_hosts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

Hosts in the `etc_hosts` groups have `/etc/hosts` created with entries of the format `IP_address canonical_hostname [alias]`.

By default, an entry is created for each host in this group, using `ansible_host` as the IP_address and `inventory_hostname` as the canonical hostname. This may need overriding for multi-homed hosts or hosts with multiple aliases.
By default, an entry is created for each host in this group as follows:
- The value of `ansible_host` is used as the IP_address.
- If `node_fqdn` is defined then that is used as the canonical hostname and `inventory_hostname` as an alias. Otherwise `inventory_hostname` is used as the canonical hostname.
This may need overriding for multi-homed hosts or hosts with multiple aliases.

# Variables

- `etc_hosts_template`: Template file to use. Default is the in-role template.
- `etc_hosts_hostvars`: A list of variable names, used (in the order supplied) to create the entry for each host. Default is `['ansible_host', 'inventory_hostname']`
- `etc_hosts_hostvars`: A list of variable names, used (in the order supplied) to create the entry for each host. Default is described above.
- `etc_hosts_extra_hosts`: String (possibly multi-line) defining additional hosts to add to `/etc/hosts`. Default is empty string.
4 changes: 1 addition & 3 deletions ansible/roles/etc_hosts/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
etc_hosts_template: hosts.j2
etc_hosts_hostvars:
- ansible_host
- inventory_hostname
etc_hosts_hostvars: "{{ ['ansible_host'] + (['node_fqdn'] if node_fqdn is defined else []) + ['inventory_hostname'] }}"
etc_hosts_extra_hosts: ''
68 changes: 68 additions & 0 deletions ansible/roles/freeipa/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@

# freeipa

Support FreeIPA in the appliance. In production use it is expected the FreeIPA server(s) will be external to the cluster, implying that hosts and users are managed outside the appliance. However for testing and development the role can also deploy an "in-appliance" FreeIPA server, add hosts to it and manage users in FreeIPA.

# FreeIPA Client

## Usage
- Add hosts to the `freeipa_client` group and run (at a minimum) the `ansible/iam.yml` playbook.
- Host names must match the domain name. By default (using the skeleton Terraform) hostnames are of the form `nodename.cluster_name.cluster_domain_suffix` where `cluster_name` and `cluster_domain_suffix` are Terraform variables.
- Hosts discover the FreeIPA server FQDN (and their own domain) from DNS records. If this is not set from DHCP, then use the `resolv_conf` role to configure this. For example when using the in-appliance FreeIPA development server,:

```ini
# environments/<env>/groups
...
[resolv_conf:children]
freeipa_client
...
```

```yaml
# environments/<env>/inventory/group_vars/all/resolv_conf.yml
resolv_conf_nameservers:
- "{{ hostvars[groups['freeipa_server'] | first].ansible_host }}"
```


- For production use with an external FreeIPA server, a random one-time password (OTP) must be generated when adding hosts to FreeIPA (e.g. using `ipa host-add --random ...`). This password should be set as a hostvar `freeipa_host_password`. Initial host enrolment will use this OTP to enrole the host. After this it becomes irrelevant so it does not need to be committed to git. This approach means the appliance does not require the FreeIPA administrator password.
- For development use with the in-appliance FreeIPA server, `freeipa_host_password` will be automatically generated in memory.
- The `control` host must define `appliances_state_dir` (on persistent storage). This is used to back-up keytabs to allow FreeIPA clients to automatically reenroll after e.g. reimaging. Note that:
- This is implemented when using the skeleton Terraform; on the control node `appliances_state_dir` defaults to `/var/lib/state` which is mounted from a volume.
- Nodes are not re-enroled by a [Slurm-driven reimage](../../collections/ansible_collections/stackhpc/slurm_openstack_tools/roles/rebuild/README.md) (as that does not run this role).
- If both a backed-up keytab and `freeipa_host_password` exist, the former is used.


## Role Variables for Clients

- `freeipa_host_password`. Required for initial enrolment only, FreeIPA host password as described above.
- `freeipa_setup_dns`: Optional, whether to use the FreeIPA server as the client's nameserver. Defaults to `true` when `freeipa_server` contains a host, otherwise `false`.

See also use of `appliances_state_dir` on the control node as described above.

# FreeIPA Server
As noted above this is only intended for development and testing. Note it cannot be run on the `openondemand` node as no other virtual servers must be defined in the Apache configuration.

## Usage
- Add a single host to the `freeipa_server` group and run (at a minimum) the `ansible/bootstrap.yml` and `ansible/iam.yml` playbooks.
- As well as configuring the FreeIPA server, the role will also:
- Add ansible hosts in the group `freeipa_client` as FreeIPA hosts.
- Optionally control users in FreeIPA - see `freeipa_users` below.

The FreeIPA GUI will be available on `https://<freeipa_server_ip>/ipa/ui`.

## Role Variables for Server

These role variables are only required when using `freeipa_server`:

- `freeipa_realm`: Optional, name of realm. Default is `{{ openhpc_cluster_name | upper }}.INVALID`
- `freeipa_domain`: Optional, name of domain. Default is lowercased `freeipa_realm`.
- `freeipa_ds_password`: Optional, password to be used by the Directory Server for the Directory Manager user (`ipa-server-install --ds-password`). Default is generated in `environments/<environment>/inventory/group_vars/all/secrets.yml`
- `freeipa_admin_password`: Optional, password for the IPA `admin` user. Default is generated as for `freeipa_ds_password`.
- `freeipa_server_ip`: Optional, IP address of freeipa_server host. Default is `ansible_host` of the `freeipa_server` host. Default `false`.
- `freeipa_setup_dns`: Optional bool, whether to configure the FreeIPA server as an integrated DNS server and define a zone and records. NB: This also controls whether `freeipa_client` hosts use the `freeipa_server` host for name resolution. Default `true` when `freeipa_server` contains a host.
- `freeipa_client_ip`: Optional, IP address of FreeIPA client. Default is `ansible_host`.
- `freeipa_users`: A list of dicts as per parameters for [community.general.ipa_user](https://docs.ansible.com/ansible/latest/collections/community/general/ipa_user_module.html). Note that:
- `name`, `givenname` (firstname) and `sn` (surname) are required.
- `ipa_pass` and `ipa_user` are automatically supplied.
- If `password` is set, the value should *not* be a hash (unlike `ansible.builtin.user` as used by the `basic_users` role), and it must be changed on first login. `krbpasswordexpiration` does not appear to be able to override this.
14 changes: 14 additions & 0 deletions ansible/roles/freeipa/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#freeipa_realm:
freeipa_domain: "{{ freeipa_realm | lower }}"
#freeipa_ds_password:
#freeipa_admin_password:
#freeipa_server_ip:
freeipa_setup_dns: "{{ groups['freeipa_server'] | length > 0 }}"
freeipa_client_ip: "{{ ansible_host }}" # when run on freeipa_client group!
# freeipa_host_password:
freeipa_user_defaults:
ipa_pass: "{{ freeipa_admin_password | quote }}"
ipa_user: admin
freeipa_users: [] # see community.general.ipa_user

_freeipa_keytab_backup_path: "{{ hostvars[groups['control'].0].appliances_state_dir }}/freeipa/{{ inventory_hostname }}/krb5.keytab"
35 changes: 35 additions & 0 deletions ansible/roles/freeipa/tasks/addhost.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
- name: Get ipa host information
# This uses DNS to find the ipa server, which works as this is running on the enrolled ipa server
# It doesn't fail even if the host doesn't exist
community.general.ipa_host:
name: "{{ node_fqdn }}"
ip_address: "{{ freeipa_client_ip }}"
ipa_host: "{{ groups['freeipa_server'].0 }}"
ipa_pass: "{{ vault_freeipa_admin_password }}"
ipa_user: admin
state: present
validate_certs: false
delegate_to: "{{ groups['freeipa_server'].0 }}"
register: _ipa_host_check
check_mode: yes
changed_when: false

- name: Add host to IPA
# Using random_password=true this unenroles an enroled host, hence the check above
community.general.ipa_host:
name: "{{ node_fqdn }}"
ip_address: "{{ freeipa_client_ip }}"
ipa_host: "{{ groups['freeipa_server'].0 }}"
ipa_pass: "{{ vault_freeipa_admin_password }}"
ipa_user: admin
random_password: true
state: present
validate_certs: false
delegate_to: "{{ groups['freeipa_server'].0 }}"
when: "'sshpubkeyfp' not in _ipa_host_check.host"
register: _ipa_host_add

- name: Set fact for ipa host password
set_fact:
freeipa_host_password: "{{ _ipa_host_add.host.randompassword }}"
when: _ipa_host_add.changed
14 changes: 14 additions & 0 deletions ansible/roles/freeipa/tasks/backup-keytabs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
- name: Retrieve keytabs to localhost
fetch:
src: "{{ _freeipa_keytab_backup_path }}"
dest: "{{ appliances_environment_root }}/keytabs/{{ inventory_hostname }}/"
flat: true
delegate_to: "{{ groups['control'].0 }}"
tags: retrieve

- name: Copy keytabs back to control node
copy:
src: "{{ appliances_environment_root }}/keytabs/{{ inventory_hostname }}/"
dest: "{{ _freeipa_keytab_backup_path | dirname }}"
delegate_to: "{{ groups['control'].0 }}"
tags: deploy
4 changes: 4 additions & 0 deletions ansible/roles/freeipa/tasks/client-install.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

- name: Install FreeIPA client package
dnf:
name: ipa-client
87 changes: 87 additions & 0 deletions ansible/roles/freeipa/tasks/enrole.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# based on https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html/installing_identity_management/assembly_installing-an-idm-client_installing-identity-management

- name: Retrieve persisted keytab from previous enrolement
slurp:
src: "{{ _freeipa_keytab_backup_path }}"
delegate_to: "{{ groups['control'] | first }}"
register: _slurp_persisted_keytab
failed_when: false

- name: Write persisted keytab from previous enrolment
copy:
content: "{{ _slurp_persisted_keytab.content | b64decode }}"
dest: /tmp/krb5.keytab
owner: root
group: root
mode: ug=rw,o=
when: '"content" in _slurp_persisted_keytab'

- name: Renrole with FreeIPA using backed-up keytab
# reenrolment requires --force-join and --password, or --keytab
# renrolement means:
# 1. A new host certificate is issued
# 2. The old host certificate is revoked
# 3. New SSH keys are generated
# 4. ipaUniqueID is preserved
# and ALSO that the keytab is changed!
command:
cmd: >
ipa-client-install
--unattended
--mkhomedir
--enable-dns-updates
--keytab /tmp/krb5.keytab
when: '"content" in _slurp_persisted_keytab'
register: ipa_client_install_keytab
changed_when: ipa_client_install_keytab.rc == 0
failed_when: >
ipa_client_install_keytab.rc !=0 and
'IPA client is already configured' not in ipa_client_install_keytab.stderr

- name: Enrole with FreeIPA using random password
# Note --password is overloaded - it's bulkpassword unless --principal or --force-join is used in which case it's admin password
command:
cmd: >
ipa-client-install
--unattended
--mkhomedir
--enable-dns-updates
--password '{{ freeipa_host_password }}'
when:
- '"content" not in _slurp_persisted_keytab'
- freeipa_host_password is defined
register: ipa_client_install_password
changed_when: ipa_client_install_password.rc == 0
failed_when: >
ipa_client_install_password.rc != 0 and
'IPA client is already configured' not in ipa_client_install_password.stderr

- name: Ensure NFS RPC security service is running
# This service is installed by nfs-utils, which attempts to start it.
# It has ConditionPathExists=/etc/krb5.keytab which fails if host is not enroled.
# This task avoids a reboot.
systemd:
name: rpc-gssd.service
state: started
enabled: true

- name: Retrieve current keytab
slurp:
src: /etc/krb5.keytab
register: _slurp_current_keytab
failed_when: false

- name: Ensure keytab backup directory exists
file:
path: "{{ _freeipa_keytab_backup_path | dirname }}"
state: directory
owner: root
group: root
mode: ug=wrX,o=
delegate_to: "{{ groups['control'] | first }}"

- name: Persist keytab
copy:
content: "{{ _slurp_current_keytab.content | b64decode }}"
dest: "{{ _freeipa_keytab_backup_path }}"
delegate_to: "{{ groups['control'] | first }}"
Loading