Skip to content

feat(drivers): let a signed read-only driver send its declared MQTT read requests - #2071

Merged
frahlg merged 1 commit into
masterfrom
mqtt-read-requests
Nov 22, 2026
Merged

frahlg merged 1 commit into
masterfrom
mqtt-read-requests

Conversation

@frahlg

@frahlg frahlg commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

Paired with srcfl/device-drivers#275 (the channel side). 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"; it stops 60 s after the last one). victron_mqtt 1.2.0 (srcfl/device-drivers#268, merged today) sends it every 30 s.

victron_mqtt is not bundled (drivers/BUNDLED_SOURCE.json lists victron, not victron_mqtt), so every FTW user runs it from the signed channel under a read-only RuntimePolicy, and allowWrite refuses its publish ("read-only driver cannot write"). On a GX with no other MQTT client the values stop and the driver goes stale.

Change

  • RuntimePolicy.MQTTReadRequestTopics (and CatalogEntry.MQTTReadRequestTopics, JSON mqtt_read_request_topics). driverrepo copies it from the verified signed manifest's metadata, the same way it copies AuthPostPaths. Signature checks are unchanged: a manifest altered after signing is refused, and the policy stays the verified one.
  • A read request is not a write, so it needs no write permission. A read-only policy that declares topics and holds mqtt.subscribe may publish to those topics. validate still refuses mqtt.publish in a read-only policy, as before. It also refuses a bad pattern, so a malformed signed entry fails at start.
  • host.mqtt_publish goes through a new allowMQTTPublish. A publish from a signed read-only driver passes only when the topic matches a declared pattern level by level. Everything else, and every publish from a driver without a policy, still goes through allowWrite.
  • The new code lives in go/internal/drivers/mqtt_read_request.go. host.go and lua.go change by one field and one line, to stay clear of feat(control): read the inverter stream and say when its grid headroom is gone #2070, feat(drivers): add host.http_put for device APIs that write with PUT #2028 and fix(battery): explain calibration and suspend manual control #2017.

Because the signed policy holds no new permission, a Core without this PR accepts it, starts the driver, and refuses the request as it does today.

Limits

  • Topic patterns. The first level must be exactly R, Venus's read-request namespace. A literal first level alone would not be enough: W/+/settings/0/Settings/CGwacs/AcPowerSetPoint is a valid pattern and a Venus write. And directManifestRuntimePolicy also builds policies for a third-party repository whose key the owner trusts, so we are not always the signer. + stands for one whole level and # is refused. A level is printable ASCII without spaces. Patterns and topics are at most 256 bytes. A + must match a non-empty level with no wildcard in it.
  • Payload: 1 KiB. A Venus keep-alive is empty or {"keepalive-options": ["suppress-republish"]} (about 45 bytes).
  • Rate: six per driver in any 60 s. Venus needs one a minute; Victron's example and the driver send one every 30 s, so six leaves room for a restart without a refusal. A refused request does not count.

Together that caps a declared topic at about 130 bytes a second, too little to be a write channel.

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

  • Publish to any topic its signed manifest does not declare. That includes W/..., another R/... topic, a deeper or shorter topic, and one carrying +, # or an empty level.
  • Publish more than 1 KiB, or more than six requests a minute.
  • Hold mqtt.publish, or any other write permission. validate refuses it with or without declared topics.
  • Declare its own topics. They come only from the signed manifest's metadata; the Lua file's own DRIVER table plays no part. The channel build in feat(channel): let a read-only MQTT driver declare its read requests; victron_mqtt 1.2.1 device-drivers#275 refuses them on a driver that is not MQTT or that controls.
  • Write Modbus, serial, HTTP (beyond its declared sign-in paths) or WebSocket, in any phase, as before.

A declared read request still meets allowWrite's other gates. Setup measurement mode holds it, so a GX with no other MQTT client goes quiet until setup ends, and a fingerprint probe never sends one. DeviceReadOnly is left out: it means another client owns the driver's Modbus endpoint (registry.go sets it from the Modbus capability), and a read request goes to the MQTT broker, not to that endpoint. Bundled, local and control-capable signed drivers run without a policy and publish as before: any topic, any size, no rate limit, still blocked in setup measurement mode.

Tests

