2024-09-28 22:21:42 +03:00
|
|
|
from typing import Optional
|
|
|
|
|
|
2025-05-21 15:02:13 +03:00
|
|
|
from pydantic import Field, field_validator
|
2024-09-28 22:21:42 +03:00
|
|
|
|
|
|
|
|
from .base import FrigateBaseModel
|
|
|
|
|
from .env import EnvString
|
|
|
|
|
|
|
|
|
|
__all__ = ["ProxyConfig", "HeaderMappingConfig"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class HeaderMappingConfig(FrigateBaseModel):
|
|
|
|
|
user: str = Field(
|
2026-02-27 18:55:36 +03:00
|
|
|
default=None,
|
|
|
|
|
title="User header",
|
|
|
|
|
description="Header containing the authenticated username provided by the upstream proxy.",
|
2024-09-28 22:21:42 +03:00
|
|
|
)
|
2025-03-08 19:01:08 +03:00
|
|
|
role: str = Field(
|
|
|
|
|
default=None,
|
2026-02-27 18:55:36 +03:00
|
|
|
title="Role header",
|
|
|
|
|
description="Header containing the authenticated user's role or groups from the upstream proxy.",
|
2025-03-08 19:01:08 +03:00
|
|
|
)
|
2025-08-26 01:58:41 +03:00
|
|
|
role_map: Optional[dict[str, list[str]]] = Field(
|
|
|
|
|
default_factory=dict,
|
2026-02-27 18:55:36 +03:00
|
|
|
title=("Role mapping"),
|
|
|
|
|
description="Map upstream group values to Frigate roles (for example map admin groups to the admin role).",
|
2025-08-26 01:58:41 +03:00
|
|
|
)
|
2024-09-28 22:21:42 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class ProxyConfig(FrigateBaseModel):
|
|
|
|
|
header_map: HeaderMappingConfig = Field(
|
|
|
|
|
default_factory=HeaderMappingConfig,
|
2026-02-27 18:55:36 +03:00
|
|
|
title="Header mapping",
|
|
|
|
|
description="Map incoming proxy headers to Frigate user and role fields for proxy-based auth.",
|
2024-09-28 22:21:42 +03:00
|
|
|
)
|
|
|
|
|
logout_url: Optional[str] = Field(
|
2026-02-27 18:55:36 +03:00
|
|
|
default=None,
|
|
|
|
|
title="Logout URL",
|
|
|
|
|
description="URL to redirect users to when logging out via the proxy.",
|
2024-09-28 22:21:42 +03:00
|
|
|
)
|
|
|
|
|
auth_secret: Optional[EnvString] = Field(
|
|
|
|
|
default=None,
|
2026-02-27 18:55:36 +03:00
|
|
|
title="Proxy secret",
|
|
|
|
|
description="Optional secret checked against the X-Proxy-Secret header to verify trusted proxies.",
|
2024-09-28 22:21:42 +03:00
|
|
|
)
|
2025-05-06 05:42:24 +03:00
|
|
|
default_role: Optional[str] = Field(
|
2026-02-27 18:55:36 +03:00
|
|
|
default="viewer",
|
|
|
|
|
title="Default role",
|
|
|
|
|
description="Default role assigned to proxy-authenticated users when no role mapping applies (admin or viewer).",
|
2025-05-06 05:42:24 +03:00
|
|
|
)
|
2025-05-21 15:02:13 +03:00
|
|
|
separator: Optional[str] = Field(
|
|
|
|
|
default=",",
|
2026-02-27 18:55:36 +03:00
|
|
|
title="Separator character",
|
|
|
|
|
description="Character used to split multiple values provided in proxy headers.",
|
2025-05-21 15:02:13 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
@field_validator("separator", mode="before")
|
|
|
|
|
@classmethod
|
|
|
|
|
def validate_separator_length(cls, v):
|
|
|
|
|
if v is not None and len(v) != 1:
|
|
|
|
|
raise ValueError("Separator must be exactly one character")
|
|
|
|
|
return v
|