Skip to main content

Custom permissions and permission checks

authentik: 2026.11.0+Preview

Custom permissions and permission checks extend role-based access control (RBAC) when built-in permissions do not provide the access rules that you need:

  • A custom permission is a permission that you define for an authentik model, such as a user or group. You assign it to roles like any built-in permission. Creating or assigning a custom permission does not grant access by itself. Use a permission check to define what a custom permission allows.
  • A permission check is Python code that defines access rules for one or more API endpoints. For example, a check can hide the salary attribute returned by core/users:retrieve unless the user has the custom_read_salary permission.

Custom permissions​

Create custom permissions for specific tasks, such as reading a user's salary.

Create a custom permission​

  1. In the Admin interface, navigate to Customization > Custom Permissions and click Create.
  2. Configure the following fields:
    • Model: Select the model that the permission applies to. For instance-wide permissions, select authentik_rbac.systempermission.
    • Codename: Enter custom_ followed by one or more lowercase letters, digits, or underscores, such as custom_read_salary.
    • Name: Enter a descriptive name for the permission.
  3. Save the permission, then assign it to a role. You can assign it globally, assign it on individual objects of its model, or include it in initial permissions.

Creating, renaming, and deleting custom permissions require the corresponding Can add Custom permission, Can change Custom permission, and Can delete Custom permission permissions. You can change a permission's name, but not its codename or model. Deleting a custom permission also removes its assignments.

Permission checks​

Permission checks are Python code that you attach to API endpoints to control what users can see or change. They can use custom permissions or other conditions to allow or deny access, filter lists, or protect fields.

Create a permission check​

Privileged server-side code

Permission checks execute Python code on the server and can override access controls, including checks on endpoints that assign roles, permissions, or credentials. Grant permission to create or edit checks only to users whom you trust with superuser access.

  1. In the Admin interface, navigate to System > Settings, enable Custom permissions in the Flags section, and save the settings. Checks do not run while this setting is disabled.
  2. Navigate to Customization > Permission Checks and click Create.
  3. Configure the following fields:
    • Name: Enter a descriptive name for the check.
    • Endpoints: Select the API endpoints that the check applies to. Endpoints are named <path>:<action>, such as core/users:list or core/groups:add_user, and each entry lists the functions that the endpoint supports. Each endpoint can be bound to only one check.
    • Expression: Enter Python code defining one or more of the check functions. See the examples below.
  4. Save the check and test it with a non-superuser account. Superusers bypass all permission checks.
Review checks after upgrades

An authentik upgrade can rename or remove endpoints, or change the functions that they support. A check stops running on bound endpoints that no longer exist, and a function stops running on endpoints that no longer support it. This happens silently and includes functions that restrict access, so after an upgrade a check might no longer deny, narrow, or hide what it did before.

  • On the Permission Checks page, endpoints that no longer exist are labeled No longer exists in the Bound to column.
  • If a check's field rules name fields that an endpoint lacks, the check's form lists them after the check has run on that endpoint.
  • Functions that an endpoint no longer supports are not flagged.

Review the release notes for API changes and retest your checks after upgrading. If a function raises an exception because something that it relies on has changed, such as a removed model field, authentik logs the failure and denies or fails the request as described in Permission check functions.

Permission check functions​

FunctionRunsReturns
has_permission(request)On each requestTrue to keep authentik's decision; False to deny access
has_object_permission(request, obj)On endpoints that act on an individual objectTrue to keep authentik's decision; False to deny access
narrow_list(request, queryset)On lists, with the objects authentik allows the user to listA QuerySet of the same model containing the objects to keep
widen_list(request, queryset)On lists, with everything the endpoint can listA QuerySet of the same model containing the objects to add
alter_response(request, data)After the endpoint, on successful responses with dataJSON-serializable response data
hidden_fields(request, obj)On supported list, detail, create, and update endpointsA set of paths the user cannot see
readonly_fields(request, obj)On supported create and update endpointsA set of paths the user cannot change

has_permission and has_object_permission work like permissions in Django REST framework, except that returning True keeps authentik's decision instead of granting access. To grant access that authentik would deny, raise PermissionCheckSkipException in either function. This does not bypass other permission decisions or validation inside the endpoint.

Any function can raise PermissionDenied("<reason>") to deny the request with a message for the user. If a function raises any other exception or returns the wrong type, authentik logs the failure. For has_permission, has_object_permission, narrow_list, and widen_list, it then denies the request; for alter_response, hidden_fields, and readonly_fields, the request fails with an error.

Besides the functions available to expressions, checks can use endpoint, the endpoint that the request is for, such as core/groups:add_user. The data that the request sends is in request.data.

Lists and objects​

