fix(pihole)!: refuse a non-empty app password and render app_pwhash empty

Released pihole-FTL checks an app_pwhash that does not start with `$` as a
legacy double-SHA256 hash and, on a match, upgrades it to a BALLOON hash
written into the main webserver.api.pwhash. One login with the app
password the role rendered therefore replaced the web password. FTL
master fixes this, no release has it yet, and the role does not pin FTL.

validate.yml now refuses a non-empty config.webserver.api.app_password,
and the template always renders app_pwhash = "", which FTL treats as app
passwords disabled. The key stays in the defaults; only a value is
refused. Molecule verifies the rendered empty hash and the new refusal.

BREAKING CHANGE: a non-empty config.webserver.api.app_password now fails
the role, and app_pwhash always renders empty.

Refs: #383
Assisted-by: Claude Code
This commit is contained in:
Defame1297 committed 2026-12-06 21:35:12 +00:00
1 parent 7cb99de32d
commit cb78edff6f
7 files changed
+37 -7

No files matched your search

@@ -0,0 +1,7 @@
---
breaking_changes:
- >-
pihole - A non-empty ``config.webserver.api.app_password`` is now refused, and ``app_pwhash``
always renders empty, which disables app passwords. Released pihole-FTL upgrades a
legacy-hashed app password on login by writing the new hash into the main ``pwhash``, so one
login with the app password replaced the web password.
+2 -1
View File
@@ -58,13 +58,14 @@ The input asserts carry `always` (and `assert`), so they run whatever tags are s
## Tests
The `default` molecule scenario runs in CI only, on two platforms: `${MOLECULE_IMAGE}` (Ubuntu 24.04) and `${MOLECULE_IMAGE_2604}` (Ubuntu 26.04). It replaces the upstream repository with a local stub whose installer only logs its arguments and creates the database file, so it tests the merge, the asserts, the user, the configuration directory and the rendered `pihole.toml` (owner, group and mode), the clone's checked-out version, the installer sequence (install once, then reconfigure from the handler) and idempotence, not Pi-hole itself: no pihole-FTL service runs, so that the service loaded the configuration is not verified. It runs `check` before the converge (a fresh host) and after it (a configured host). Negative tests in `verify.yml` cover a host without Ubuntu facts, a missing `pihole_web_password`, an unset interface, empty upstreams, a non-string password and the placeholder password.
The `default` molecule scenario runs in CI only, on two platforms: `${MOLECULE_IMAGE}` (Ubuntu 24.04) and `${MOLECULE_IMAGE_2604}` (Ubuntu 26.04). It replaces the upstream repository with a local stub whose installer only logs its arguments and creates the database file, so it tests the merge, the asserts, the user, the configuration directory and the rendered `pihole.toml` (owner, group and mode), the clone's checked-out version, the installer sequence (install once, then reconfigure from the handler) and idempotence, not Pi-hole itself: no pihole-FTL service runs, so that the service loaded the configuration is not verified. It runs `check` before the converge (a fresh host) and after it (a configured host). Negative tests in `verify.yml` cover a host without Ubuntu facts, a missing `pihole_web_password`, an unset interface, empty upstreams, a non-string password, the placeholder password and a non-empty app password.
## Notes
- Idempotent: yes.
- Merge model: the role sets an internal fact to `pihole_default | combine(pihole_overrides | default({}), recursive=True)`. The input is only read, never overwritten, so each run recomputes the merge. Dictionaries are not merged across variable sources, so define `pihole_overrides` in one place only.
- Secrets: the password is hashed twice with SHA-256 in the template (`pwhash`). The merge and both template tasks use `no_log`, and the templates `diff: false`, so a `pihole.toml` change shows no diff. `pihole_testing` masks the web password, app password and TOTP secret in its output. `totp_secret` and `app_password` default to empty strings.
- App passwords: `config.webserver.api.app_password` must stay empty, and the role fails otherwise; `app_pwhash` always renders empty, which disables app passwords. Released pihole-FTL upgrades a legacy-hashed (double SHA-256) app password on login by writing the new hash into the main `pwhash`, so one login with the app password would replace the web password.
- Install flow: the role creates the `pihole` system user (nologin), the configuration directory and, on first install, `pihole.toml`, because the unattended installer needs it first. It clones `repo.version` and runs the installer with `--unattended` only when `config.files.database` does not exist yet. A change to `pihole.toml` notifies the `reconfigure pihole` handler, which runs the installer with `--reconfigure --unattended`.
- Updates: the role does not upgrade an installed Pi-hole; changing `repo.version` only moves the clone.
- Check mode: `--check` is the supported preview; a play-level `check_mode: true` is not supported. On a host where the configuration directory does not exist yet, the `pihole.toml` template tasks are skipped under `--check`, because the directory they write into is not created.
+1 -1
View File
@@ -308,7 +308,7 @@ pihole_default:
password: "{{ pihole_web_password }}"
# Pi-hole 2FA TOTP secret.
totp_secret: ""
# Pi-hole application password (to circumvent 2FA for legacy 3rd-party services)
# Pi-hole application password: must stay empty, app_pwhash always renders empty (README Notes)
app_password: ""
# Should application password API sessions be allowed to modify config settings?
app_sudo: false
+5 -1
View File
@@ -47,7 +47,11 @@ argument_specs:
C(config.dns.interface) must be set (string, for example C(eth0)): its default is an empty placeholder
and the role fails until it is set. C(config.dns.upstreams) (list of IP addresses or hostnames,
optionally with C(#port)) must stay non-empty. C(config.webserver.api.password) must stay a string.
C(config.webserver.api.totp_secret) and C(config.webserver.api.app_password) are also credentials.
C(config.webserver.api.totp_secret) is also a credential.
- >-
C(config.webserver.api.app_password) must stay empty and C(app_pwhash) always renders empty, which
disables app passwords: released pihole-FTL replaces the main web password on a login with a
legacy-hashed app password.
- >-
Other keys the tasks read are C(repo.remote), C(repo.version) (a tag, default C(v6.4)), C(repo.path)
(default C(~/.cache/pi-hole) of the connecting user), C(user), C(group) (both default C(pihole)) and
+8 -1
View File
@@ -56,7 +56,7 @@
database: passwd
key: pihole
- name: The config carries the overridden upstreams and a hashed password
- name: The config carries the overridden upstreams, a hashed password and no app password
ansible.builtin.assert:
that:
- "'9.9.9.9' in pihole_test_toml_content"
@@ -66,6 +66,7 @@
- "'\"eth0\"' not in pihole_test_toml_content"
- "'molecule-test-password' not in pihole_test_toml_content"
- pihole_test_toml_content is search('(?m)^\\s*pwhash = \"[0-9a-f]{64}\"')
- pihole_test_toml_content is search('(?m)^\\s*app_pwhash = \"\"$')
quiet: true
vars:
pihole_test_toml_content: "{{ pihole_test_toml.content | b64decode }}"
@@ -167,3 +168,9 @@
dns: {interface: molecule0}
webserver: {api: {password: changetoyourownpassword}}
expect: placeholder changetoyourownpassword
- name: app-password-set
overrides:
config:
dns: {interface: molecule0}
webserver: {api: {password: molecule-test-password, app_password: molecule-test-app-password}}
expect: app_password must stay empty
+11
View File
@@ -53,3 +53,14 @@
The web password is the placeholder changetoyourownpassword: set pihole_web_password, or
pihole_overrides.config.webserver.api.password, to a secret of your own.
quiet: true
# Released pihole-FTL upgrades a legacy-hashed app password on login by writing the new hash
# into the main pwhash, so the role renders app_pwhash empty, which disables app passwords.
- name: Check that no app password is set
ansible.builtin.assert:
that:
- (__pihole_candidate.config.webserver.api.app_password | default('', true)) == ''
fail_msg: >-
config.webserver.api.app_password must stay empty: released pihole-FTL replaces the main
web password when someone logs in with an app password the role has hashed (see #541).
quiet: true
+3 -3
View File
@@ -838,9 +838,9 @@
#
# Possible values are:
# <valid Pi-hole password hash>
# NOTE! I am assuming this should be double-hashed just like the regular password, but
# this assumption has not been tested!
app_pwhash = "{{ __pihole_effective.config.webserver.api.app_password | hash('sha256') | hash('sha256') }}"
# Always empty, which disables app passwords: the role refuses app_password, because
# released pihole-FTL rewrites the main pwhash on a login with a legacy-hashed app password.
app_pwhash = ""
# Should application password API sessions be allowed to modify config settings?
# Setting this to true allows third-party applications using the application password