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
+49
View File
@@ -240,6 +240,55 @@ def test_an_upload_may_ask_for_the_ring(
store.volatile = previous
def test_a_ring_never_holds_more_than_its_bound_and_one_frame(tmp_path):
"""Frames of every size, the bound never passed by more than the newest."""
ring = VolatileStore(tmp_path / "ring", limit_bytes=10_000)
sizes = [700, 9_000, 30, 12_000, 4_000, 4_000, 2_500, 9_999, 1, 6_000] * 3
for index, size in enumerate(sizes):
ring.put([bytes([index % 256]) * size])
assert ring.size <= ring.limit_bytes or len(ring._frames) == 1
assert ring.size <= ring.limit_bytes + size
def test_a_volatile_upload_is_held_to_the_frame_cap(
client: TestClient,
superuser_token_headers: dict[str, str],
monkeypatch: pytest.MonkeyPatch,
) -> None:
"""A frame is held in memory whole, so it is refused past a few MB before
any of it is read, and a chunked one as soon as it passes the cap."""
store = client.app.state.artifact_store
previous = store.volatile
store.volatile = VolatileStore(
store.root.parent / "test-ring", limit_bytes=1_000_000
)
monkeypatch.setattr(settings, "MAX_FRAME_BYTES", 1000)
url = f"{settings.API_V1_STR}/artifacts?volatile=1&media_type=image%2Fjpeg"
try:
declared = client.put(url, headers=superuser_token_headers, content=b"x" * 1001)
assert declared.status_code == 413
def chunks():
for _ in range(5):
yield b"x" * 400
chunked = client.put(url, headers=superuser_token_headers, content=chunks())
assert chunked.status_code == 413
assert store.volatile.size == 0
fits = client.put(url, headers=superuser_token_headers, content=b"x" * 1000)
assert fits.status_code == 200, fits.text
# The durable store keeps its own, larger cap.
kept = client.put(
f"{settings.API_V1_STR}/artifacts",
headers=superuser_token_headers,
content=b"y" * 5000,
)
assert kept.status_code == 200, kept.text
finally:
store.volatile = previous
def test_a_type_that_can_run_script_is_served_sandboxed(
client: TestClient, superuser_token_headers: dict[str, str]
) -> None: