Skip to content

feat(channel): let a read-only MQTT driver declare its read requests; victron_mqtt 1.2.1 - #275

Merged
frahlg merged 2 commits into
mainfrom
mqtt-read-requests
Nov 22, 2026
Merged

frahlg merged 2 commits into
mainfrom
mqtt-read-requests

Conversation

@frahlg

@frahlg frahlg commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

Paired with srcfl/ftw#2071 (Core). The two PRs can merge in either order; see "Merge order".

Why

Venus OS on a Victron GX publishes its MQTT values only while a client sends a read request to R/<portal ID>/keepalive (victronenergy/dbus-flashmq README, "Keep-alive"). victron_mqtt 1.2.0 (#268) sends one every 30 s, but from the signed channel it never reaches the GX:

  • the channel's generated guard sets host.mqtt_publish = __sourceful_ftw_write_denied for every read-only driver, and
  • FTW Core refuses every publish from a driver it runs under a read-only policy.

victron_mqtt is not bundled in FTW, so every FTW user runs the channel copy.

Change

Two commits.

1. feat(channel): let a read-only MQTT driver declare its read requests. No published artifact changes: check-versions against drivers-beta reports added: [], changed: [].

  • A catalog manifest may list mqtt_read_request_topics, for example ["R/+/keepalive"]. It sits in the manifest rather than the DRIVER table because victron_mqtt has no DRIVER table, and it is a grant that review should see beside control and protocol.
  • tools/manifest_parser.py holds the topic rule, the same as Core's. The first level must be exactly R, Venus's read-request namespace. A literal first level alone would admit W/+/settings/..., a Venus write. + is a whole level, # is refused, levels are printable ASCII without spaces (checked with fullmatch, so a trailing newline is refused as Core refuses it), at most 256 bytes.
  • tools/ftw_repository.py checks each topic, refuses the list on a driver that is not MQTT or that controls, carries it into the signed metadata, and generates a guard. The guard lets host.mqtt_publish and host.mqtt_pub through only to a topic under R/ that matches a declared pattern level by level, with at most 1 KiB of string payload, and raises for anything else. It checks the R/ level itself, so it does not rely on the build's check. Only a driver that declares topics gets the guard.
  • A read request is not a write, so the driver gets no write permission. Its signed permissions stay ["mqtt.subscribe"], and verification still refuses mqtt.publish on a read-only driver, declared topics or not. A Core that does not know the field therefore accepts the policy, starts the driver, and refuses the request as it does today.
  • Signed-manifest verification also refuses a bad topic, or topics without mqtt.subscribe. validate_manifest.py (make check) holds the manifest to the same rule.
  • Docs: a short section in docs/WRITING-A-DRIVER.md, "A read-only driver that has to ask", covering the sign-in paths (not documented here before) and read-request topics. Also spec/manifest-v2.md (field, rule 13, V2.5) and spec/host-api.md.

2. feat(victron_mqtt): declare the Venus keep-alive as a read request (1.2.1). Only manifests/victron_mqtt.yaml gains mqtt_read_request_topics: ["R/+/keepalive"]. The Lua source is unchanged. The artifact changes, so the version moves from 1.2.0 (published) to 1.2.1, with the generated catalog files and a changelog entry.

Trust model: what a read-only driver still cannot do

  • Publish to any topic its manifest does not declare. That includes W/..., another R/... topic, a deeper or shorter one, and one carrying +, #, a space or an empty level. Both the guard and Core check this.
  • Publish outside R/, Venus's read-request namespace, whatever its manifest says.
  • Publish more than 1 KiB, or, on a Core with feat(drivers): let a signed read-only driver send its declared MQTT read requests ftw#2071, more than six read requests a minute. That Core also holds read requests in setup measurement mode and fingerprint probes, as it holds writes.
  • Hold mqtt.publish or any other write permission.
  • Grant itself topics. They come from the reviewed catalog manifest into the signed metadata; the driver's own Lua plays no part, and Core reads them only from the verified signed manifest.
  • Write Modbus, serial, or HTTP beyond its declared sign-in paths. Those guards are unchanged.

Signing is unchanged. Public PR builds stay unsigned; only the release workflow on main signs.

Tests

tests/test_ftw_repository.py:

  • The topic rule accepts and refuses the same cases as Core, including W/+/x, W/+/settings/0/Settings/CGwacs/AcPowerSetPoint, X/+/keepalive, +/abc123/keepalive, R, keepalive and R/+/keepalive\n.
  • A guard built from an unvalidated W/+/x pattern still refuses W/abc123/x, run in ./lua55.
  • A declared topic reaches the metadata and the guard, the permissions stay ["mqtt.subscribe"], and the signed manifest verifies.
  • The generated artifact, run in ./lua55 with a mock host:
    • sends R/abc123/keepalive: empty, with the suppress-republish JSON, with 1024 bytes, and through mqtt_pub too;
    • raises for W/..., R/abc123/system/0/Serial, R/abc123/keepalive/x, R/abc123, R/#, R/#/keepalive, R/+/keepalive, R//keepalive, a space, an empty topic, 1025 bytes and a nil topic;
    • the mock received exactly four.
  • Bad topics (including a W/ pattern), a Modbus driver (sdm630) and a control driver (ferroamp) are refused while building.
  • Signed-manifest verification refuses mqtt.publish with or without topics, topics without mqtt.subscribe, and R/#. make check's manifest validator refuses the same.
  • No read-only driver holds mqtt.publish, and only victron_mqtt loses the blanket publish denial.

Older Core, checked against FTW master's own code. I built this branch's signed victron_mqtt 1.2.1 entry and artifact with a throwaway key. A temporary FTW driverrepo test (not committed) installed them from a signed manifest, built the runtime policy and started the driver with a fake broker.

Results:

  • make check: 5429 passed, 928 skipped.
  • make test-driver ID=victron_mqtt: 76 passed, 4 skipped.
  • check-versions against drivers-beta (8c84ab9): commit 1 alone changes nothing; both commits change only victron_mqtt, under a higher version.

Merge order

The two PRs merge independently.

#266, #267, #268, #269, #270, #272, #273 and #274 merged while this was being written. This branch is based on main after them.

Not tested against a real GX.

Refs #256

🤖 Generated with Claude Code

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-22T12:58:39.007667Z bc899cb PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@frahlg
frahlg force-pushed the mqtt-read-requests branch from bc899cb to c20fc1b Compare November 22, 2026 13:04
frahlg and others added 2 commits November 22, 2026 14:14
Venus OS on a Victron GX publishes its MQTT values only while a client
sends R/<portal ID>/keepalive. A driver from the signed channel cannot
send one: the generated guard turns host.mqtt_publish into an error for
every read-only driver, and FTW Core refuses the publish too.

A catalog manifest may now list mqtt_read_request_topics. The channel
build checks each topic, refuses the list on a driver that is not MQTT
or that controls, carries it into the signed metadata, and generates a
guard that lets host.mqtt_publish and host.mqtt_pub through only to a
matching topic with at most 1 KiB of payload.

A topic must start with R/, Venus's read-request namespace: a literal
first level alone would admit W/+/settings/..., a Venus write. "+" is a
whole level, "#" is refused, levels are printable ASCII without spaces,
at most 256 bytes. The guard checks the R/ level itself as well.

A read request is not a write, so the driver gets no write permission:
the signed permissions stay read-only and verification still refuses
mqtt.publish on a read-only driver. An FTW Core that does not know the
field runs the driver as before and refuses the request. Verification
and make check hold the topics to the same rule, and verification wants
mqtt.subscribe beside them. Every other artifact is byte for byte the
same.

Refs #256

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Fredrik Ahlgren <fredrik@sourceful-labs.com>
….2.1)

1.2.0 sends R/<portal ID>/keepalive every 30 s, but the signed channel's
guard and FTW refuse every publish from this read-only driver, so the
keep-alive never reached a GX from the channel.

The manifest now lists R/+/keepalive in mqtt_read_request_topics. The
channel's guard lets the driver publish to that topic alone, with at
most 1 KiB of payload; an FTW Core with srcfl/ftw#2071 also limits it to
six a minute. The driver still holds only mqtt.subscribe, so a Core
without srcfl/ftw#2071 runs it as it runs 1.2.0 and refuses the request.
The Lua source is unchanged. A changed artifact needs a new version, so
1.2.1.

Refs #256

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Fredrik Ahlgren <fredrik@sourceful-labs.com>
@frahlg
frahlg force-pushed the mqtt-read-requests branch from c20fc1b to 02d0325 Compare November 22, 2026 13:16
@frahlg
frahlg merged commit e7b94b1 into main Nov 22, 2026
5 checks passed
@frahlg
frahlg deleted the mqtt-read-requests branch November 22, 2026 13:19
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