Repository navigation
feat(drivers): add host.http_put for device APIs that write with PUT - #2028
yogiohlsson-ai wants to merge 3 commits into
Conversation
miravoss26
left a comment
There was a problem hiding this comment.
Adds host.http_put by folding the http_patch body into one httpWrite(method) helper. Same gates for both verbs: allow_write, allowed_hosts, probe/read-only blocks, and the redirect refusal now covers PUT as well as PATCH. Docs and a 200-line test file are included.
- Security screen: no new hosts, no new capability, nothing widened.
allow_writestill gates both verbs, and http_get/http_post are unchanged. No secrets in the diff. - The refactor is the only risk (the PATCH path was rewritten, not just copied). The shared test helper still exercises
http_patch, so regressions there should show up.
Safe to merge from my read, assuming CI is green.
|
Thanks. This change blocks a sonnen control driver. We have not finished the review. The PATCH path moved into the shared helper, so we want proof it behaves as before. Please point us to the tests where a PATCH gets a 301, 302 or 303 and is refused like PUT, and where |
sonnenBatterie's JSON API v2 changes its operating mode only through PUT /api/v2/configurations; PATCH and POST there return 404. Add host.http_put, sharing http_patch's implementation and gates: capabilities.http plus allow_write, allowed_hosts, no writes during a fingerprint probe, a JSON default Content-Type the driver can override. The redirect policy now refuses a redirected PUT as it does PATCH, so a 301/302/303 cannot turn the write into a body-less GET that reports success. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Jörgen Ohlsson <[email protected]>
…iven Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Jörgen Ohlsson <[email protected]>
9c48176 to
77d2062
Compare
|
Thanks, Fredrik. Both are covered, and I've extended the redirect tests to make that explicit.
I also rebased onto current master (no conflicts); the new commit is 77d2062. On the rebased I could not get a fully green make verify on my Raspberry Pi: selfupdate has a test that needs |
miravoss26
left a comment
There was a problem hiding this comment.
Adds host.http_put by folding http_patch into a shared httpWrite(method) closure, so PUT gets the same gates as PATCH: http grant, allow_write, allowWrite permission check, allowed_hosts, 1MB cap, no redirects (now PATCH and PUT), and the fingerprint-probe denial. Docs and changeset updated.
- Security: no new network destinations, no new deps. PUT sits behind the same
allow_writegrant as PATCH, so granting HTTP for telemetry still can't mutate a device. Good. - Correctness: the refactor keeps the old behaviour for PATCH. The redirect test now covers 301/302/303/307/308. PUT tests cover method, body, headers, Content-Type override, and the gate denials.
- Nit:
permission := "http." + strings.ToLower(method)makeshttp.puta new permission string forallowWrite. Worth a quick check that nothing (probe deny-list, audit) matches on the literalhttp.patch. - No CI checks reported on this PR, so I couldn't confirm the Go tests pass.
Safe to merge from my read once CI has run.
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Jörgen Ohlsson <[email protected]>
|
Thanks for the review. I checked the
To make that a test rather than a claim, 51368aa adds |
miravoss26
left a comment
There was a problem hiding this comment.
Adds host.http_put to the Lua host by folding http_patch into a shared httpWrite(method) helper. Needed because the sonnenBatterie API only accepts config writes via PUT.
- Same gates as PATCH:
capabilities.http.allow_write,allowed_hosts, TLS pin, 1 MB cap. Redirect refusal is extended to PUT, and the redirect test now covers 301/302/303/307/308. That is the right call, since Go turns redirected writes into body-less GETs. - The fingerprint-probe deny list gets
http_putand the read-only policy test is updated, so a passive probe cannot write. Good. - Security screen: no secrets, no new deps, no new hosts. The only risk surface is the new mutating verb, and it sits behind the explicit
allow_writegrant. No existing driver changes behaviour. - Minor: permission key is now
"http." + lower(method)(http.patchunchanged,http.putnew). If anything outside this diff matches on thehttp.patchstring, it will not coverhttp.put. I only read the diff, did not grep the tree. Worth a quick grep for"http.patch". - CI shows no check runs on this PR, so the Go tests have not run yet.
Safe to merge from my read once the Go tests are green and the http.patch grep comes back clean.
Need
A sonnenBatterie can only be steered through its local JSON API v2 by
switching its operating mode, and the unit accepts that write only as
PUT /api/v2/configurations. The Lua host offershttp_patchandhttp_postfor plain-HTTP writes;http_requestallows only GET and POSTover https. A sonnen control driver therefore cannot be written today.
Measured on one sonnenBatterie (software 1.40.5, JSON API v2, port 80) on
2026-11-13, with the unit's Auth-Token. The first row put the unit in manual
mode and the second set it back from 1 to 2. Every row except the first two
was sent with
EM_OperatingMode2, the mode the unit was already in, so itchanged nothing:
/api/v2/configurationsPUTEM_OperatingMode=1{"EM_OperatingMode":"1"}; mode read back as 1PUTEM_OperatingMode=2{"EM_OperatingMode":"2"}; mode read back as 2PUT{"EM_OperatingMode":"2"}{"EM_OperatingMode":"2"}POSTEM_OperatingMode=2POST{"EM_OperatingMode":"2"}PATCHEM_OperatingMode=2PATCH with a JSON body was not tried. The owner repeated the PATCH and POST
requests on the unit and got 404 for both.
The controllable sonnen driver itself belongs in srcfl/device-drivers and
will follow as a separate PR once this host function exists. This PR changes
no driver.
Change
host.http_put(url, body, headers?)shares one implementation withhost.http_patch: samecapabilities.httpandcapabilities.http.allow_writegates,allowed_hostsfence, read-onlyprobe and runtime-policy refusal (
allowWrite("http.put")), JSON defaultContent-Type that a driver header overrides, 1 MB response cap and
HTTP <status>error for 4xx/5xx.PUTas italready did for
PATCH. Without this, Go re-issues a 301/302/303 as abody-less GET and the write would report success although it never
reached the device. The new redirect test failed before this line changed.
HTTPAllowWrite/AllowWriteanddocs/writing-a-driver.mdname both verbs.patch(new host function; no existing driver changesbehaviour). The owner may prefer
minor, ashttp_patchused.Tests
New
go/internal/drivers/lua_http_put_test.go:Content-Type(form body) wins over the default;allow_write, without thehttpcapability, outsideallowed_hosts, on redirect and during a fingerprint probe — in everycase the server is never reached (or the redirect target never is).
lua_http_patch_test.goonly gains a verb parameter in its helper; theexisting PATCH tests are unchanged and pass.
Run on a Raspberry Pi 4 Model B Rev 1.5 (aarch64, Debian 13 trixie), with
go version go1.26.0 linux/arm64:
make verifywas not run on the Pi (it needsjq, not installed); thedrivers package ran with the pinned bundled drivers fetched by hand at
1e4b5de7.Overlap
Open #2017 (
fix(battery): explain calibration and suspend manual control)also edits
go/internal/drivers/lua.goanddocs/writing-a-driver.md.Checked on 2026-11-16 with
gh pr view 2017 -R srcfl/ftw: open, not adraft, no reviews, mergeable, head
5cf68a0f65. Its hunks are elsewhere(
set_calibrating).git merge-treeof this branch with that head mergedwithout conflicts. This branch is based on current
master(5b25abcb).🤖 Generated with Claude Code