Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
aee9647
Log TURN credential requests under their own turn module (ADR-0871)
James-Chapman Nov 20, 2026
785de5b
List every log module in the example configurations
James-Chapman Nov 20, 2026
35567e7
Share the module log-level test helper, and correct the TURN logging …
James-Chapman Nov 20, 2026
696b10b
Assert uri_count in the TURN log, and restate why the username is wit…
James-Chapman Nov 20, 2026
0ddf09e
Test the example configs' log module list, and state every TURN log f…
James-Chapman Nov 20, 2026
9708790
Ignore comments in the log module scan, and record its rules in ADR-0872
James-Chapman Nov 20, 2026
563da34
Read a sv or s suffixed module literal in the level-call scan
James-Chapman Nov 20, 2026
b7d81f4
Read level calls on the logger only, and name what the module scan skips
James-Chapman Nov 20, 2026
7e2c682
Say why the level-call scan skips a logger reached through another ob…
James-Chapman Nov 20, 2026
4395790
Resolve the audit overload's module, and report a constant with two v…
James-Chapman Nov 20, 2026
e2d1c6c
Assert the TURN reason field, read audit calls by shape, and narrow "…
James-Chapman Nov 21, 2026
0f67b44
Say which first arguments the audit-call scan cannot parse
James-Chapman Nov 21, 2026
28d3bad
Accept the s suffix on a brace-initialised module constant
James-Chapman Nov 21, 2026
a61eb43
Resolve a same-file constant before skipping a forwarding name
James-Chapman Nov 21, 2026
94d24bc
Report a logger call whose arguments the module scan cannot read
James-Chapman Nov 21, 2026
dc0886d
Find logger calls only outside literals, and skip only bare forwardin…
James-Chapman Nov 21, 2026
f06c97a
Fix the clang-tidy findings on the TURN log: const& fields, checked o…
James-Chapman Nov 21, 2026
72acb55
Report a qualified log module name instead of matching its last segment
James-Chapman Nov 21, 2026
1d0e3cf
Skip a forwarding module name only where the file declares it a param…
James-Chapman Nov 21, 2026
87fc45d
Say what the source-reading tooling tests guarantee, and how ADR-0872…
James-Chapman Nov 21, 2026
9e226c7
Read a TURN log field up to the next field, not the first space
James-Chapman Nov 21, 2026
a62d8bd
Report a module constant the file also reassigns from a non-literal
James-Chapman Nov 21, 2026
6772580
Describe the turn module's diagnostics in the debug-logging guide
James-Chapman Nov 21, 2026
45853cb
Report a copy of a forwarding parameter the file reassigns
James-Chapman Nov 21, 2026
3b9223c
Check every turn line's user_id field, and say what the module table is
James-Chapman Nov 21, 2026
e73af27
Include <cstddef> for std::size_t in the TURN log test helpers
James-Chapman Nov 21, 2026
00a3ff5
Return the found TURN log line as a string, so no optional is unwrapped
James-Chapman Nov 21, 2026
3f468a3
Mark GCC's braced-list cleanup in the TURN log calls excluded from co…
James-Chapman Nov 21, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ Changes before 1.0.0 are in [CHANGELOG-pre-release.md](CHANGELOG-pre-release.md)
which `/versions` lists (ADR-0865).
* The account_data extension follows its `lists` and `rooms` scope, whatever the user's membership; receipts send a
room's initial receipts on entering scope and those on a new timeline (MSC4548, MSC4551, ADR-0865).
* `GET /voip/turnServer` logs under its own `turn` module, set with `log_modules.turn`: credentials issued (info),
unavailable (error) and no TURN configured (debug), with the user ID and never a credential (ADR-0871).
* Tests set a log module's level through one shared helper, `tests/support/ModuleLogLevel.hpp`, instead of a copy per
file; the security coding rules state the TURN logging rule and why the username is withheld.

## Security Fixes

Expand Down Expand Up @@ -177,6 +181,10 @@ Changes before 1.0.0 are in [CHANGELOG-pre-release.md](CHANGELOG-pre-release.md)
* The Fedora 44 and 45 RPMs build again: GCC 16 refused `std::ranges::find` with a bare string literal under C++26,
and `reject-unsafe.sh` now rejects that form in code and tests (ADR-0870).
* The AlmaLinux and openSUSE CI suites install diffutils, which the integration shard check needs for `cmp` and `diff`.
* The example configurations list every module a structured logger call names (twelve were missing, `token` is
gone), and a tooling test fails when that list and the modules the sources name differ (ADR-0872).
* The TURN log calls mark GCC's cleanup of their braced field lists excluded from coverage, a compiler path no test
can reach; the testing standards say when such a marker is allowed (ADR-0874).

