Skip to content

feat(config): read secrets from files with a _file suffix - #309

Open
diferhe wants to merge 3 commits into
Python-roborock:mainfrom
diferhe:feat/config-secret-files
Open

diferhe wants to merge 3 commits into
Python-roborock:mainfrom
diferhe:feat/config-secret-files

Conversation

@diferhe

@diferhe diferhe commented Nov 29, 2026 •

Copy link
Copy Markdown

What does this PR do?

Every secret that config.toml holds inline can now be read from a separate file instead, by adding _file to the key:

  • admin.password_hash_file
  • admin.session_secret_file
  • admin.protocol_login_pin_hash_file
  • turn.password_file
  • network.localkey_file
  • network.mqtt_password_file

This keeps secrets out of config files that are generated by tools or stored in world-readable places, and works with Docker secrets, systemd credentials, sops-nix, agenix and similar tools. The existing tls.*_file options already work this way.

Details:

  • A relative path is resolved against the directory of the config file, the same as the existing tls.*_file options.
  • Setting both the inline value and the _file variant is an error, because it is unclear which one should win.
  • A missing, unreadable or empty file stops the server with an error that names the key and the path.
  • Inline values keep working unchanged, so existing Docker and Home Assistant add-on configs are not affected.
  • mitm_redirect.py reads admin.session_secret to enable protocol session sync. It now also understands admin.session_secret_file, follows a symlinked config.toml like the server does, and reports a file it cannot read.

The options are documented in config.example.toml.

Before you open this PR (optional, but very helpful)

  • I checked for duplicates.
  • I reviewed 1–2 other open PRs and tested whether they work on my vacuum.

PRs I reviewed:

Proof that it works

Tested on:

  • Vacuum model: not tested on a vacuum (config loading only)
  • Firmware version: n/a
  • Server version / commit: 78018a0
  • Install method (Docker / Home Assistant add-on / other): unit tests

What I did and what happened:

New tests in tests/test_config.py and tests/test_mitm_redirect.py cover:

  • each admin secret read from a relative file
  • the network and TURN secrets read from absolute files
  • an error when both the value and the file are set
  • errors for a missing file and an empty file
  • an inline numeric value keeping its value
  • session_secret_file in the MITM launcher, a file it cannot read, and a symlinked config

uv run pytest -q passes in full.

Screenshots (required for any UI change)

No UI changes.

Every secret that the config holds inline can now be read from a separate
file: admin.password_hash, admin.session_secret, admin.protocol_login_pin_hash,
turn.password, network.localkey and network.mqtt_password. This keeps
secrets out of config files that are generated by tools or stored in
world-readable places, and works with Docker secrets, systemd credentials
and similar mechanisms. Inline values keep working unchanged.
The MITM launcher reads admin.session_secret to enable protocol session
sync. It now also reads admin.session_secret_file and reports a file that
cannot be read. Inline secrets that are not strings, such as a numeric MQTT
password, keep their previous value.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant