authentik.outposts.permissions
Outpost permissions
1"""Outpost permissions""" 2 3from rest_framework.permissions import BasePermission 4from rest_framework.request import Request 5 6from authentik.core.models import User, UserTypes 7from authentik.outposts.models import USER_PREFIX_OUTPOSTS 8from authentik.root.middleware import ClientIPMiddleware 9 10 11def is_outpost_service_account(user: User | None) -> bool: 12 """Check if `user` is the service account of an outpost""" 13 if not user or not user.is_authenticated: 14 return False 15 if user.type != UserTypes.INTERNAL_SERVICE_ACCOUNT: 16 return False 17 return user.username.startswith(USER_PREFIX_OUTPOSTS) 18 19 20class IsOutpostServiceAccount(BasePermission): 21 """Permission class which only allows the service accounts of outposts""" 22 23 def has_permission(self, request: Request, view) -> bool: 24 return is_outpost_service_account(request.user) 25 26 27class IsOutpostDelegatedRequest(BasePermission): 28 """Permission class which only allows requests that an outpost sends on behalf of 29 another user, authenticated by the outpost's own token""" 30 31 def has_permission(self, request: Request, view) -> bool: 32 return is_outpost_service_account(ClientIPMiddleware.get_outpost_user(request))
12def is_outpost_service_account(user: User | None) -> bool: 13 """Check if `user` is the service account of an outpost""" 14 if not user or not user.is_authenticated: 15 return False 16 if user.type != UserTypes.INTERNAL_SERVICE_ACCOUNT: 17 return False 18 return user.username.startswith(USER_PREFIX_OUTPOSTS)
Check if user is the service account of an outpost
class
IsOutpostServiceAccount(rest_framework.permissions.BasePermission):
21class IsOutpostServiceAccount(BasePermission): 22 """Permission class which only allows the service accounts of outposts""" 23 24 def has_permission(self, request: Request, view) -> bool: 25 return is_outpost_service_account(request.user)
Permission class which only allows the service accounts of outposts
class
IsOutpostDelegatedRequest(rest_framework.permissions.BasePermission):
28class IsOutpostDelegatedRequest(BasePermission): 29 """Permission class which only allows requests that an outpost sends on behalf of 30 another user, authenticated by the outpost's own token""" 31 32 def has_permission(self, request: Request, view) -> bool: 33 return is_outpost_service_account(ClientIPMiddleware.get_outpost_user(request))
Permission class which only allows requests that an outpost sends on behalf of another user, authenticated by the outpost's own token