fix: generate Dex bcrypt hash with htpasswd
Homelab Main / validate (push) Successful in 17s Details
Homelab Main / running-update (push) Successful in 7s Details
Homelab Main / debian-ops (push) Successful in 1m15s Details

This commit is contained in:
juvenal.diaz 2026-09-30 12:11:43 -06:00
parent da5a544f47
commit 6dd6ebce82
1 changed files with 12 additions and 6 deletions

View File

@ -580,12 +580,18 @@ dex_public_url() {
}
dex_bcrypt_hash() {
local image="$1"
local password="$2"
local password="$1"
local helper_image="${DEX_HTPASSWD_IMAGE:-httpd:2.4-alpine}"
local output
output="$(sudo docker run --rm "${image}" hash-password "${password}")"
printf '%s\n' "${output}" | grep -Eo '\$2[aby]\$[0-9]{2}\$[^[:space:]]+' | tail -n 1
if command -v htpasswd >/dev/null 2>&1; then
output="$(printf '%s\n' "${password}" | htpasswd -BinC 10 dex)"
else
sudo docker pull "${helper_image}" >/dev/null
output="$(printf '%s\n' "${password}" | sudo docker run --rm -i "${helper_image}" htpasswd -BinC 10 dex)"
fi
printf '%s\n' "${output}" | awk -F: '/^dex:/ { print $2; exit }'
}
render_dex_config() {
@ -691,9 +697,9 @@ deploy_dex() {
repair_local_docker_iptables
sudo docker pull "${image}"
dex_user_password_hash="$(dex_bcrypt_hash "${image}" "${DEX_USER_PASSWORD}")"
dex_user_password_hash="$(dex_bcrypt_hash "${DEX_USER_PASSWORD}")"
if [[ -z "${dex_user_password_hash}" ]]; then
echo "Could not generate Dex bcrypt password hash." >&2
echo "Could not generate Dex bcrypt password hash with htpasswd." >&2
exit 1
fi