Dotfiles/setup/modules/FreeipaAnsible/ansible/deploy-ansipa-policies.yml

130 lines
5.0 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

---
# deploy-ansipa-policies.yml — deploy the policy enforcement daemon to enrolled clients.
#
# Installs ansipa-enforce-policies.sh and a systemd timer that runs it every 30 minutes.
# Device policies (FreeIPA host groups — applied to the whole machine):
# dev_daemon-enable-<unit> Ensure <unit> is enabled and running; reverted when host leaves group
# dev_daemon-disable-<unit> Ensure <unit> is disabled and stopped; reverted when host leaves group
# dev_timeshift-backup Enforce daily Timeshift snapshots (03:00)
# dev_security-scan Enforce daily ClamAV + rkhunter + chkrootkit scans + SMB upload (02:00)
# dev_no-local-users Lock local account passwords; only FreeIPA accounts can auth
# dev_local-sudo-<username> Grant <username> local sudo on this device; reverted when host leaves
# dev_ssh_<userid> Distribute <userid>'s SSH public keys from IPA to authorized_keys
# on this device; allows that IPA user to SSH in from any of their
# registered keys without a password. Keys stored in IPA via:
# ipa user-mod <userid> --sshpubkey='ssh-ed25519 AAAA...'
#
# User policies (FreeIPA user groups — follow the user across all enrolled devices):
# usr_admin Grant full sudo on every enrolled host (sudoers drop-in, SSSD-resolved)
# usr_block-binary-<name> Block execution of <name> via a PATH-priority wrapper
# usr_prt_<printer> Auto-add printer at login (per-user); URI in IPA group description
# usr_scan-notify Fetch alerts from server, notify user every 10 min until acknowledged
# usr_smb_r_<name> Mount read-only Samba share ~/name for members; credentials in IPA group description
# usr_smb_rw_<name> Mount read-write Samba share ~/name for members (rw beats r if both)
#
# Prerequisites:
# - Host enrolled in FreeIPA (sssd + ipa CLI available)
# - For dev_security-scan / usr_scan-notify: samba-client installed (handled below)
# - For dev_security-scan / usr_scan-notify: smb_scan_password set (use ansible-vault in production)
# - For security-scan tools: also add host to dev_mod_anti-malware group
# - For timeshift-backup: also add host to dev_mod_timeshift group
#
# Usage:
# ansible-playbook -i inventory deploy-ansipa-policies.yml \
# -e smb_scan_password=<password> # or use --vault-password-file
- name: Deploy FreeIPA policy enforcer
hosts: all
become: yes
vars:
smb_scan_password: "{{ smb_scan_password | mandatory('smb_scan_password is required — use -e smb_scan_password=... or ansible-vault') }}"
tasks:
- name: Install required packages
package:
name: "{{ item }}"
state: present
loop:
- samba-client
- cups
- cifs-utils # needed for usr_smb_* CIFS mounts
- openssh-server # needed for dev_ssh_* (sshd must be running to accept keys)
ignore_errors: yes
- name: Deploy SMB credentials file
copy:
dest: /etc/ansipa-smb.creds
mode: '0600'
owner: root
group: root
content: |
username = scanupload
password = {{ smb_scan_password }}
domain = WORKGROUP
- name: Deploy policy enforcer script
copy:
src: ansipa-enforce-policies.sh
dest: /usr/local/bin/ansipa-enforce-policies.sh
mode: '0755'
- name: Deploy alert fetch script
copy:
src: ansipa-fetch-alerts.sh
dest: /usr/local/bin/ansipa-fetch-alerts.sh
mode: '0755'
- name: Deploy user notification daemon
copy:
src: ansipa-scan-notify.sh
dest: /usr/local/bin/ansipa-scan-notify.sh
mode: '0755'
- name: Create policy state directory
file:
path: /var/lib/ansipa-policies
state: directory
mode: '0700'
- name: Install policy enforcer systemd service
copy:
dest: /etc/systemd/system/ansipa-enforce-policies.service
mode: '0644'
content: |
[Unit]
Description=Enforce FreeIPA host-group policies (binary blocks, backups, scans)
After=network-online.target sssd.service
Wants=network-online.target
[Service]
Type=oneshot
ExecStart=/usr/local/bin/ansipa-enforce-policies.sh
StandardOutput=journal
StandardError=journal
- name: Install policy enforcer systemd timer
copy:
dest: /etc/systemd/system/ansipa-enforce-policies.timer
mode: '0644'
content: |
[Unit]
Description=Periodic FreeIPA policy enforcement
[Timer]
OnBootSec=5min
OnUnitActiveSec=30min
[Install]
WantedBy=timers.target
- name: Reload systemd
command: systemctl daemon-reload
- name: Enable and start policy enforcer timer
systemd:
name: ansipa-enforce-policies.timer
enabled: yes
state: started