## Release notes

Expand Down
16 changes: 15 additions & 1 deletion config/merovingian.conf.bsd.example
Original file line number Diff line number Diff line change
Expand Up @@ -911,34 +911,46 @@ appservice.max_queued_events=100000
# every other module sees. Restart is required for changes to take effect.
# Merovingian needs to run with the --debug parameter to enable debug logging.
# — see docs/log-filtering.md.
# Every module a structured logger call names. The legacy LOG_* lines log
# under the calling function's name instead (for example `main`), and a
# function name is a valid key that this list leaves out:
# log_modules.appservice=info
# log_modules.auth=info
# log_modules.client_server=info
# log_modules.connection_parker=info
# log_modules.crypto=info
# log_modules.delayed_events=info
# log_modules.dispatch_worker=info
# log_modules.event=info
# log_modules.event_auth=info
# log_modules.event_query=info
# log_modules.event_signer=info
# log_modules.federation=info
# log_modules.federation_policy=info
# log_modules.federation_proxy=info
# log_modules.federation_security=info
# log_modules.hardening_self_check=info
# log_modules.http_server=info
# log_modules.identity=info
# log_modules.inbound_ingestion=info
# log_modules.key_query=info
# log_modules.livekit=info
# log_modules.local_router=info
# log_modules.local_services=info
# log_modules.media_repository=info
# log_modules.media_security=info
# log_modules.media_service=info
# log_modules.membership_endpoints=info
# log_modules.migration=info
# log_modules.oauth=info
# log_modules.outbound_client=info
# log_modules.outbound_transaction=info
# log_modules.persistent_store=info
# log_modules.policy_engine=info
# log_modules.postgresql_store=info
# log_modules.presence=info
# log_modules.rate_limit=info
# log_modules.redaction=info
# log_modules.remote_key_resolver=info
# log_modules.rooms=info
# log_modules.runtime=info
Expand All @@ -948,12 +960,14 @@ appservice.max_queued_events=100000
# log_modules.signing_service=info
# log_modules.sqlite_store=info
# log_modules.state_resolution=info
# log_modules.stream_token_epoch=info
# log_modules.sync_filter=info
# log_modules.sync_notifier=info
# log_modules.thread_pool=info
# log_modules.tls=info
# log_modules.token=info
# log_modules.transactions=info
# log_modules.turn=info
# log_modules.worker_pool=info

# All log module config
# Setting this to debug on a live server will open the floodgates
Expand Down
16 changes: 15 additions & 1 deletion config/merovingian.conf.example
Original file line number Diff line number Diff line change
Expand Up @@ -884,34 +884,46 @@ appservice.max_queued_events=100000
# every other module sees. Restart is required for changes to take effect.
# Merovingian needs to run with the --debug parameter to enable debug logging.
# — see docs/log-filtering.md.
# Every module a structured logger call names. The legacy LOG_* lines log
# under the calling function's name instead (for example `main`), and a
# function name is a valid key that this list leaves out:
# log_modules.appservice=info
# log_modules.auth=info
# log_modules.client_server=info
# log_modules.connection_parker=info
# log_modules.crypto=info
# log_modules.delayed_events=info
# log_modules.dispatch_worker=info
# log_modules.event=info
# log_modules.event_auth=info
# log_modules.event_query=info
# log_modules.event_signer=info
# log_modules.federation=info
# log_modules.federation_policy=info
# log_modules.federation_proxy=info
# log_modules.federation_security=info
# log_modules.hardening_self_check=info
# log_modules.http_server=info
# log_modules.identity=info
# log_modules.inbound_ingestion=info
# log_modules.key_query=info
# log_modules.livekit=info
# log_modules.local_router=info
# log_modules.local_services=info
# log_modules.media_repository=info
# log_modules.media_security=info
# log_modules.media_service=info
# log_modules.membership_endpoints=info
# log_modules.migration=info
# log_modules.oauth=info
# log_modules.outbound_client=info
# log_modules.outbound_transaction=info
# log_modules.persistent_store=info
# log_modules.policy_engine=info
# log_modules.postgresql_store=info
# log_modules.presence=info
# log_modules.rate_limit=info
# log_modules.redaction=info
# log_modules.remote_key_resolver=info
# log_modules.rooms=info
# log_modules.runtime=info
Expand All @@ -921,12 +933,14 @@ appservice.max_queued_events=100000
# log_modules.signing_service=info
# log_modules.sqlite_store=info
# log_modules.state_resolution=info
# log_modules.stream_token_epoch=info
# log_modules.sync_filter=info
# log_modules.sync_notifier=info
# log_modules.thread_pool=info
# log_modules.tls=info
# log_modules.token=info
# log_modules.transactions=info
# log_modules.turn=info
# log_modules.worker_pool=info

