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:
co-authored by
Claude Opus 5.5
parent
02b736c9e8
commit
f679264b3a
@@ -43,12 +43,14 @@ from datetime import datetime, timedelta
|
||||
from typing import Any, cast
|
||||
|
||||
import httpx
|
||||
import orjson
|
||||
import redis
|
||||
from fastapi import APIRouter, Depends, HTTPException, Request
|
||||
from fastapi.concurrency import run_in_threadpool
|
||||
from pydantic import BaseModel, Field, ValidationError, field_validator
|
||||
|
||||
from fluksio.api.deps import (
|
||||
CAMERA_IS_SUPERUSERS,
|
||||
CurrentUser,
|
||||
DeviceStoreDep,
|
||||
get_current_active_superuser,
|
||||
@@ -120,6 +122,10 @@ HELLO_LENGTH = 64
|
||||
#: The most a capability report may weigh. A panel with every header pin
|
||||
#: reported is a few kB.
|
||||
REPORT_MAX = 16 * 1024
|
||||
#: The most it may weigh as kept, with each named ``config_schemas`` entry put
|
||||
#: in place: thirty pins naming one schema send it once and keep it thirty
|
||||
#: times. The P4 panel's is about 7 kB.
|
||||
REPORT_STORED_MAX = 64 * 1024
|
||||
|
||||
|
||||
class _Pending(BaseModel):
|
||||
@@ -690,9 +696,13 @@ async def read_ice(device_id: str, store: DeviceStoreDep, user: CurrentUser) ->
|
||||
|
||||
STUN and TURN servers, the TURN ones with credentials of the caller's own
|
||||
that expire. Empty when none are set, which is enough on one network.
|
||||
Only for whoever may see the device's camera (``DeviceDef.viewers``).
|
||||
"""
|
||||
if await run_in_threadpool(store.find, device_id) is None:
|
||||
device = await run_in_threadpool(store.find, device_id)
|
||||
if device is None:
|
||||
raise _not_found(device_id)
|
||||
if not user.is_superuser and device.viewers != "members":
|
||||
raise HTTPException(status_code=403, detail=CAMERA_IS_SUPERUSERS)
|
||||
servers = [IceServer(**server) for server in ice_servers(str(user.id))]
|
||||
return IceServers(ice_servers=servers, ttl=ICE_TTL_S)
|
||||
|
||||
@@ -745,6 +755,12 @@ async def put_report(device_id: str, request: Request, store: DeviceStoreDep) ->
|
||||
include_url=False, include_input=False, include_context=False
|
||||
),
|
||||
)
|
||||
if len(orjson.dumps(report.stored())) > REPORT_STORED_MAX:
|
||||
raise HTTPException(
|
||||
status_code=413,
|
||||
detail=f"A report is at most {REPORT_STORED_MAX // 1024} KB once "
|
||||
"its config_schemas are put in place",
|
||||
)
|
||||
for part in left_out:
|
||||
logger.warning("Device '%s' reported %s, left out", device_id, part)
|
||||
first = await run_in_threadpool(store.report, device_id, report)
|
||||
|
||||
Reference in New Issue
Block a user