From 2351740aa7f879f2225efafd9dc7fbfa067bfc7a Mon Sep 17 00:00:00 2001 From: Phil Date: Fri, 27 Nov 2026 11:53:42 -0700 Subject: [PATCH] Tinyauth: Pocket ID login in front of Baikal admin and Changedetection UI Caddy (sso) snippet does forward_auth to Tinyauth for a given matcher; Tinyauth sends people to Pocket ID and requires tinyauth_admin_group. Baikal: only /admin. Changedetection: everything except /api/. New subdomain auth.thesatelliteoflove.com (dropped from removed_records). Co-Authored-By: Claude Opus 5.5 --- dns.yml | 4 +-- group_vars/all/domains.yml | 1 + group_vars/all/infrastructure.yml | 4 ++- roles/docker/tasks/infrastructure/main.yml | 4 +++ .../docker/tasks/infrastructure/tinyauth.yml | 31 +++++++++++++++++++ roles/docker/templates/Caddyfile.j2 | 22 +++++++++++++ .../docker/templates/tinyauth-compose.yml.j2 | 20 ++++++++++++ roles/docker/templates/tinyauth-env.j2 | 27 ++++++++++++++++ 8 files changed, 110 insertions(+), 3 deletions(-) create mode 100644 roles/docker/tasks/infrastructure/tinyauth.yml create mode 100644 roles/docker/templates/tinyauth-compose.yml.j2 create mode 100644 roles/docker/templates/tinyauth-env.j2 diff --git a/dns.yml b/dns.yml index d573181..b5be972 100644 --- a/dns.yml +++ b/dns.yml @@ -51,6 +51,8 @@ ip: "{{ network.netcup_ip }}" - name: id ip: "{{ network.netcup_ip }}" + - name: auth # Tinyauth (was Authentik until 2026-10-31) + ip: "{{ network.netcup_ip }}" - name: nerder.land dns_records: - name: "forms" @@ -106,8 +108,6 @@ ip: "{{ network.netcup_ip }}" - name: "sync" # kosync, replaced by Kavita ip: "{{ network.netcup_ip }}" - - name: "auth" # Authentik, replaced by Pocket ID - ip: "{{ network.netcup_ip }}" - name: "files" ip: "{{ network.netcup_ip }}" - name: "kanboard" diff --git a/group_vars/all/domains.yml b/group_vars/all/domains.yml index 2ec2072..b83ea69 100644 --- a/group_vars/all/domains.yml +++ b/group_vars/all/domains.yml @@ -27,6 +27,7 @@ subdomains: gokapi: "gokapi.{{ primary_domain }}" # Gokapi file sharing pocketid: "id.{{ primary_domain }}" # Pocket ID passkey OIDC starpunk: "starpunk.{{ primary_domain }}" # Micropub for the main site + tinyauth: "auth.{{ primary_domain }}" # Tinyauth: Pocket ID login in front of admin pages # Email domains for notifications email_domains: diff --git a/group_vars/all/infrastructure.yml b/group_vars/all/infrastructure.yml index 8b01935..47de1fb 100644 --- a/group_vars/all/infrastructure.yml +++ b/group_vars/all/infrastructure.yml @@ -30,4 +30,6 @@ paths: # Notification services notifications: - appriseapi_endpoint: "http://apprise:8000/notify/apprise" \ No newline at end of file + appriseapi_endpoint: "http://apprise:8000/notify/apprise" +# Pocket ID group allowed through Tinyauth to admin pages. +tinyauth_admin_group: admins diff --git a/roles/docker/tasks/infrastructure/main.yml b/roles/docker/tasks/infrastructure/main.yml index 55597dc..8c19e35 100644 --- a/roles/docker/tasks/infrastructure/main.yml +++ b/roles/docker/tasks/infrastructure/main.yml @@ -9,6 +9,10 @@ import_tasks: pocketid.yml tags: pocketid +- name: Install tinyauth + import_tasks: tinyauth.yml + tags: tinyauth + - name: Template out the dockge compose file ansible.builtin.template: src: dockge-compose.yml.j2 diff --git a/roles/docker/tasks/infrastructure/tinyauth.yml b/roles/docker/tasks/infrastructure/tinyauth.yml new file mode 100644 index 0000000..bbb0649 --- /dev/null +++ b/roles/docker/tasks/infrastructure/tinyauth.yml @@ -0,0 +1,31 @@ +# Tinyauth: Caddy forward_auth target that sends people to Pocket ID before +# they reach admin pages of apps without their own SSO (see the (sso) +# snippet in Caddyfile.j2). Only reachable through Caddy on the lava network. +- name: make tinyauth directories + ansible.builtin.file: + path: "{{ item }}" + state: directory + loop: + - /opt/stacks/tinyauth + +- name: Template out the tinyauth compose file + ansible.builtin.template: + src: tinyauth-compose.yml.j2 + dest: /opt/stacks/tinyauth/compose.yml + owner: root + mode: '0644' + +- name: Template out the tinyauth .env file + ansible.builtin.template: + src: tinyauth-env.j2 + dest: /opt/stacks/tinyauth/.env + owner: root + mode: '0640' + group: docker + diff: false # contains the Pocket ID client secret + +- name: deploy tinyauth stack + community.docker.docker_compose_v2: + project_src: /opt/stacks/tinyauth + files: + - compose.yml diff --git a/roles/docker/templates/Caddyfile.j2 b/roles/docker/templates/Caddyfile.j2 index d7683c5..5869a64 100644 --- a/roles/docker/templates/Caddyfile.j2 +++ b/roles/docker/templates/Caddyfile.j2 @@ -63,6 +63,16 @@ } } +# Require a Pocket ID login (via Tinyauth) for requests matching the named +# matcher passed as the argument, e.g. "import sso @admin". Tinyauth also +# checks group membership per app (tinyauth-env.j2). +(sso) { + forward_auth {args[0]} tinyauth:3000 { + uri /api/auth/caddy + copy_headers Remote-User Remote-Email Remote-Groups + } +} + # Every proxied site: log, HSTS and the shared headers. (site) { import logging @@ -76,6 +86,12 @@ reverse_proxy pocket-id:1411 } +{{ subdomains.tinyauth }} { + import site + import no_framing + reverse_proxy tinyauth:3000 +} + paper.thesatelliteoflove.com { import site import no_framing @@ -87,6 +103,9 @@ cal.thesatelliteoflove.com { import no_framing redir /.well-known/caldav /dav.php 302 redir /.well-known/carddav /dav.php 302 + # Web admin needs Pocket ID; CalDAV/CardDAV (/dav.php) stays as is. + @admin path /admin /admin/* + import sso @admin reverse_proxy baikal-baikal-1:80 } @@ -111,6 +130,9 @@ loclog.thesatelliteoflove.com { watcher.thesatelliteoflove.com { import site import no_framing + # UI needs Pocket ID; the API (own key) stays reachable for scripts. + @ui not path /api/* + import sso @ui reverse_proxy changedetection:5000 } diff --git a/roles/docker/templates/tinyauth-compose.yml.j2 b/roles/docker/templates/tinyauth-compose.yml.j2 new file mode 100644 index 0000000..4449f12 --- /dev/null +++ b/roles/docker/templates/tinyauth-compose.yml.j2 @@ -0,0 +1,20 @@ +services: + tinyauth: + image: ghcr.io/tinyauthapp/tinyauth:{{ tinyauth_version | default('v5') }} + container_name: tinyauth + restart: unless-stopped + env_file: .env + volumes: + - ./data:/data + # Token and userinfo calls go to Pocket ID on our own public IP. + extra_hosts: + - "{{ subdomains.pocketid }}:{{ docker.hairpin_ip }}" + security_opt: + - no-new-privileges:true + labels: + mag37.dockcheck.update: true + +networks: + default: + external: true + name: {{ docker.network_name }} diff --git a/roles/docker/templates/tinyauth-env.j2 b/roles/docker/templates/tinyauth-env.j2 new file mode 100644 index 0000000..99c1bba --- /dev/null +++ b/roles/docker/templates/tinyauth-env.j2 @@ -0,0 +1,27 @@ +# https://tinyauth.app/docs/reference/configuration/ +TINYAUTH_APPURL=https://{{ subdomains.tinyauth }} +# Only Caddy talks to Tinyauth; trust its X-Forwarded-* headers. +TINYAUTH_AUTH_TRUSTEDPROXIES={{ docker.hairpin_ip }} +TINYAUTH_LABELPROVIDER=none +TINYAUTH_OIDC_PRIVATEKEYPATH=/data/tinyauth_oidc_key +TINYAUTH_OIDC_PUBLICKEYPATH=/data/tinyauth_oidc_key.pub + +# Pocket ID is the only login method (no TINYAUTH_AUTH_USERS). +TINYAUTH_OAUTH_AUTOREDIRECT=pocketid +TINYAUTH_OAUTH_PROVIDERS_POCKETID_NAME=Pocket ID +TINYAUTH_OAUTH_PROVIDERS_POCKETID_CLIENTID={{ vault_tinyauth.pocketid.client_id }} +TINYAUTH_OAUTH_PROVIDERS_POCKETID_CLIENTSECRET={{ vault_tinyauth.pocketid.client_secret }} +TINYAUTH_OAUTH_PROVIDERS_POCKETID_AUTHURL=https://{{ subdomains.pocketid }}/authorize +TINYAUTH_OAUTH_PROVIDERS_POCKETID_TOKENURL=https://{{ subdomains.pocketid }}/api/oidc/token +TINYAUTH_OAUTH_PROVIDERS_POCKETID_USERINFOURL=https://{{ subdomains.pocketid }}/api/oidc/userinfo +TINYAUTH_OAUTH_PROVIDERS_POCKETID_REDIRECTURL=https://{{ subdomains.tinyauth }}/api/oauth/callback/pocketid +TINYAUTH_OAUTH_PROVIDERS_POCKETID_SCOPES=openid email profile groups + +# Protected apps. Each needs Pocket ID group membership; paths outside the +# protected ones are also excluded on the Caddy side. +TINYAUTH_APPS_BAIKAL_CONFIG_DOMAIN={{ subdomains.cal }} +TINYAUTH_APPS_BAIKAL_OAUTH_GROUPS={{ tinyauth_admin_group }} +TINYAUTH_APPS_BAIKAL_PATH_BLOCK=^/admin +TINYAUTH_APPS_WATCHER_CONFIG_DOMAIN={{ subdomains.watcher }} +TINYAUTH_APPS_WATCHER_OAUTH_GROUPS={{ tinyauth_admin_group }} +TINYAUTH_APPS_WATCHER_PATH_ALLOW=^/api/