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:
@@ -669,11 +669,11 @@ class CloudConnector:
|
||||
"""
|
||||
from sqlmodel import Session
|
||||
|
||||
from fluksio.api.deps import user_from_token
|
||||
from fluksio.api.deps import hidden_from, user_from_token
|
||||
from fluksio.api.routes.flows import (
|
||||
carried,
|
||||
demand_frame,
|
||||
device_of,
|
||||
event_for_panel,
|
||||
panel_scope,
|
||||
revoked,
|
||||
snapshot_payload,
|
||||
@@ -719,12 +719,14 @@ class CloudConnector:
|
||||
|
||||
await socket.send(_dump({"op": "ws_open_ok", "id": stream_id}))
|
||||
|
||||
# The cameras a person may not see, looked at again per event.
|
||||
hidden = hidden_from(user, self._app, device=only is not None)
|
||||
controller = getattr(self._app.state, "flow_controller", None)
|
||||
told: list[str] = []
|
||||
if controller is not None:
|
||||
# A device here sends its frames over HTTP: the tunnel carries
|
||||
# text only.
|
||||
snapshot = snapshot_payload(controller, only, device, "http")
|
||||
snapshot = snapshot_payload(controller, only, device, "http", hidden)
|
||||
told = list(snapshot.get("demand", []))
|
||||
await socket.send(
|
||||
_dump({"op": "ws_msg", "id": stream_id, "text": _dump(snapshot)})
|
||||
@@ -743,7 +745,7 @@ class CloudConnector:
|
||||
|
||||
def heard(text: str) -> None:
|
||||
nonlocal wanted
|
||||
asked = wanted_names(text, only)
|
||||
asked = wanted_names(text, only, hidden)
|
||||
if asked is not None:
|
||||
wanted = asked
|
||||
demand.want(viewer, asked)
|
||||
@@ -754,6 +756,7 @@ class CloudConnector:
|
||||
person=str(user.id) if only is None else "",
|
||||
device=device,
|
||||
devices=getattr(self._app.state, "device_store", None),
|
||||
superuser=user.is_superuser,
|
||||
)
|
||||
|
||||
self._listeners[stream_id] = heard
|
||||
@@ -793,15 +796,37 @@ class CloudConnector:
|
||||
if sender not in done:
|
||||
continue
|
||||
event = sender.result()
|
||||
if event.get("type") == "device_demand":
|
||||
# Behind far enough to lose events, a device catches up
|
||||
# as after a dashboard: the lost one may have been its
|
||||
# demand or its unpairing. A person whose cameras opened
|
||||
# or closed is sent what may be seen now.
|
||||
resync = only is not None and event_bus.dropped(queue)
|
||||
if only is None:
|
||||
fresh = hidden_from(user, self._app)
|
||||
if fresh != hidden:
|
||||
hidden = fresh
|
||||
wanted -= hidden
|
||||
demand.want(viewer, wanted)
|
||||
resync = True
|
||||
kind = event.get("type")
|
||||
if kind == "device_demand":
|
||||
# For the device it names, and for nobody else.
|
||||
if device and event.get("device") == device:
|
||||
text = demand_frame(list(event.get("ports") or []))
|
||||
await socket.send(
|
||||
_dump({"op": "ws_msg", "id": stream_id, "text": text})
|
||||
)
|
||||
elif only is not None and kind == "dashboard_changed":
|
||||
resync = True
|
||||
elif carried(event, only, hidden):
|
||||
await socket.send(
|
||||
_dump(
|
||||
{"op": "ws_msg", "id": stream_id, "text": _dump(event)}
|
||||
)
|
||||
)
|
||||
if not resync:
|
||||
continue
|
||||
if only is not None and event.get("type") == "dashboard_changed":
|
||||
if only is not None:
|
||||
if device and revoked(token, self._app):
|
||||
# Unpaired or deleted: 1008 sends it to check.
|
||||
await socket.send(
|
||||
@@ -817,24 +842,26 @@ class CloudConnector:
|
||||
only = panel_scope(token, self._app) or set()
|
||||
wanted &= only
|
||||
demand.want(viewer, wanted)
|
||||
if controller is not None:
|
||||
catch_up = snapshot_payload(
|
||||
controller, only, device, "http"
|
||||
if controller is not None:
|
||||
catch_up = snapshot_payload(
|
||||
controller, only, device, "http", hidden
|
||||
)
|
||||
await socket.send(
|
||||
_dump(
|
||||
{
|
||||
"op": "ws_msg",
|
||||
"id": stream_id,
|
||||
"text": _dump(catch_up),
|
||||
}
|
||||
)
|
||||
await socket.send(
|
||||
_dump(
|
||||
{
|
||||
"op": "ws_msg",
|
||||
"id": stream_id,
|
||||
"text": _dump(catch_up),
|
||||
}
|
||||
)
|
||||
)
|
||||
if kind == "dashboard_changed" and only is not None:
|
||||
# After the snapshot, as the device socket sends it.
|
||||
await socket.send(
|
||||
_dump(
|
||||
{"op": "ws_msg", "id": stream_id, "text": _dump(event)}
|
||||
)
|
||||
elif only is not None and not event_for_panel(event, only):
|
||||
continue
|
||||
await socket.send(
|
||||
_dump({"op": "ws_msg", "id": stream_id, "text": _dump(event)})
|
||||
)
|
||||
)
|
||||
except asyncio.CancelledError:
|
||||
raise
|
||||
except Exception as exc:
|
||||
|
||||
Reference in New Issue
Block a user