Files
ericandClaude Opus 5.5 8c0c4e16dd Own LDAP account and mail: funkwhale@eom.dev
tasks/ldap.yml keeps cn=Funkwhale (password from Vault, in Funkwhale Users,
Postfix Users and Dovecot Users). Mail goes out as funkwhale@eom.dev instead
of listmonk's news account, and the account is a Dex superuser.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-10 17:44:37 -05:00

44 lines
1.7 KiB
Django/Jinja

#!/bin/sh
# Runs inside the OpenLDAP pod (its LDAP_ADMIN_PASSWORD), from tasks/ldap.yml.
# Makes sure the service's LDAP account exists, has the password from Vault
# and is in its groups; prints "changed=N".
set -eu
l() { c=$1; shift; "$c" -x -H ldap://localhost -D "cn=admin,{{ funkwhale_ldap_base_dn }}" -w "$LDAP_ADMIN_PASSWORD" "$@"; }
DN={{ _funkwhale_ldap_dn | quote }}
PW=$(printf %s {{ funkwhale_smtp_password | b64encode | quote }} | base64 -d)
changed=0
if ! l ldapsearch -LLL -s base -b "$DN" dn >/dev/null 2>&1; then
uidn=$(l ldapsearch -LLL -b {{ funkwhale_ldap_base_dn | quote }} "(uidNumber=*)" uidNumber |
awk '/^uidNumber:/ { print $2 }' | sort -n | tail -1)
printf '%s\n' \
"dn: $DN" \
"objectClass: inetOrgPerson" \
"objectClass: posixAccount" \
"objectClass: top" \
"cn: {{ funkwhale_ldap_account.cn }}" \
"sn: {{ funkwhale_ldap_account.cn }}" \
"uid: {{ funkwhale_ldap_account.uid }}" \
"uidNumber: $((uidn + 1))" \
"gidNumber: {{ funkwhale_ldap_account.gid_number }}" \
"homeDirectory: /home/users/{{ funkwhale_ldap_account.uid }}" \
"mail: {{ funkwhale_ldap_account.mail }}" | l ldapadd >/dev/null
echo "created $DN" >&2
changed=1
fi
if ! ldapwhoami -x -H ldap://localhost -D "$DN" -w "$PW" >/dev/null 2>&1; then
l ldappasswd -s "$PW" "$DN" >/dev/null
echo "set the password of $DN" >&2
changed=1
fi
{% for group in funkwhale_ldap_account.groups %}
if ! l ldapsearch -LLL -s base -b {{ group | quote }} "(uniqueMember=$DN)" dn | grep -q '^dn:'; then
printf '%s\n' "dn: {{ group }}" "changetype: modify" "add: uniqueMember" "uniqueMember: $DN" | l ldapmodify >/dev/null
echo "added $DN to {{ group }}" >&2
changed=1
fi
{% endfor %}
echo "changed=$changed"