Camera permission and review fixes (openpanel C3, C4)

C4: a device's `viewers` (superusers by default, or members) covers the
image and video messages its ports publish. Anyone else gets none of their
values on the socket, in the catalogue or a flow's state, 403 for their
history, for the frames they hold (the last 8 included) and for TURN
credentials, no bytes when asking for them, and `bye: forbidden` for a live
view. A device credential stays bounded by its dashboards. The device page
sets it in its Camera section, and a tile the viewer may not see says
"No access to this camera" and asks the camera for nothing.

C3:
- A volatile upload is held to MAX_FRAME_BYTES (4 MiB, 413 above it, read
  without extra copies), and so is a frame on a device's socket.
- A frame the engine holds in memory is written to the ring directory
  before a local worker is handed it, so load_artifact finds it.
- A socket the bus dropped events for catches up with a snapshot, demand
  included, and a device's credential is checked again per frame, cached by
  the flow store revision and its nonce, so a lost event never keeps an
  unpaired device's frames coming.
- A report is at most 64 KB once its named config_schemas are put in place.
- A device away for 60 s has its true bool messages set to false.
- Refused frames are logged by fixed keys, a frame is named after its
  message, `fluksio serve` waits 5 s for open connections, a tile with a
  stream URL creates no demand, the 8-name cap keeps the newest names.
- Every container's log rotates (json-file, 3 x 10 MB).
This commit is contained in:
Melvin Strobl
2026-10-17 09:20:04 +02:00
parent 6a98dcd23f
commit 72c1d73e96
36 changed files with 1268 additions and 152 deletions
+31 -4
View File
@@ -177,10 +177,12 @@ def _device_digests(device: DeviceDef, request: Request) -> set[str]:
controller: FlowController | None = getattr(
request.app.state, "flow_controller", None
)
if controller is None:
return set()
names = _device_messages(device, request)
if not names:
return digests_of(controller, _device_messages(device, request))
def digests_of(controller: FlowController | None, names: set[str]) -> set[str]:
"""The artifacts these messages point at now, and the last few before."""
if controller is None or not names:
return set()
found: set[str] = set()
for value in controller.state.get_present(sorted(names)).values():
@@ -191,6 +193,19 @@ def _device_digests(device: DeviceDef, request: Request) -> set[str]:
return found
def hidden_from(user: User, app: Any, *, device: bool = False) -> frozenset[str]:
"""The camera messages ``user`` may not see (``DeviceDef.viewers``).
None for a superuser, and none for a device credential, which its
dashboards bound instead: a superuser assigned them, camera tiles
included. ``device`` says the caller is one.
"""
if device or user.is_superuser:
return frozenset()
store: DeviceStore | None = getattr(app.state, "device_store", None)
return store.restricted() if store is not None else frozenset()
def _device_may(payload: dict[str, Any], request: Request) -> None:
"""Refuse anything a wall panel has no business asking for.
@@ -520,6 +535,18 @@ def get_current_user(request: Request, session: SessionDep, token: TokenDep) ->
CurrentUser = Annotated[User, Depends(get_current_user)]
def get_hidden(request: Request, user: CurrentUser) -> frozenset[str]:
"""The camera messages the caller of this request may not see."""
device = getattr(request.state, "device", None) is not None
return hidden_from(user, request.app, device=device)
HiddenDep = Annotated[frozenset[str], Depends(get_hidden)]
#: Why a camera's values, bytes or live view are refused.
CAMERA_IS_SUPERUSERS = "Only a superuser may see this camera"
def get_flow_controller(request: Request) -> FlowController:
controller: FlowController | None = getattr(
request.app.state, "flow_controller", None