mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-05-09 15:05:26 +03:00
Compare commits
2 Commits
01392e03ac
...
1c26bc289e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1c26bc289e | ||
|
|
0371b60c71 |
@ -994,7 +994,7 @@ MemryX `.dfp` models are automatically downloaded at runtime, if enabled, to the
|
|||||||
|
|
||||||
#### YOLO-NAS
|
#### YOLO-NAS
|
||||||
|
|
||||||
The [YOLO-NAS](https://github.com/Deci-AI/super-gradients/blob/master/YOLONAS.md) model included in this detector is downloaded from the [Models Section](#downloading-yolo-nas-model) and compiled to DFP with [mx_nc](https://developer.memryx.com/tools/neural_compiler.html#usage).
|
The [YOLO-NAS](https://github.com/Deci-AI/super-gradients/blob/master/YOLONAS.md) model included in this detector is downloaded from the [Models Section](#downloading-yolo-nas-model) and compiled to DFP with [mx_nc](https://developer.memryx.com/2p1/tools/neural_compiler.html#usage).
|
||||||
|
|
||||||
**Note:** The default model for the MemryX detector is YOLO-NAS 320x320.
|
**Note:** The default model for the MemryX detector is YOLO-NAS 320x320.
|
||||||
|
|
||||||
@ -1028,7 +1028,7 @@ model:
|
|||||||
|
|
||||||
#### YOLOv9
|
#### YOLOv9
|
||||||
|
|
||||||
The YOLOv9s model included in this detector is downloaded from [the original GitHub](https://github.com/WongKinYiu/yolov9) like in the [Models Section](#yolov9-1) and compiled to DFP with [mx_nc](https://developer.memryx.com/tools/neural_compiler.html#usage).
|
The YOLOv9s model included in this detector is downloaded from [the original GitHub](https://github.com/WongKinYiu/yolov9) like in the [Models Section](#yolov9-1) and compiled to DFP with [mx_nc](https://developer.memryx.com/2p1/tools/neural_compiler.html#usage).
|
||||||
|
|
||||||
##### Configuration
|
##### Configuration
|
||||||
|
|
||||||
@ -1122,7 +1122,24 @@ To use your own model:
|
|||||||
|
|
||||||
5. Update the `labelmap_path` to match your custom model's labels.
|
5. Update the `labelmap_path` to match your custom model's labels.
|
||||||
|
|
||||||
For detailed instructions on compiling models, refer to the [MemryX Compiler](https://developer.memryx.com/tools/neural_compiler.html#usage) docs and [Tutorials](https://developer.memryx.com/tutorials/tutorials.html).
|
#### Compile the Model
|
||||||
|
|
||||||
|
Custom models must be compiled using **MemryX SDK 2.1**.
|
||||||
|
|
||||||
|
Before compiling your model, install the MemryX Neural Compiler tools from the
|
||||||
|
[Install Tools](https://developer.memryx.com/2p1/get_started/install_tools.html) page on the **host**.
|
||||||
|
|
||||||
|
Once the SDK 2.1 environment is set up, follow the
|
||||||
|
[MemryX Compiler](https://developer.memryx.com/2p1/tools/neural_compiler.html#usage) documentation to compile your model.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
mx_nc -m ./yolov9.onnx --dfp_fname ./yolov9.dfp -is "1,3,640,640" -c 4 --autocrop -v
|
||||||
|
```
|
||||||
|
> **Note:** `-is` specifies the input shape. Use your model's input dimensions.
|
||||||
|
|
||||||
|
For detailed instructions on compiling models, refer to the [MemryX Compiler](https://developer.memryx.com/2p1/tools/neural_compiler.html#usage) docs and [Tutorials](https://developer.memryx.com/2p1/tutorials/tutorials.html).
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
# The detector automatically selects the default model if nothing is provided in the config.
|
# The detector automatically selects the default model if nothing is provided in the config.
|
||||||
|
|||||||
@ -297,7 +297,7 @@ The MemryX MX3 Accelerator is available in the M.2 2280 form factor (like an NVM
|
|||||||
|
|
||||||
#### Installation
|
#### Installation
|
||||||
|
|
||||||
To get started with MX3 hardware setup for your system, refer to the [Hardware Setup Guide](https://developer.memryx.com/get_started/hardware_setup.html).
|
To get started with MX3 hardware setup for your system, refer to the [Hardware Setup Guide](https://developer.memryx.com/2p1/get_started/hardware_setup.html).
|
||||||
|
|
||||||
Then follow these steps for installing the correct driver/runtime configuration:
|
Then follow these steps for installing the correct driver/runtime configuration:
|
||||||
|
|
||||||
@ -306,6 +306,12 @@ Then follow these steps for installing the correct driver/runtime configuration:
|
|||||||
3. Run the script with `./user_installation.sh`
|
3. Run the script with `./user_installation.sh`
|
||||||
4. **Restart your computer** to complete driver installation.
|
4. **Restart your computer** to complete driver installation.
|
||||||
|
|
||||||
|
:::warning
|
||||||
|
|
||||||
|
For manual setup, use **MemryX SDK 2.1** only. Other SDK versions are not supported for this setup. See the [SDK 2.1 documentation](https://developer.memryx.com/2p1/index.html)
|
||||||
|
|
||||||
|
:::
|
||||||
|
|
||||||
#### Setup
|
#### Setup
|
||||||
|
|
||||||
To set up Frigate, follow the default installation instructions, for example: `ghcr.io/blakeblackshear/frigate:stable`
|
To set up Frigate, follow the default installation instructions, for example: `ghcr.io/blakeblackshear/frigate:stable`
|
||||||
|
|||||||
@ -17,9 +17,90 @@ from ws4py.websocket import WebSocket as WebSocket_
|
|||||||
|
|
||||||
from frigate.comms.base_communicator import Communicator
|
from frigate.comms.base_communicator import Communicator
|
||||||
from frigate.config import FrigateConfig
|
from frigate.config import FrigateConfig
|
||||||
|
from frigate.const import (
|
||||||
|
CLEAR_ONGOING_REVIEW_SEGMENTS,
|
||||||
|
EXPIRE_AUDIO_ACTIVITY,
|
||||||
|
INSERT_MANY_RECORDINGS,
|
||||||
|
INSERT_PREVIEW,
|
||||||
|
NOTIFICATION_TEST,
|
||||||
|
REQUEST_REGION_GRID,
|
||||||
|
UPDATE_AUDIO_ACTIVITY,
|
||||||
|
UPDATE_AUDIO_TRANSCRIPTION_STATE,
|
||||||
|
UPDATE_BIRDSEYE_LAYOUT,
|
||||||
|
UPDATE_CAMERA_ACTIVITY,
|
||||||
|
UPDATE_EMBEDDINGS_REINDEX_PROGRESS,
|
||||||
|
UPDATE_EVENT_DESCRIPTION,
|
||||||
|
UPDATE_MODEL_STATE,
|
||||||
|
UPDATE_REVIEW_DESCRIPTION,
|
||||||
|
UPSERT_REVIEW_SEGMENT,
|
||||||
|
)
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
# Internal IPC topics — NEVER allowed from WebSocket, regardless of role
|
||||||
|
_WS_BLOCKED_TOPICS = frozenset(
|
||||||
|
{
|
||||||
|
INSERT_MANY_RECORDINGS,
|
||||||
|
INSERT_PREVIEW,
|
||||||
|
REQUEST_REGION_GRID,
|
||||||
|
UPSERT_REVIEW_SEGMENT,
|
||||||
|
CLEAR_ONGOING_REVIEW_SEGMENTS,
|
||||||
|
UPDATE_CAMERA_ACTIVITY,
|
||||||
|
UPDATE_AUDIO_ACTIVITY,
|
||||||
|
EXPIRE_AUDIO_ACTIVITY,
|
||||||
|
UPDATE_EVENT_DESCRIPTION,
|
||||||
|
UPDATE_REVIEW_DESCRIPTION,
|
||||||
|
UPDATE_MODEL_STATE,
|
||||||
|
UPDATE_EMBEDDINGS_REINDEX_PROGRESS,
|
||||||
|
UPDATE_BIRDSEYE_LAYOUT,
|
||||||
|
UPDATE_AUDIO_TRANSCRIPTION_STATE,
|
||||||
|
NOTIFICATION_TEST,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
# Read-only topics any authenticated user (including viewer) can send
|
||||||
|
_WS_VIEWER_TOPICS = frozenset(
|
||||||
|
{
|
||||||
|
"onConnect",
|
||||||
|
"modelState",
|
||||||
|
"audioTranscriptionState",
|
||||||
|
"birdseyeLayout",
|
||||||
|
"embeddingsReindexProgress",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def _check_ws_authorization(
|
||||||
|
topic: str,
|
||||||
|
role_header: str | None,
|
||||||
|
separator: str,
|
||||||
|
) -> bool:
|
||||||
|
"""Check if a WebSocket message is authorized.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
topic: The message topic.
|
||||||
|
role_header: The HTTP_REMOTE_ROLE header value, or None.
|
||||||
|
separator: The role separator character from proxy config.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
True if authorized, False if blocked.
|
||||||
|
"""
|
||||||
|
# Block IPC-only topics unconditionally
|
||||||
|
if topic in _WS_BLOCKED_TOPICS:
|
||||||
|
return False
|
||||||
|
|
||||||
|
# No role header: default to viewer (fail-closed)
|
||||||
|
if role_header is None:
|
||||||
|
return topic in _WS_VIEWER_TOPICS
|
||||||
|
|
||||||
|
# Check if any role is admin
|
||||||
|
roles = [r.strip() for r in role_header.split(separator)]
|
||||||
|
if "admin" in roles:
|
||||||
|
return True
|
||||||
|
|
||||||
|
# Non-admin: only viewer topics allowed
|
||||||
|
return topic in _WS_VIEWER_TOPICS
|
||||||
|
|
||||||
|
|
||||||
class WebSocket(WebSocket_): # type: ignore[misc]
|
class WebSocket(WebSocket_): # type: ignore[misc]
|
||||||
def unhandled_error(self, error: Any) -> None:
|
def unhandled_error(self, error: Any) -> None:
|
||||||
@ -49,6 +130,7 @@ class WebSocketClient(Communicator):
|
|||||||
|
|
||||||
class _WebSocketHandler(WebSocket):
|
class _WebSocketHandler(WebSocket):
|
||||||
receiver = self._dispatcher
|
receiver = self._dispatcher
|
||||||
|
role_separator = self.config.proxy.separator or ","
|
||||||
|
|
||||||
def received_message(self, message: WebSocket.received_message) -> None: # type: ignore[name-defined]
|
def received_message(self, message: WebSocket.received_message) -> None: # type: ignore[name-defined]
|
||||||
try:
|
try:
|
||||||
@ -63,11 +145,25 @@ class WebSocketClient(Communicator):
|
|||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
logger.debug(
|
topic = json_message["topic"]
|
||||||
f"Publishing mqtt message from websockets at {json_message['topic']}."
|
|
||||||
|
# Authorization check (skip when environ is None — direct internal connection)
|
||||||
|
role_header = (
|
||||||
|
self.environ.get("HTTP_REMOTE_ROLE") if self.environ else None
|
||||||
)
|
)
|
||||||
|
if self.environ is not None and not _check_ws_authorization(
|
||||||
|
topic, role_header, self.role_separator
|
||||||
|
):
|
||||||
|
logger.warning(
|
||||||
|
"Blocked unauthorized WebSocket message: topic=%s, role=%s",
|
||||||
|
topic,
|
||||||
|
role_header,
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
|
logger.debug(f"Publishing mqtt message from websockets at {topic}.")
|
||||||
self.receiver(
|
self.receiver(
|
||||||
json_message["topic"],
|
topic,
|
||||||
json_message["payload"],
|
json_message["payload"],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
166
frigate/test/test_ws_auth.py
Normal file
166
frigate/test/test_ws_auth.py
Normal file
@ -0,0 +1,166 @@
|
|||||||
|
"""Tests for WebSocket authorization checks."""
|
||||||
|
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
from frigate.comms.ws import _check_ws_authorization
|
||||||
|
from frigate.const import INSERT_MANY_RECORDINGS, UPDATE_CAMERA_ACTIVITY
|
||||||
|
|
||||||
|
|
||||||
|
class TestCheckWsAuthorization(unittest.TestCase):
|
||||||
|
"""Tests for the _check_ws_authorization pure function."""
|
||||||
|
|
||||||
|
DEFAULT_SEPARATOR = ","
|
||||||
|
|
||||||
|
# --- IPC topic blocking (unconditional, regardless of role) ---
|
||||||
|
|
||||||
|
def test_ipc_topic_blocked_for_admin(self):
|
||||||
|
self.assertFalse(
|
||||||
|
_check_ws_authorization(
|
||||||
|
INSERT_MANY_RECORDINGS, "admin", self.DEFAULT_SEPARATOR
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_ipc_topic_blocked_for_viewer(self):
|
||||||
|
self.assertFalse(
|
||||||
|
_check_ws_authorization(
|
||||||
|
UPDATE_CAMERA_ACTIVITY, "viewer", self.DEFAULT_SEPARATOR
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_ipc_topic_blocked_when_no_role(self):
|
||||||
|
self.assertFalse(
|
||||||
|
_check_ws_authorization(
|
||||||
|
INSERT_MANY_RECORDINGS, None, self.DEFAULT_SEPARATOR
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
# --- Viewer allowed topics ---
|
||||||
|
|
||||||
|
def test_viewer_can_send_on_connect(self):
|
||||||
|
self.assertTrue(
|
||||||
|
_check_ws_authorization("onConnect", "viewer", self.DEFAULT_SEPARATOR)
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_viewer_can_send_model_state(self):
|
||||||
|
self.assertTrue(
|
||||||
|
_check_ws_authorization("modelState", "viewer", self.DEFAULT_SEPARATOR)
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_viewer_can_send_audio_transcription_state(self):
|
||||||
|
self.assertTrue(
|
||||||
|
_check_ws_authorization(
|
||||||
|
"audioTranscriptionState", "viewer", self.DEFAULT_SEPARATOR
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_viewer_can_send_birdseye_layout(self):
|
||||||
|
self.assertTrue(
|
||||||
|
_check_ws_authorization("birdseyeLayout", "viewer", self.DEFAULT_SEPARATOR)
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_viewer_can_send_embeddings_reindex_progress(self):
|
||||||
|
self.assertTrue(
|
||||||
|
_check_ws_authorization(
|
||||||
|
"embeddingsReindexProgress", "viewer", self.DEFAULT_SEPARATOR
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
# --- Viewer blocked from admin topics ---
|
||||||
|
|
||||||
|
def test_viewer_blocked_from_restart(self):
|
||||||
|
self.assertFalse(
|
||||||
|
_check_ws_authorization("restart", "viewer", self.DEFAULT_SEPARATOR)
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_viewer_blocked_from_camera_detect_set(self):
|
||||||
|
self.assertFalse(
|
||||||
|
_check_ws_authorization(
|
||||||
|
"front_door/detect/set", "viewer", self.DEFAULT_SEPARATOR
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_viewer_blocked_from_camera_ptz(self):
|
||||||
|
self.assertFalse(
|
||||||
|
_check_ws_authorization("front_door/ptz", "viewer", self.DEFAULT_SEPARATOR)
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_viewer_blocked_from_global_notifications_set(self):
|
||||||
|
self.assertFalse(
|
||||||
|
_check_ws_authorization(
|
||||||
|
"notifications/set", "viewer", self.DEFAULT_SEPARATOR
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_viewer_blocked_from_camera_notifications_suspend(self):
|
||||||
|
self.assertFalse(
|
||||||
|
_check_ws_authorization(
|
||||||
|
"front_door/notifications/suspend", "viewer", self.DEFAULT_SEPARATOR
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_viewer_blocked_from_arbitrary_unknown_topic(self):
|
||||||
|
self.assertFalse(
|
||||||
|
_check_ws_authorization(
|
||||||
|
"some_random_topic", "viewer", self.DEFAULT_SEPARATOR
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
# --- Admin access ---
|
||||||
|
|
||||||
|
def test_admin_can_send_restart(self):
|
||||||
|
self.assertTrue(
|
||||||
|
_check_ws_authorization("restart", "admin", self.DEFAULT_SEPARATOR)
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_admin_can_send_camera_detect_set(self):
|
||||||
|
self.assertTrue(
|
||||||
|
_check_ws_authorization(
|
||||||
|
"front_door/detect/set", "admin", self.DEFAULT_SEPARATOR
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_admin_can_send_camera_ptz(self):
|
||||||
|
self.assertTrue(
|
||||||
|
_check_ws_authorization("front_door/ptz", "admin", self.DEFAULT_SEPARATOR)
|
||||||
|
)
|
||||||
|
|
||||||
|
# --- Comma-separated roles ---
|
||||||
|
|
||||||
|
def test_comma_separated_admin_viewer_grants_admin(self):
|
||||||
|
self.assertTrue(
|
||||||
|
_check_ws_authorization("restart", "admin,viewer", self.DEFAULT_SEPARATOR)
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_comma_separated_viewer_admin_grants_admin(self):
|
||||||
|
self.assertTrue(
|
||||||
|
_check_ws_authorization("restart", "viewer,admin", self.DEFAULT_SEPARATOR)
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_comma_separated_with_spaces(self):
|
||||||
|
self.assertTrue(
|
||||||
|
_check_ws_authorization("restart", "viewer, admin", self.DEFAULT_SEPARATOR)
|
||||||
|
)
|
||||||
|
|
||||||
|
# --- Custom separator ---
|
||||||
|
|
||||||
|
def test_pipe_separator(self):
|
||||||
|
self.assertTrue(_check_ws_authorization("restart", "viewer|admin", "|"))
|
||||||
|
|
||||||
|
def test_pipe_separator_no_admin(self):
|
||||||
|
self.assertFalse(_check_ws_authorization("restart", "viewer|editor", "|"))
|
||||||
|
|
||||||
|
# --- No role header (fail-closed) ---
|
||||||
|
|
||||||
|
def test_no_role_header_blocks_admin_topics(self):
|
||||||
|
self.assertFalse(
|
||||||
|
_check_ws_authorization("restart", None, self.DEFAULT_SEPARATOR)
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_no_role_header_allows_viewer_topics(self):
|
||||||
|
self.assertTrue(
|
||||||
|
_check_ws_authorization("onConnect", None, self.DEFAULT_SEPARATOR)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
||||||
Loading…
Reference in New Issue
Block a user