Repository navigation
adguard plugin: DNS sinkhole per managed device - #29
Merged
Merged
Conversation
First in-core plugin (PLAN.md §"Plugin lifecycle"). Reconcile semantics: - Block leg: for every managed device of the locked user with a known MAC, ensure an AdGuard client exists with that MAC and upstreams=[sinkhole_upstream] (default 0.0.0.0). Auto-registers on first lock — curfew is the source of truth, no separate push step required to make locking work end-to-end. - Unblock leg: clear upstreams on AdGuard clients we sinkholed; leave any with operator-set non-default upstreams alone. No auto-create on this leg — there's nothing to clear if no client exists. Both legs idempotent (safety-net resync re-runs reconcile periodically). HTTP errors caught + converted to ReconcileResult.error so the runtime audits as plugin.reconcile_failed rather than letting an exception escape the reconcile boundary. Per ADR-013's secret convention, the AdGuard admin password is read from an env var named in config — never stored in state.sqlite. Tests use httpx.MockTransport (no respx dep) and cover: auto-register, update with wrong upstream, idempotent skip, MAC matching by any of a device's MACs, case-insensitive MAC lookup, multi-MAC consolidation, unblock paths, empty-mac/unmanaged skip, no-devices short-circuit (saves the GET), 5xx → ReconcileResult.error, custom sinkhole_upstream, missing-env-var KeyError at __init__.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
0.0.0.0(configurable). On unlock, upstreams clear.ReconcileResult.error→ audited asplugin.reconcile_failedper PLUGINS.md.password_env), never stored instate.sqlite.Files
plugins/adguard/manifest.toml,plugins/adguard/plugin.py— plugin (Pydantic Config +httpx.AsyncClientwith Basic auth).core/tests/test_adguard_plugin.py— 18 unit tests usinghttpx.MockTransport(norespxdep needed).Config
{ "url": "http://adguard.lan", "username": "admin", "password_env": "ADGUARD_PASSWORD", "sinkhole_upstream": "0.0.0.0" }Test plan
just checkclean (lint, mypy, all Python tests, web, build)ReconcileResult.error, custom sinkhole upstream, missing-env-var fails at__init__discover_plugins("plugins")returnsadguard: AdGuard Home v1.0.0)