Skip to content

feat: expose selected JSON-RPC methods over authenticated HTTP - #1515

Open
nitishagar wants to merge 1 commit into
jetkvm:devfrom
nitishagar:feat/rpc-http-rest-api
Open

feat: expose selected JSON-RPC methods over authenticated HTTP#1515
nitishagar wants to merge 1 commit into
jetkvm:devfrom
nitishagar:feat/rpc-http-rest-api

Conversation

@nitishagar

Copy link
Copy Markdown
Contributor

Summary

Exposes a reviewed subset of JSON-RPC methods over an authenticated HTTP endpoint, so scripts and automation can drive device configuration (TLS, network, device ID) without a browser/WebRTC data channel.

Closes #1320

Change

  • New POST /rpc/:method route registered inside the existing protected group, so it inherits the current local-auth cookie check (no new auth scheme).
  • handleRPCDispatch looks the method up in an opt-in allowlist (httpExposedRPC: getTLSState, setTLSState, getNetworkSettings, setNetworkSettings, getDeviceID), binds an optional JSON body to map[string]any, and dispatches through the same callRPCHandler path the WebRTC transport uses — so semantics (including panic recovery) are identical.

Behavior

  • Unauthenticated → 401; non-allowlisted method → 404; malformed JSON → 400; handler error or panic → 500; success → 200 with the method result as JSON.
  • Additive only: no changes to rpcHandlers, callRPCHandler, RPCHandler, or any existing route.

Not doing

No new token scheme, no blanket exposure of all RPC methods, no resource-oriented REST verbs, no client SDK.

Testing

  • Added web_test.go (httptest against setupRouter()): 401 unauth, 404 non-allowlisted, result-shape for getDeviceID/getTLSState, 400 malformed JSON, error→500, and a real panic→500 verifying recovery is wired through the HTTP path. Follows the existing //go:build linux && arm convention for kvm-package tests (runs in the on-device test build).
  • Manual: curl -X POST with a valid authToken cookie returns the method result; without it, 401.

Add POST /rpc/:method under the existing protected (local-auth) route
group, dispatching an opt-in allowlist of methods (getTLSState,
setTLSState, getNetworkSettings, setNetworkSettings, getDeviceID) through
the same callRPCHandler path the WebRTC data channel uses. This lets
scripts drive device config over plain HTTP without a browser, reusing
the existing cookie auth.

Non-allowlisted methods return 404, unauthenticated requests 401, malformed
JSON 400, and handler errors or panics 500 (panic recovery is inherited
from callRPCHandler). Additive only: no existing route or handler changes.

Closes jetkvm#1320
@nitishagar
nitishagar marked this pull request as ready for review July 2, 2026 08:36
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.

feat: expose JSON-RPC methods over HTTP REST API

1 participant