# All log module config
# Setting this to debug on a live server will open the floodgates
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# TURN credential requests log under their own `turn` module, and never log a credential

* Status: accepted
* Date: 2026-11-20

## Context and Problem Statement

`GET /_matrix/client/v3/voip/turnServer` is handled inline in `ClientServerRuntime.cpp`, whose file-local
`log_diagnostic` wrapper files every line under the `client_server` module. Its one diagnostic,
`turn.credentials_unavailable`, could therefore be raised or silenced only together with every other client-server
line, and an issued credential was not logged at all. An operator debugging calls ("why does this client get no
relay?") had nothing to filter on. LiveKit already has its own `livekit` module (`log_modules.livekit`).

## Decision Drivers

* An operator must be able to turn TURN logging up or down without touching `client_server`.
* The answer holds a working credential: the username (`<expiry>:<user_id>` with a shared secret, or the static one)
and the password. Neither may reach a log, and the shared secret never leaves the request's `SecretBuffer`
(ADR-0480).

## Considered Options

* Keep the lines under `client_server` and add an issued line there.
* Log the route under a `turn` module through its own wrapper, `log_turn_diagnostic`.
* Move the whole route out of `ClientServerRuntime.cpp` into a TURN service file with its own module constant.

## Decision Outcome

Chosen option: "a `turn` module through `log_turn_diagnostic`". The route logs `turn.credentials_issued` (info),
`turn.credentials_unavailable` (error) and `turn.not_configured` (debug), each with `user_id`; the issued line adds
`credential` (`static` or `shared_secret`), `ttl_seconds` and `uri_count`, and the unavailable line a fixed `reason`.
No field carries credential text: the username, the password and the shared secret are never fields of any line. Moving the route out of `ClientServerRuntime.cpp` was not needed to get a module
of its own and would have moved forty lines of unrelated JSON building with it.

### Positive Consequences

* `log_modules.turn` sets the level of every line the TURN handler writes; `log_modules.turn=warning` hides the
per-request info line. Only requests that reach the handler are logged there: a missing, expired or unknown access
token is refused with 401 before it, and logged as `request.auth.rejected` (debug) under `client_server`, so look
there for authentication failures. `turn.not_configured` is a debug line, which reaches the console only when the
server also runs with `--debug`.
* Each logging test asserts that the line's module tag is `turn`, so a line moved back under `client_server` fails
it. The issued-credential and unreadable-secret scenarios also silence `client_server`, so no client-server line
can stand in for the TURN one either way.

### Negative Consequences

* An issued credential is one info line per successful request at the default level. The ttl does not bound that:
a client may ask again before its credential expires (for example at the start of each call), and every request
writes a line. An operator who finds it loud sets `log_modules.turn=warning`.
* Changing the module of `turn.credentials_unavailable` means a filter on `client_server` no longer sees it.

## Rules for future code

* A new diagnostic of `GET /voip/turnServer` goes through `log_turn_diagnostic`, never the `client_server` wrapper.
* Never add the username or the password as a field, even at debug or trace level. The password is the secret that
matters. The username is withheld for two reasons that hold whatever else the line carries:
* With static credentials (`server.turn.username`) it is a configured value that nothing else in a log reveals, the
same for every user, and one of the two halves of a credential every user of the server may relay with.
* One rule for both kinds keeps every line free of credential text, so a log can be pasted into an issue or a
support thread without first working out which parts of it are safe.
* With a shared secret, withholding the username hides little: it is `<expiry>:<user_id>`, and the expiry can be
rebuilt to the second from the line's timestamp and `ttl_seconds`. That is accepted, because the username without the
password, which needs the shared secret, grants nothing. Do not read it as a reason to start logging the username:
the static case still forbids it.

## Links

* Refines [ADR-0480](0480-turn-credentials-come-from-a-coturn-shared-secret-file-through-an-openssl-hmac-sha1.md)
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# The example configs list every log module, and a tooling test reads the modules from the sources

* Status: accepted
* Date: 2026-11-20

## Context and Problem Statement

`log_modules.<name>` accepts any name: the bootstrap passes it to `SingleLog::set_module_log_level` without a registry.
The example configurations (`config/merovingian.conf.example` and its BSD edition) are where an operator learns which
names exist, and their list drifted: twelve modules the server logs under were missing and one, `token`, was logged under
by nothing. How do the examples stay complete without someone remembering to edit them?

## Decision Drivers

* A module added to or removed from the sources must fail a test until both examples agree.
* The check must not need a list kept by hand, which would only move the drift into the test.
* It must not miss a module silently when a logger call takes a form the check does not know.

## Considered Options

* A hand-kept list of modules in the test, compared with the examples.
* A tooling test that reads the module names from the logger calls in `src/` and `include/`.
* A module registry in C++ that the logger, the config parser and a test all read.

## Decision Outcome

Chosen option: "a tooling test that reads the module names from the sources",
`ExampleLogModuleListTests` in `tests/tooling/test_example_config.py`. It blanks C++ comments (a comment that quotes a
call names no module) and finds calls and constants only outside string literals (logger-call text inside a string is
no call), then reads the first argument of the qualified `observability::log_diagnostic` and
`log_diagnostic_audit` calls and of `SingleLog` level calls, the second argument of the homeserver's
`log_diagnostic_audit(database, "module", ...)` overload, and resolves an identifier through a string constant defined
in the same file. Each example must list exactly that set as `# log_modules.<name>=` lines, each once. A hand-kept list
drifts like the examples did. A registry is the larger change: every logger call site and the config parser would move
to it, for a list that exists to be documented.

### Positive Consequences

* A new module fails the test, with its name, until both examples list it; a module nothing logs under any more fails
until it is dropped.
* A first argument the scan cannot resolve fails the test instead of shrinking the expected set, and so does a call
of a known form whose arguments it cannot read (`(kModule)`, `module_of(rt)`, `database_of(rt)`): each form has an
opening pattern that finds every call of that form, and an opening the full pattern cannot read is reported with
the call quoted.

### Negative Consequences

* The scan is text, not a C++ parser: it knows the call forms above, and a new form must be taught to it.
* A module constant shared from another file (a header) is not resolved and fails the test.
* Level calls are recognised by their receiver, so one through a receiver the rule does not name is missed rather than
failed. Reading every `.info(...)` instead would take other types' methods for modules and demand example lines for
modules that do not exist; the receiver rule is the price of not doing that.

## Rules for future code

* Name a logger call's module with a string literal, or with a string constant defined in the same file under a name
given no other value there: the scan does not know scopes, so a name two functions each define with a different value
is reported as ambiguous. The database audit overload's module argument follows the same rule. A parameter
that only forwards a caller's module is named `logger`, `mod` or `module`, which the scan skips, but only when the
file defines no string constant of that name (a constant always resolves first) and declares the name as a string
parameter or gives it a value only by copying one (`auto const mod = std::string{logger};`), a parameter the file
never gives another value (`logger = module_for(kind);` makes a copy of it reported). So the skip goes by
role: a local holding a computed module (`module = module_for(kind)`), or a name the file never declares, is
reported. `__func__` is skipped on its name alone:
the legacy `LOG_*` macros log under the calling function's name, which is no module and is not listed in the
examples. These four identifiers are the only first arguments the scan skips; say so wherever the test is described.
* Call a level method (`info`, `warning`, ...) directly only on `SingleLog::instance()` or on a reference named `log`
or `logger`. The scan reads level calls on those receivers only, so a method of another type that happens to be named
`warning` never becomes a module. A level call through any other receiver breaks this rule, and the scan does not
see it.
* To share a module constant across files, or to log through a new call form, extend `source_log_modules` in the test
in the same change. Never relax or delete the assertion to get past it.
* The examples list every module a structured logger call names, not a selection of common ones, and say that the
legacy `LOG_*` macros' function names are left out. Do not trim the list.
* The homeserver's `log_diagnostic_audit(database, module, ...)` is recognised by its shape (an unqualified call that
is not a declaration and does not open with a literal), never by what the database is called, so an alias such as
`db` is read. Pass the database as a name, a member expression or `*pointer`; any other first argument (`(db)`,
`database_of(rt)`) is reported, and so is the module argument of any call when it is neither a literal nor a name.
Call a file-local wrapper with its event as a literal: one called with a variable event has the same shape and is
reported as unresolved.

## Links

* See [ADR-0871](0871-turn-credential-requests-log-under-their-own-turn-module.md): the `turn` module it adds is one of
the modules the examples must list.
Loading
Loading