LibrePortal/scripts/network/traefik/traefik_login_credentials.sh
librelad 875a60f90f LibrePortal v0.1.0 — initial release
A free, open, self-hosted app platform (GNU AGPLv3): one-click app deploys,
Traefik reverse proxy with automatic SSL, rootless Docker support, gluetun
VPN routing, and a web dashboard to manage it all.

Free & open forever to self-host; optional paid hosted services fund it.
See PROMISE.md.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

Signed-off-by: librelad <librelad@digitalangels.vip>
2026-05-21 20:37:54 +01:00

24 lines
1.1 KiB
Bash
Executable File

#!/bin/bash
traefikSetupLoginCredentials()
{
local protectionauth_file="$containers_dir/traefik/etc/dynamic/middlewears/protectionauth.yml"
if [ -f "$protectionauth_file" ]; then
# Refuse to write empty/placeholder credentials — htpasswd -Bbn "" ""
# silently produces a hash that effectively allows blank-credential
# logins, which would leave the dashboard unprotected.
if [[ -z "$CFG_TRAEFIK_USER" || -z "$CFG_TRAEFIK_PASS" \
|| "$CFG_TRAEFIK_PASS" == RANDOMIZEDPASSWORD* ]]; then
isError "Traefik dashboard credentials are not set (CFG_TRAEFIK_USER / CFG_TRAEFIK_PASS). Skipping auth middleware write — refusing to leave dashboard unprotected."
return 1
fi
# Setup BasicAuth credentials
local login_credentials=$(htpasswd -Bbn "$CFG_TRAEFIK_USER" "$CFG_TRAEFIK_PASS")
local result=$(sudo sed -i '/#protection credentials/d' "$protectionauth_file")
checkSuccess "Delete the line containing protection credentials"
local result=$(sudo sed -i "/users:/a\\ - '$login_credentials' #protection credentials" "$protectionauth_file")
checkSuccess "Add the new line with new protection credentials"
fi
}