Skip to content

feat(filter): category filter per instance - #19

Open
ks98 wants to merge 19 commits into
feat/webui-pluginfrom
feat/filter-categories
Open

ks98 wants to merge 19 commits into
feat/webui-pluginfrom
feat/filter-categories

Conversation

@ks98

@ks98 ks98 commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

Second of four stacked PRs for 7.3.11, based on feat/webui-plugin.

Category filter per instance (ADR-022): 48 categories from packaged open lists in one catalog built on the proxy host, templates, schedules, protected list, exceptions, own lists and categories, SafeSearch without decrypting, German block page, WebUI tabs. Needs the data-plane image from this branch; until DEFAULT_IMAGE is pinned, filter settings are stored without effect and reported as image_without_filter. Must land together with activity-log before the image pin.

Tested: fast tier, install/upgrade smoke emulated locally, lab tests and a cold verification.

Kevin Stenzel added 19 commits November 25, 2026 10:34
…eZi lists

lmnsquid-catalog update downloads the sources described in the packaged
sources.yml (extendable in /etc/linuxmuster-squid/catalog.yml) with
conditional GETs, parses them streaming (domains, hosts, wildcard,
adblock, rpz, UT1 archive), sorts on disk and writes one SQLite file
(domain -> category and source bit masks). A source below min_entries or
a category shrinking by more than half stops the build and keeps the
active catalog; the new file is checked and switched in by an atomic
symlink, the previous one kept. filterdecision.py is the decision
(exam mode, exceptions, protected list, categories, schedules,
fail-closed) shared with the image's helper. Measured: 5.6 million
domains, 195 MiB, 70 s, 44 MiB RSS plus 64 MiB for sort.
… block page

squid asks the external ACL helper lmn-filter-acl (%DST and the TLS SNI,
concurrency, ttl 60 s) whether a request falls under the instance's
filter: exam mode, exceptions, protected list, catalog categories and
schedules from /etc/squid/lists/filter.json and the catalog mounted at
/etc/squid/catalog. Without filter.json it blocks nothing. HTTP gets a
German block page with the reason; HTTPS stays as before (certificate
warning / terminate). allowed.domains (exceptions) beat the own
blocklist; an empty list changes nothing. hosts_file = /etc/hosts plus
safesearch.hosts, so squid connects to the SafeSearch addresses (also for
CONNECT). filter.log holds day and category of filtered requests only.
Verified against squid 6.14 in the image: notes reach the log on cached
answers, reconfigure empties the helper cache, %o needs ASCII.
…d statistics per instance

API: GET/PUT /v1/instances/{name}/filter (categories, schedules,
SafeSearch; applied at once with a reconfigure), POST/DELETE .../exam
(refused unless the running image has the filter), .../filter/lookup
("why is X blocked"), .../filter/stats, .../allowlist like the
blocklist, GET /v1/catalog, POST /v1/catalog/update, /v1/catalog/lookup;
/v1/status gains a filter summary. CLI: lmnsquid filter|allowlist|catalog.
Containers get the catalog directory as a read-only mount (one
replacement each, done by the update-all of the release that pins the
image); SafeSearch addresses are resolved at every change and container
creation, the last known one is kept.
linuxmuster-squid-catalog.timer (01:30 + up to 2 h random delay,
persistent) runs lmnsquid-catalog update --if-needed as lmnsquid with
MemoryMax=400M; it downloads nothing while no instance uses categories.
Enabled like the service (the admin's decision kept), stopped on
remove, forgotten on purge; purge already removes /var/lib/linuxmuster-squid
with the catalog.
…pply and overview

Per instance a "Filter" tab: exam mode with duration, domain list and the
template "school server only" (visible state, end now), categories by
group with size, sources and licences, time windows per category,
profiles (the one matching the role suggested), SafeSearch (switching it
on pre-selects "search engines without SafeSearch"), the catalog state
of the proxy server with "update now", "why is X blocked?" and the
statistics as bars. Exceptions get their own tab (allowlist, like the
blocklist). "Apply to other instances" sends the settings to any
instances on any connected proxy servers (one result each, e.g. every
students instance); "Filter per school" lists all instances with their
filter, SafeSearch, exam and catalog state. Same rules as before: global
administrators only on the server, JSON + same-origin for every change,
German texts, lmn73 buttons.
…ff rules

lmn_filterdecision.py is byte-identical to controlplane/lmnsquid/
filterdecision.py; with ruff's default line length the copy would be
formatted differently. image/ruff.toml applies the project's settings.
…y 5 s

The helper did a stat() of protected.domains on every lookup and split the
host name three times. Measured in the image against the full catalog
(5.6 million domains, half of the names listed): 7 700 -> 13 000-14 000
lookups/s per helper process, protocol included.
…all, changelog

ADR-022 records the design and where it deviates from the task (the
protected list does not override the own blocklist, the exam end is
checked by the helper, statistics in their own file instead of %et in
access.log, the offered categories, English CLI help, nightly rebuild),
with the measurements. ADR-016 amended: categories and the exam mode apply
to noauth domains.
…, noauth, SNI, exam end, fail-closed

New instance squid-filter (squid7) with a small catalog built by the
production builder (scripts/tests/make_test_catalog.py) in a temporary
directory. 24 new assertions; the whole suite: 80 passed, 0 failed
(local Docker, 2026-11-24).
…n every service

The integration tests pass a temporary catalog_dir (the default is under
/var/lib). New: catalog mount read-only, filter_active, reload with
SafeSearch hosts, the helper inside the container, filter_stats by exec.
The rotation test expects the (empty) filter.log. 7 passed locally.
…time zone; exam mode removed

Catalog format 2: domain -> bit mask of feeds (one source for one
category) plus each category's variants (which lists, how strict, a
recommended default, warnings for strict levels), so the helper decides
per instance which lists count. 48 categories with German descriptions
and examples, expert categories (remaining usable UT1 categories, HaGeZi
pop-ups, DynDNS, abused TLDs, URL shorteners), further sources whose
licences were read at the primary source (ShadowWhisperer, StevenBlack
extension-only, Sinfonietta, durablenapkin, NoCoin, dibdot,
PeterDaveHello), profiles students/primary/teachers/staff/guests. Only
the recommended lists and what an instance uses are downloaded; a
selection needing a missing list starts an update; unchanged inputs
build nothing. Own sources (https, validated) and own categories with a
hand-entered list that applies within seconds (API /v1/catalog/custom,
CLI lmnsquid catalog own, WebUI "Eigene Listen"). Schedules in
filter_timezone (default Europe/Berlin); the WebUI setup sets the VM's
zone. Block page text in ISO-8859-1 (umlauts via squid's &#NNN;).
WebUI: compact category rows, folding groups with counters and search,
templates with preview, bulk changes per instance, overview of active
categories, "zu alt" for old control planes. CLI: readable errors,
catalog categories, profile --dry-run, set --variant. The exam mode is
removed (Kevin); exam keys of an older filter.json are ignored.
Measured: defaults 5.65 M domains, 237 MiB, 96 s; broad expert
selection 7.84 M, 327 MiB, 140 s; RSS < 50 + 69 MiB, under a 400 MiB
limit; unchanged nightly run 7.8 s.
squid-filter's catalog now holds two ads variants under the real source
ids and an own category: light -> pro switched by reconfigure, an own
list changed without one. 81 passed, 0 failed locally.
…s, time zone), operations, changelog

