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).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0138N7k5PT4dcR1iEqXaaQ9k
This commit is contained in:
Melvin Strobl
2026-10-17 09:20:04 +02:00
co-authored by Claude Opus 5.5
parent 02b736c9e8
commit f679264b3a
36 changed files with 1268 additions and 152 deletions
+37
View File
@@ -68,6 +68,9 @@ PORT_PATTERN = re.compile(r"^[a-z0-9_.]+$")
#: The node type that stands for a device in a flow.
DEVICE_TYPE = "device"
#: The dtypes a device's ``viewers`` setting covers: what a camera sends.
CAMERA_DTYPES = frozenset({"image", "video"})
@dataclass(frozen=True)
class Binding:
@@ -104,6 +107,7 @@ class DeviceBinding(BaseModel):
port: str
message: str
direction: Literal["in", "out"]
dtype: str = ""
def bindings_of(flow: FlowDef) -> list[Binding]:
@@ -149,6 +153,11 @@ class DeviceDef(BaseModel):
#: touched rather than pointed at. A fact about the screen, not about any
#: dashboard on it.
touch: bool = False
#: Who may see what the device's camera sends, its ``image`` and ``video``
#: ``in`` messages, their bytes and its live view: superusers only, or
#: every member too. A device credential is bounded by its dashboards
#: instead, which a superuser assigned.
viewers: Literal["superusers", "members"] = "superusers"
#: Bumped on every save. A save based on an older one is refused.
version: int = 0
@@ -401,6 +410,9 @@ class DeviceStore:
self._states_seen: (
tuple[tuple[int, int, int], dict[str, DeviceState]] | None
) = None
#: The camera messages only superusers may see, at the flow store
#: revision they were worked out at. A device save commits there too.
self._restricted: tuple[int, frozenset[str]] | None = None
def _file(self, device_id: str) -> Path:
return self.root / f"{checked(device_id)}.json"
@@ -459,6 +471,30 @@ class DeviceStore:
found.append(binding)
return found
def restricted(self) -> frozenset[str]:
"""The messages only a superuser may see: what the cameras of devices
whose ``viewers`` are superusers publish, their ``image`` and ``video``
``in`` ports.
Asked on every value a person's socket carries, so worked out again
only once the flow store commits, which every device save does.
"""
revision = self.flows.revision
held = self._restricted
if held is not None and held[0] == revision:
return held[1]
wiring = self.wiring()
found = frozenset(
binding.message
for device in self.list()
if device.viewers == "superusers"
for binding in wiring.get(device.id, ())
if binding.direction == "in" and binding.dtype in CAMERA_DTYPES
)
# Keyed by the revision read before, so a commit meanwhile is seen.
self._restricted = (revision, found)
return found
def io(self, device_id: str) -> list[DeviceIo]:
"""The ports as the device reads them."""
return [
@@ -481,6 +517,7 @@ class DeviceStore:
port=b.port,
message=b.message,
direction=b.direction,
dtype=b.dtype,
)
for b in self.wiring().get(device_id, [])
),