mirror of
https://github.com/blakeblackshear/frigate.git
synced 2025-12-18 19:16:42 +03:00
consider anonymous user authenticated (#21335)
Some checks are pending
CI / AMD64 Build (push) Waiting to run
CI / ARM Build (push) Waiting to run
CI / Jetson Jetpack 6 (push) Waiting to run
CI / AMD64 Extra Build (push) Blocked by required conditions
CI / ARM Extra Build (push) Blocked by required conditions
CI / Synaptics Build (push) Blocked by required conditions
CI / Assemble and push default build (push) Blocked by required conditions
Some checks are pending
CI / AMD64 Build (push) Waiting to run
CI / ARM Build (push) Waiting to run
CI / Jetson Jetpack 6 (push) Waiting to run
CI / AMD64 Extra Build (push) Blocked by required conditions
CI / ARM Extra Build (push) Blocked by required conditions
CI / Synaptics Build (push) Blocked by required conditions
CI / Assemble and push default build (push) Blocked by required conditions
* consider anonymous user authenticated * simplify and update comments
This commit is contained in:
parent
78eace258e
commit
3edfd905de
@ -143,17 +143,6 @@ def require_admin_by_default():
|
|||||||
return admin_checker
|
return admin_checker
|
||||||
|
|
||||||
|
|
||||||
def _is_authenticated(request: Request) -> bool:
|
|
||||||
"""
|
|
||||||
Helper to determine if a request is from an authenticated user.
|
|
||||||
|
|
||||||
Returns True if the request has a valid authenticated user (not anonymous).
|
|
||||||
Port 5000 internal requests are considered anonymous despite having admin role.
|
|
||||||
"""
|
|
||||||
username = request.headers.get("remote-user")
|
|
||||||
return username is not None and username != "anonymous"
|
|
||||||
|
|
||||||
|
|
||||||
def allow_public():
|
def allow_public():
|
||||||
"""
|
"""
|
||||||
Override dependency to allow unauthenticated access to an endpoint.
|
Override dependency to allow unauthenticated access to an endpoint.
|
||||||
@ -173,27 +162,24 @@ def allow_public():
|
|||||||
|
|
||||||
def allow_any_authenticated():
|
def allow_any_authenticated():
|
||||||
"""
|
"""
|
||||||
Override dependency to allow any authenticated user (bypass admin requirement).
|
Override dependency to allow any request that passed through the /auth endpoint.
|
||||||
|
|
||||||
Allows:
|
Allows:
|
||||||
- Port 5000 internal requests (have admin role despite anonymous user)
|
- Port 5000 internal requests (remote-user: "anonymous", remote-role: "admin")
|
||||||
- Any authenticated user with a real username (not "anonymous")
|
- Authenticated users with JWT tokens (remote-user: username)
|
||||||
|
- Unauthenticated requests when auth is disabled (remote-user: "anonymous")
|
||||||
|
|
||||||
Rejects:
|
Rejects:
|
||||||
- Port 8971 requests with anonymous user (auth disabled, no proxy auth)
|
- Requests with no remote-user header (did not pass through /auth endpoint)
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
@router.get("/authenticated-endpoint", dependencies=[Depends(allow_any_authenticated())])
|
@router.get("/authenticated-endpoint", dependencies=[Depends(allow_any_authenticated())])
|
||||||
"""
|
"""
|
||||||
|
|
||||||
async def auth_checker(request: Request):
|
async def auth_checker(request: Request):
|
||||||
# Port 5000 requests have admin role and should be allowed
|
# Ensure a remote-user has been set by the /auth endpoint
|
||||||
role = request.headers.get("remote-role")
|
username = request.headers.get("remote-user")
|
||||||
if role == "admin":
|
if username is None:
|
||||||
return
|
|
||||||
|
|
||||||
# Otherwise require a real authenticated user (not anonymous)
|
|
||||||
if not _is_authenticated(request):
|
|
||||||
raise HTTPException(status_code=401, detail="Authentication required")
|
raise HTTPException(status_code=401, detail="Authentication required")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user