Lab findings of 2026-11-24 addressed: schedule time zone, raw 404 of old
control planes, umlauts on the block page, nightly rebuild of unchanged
lists, raw CLI errors, noisy category selection.
…ne, lookup variants, catalog reason in the WebUI

Lab retest of 68e3ec2: an own source with 0 entries failed every run and
kept all lists stale. Each source is now parsed and checked on its own;
one that cannot be downloaded or read, has too few entries or would
shrink by more than half is built from its last good download (kept per
source in the cache) or left out, and the rest is rebuilt and activated.
A refused download is forgotten so the next run gets it in full. Such
sources are listed with reason and 'since' in GET /v1/catalog, the CLI
and the WebUI; after 7 days a warning (instance problem
catalog_lists_old). A youth protection category without any list in the
catalog fails closed. Sources no instance uses leave catalog and cache.
PUT /filter returns the expert/strict warnings, printed by the CLI;
settings carry the effective time zone; the lookup names the variants a
name is listed in; the WebUI shows why a catalog is unusable, the
templates as one menu, only groups with active categories open, full
variant names; no trailing 'Not Found' after 'zu alt'.
- WebUI overview repeats over groups computed once per catalog load; the
  counts are bound with ng:bind (raw {{ }} before); own categories show one
  counter; every category with variants has one chosen after a template;
  template lines stay under 512 characters (lintian source-is-missing).
- SafeSearch for Ecosia and Brave Search via their documented DNS overrides;
  the last resolved addresses are kept host-wide; an engine switched on
  without any address is blocked (safesearch_unavailable) and reported as
  safesearch_unresolved instead of being left unfiltered.
- Packaged supplement of nosafesearch: Startpage, Qwant, Mojeek, MetaGer,
  Yahoo/AOL search, Ask, Dogpile, Yandex, Kagi.
- The fingerprint hashes download content, so a source refused again with
  the same bytes builds nothing; a refused source does not count as missing
  for PUT filter; a PUT without a change writes, reloads and starts nothing;
  a removed own source leaves the problems and the cache at once.
- The image carries the label org.faircomp.linuxmuster-squid.filter; status
  reports image_without_filter for an instance on an older image.
- Help of filter schedule names filter_timezone; 'within seconds' corrected
  to up to ~60 s; docs on misclassified list entries.
Lists a new package brings (e.g. lmn-nosafesearch) applied only after the
next filter change or the nightly run. The postinst now starts the catalog
unit without blocking on an upgrade while the nightly timer is enabled; the
unit's --if-needed keeps hosts without the filter untouched, a failed start
never fails the install. A removed own source also leaves status.json's
sources at once.
The filter dialogs use the scrollable dialog layout of f861718; the
category groups of the filter tab and the instance list of the bulk dialog
get their own scroll area (at most 55% of the window), so SafeSearch, save
and apply stay within reach. Checked headless (Chromium, Firefox, 1366x768):
header and footer inside the window for every dialog.
The category list, the bulk instance list (422 px at most) and the
container log (450 px) had fixed heights larger than the visible dialog
body at 125 % zoom (lab, 1093x614 CSS pixels): two scroll areas inside each
other. Their height is now the window minus the dialog's frame and
controls, with a floor of 140 px. Checked headless at 1366x768 and
1093x614 in Chromium and Firefox (every inner area fits into the visible
body; the previous CSS fails that check).
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