go/internal/drivers/read_only_mqtt_read_request_test.go:

  • validate accepts:
    • R/+/keepalive with mqtt.subscribe only;
    • several topics, or a literal topic;
    • topics without mqtt.subscribe (they grant nothing).
  • validate refuses:
    • mqtt.publish with or without topics;
    • any first level but R: W/+/x, W/+/settings/0/Settings/CGwacs/AcPowerSetPoint, X/+/keepalive, r/+/keepalive, +/+/keepalive, R alone, keepalive;
    • R/#, #, keep#alive, +x;
    • empty levels, a leading or trailing slash, $SYS/...;
    • a space, a control byte, an empty topic, 257 bytes;
    • an invalid topic even without mqtt.subscribe;
    • a policy that is not read-only.
  • Matching level by level, including the 256-byte boundary, and an invalid pattern matching nothing.
  • A managed driver:
    • sends to R/abc123/keepalive with both payloads and with 1024 bytes;
    • is refused for W/abc123/settings/..., R/abc123/system/0/Serial, R/abc123/keepalive/x, R/#, R/#/keepalive, R/+/keepalive and R//keepalive;
    • is refused for 1025 bytes, without mqtt.subscribe, or with no declared topics;
    • is refused in setup measurement mode and in a fingerprint probe, as a W/ write is.
  • Rate: six sent, the seventh refused, still refused at 59 s, sent at 60 s, and a keep-alive every 30 s for 10 minutes never refused.
  • No policy: any topic, 2 KiB and 12 publishes all sent; setup measurement mode still blocks them.

go/internal/driverrepo/mqtt_read_request_policy_test.go:

  • A signed manifest with mqtt.subscribe and the topics yields a policy without mqtt.publish, and NewLuaDriverWithPolicy accepts it.
  • A tampered manifest is refused and leaves the verified policy.
  • A signed R/# makes the Lua constructor refuse the policy.

With the old allowWrite call put back in lua.go, both managed-driver tests fail and the no-policy test passes.

Older Core, checked against master's own code. I built the signed victron_mqtt 1.2.1 entry and artifact from srcfl/device-drivers#275 with its channel tool, using a throwaway key. A temporary driverrepo test (not committed) served them over a signed manifest, installed the driver, built its runtime policy and started it with a fake broker. After the GX's N/c0619ab1234/system/0/Serial it polled three times.

  • On a scratch worktree of origin/master (1015e6b), the driver installs and passes validate. Its policy holds mqtt.subscribe only. It starts, and its keep-alive is refused (mqtt.publish: read-only driver cannot write) with one warning. Nothing reaches the broker, the same as 1.2.0 today.
  • On this branch, the same entry sends R/c0619ab1234/keepalive.

Results:

  • go test ./internal/drivers/ ./internal/driverrepo/: ok.
  • GOFLAGS=-p=4 make verify: 88 packages ok, vet and build clean.

Merge order

The two PRs merge independently.

Changeset: minor (a new capability for signed drivers), which needs the owner's approval. Not tested against a real GX.

Refs srcfl/device-drivers#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:54:49.422992Z 0ba27fd 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 added a commit to srcfl/device-drivers that referenced this pull request Nov 22, 2026
….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 0ba27fd to 1f4fcfd Compare November 22, 2026 13:05
…ead requests

Victron's Venus OS publishes its MQTT values only while a client sends
R/<portal ID>/keepalive. victron_mqtt is not bundled, so every FTW user
runs it from the signed channel under a read-only policy, and allowWrite
refused its keep-alive. Without one the GX goes quiet and the driver
goes stale.

RuntimePolicy gains MQTTReadRequestTopics, carried from the signed
manifest's metadata the way AuthPostPaths is. A read request is not a
write, so it needs no write permission: a read-only policy that declares
topics and holds mqtt.subscribe may publish to those topics, and
validate still refuses mqtt.publish. A Core without this change accepts
the same signed policy and refuses the request, as before.

validate refuses a bad pattern. A topic must start with R/, Venus's
read-request namespace: a literal first level alone would admit
W/+/settings/..., a Venus write, and a third-party repository's key may
have signed the manifest. "+" is a whole level, "#" is refused, levels
are printable ASCII without spaces, at most 256 bytes.

host.mqtt_publish from such a driver passes only to a topic that matches
a declared pattern level by level, with at most 1 KiB of payload and six
requests in any 60 s. Setup measurement mode and fingerprint probes hold
it as they hold writes. Every other publish, and every publish from a
driver without a policy, goes through allowWrite unchanged.

Refs srcfl/device-drivers#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 1f4fcfd to 10ca649 Compare November 22, 2026 13:16
frahlg added a commit to srcfl/device-drivers that referenced this pull request Nov 22, 2026
….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 added a commit to srcfl/device-drivers that referenced this pull request Nov 22, 2026
… victron_mqtt 1.2.1 (#275)

* feat(channel): let a read-only MQTT driver declare its read requests

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>

* feat(victron_mqtt): declare the Venus keep-alive as a read request (1.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>

---------

Signed-off-by: Fredrik Ahlgren <fredrik@sourceful-labs.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
@frahlg
frahlg merged commit e1de7f1 into master Nov 22, 2026
21 checks passed
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