narrow_list can only remove objects from authentik's list, and widen_list can only add objects that the endpoint could list. Objects left out of the result are also not found on detail endpoints, and requests cannot reference them. For example, to add a user to a group or remove them from one, the user must be in the requester's core/users:list results.

Field rules​

Paths start with a response field, such as email, and can continue into JSON fields and nested objects, such as attributes.salary or users_obj.attributes.salary. A path applies to every item in a list; users_obj[pk=42] selects only the item whose pk is 42. If a path starts with a field that the endpoint does not have, authentik logs it and shows it on the check's form after the check runs.

Field rules apply only to the endpoints that the check is bound to, so bind the check to every endpoint that returns the protected fields. When obj is None, hidden_fields must return every path that it hides on any individual object, without selectors; otherwise the request fails. For example, if hidden_fields returns users_obj[pk=42].attributes.salary for an object, it must return users_obj.attributes.salary when obj is None.

OperationHidden key, such as attributes.salaryHidden field, such as emailRead-only path
ReadingOmittedShown emptyShown
WritingIgnored; stored value preservedIgnored; stored value preservedChanges rejected

On endpoints using authentik's QLSearch backend, DjangoQL searches treat hidden JSON paths as absent keys. Explicit searches, filters, and ordering on hidden whole fields are rejected; free-text search excludes those fields. These protections do not cover separate JSON-key filter or ordering parameters, and might not apply to other search backends.

Hidden paths into read-only nested objects, and paths with selectors, affect response data only. They do not restrict writes or queries. Hidden attribute keys are excluded from object attribute validation.

Responses​

alter_response changes response data, not the status or headers. It runs after the endpoint has executed, so a denial or failure at this stage does not guarantee that a write is rolled back. Use permission functions to prevent an operation.

Examples​

Each example names the custom permissions to create and the endpoints to bind the check to. Because each endpoint can be bound to only one check, combine examples that share an endpoint into one check.

Delegate service account creation​

Let holders of the custom permission custom_add_service_account on authentik_core.user create service accounts. Assign it globally and bind the check to core/users:service_account.

def has_permission(request):
if request.user.has_perm("authentik_core.custom_add_service_account"):
raise PermissionCheckSkipException
return True

Let users leave groups​

Let users remove themselves from groups whose attributes contain self_service_leave: true. Bind the check to core/users:list and core/groups:remove_user. widen_list includes the requester in their own user list so that the removal request can reference them.

def widen_list(request, queryset):
return queryset.filter(pk=request.user.pk)

def has_object_permission(request, obj):
if (
ak_user_by(pk=request.data.get("pk")) == request.user
and obj.attributes.get("self_service_leave", False)
):
raise PermissionCheckSkipException
return True

Let managers add direct reports to groups​

Users whose manager attribute contains a manager's UUID directly report to that manager. Let managers see their reports and add them to groups whose attributes contain managers_may_assign: true. Bind the check to core/users:list and core/groups:add_user.

def widen_list(request, queryset):
return queryset.filter(attributes__manager=str(request.user.uuid))

def has_object_permission(request, obj):
target = ak_user_by(pk=request.data.get("pk"))
if (
target is not None
and target.attributes.get("manager") == str(request.user.uuid)
and obj.attributes.get("managers_may_assign", False)
):
raise PermissionCheckSkipException
return True

Show salaries only to some users​

Show users' salary attribute only to holders of the custom permission custom_read_salary on authentik_core.user. Changing a salary requires both custom_read_salary and custom_change_salary. Assign these permissions globally or on individual users.

Bind the check to core/users:list, core/users:retrieve, core/users:update, and core/users:partial_update. Because group responses include member data, also bind it to core/groups:list and core/groups:retrieve. On group endpoints, obj is a group, and the check evaluates each member separately.

def hidden_fields(request, obj):
if endpoint.startswith("core/groups:"):
if obj is None:
return {"users_obj.attributes.salary"}
return {
f"users_obj[pk={member.pk}].attributes.salary"
for member in obj.users.all()
if not request.user.has_perm("authentik_core.custom_read_salary", member)
}
if request.user.has_perm("authentik_core.custom_read_salary", obj):
return set()
return {"attributes.salary"}

def readonly_fields(request, obj):
if request.user.has_perm("authentik_core.custom_change_salary", obj):
return set()
return {"attributes.salary"}

Trim system information​

Show the HTTP headers and runtime details from the system information endpoint only to holders of the custom permission custom_view_runtime_details on authentik_rbac.systempermission. Bind the check to both admin/system:get and admin/system:post, because both methods return this data.

def alter_response(request, data):
if request.user.has_perm("authentik_rbac.custom_view_runtime_details"):
return data
return {key: value for key, value in data.items() if key not in {"http_headers", "runtime"}}