website/docs/endpoint-devices/device-compliance/device-compliance-policy.md
Device compliance policies are used to limit access to authentik and applications based on Device Compliance information.
Device compliance policies are currently in development and inaccessible. However, similar functionality can be achieved with existing stages and policies.
You must have configured compliance in authentik and on the endpoint device (Linux, Windows, macOS).
To access device facts within a flow, the flow must include an Endpoint stage. The Endpoint stage fetches device facts via a configured Connector and adds them to the Flow context.
The following example shows how to use these facts within an expression policy.
flow_plan = request.context.get("flow_plan") # set a flow_plan object
device = flow_plan.context.get("device") # set a device object
name = device.name # the name of the device
facts = device.cached_facts.data
ak_logger.debug("device facts", facts=facts)
The following are examples of how device compliance can currently be implemented:
If your goal is to only allow authentication via endpoint devices, this is achievable by adding an Endpoint stage to your authentication flow.
authentik agent)Device requiredIf your goal is to only allow authentication via a specific type of endpoint device, this is achievable by adding an Endpoint stage and a Deny stage to your authentication flow.
The following example will only allow authentication via Apple devices.
authentik agent)Device requiredOn the Stage Bindings tab, click Create and bind stage.
Select Deny Stage as the stage type and configure the following settings:
Click Next.
Select the Order for the stage. Ensure that this number is higher than the Endpoint stage created in the previous section.
Click Finish.
Expand the Deny stage that you just created and click Create and bind Policy.
Select Expression policy as the policy type, click Next, and configure the following settings:
flow_plan = request.context.get("flow_plan")
device = flow_plan.context.get("device")
if device.manufacturer.lower() != "apple":
return True
return False
Click Next and then click Finish.