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
@@ -18,8 +18,11 @@ from sqlmodel import Session
|
||||
from starlette.concurrency import run_in_threadpool
|
||||
|
||||
from fluksio.api.deps import (
|
||||
CAMERA_IS_SUPERUSERS,
|
||||
FlowControllerDep,
|
||||
digests_of,
|
||||
get_current_active_superuser,
|
||||
hidden_from,
|
||||
user_from_token,
|
||||
worker_claims,
|
||||
)
|
||||
@@ -63,6 +66,8 @@ def artifact_caller(request: Request) -> str:
|
||||
user = user_from_token(session, token, request)
|
||||
if user is None:
|
||||
raise HTTPException(status_code=401, detail="Not authenticated")
|
||||
# For the camera check a fetch is held to, which a worker is not.
|
||||
request.state.person = user
|
||||
return user.email
|
||||
|
||||
|
||||
@@ -103,26 +108,30 @@ async def put_artifact(
|
||||
watching now, which the oldest of falls out of memory rather than being
|
||||
kept. A worker on another host or a device publishing a camera sends this.
|
||||
It is read into memory, where the ring holds it, and never touches the
|
||||
disk.
|
||||
disk, so it is held to ``MAX_FRAME_BYTES`` rather than the store's cap.
|
||||
"""
|
||||
store = _store(request)
|
||||
cap = settings.MAX_ARTIFACT_BYTES
|
||||
ring = store.volatile if volatile else None
|
||||
cap = settings.MAX_FRAME_BYTES if ring is not None else settings.MAX_ARTIFACT_BYTES
|
||||
declared = request.headers.get("content-length")
|
||||
if cap and declared and declared.isdigit() and int(declared) > cap:
|
||||
raise HTTPException(
|
||||
status_code=413, detail=f"An artifact may be at most {cap} bytes"
|
||||
)
|
||||
ring = store.volatile if volatile else None
|
||||
if ring is not None:
|
||||
body = bytearray()
|
||||
# The chunks as they came, joined once: the frame is copied into
|
||||
# memory one time, never past the cap.
|
||||
chunks: list[bytes] = []
|
||||
size = 0
|
||||
async for chunk in request.stream():
|
||||
body += chunk
|
||||
if cap and len(body) > cap:
|
||||
size += len(chunk)
|
||||
if cap and size > cap:
|
||||
raise HTTPException(
|
||||
status_code=413,
|
||||
detail=f"An artifact may be at most {cap} bytes",
|
||||
)
|
||||
return await run_in_threadpool(ring.put, [bytes(body)], name, media_type)
|
||||
chunks.append(chunk)
|
||||
return await run_in_threadpool(ring.put, chunks, name, media_type)
|
||||
handle = tempfile.NamedTemporaryFile(dir=store.root, delete=False)
|
||||
written = 0
|
||||
try:
|
||||
@@ -158,6 +167,15 @@ def get_artifact(
|
||||
scrubbing through a file asks for them.
|
||||
"""
|
||||
store = _store(request)
|
||||
user = getattr(request.state, "person", None)
|
||||
if user is not None:
|
||||
# What a camera only superusers may see points at, now or in its last
|
||||
# few frames. A worker's node reads anything, as node code can.
|
||||
device = getattr(request.state, "device", None) is not None
|
||||
hidden = hidden_from(user, request.app, device=device)
|
||||
controller = getattr(request.app.state, "flow_controller", None)
|
||||
if hidden and digest in digests_of(controller, set(hidden)):
|
||||
raise HTTPException(status_code=403, detail=CAMERA_IS_SUPERUSERS)
|
||||
path = store.path(digest)
|
||||
# A live frame is held in memory, not on disk.
|
||||
frame = store.volatile.get(digest) if path is None and store.volatile else None
|
||||
|
||||
Reference in New Issue
Block a user