Rebuild auth on Keycloak OIDC, fix rootless Ansible deploy

Replaces the single shared HTTP Basic service-account credential (which
caused a production outage from a username mismatch) with per-user login:
Keycloak (already running on this VM for gcnm, now also fronted on
auth.friessn.de with its own "homekeeper" realm) authenticates the user
once via the landing page, FastAPI verifies the OIDC id_token and mints
its own signed session JWT as a cookie, and both Shiny apps forward that
per-session token as a Bearer credential instead of a static shared one.
Authorization is a simple ALLOWED_USERS allowlist; the old auth.users
table and bcrypt seeding are gone entirely.

Also carries forward the in-progress rootless Podman/Quadlet migration
(gitea, homekeeper, podman roles) and fixes a pre-existing bug where
each role's handlers were malformed inside tasks/main.yml instead of
their own handlers/main.yml, which broke ansible-playbook entirely.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FbiCdckkTX2HyAkyi1R39d
This commit is contained in:
friessn
2026-07-13 06:31:36 +00:00
parent 58983e6855
commit 6c9cd67a08
36 changed files with 579 additions and 245 deletions
+29 -22
View File
@@ -4,18 +4,14 @@
name:
- podman
- podman-compose # for ad-hoc use; production uses quadlets
- slirp4netns # rootless networking / port publishing
- uidmap # rootless subuid/subgid mapping
state: present
update_cache: true
- name: Create homekeeper data directories
file:
path: "{{ item }}"
state: directory
mode: "0750"
loop:
- "{{ homekeeper_data_dir }}"
- "{{ homekeeper_data_dir }}/pg_data"
- "{{ gitea_data_dir }}"
# All app data lives in named Podman volumes (created implicitly on first
# `podman run`/Quadlet start), not host bind mounts — avoids rootless UID
# mapping headaches. Nothing to pre-create here.
- name: Configure Gitea as additional registry
template:
@@ -25,35 +21,46 @@
notify: Restart podman services
- name: Login to Gitea container registry
become_user: "{{ deploy_user }}"
environment:
XDG_RUNTIME_DIR: "/run/user/{{ deploy_uid }}"
command: >
podman login {{ registry_host }}:{{ registry_port }}
podman login {{ registry_host }}
-u {{ registry_user }} -p {{ registry_token }}
register: login_result
changed_when: "'Login Succeeded' in login_result.stdout"
# Run this after Gitea is up and registry_token is set
- name: Enable podman-auto-update timer
- name: Enable linger for {{ deploy_user }} (user services survive logout/reboot)
command: "loginctl enable-linger {{ deploy_user }}"
changed_when: false
- name: Enable podman-auto-update timer (user scope)
become_user: "{{ deploy_user }}"
environment:
XDG_RUNTIME_DIR: "/run/user/{{ deploy_uid }}"
systemd:
name: podman-auto-update.timer
enabled: true
state: started
scope: user
daemon_reload: true
- name: Override auto-update timer schedule
- name: Override auto-update timer schedule (user scope)
become_user: "{{ deploy_user }}"
file:
path: "/home/{{ deploy_user }}/.config/systemd/user/podman-auto-update.timer.d"
state: directory
mode: "0755"
- name: Deploy auto-update timer schedule override
become_user: "{{ deploy_user }}"
copy:
dest: /etc/systemd/system/podman-auto-update.timer.d/override.conf
dest: "/home/{{ deploy_user }}/.config/systemd/user/podman-auto-update.timer.d/override.conf"
content: |
[Timer]
OnCalendar=
OnCalendar={{ autoupdate_schedule }}
AccuracySec=1s
mode: "0644"
notify: Reload systemd
handlers:
- name: Reload systemd
systemd:
daemon_reload: true
- name: Restart podman services
command: systemctl daemon-reload
notify: Reload user systemd