authentik.endpoints.connectors.agent.models
1from typing import TYPE_CHECKING 2from uuid import uuid4 3 4from django.db import models 5from django.templatetags.static import static 6from django.utils.translation import gettext_lazy as _ 7from rest_framework.serializers import Serializer 8 9from authentik.core.models import ExpiringModel, User, default_token_key 10from authentik.crypto.models import CertificateKeyPair 11from authentik.endpoints.models import ( 12 Connector, 13 Device, 14 DeviceAccessGroup, 15 DeviceConnection, 16 DeviceUserBinding, 17) 18from authentik.flows.stage import StageView 19from authentik.lib.generators import generate_key 20from authentik.lib.models import InternallyManagedMixin, SerializerModel 21from authentik.lib.utils.time import timedelta_string_validator 22 23if TYPE_CHECKING: 24 from authentik.endpoints.connectors.agent.controller import AgentConnectorController 25 26 27class AgentConnector(Connector): 28 """Configure authentication and add device compliance using the authentik Agent.""" 29 30 refresh_interval = models.TextField( 31 default="minutes=30", 32 validators=[timedelta_string_validator], 33 ) 34 35 auth_session_duration = models.TextField( 36 default="hours=8", validators=[timedelta_string_validator] 37 ) 38 auth_terminate_session_on_expiry = models.BooleanField(default=False) 39 authorization_flow = models.ForeignKey( 40 "authentik_flows.Flow", null=True, on_delete=models.SET_DEFAULT, default=None 41 ) 42 jwt_federation_providers = models.ManyToManyField( 43 "authentik_providers_oauth2.OAuth2Provider", blank=True, default=None 44 ) 45 46 nss_uid_offset = models.PositiveIntegerField(default=1000) 47 nss_gid_offset = models.PositiveIntegerField(default=1000) 48 49 challenge_key = models.ForeignKey(CertificateKeyPair, on_delete=models.CASCADE, null=True) 50 challenge_idle_timeout = models.TextField( 51 validators=[timedelta_string_validator], default="seconds=5" 52 ) 53 challenge_trigger_check_in = models.BooleanField(default=False) 54 55 @property 56 def icon_url(self): 57 return static("dist/assets/icons/icon.svg") 58 59 @property 60 def serializer(self) -> type[Serializer]: 61 from authentik.endpoints.connectors.agent.api.connectors import ( 62 AgentConnectorSerializer, 63 ) 64 65 return AgentConnectorSerializer 66 67 @property 68 def stage(self) -> type[StageView] | None: 69 from authentik.endpoints.connectors.agent.stage import ( 70 AuthenticatorEndpointStageView, 71 ) 72 73 return AuthenticatorEndpointStageView 74 75 @property 76 def controller(self) -> type[AgentConnectorController]: 77 from authentik.endpoints.connectors.agent.controller import AgentConnectorController 78 79 return AgentConnectorController 80 81 @property 82 def component(self) -> str: 83 return "ak-endpoints-connector-agent-form" 84 85 class Meta: 86 verbose_name = _("Agent Connector") 87 verbose_name_plural = _("Agent Connectors") 88 89 90class AgentDeviceConnection(DeviceConnection): 91 92 apple_key_exchange_key = models.TextField() 93 apple_encryption_key = models.TextField() 94 apple_enc_key_id = models.TextField() 95 apple_signing_key = models.TextField() 96 apple_sign_key_id = models.TextField() 97 98 99class AgentDeviceUserBinding(DeviceUserBinding): 100 101 apple_secure_enclave_key = models.TextField() 102 apple_enclave_key_id = models.TextField() 103 104 105class DeviceToken(InternallyManagedMixin, ExpiringModel): 106 """Per-device token used for authentication.""" 107 108 token_uuid = models.UUIDField(primary_key=True, default=uuid4) 109 device = models.ForeignKey(AgentDeviceConnection, on_delete=models.CASCADE) 110 key = models.TextField(default=generate_key) 111 112 class Meta: 113 verbose_name = _("Device Token") 114 verbose_name_plural = _("Device Tokens") 115 indexes = ExpiringModel.Meta.indexes + [ 116 models.Index(fields=["key"]), 117 ] 118 119 120class EnrollmentToken(ExpiringModel, SerializerModel): 121 """Token used during enrollment, a device will receive 122 a device token for further authentication""" 123 124 token_uuid = models.UUIDField(primary_key=True, editable=False, default=uuid4) 125 name = models.TextField() 126 key = models.TextField(default=default_token_key) 127 connector = models.ForeignKey(AgentConnector, on_delete=models.CASCADE) 128 device_group = models.ForeignKey( 129 DeviceAccessGroup, on_delete=models.SET_DEFAULT, default=None, null=True 130 ) 131 132 @property 133 def serializer(self) -> type[Serializer]: 134 from authentik.endpoints.connectors.agent.api.enrollment_tokens import ( 135 EnrollmentTokenSerializer, 136 ) 137 138 return EnrollmentTokenSerializer 139 140 class Meta: 141 verbose_name = _("Enrollment Token") 142 verbose_name_plural = _("Enrollment Tokens") 143 indexes = ExpiringModel.Meta.indexes + [ 144 models.Index(fields=["key"]), 145 ] 146 permissions = [ 147 ("view_enrollment_token_key", _("View token's key")), 148 ] 149 150 151class DeviceAuthenticationToken(InternallyManagedMixin, ExpiringModel): 152 153 identifier = models.UUIDField(default=uuid4, primary_key=True) 154 device = models.ForeignKey(Device, on_delete=models.CASCADE) 155 device_token = models.ForeignKey(DeviceToken, on_delete=models.CASCADE) 156 connector = models.ForeignKey(AgentConnector, on_delete=models.CASCADE) 157 user = models.ForeignKey(User, on_delete=models.CASCADE, null=True, default=None) 158 token = models.TextField() 159 160 def __str__(self): 161 return f"Device authentication token {self.identifier}" 162 163 class Meta(ExpiringModel.Meta): 164 verbose_name = _("Device authentication token") 165 verbose_name_plural = _("Device authentication tokens") 166 167 168class AppleNonce(InternallyManagedMixin, ExpiringModel): 169 nonce = models.TextField() 170 device_token = models.ForeignKey(DeviceToken, on_delete=models.CASCADE) 171 172 class Meta(ExpiringModel.Meta): 173 verbose_name = _("Apple Nonce") 174 verbose_name_plural = _("Apple Nonces")
28class AgentConnector(Connector): 29 """Configure authentication and add device compliance using the authentik Agent.""" 30 31 refresh_interval = models.TextField( 32 default="minutes=30", 33 validators=[timedelta_string_validator], 34 ) 35 36 auth_session_duration = models.TextField( 37 default="hours=8", validators=[timedelta_string_validator] 38 ) 39 auth_terminate_session_on_expiry = models.BooleanField(default=False) 40 authorization_flow = models.ForeignKey( 41 "authentik_flows.Flow", null=True, on_delete=models.SET_DEFAULT, default=None 42 ) 43 jwt_federation_providers = models.ManyToManyField( 44 "authentik_providers_oauth2.OAuth2Provider", blank=True, default=None 45 ) 46 47 nss_uid_offset = models.PositiveIntegerField(default=1000) 48 nss_gid_offset = models.PositiveIntegerField(default=1000) 49 50 challenge_key = models.ForeignKey(CertificateKeyPair, on_delete=models.CASCADE, null=True) 51 challenge_idle_timeout = models.TextField( 52 validators=[timedelta_string_validator], default="seconds=5" 53 ) 54 challenge_trigger_check_in = models.BooleanField(default=False) 55 56 @property 57 def icon_url(self): 58 return static("dist/assets/icons/icon.svg") 59 60 @property 61 def serializer(self) -> type[Serializer]: 62 from authentik.endpoints.connectors.agent.api.connectors import ( 63 AgentConnectorSerializer, 64 ) 65 66 return AgentConnectorSerializer 67 68 @property 69 def stage(self) -> type[StageView] | None: 70 from authentik.endpoints.connectors.agent.stage import ( 71 AuthenticatorEndpointStageView, 72 ) 73 74 return AuthenticatorEndpointStageView 75 76 @property 77 def controller(self) -> type[AgentConnectorController]: 78 from authentik.endpoints.connectors.agent.controller import AgentConnectorController 79 80 return AgentConnectorController 81 82 @property 83 def component(self) -> str: 84 return "ak-endpoints-connector-agent-form" 85 86 class Meta: 87 verbose_name = _("Agent Connector") 88 verbose_name_plural = _("Agent Connectors")
Configure authentication and add device compliance using the authentik Agent.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.
In the example::
class Pizza(Model):
toppings = ManyToManyField(Topping, related_name='pizzas')
Pizza.toppings and Topping.pizzas are ManyToManyDescriptor
instances.
Most of the implementation is delegated to a dynamically defined manager
class built by create_forward_many_to_many_manager() defined below.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example::
class Child(Model):
parent = ForeignKey(Parent, related_name='children')
Child.parent is a ForwardManyToOneDescriptor instance.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
60 @property 61 def serializer(self) -> type[Serializer]: 62 from authentik.endpoints.connectors.agent.api.connectors import ( 63 AgentConnectorSerializer, 64 ) 65 66 return AgentConnectorSerializer
Get serializer for this model
Accessor to the related objects manager on the one-to-many relation created by GenericRelation.
In the example::
class Post(Model):
comments = GenericRelation(Comment)
post.comments is a ReverseGenericManyToOneDescriptor instance.
Accessor to the related objects manager on the one-to-many relation created by GenericRelation.
In the example::
class Post(Model):
comments = GenericRelation(Comment)
post.comments is a ReverseGenericManyToOneDescriptor instance.
Accessor to the related object on the forward side of a one-to-one relation.
In the example::
class Restaurant(Model):
place = OneToOneField(Place, related_name='restaurant')
Restaurant.place is a ForwardOneToOneDescriptor instance.
Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example::
class Child(Model):
parent = ForeignKey(Parent, related_name='children')
Parent.children is a ReverseManyToOneDescriptor instance.
Most of the implementation is delegated to a dynamically defined manager
class built by create_forward_many_to_many_manager() defined below.
Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example::
class Child(Model):
parent = ForeignKey(Parent, related_name='children')
Parent.children is a ReverseManyToOneDescriptor instance.
Most of the implementation is delegated to a dynamically defined manager
class built by create_forward_many_to_many_manager() defined below.
Inherited Members
The requested object does not exist
The query returned multiple objects when only one was expected.
91class AgentDeviceConnection(DeviceConnection): 92 93 apple_key_exchange_key = models.TextField() 94 apple_encryption_key = models.TextField() 95 apple_enc_key_id = models.TextField() 96 apple_signing_key = models.TextField() 97 apple_sign_key_id = models.TextField()
AgentDeviceConnection(device_connection_uuid, device, connector, deviceconnection_ptr, apple_key_exchange_key, apple_encryption_key, apple_enc_key_id, apple_signing_key, apple_sign_key_id)
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
Accessor to the related object on the forward side of a one-to-one relation.
In the example::
class Restaurant(Model):
place = OneToOneField(Place, related_name='restaurant')
Restaurant.place is a ForwardOneToOneDescriptor instance.
Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example::
class Child(Model):
parent = ForeignKey(Parent, related_name='children')
Parent.children is a ReverseManyToOneDescriptor instance.
Most of the implementation is delegated to a dynamically defined manager
class built by create_forward_many_to_many_manager() defined below.
The requested object does not exist
The query returned multiple objects when only one was expected.
100class AgentDeviceUserBinding(DeviceUserBinding): 101 102 apple_secure_enclave_key = models.TextField() 103 apple_enclave_key_id = models.TextField()
AgentDeviceUserBinding(policy_binding_uuid, enabled, policy, group, user, target, negate, timeout, failure_result, order, policybinding_ptr, is_primary, connector, deviceuserbinding_ptr, apple_secure_enclave_key, apple_enclave_key_id)
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
Accessor to the related object on the forward side of a one-to-one relation.
In the example::
class Restaurant(Model):
place = OneToOneField(Place, related_name='restaurant')
Restaurant.place is a ForwardOneToOneDescriptor instance.
Inherited Members
The requested object does not exist
The query returned multiple objects when only one was expected.
106class DeviceToken(InternallyManagedMixin, ExpiringModel): 107 """Per-device token used for authentication.""" 108 109 token_uuid = models.UUIDField(primary_key=True, default=uuid4) 110 device = models.ForeignKey(AgentDeviceConnection, on_delete=models.CASCADE) 111 key = models.TextField(default=generate_key) 112 113 class Meta: 114 verbose_name = _("Device Token") 115 verbose_name_plural = _("Device Tokens") 116 indexes = ExpiringModel.Meta.indexes + [ 117 models.Index(fields=["key"]), 118 ]
Per-device token used for authentication.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example::
class Child(Model):
parent = ForeignKey(Parent, related_name='children')
Child.parent is a ForwardManyToOneDescriptor instance.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example::
class Child(Model):
parent = ForeignKey(Parent, related_name='children')
Parent.children is a ReverseManyToOneDescriptor instance.
Most of the implementation is delegated to a dynamically defined manager
class built by create_forward_many_to_many_manager() defined below.
Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example::
class Child(Model):
parent = ForeignKey(Parent, related_name='children')
Parent.children is a ReverseManyToOneDescriptor instance.
Most of the implementation is delegated to a dynamically defined manager
class built by create_forward_many_to_many_manager() defined below.
Inherited Members
The requested object does not exist
The query returned multiple objects when only one was expected.
121class EnrollmentToken(ExpiringModel, SerializerModel): 122 """Token used during enrollment, a device will receive 123 a device token for further authentication""" 124 125 token_uuid = models.UUIDField(primary_key=True, editable=False, default=uuid4) 126 name = models.TextField() 127 key = models.TextField(default=default_token_key) 128 connector = models.ForeignKey(AgentConnector, on_delete=models.CASCADE) 129 device_group = models.ForeignKey( 130 DeviceAccessGroup, on_delete=models.SET_DEFAULT, default=None, null=True 131 ) 132 133 @property 134 def serializer(self) -> type[Serializer]: 135 from authentik.endpoints.connectors.agent.api.enrollment_tokens import ( 136 EnrollmentTokenSerializer, 137 ) 138 139 return EnrollmentTokenSerializer 140 141 class Meta: 142 verbose_name = _("Enrollment Token") 143 verbose_name_plural = _("Enrollment Tokens") 144 indexes = ExpiringModel.Meta.indexes + [ 145 models.Index(fields=["key"]), 146 ] 147 permissions = [ 148 ("view_enrollment_token_key", _("View token's key")), 149 ]
Token used during enrollment, a device will receive a device token for further authentication
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example::
class Child(Model):
parent = ForeignKey(Parent, related_name='children')
Child.parent is a ForwardManyToOneDescriptor instance.
Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example::
class Child(Model):
parent = ForeignKey(Parent, related_name='children')
Child.parent is a ForwardManyToOneDescriptor instance.
133 @property 134 def serializer(self) -> type[Serializer]: 135 from authentik.endpoints.connectors.agent.api.enrollment_tokens import ( 136 EnrollmentTokenSerializer, 137 ) 138 139 return EnrollmentTokenSerializer
Get serializer for this model
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
Inherited Members
The requested object does not exist
The query returned multiple objects when only one was expected.
152class DeviceAuthenticationToken(InternallyManagedMixin, ExpiringModel): 153 154 identifier = models.UUIDField(default=uuid4, primary_key=True) 155 device = models.ForeignKey(Device, on_delete=models.CASCADE) 156 device_token = models.ForeignKey(DeviceToken, on_delete=models.CASCADE) 157 connector = models.ForeignKey(AgentConnector, on_delete=models.CASCADE) 158 user = models.ForeignKey(User, on_delete=models.CASCADE, null=True, default=None) 159 token = models.TextField() 160 161 def __str__(self): 162 return f"Device authentication token {self.identifier}" 163 164 class Meta(ExpiringModel.Meta): 165 verbose_name = _("Device authentication token") 166 verbose_name_plural = _("Device authentication tokens")
DeviceAuthenticationToken(expires, expiring, identifier, device, device_token, connector, user, token)
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example::
class Child(Model):
parent = ForeignKey(Parent, related_name='children')
Child.parent is a ForwardManyToOneDescriptor instance.
Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example::
class Child(Model):
parent = ForeignKey(Parent, related_name='children')
Child.parent is a ForwardManyToOneDescriptor instance.
Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example::
class Child(Model):
parent = ForeignKey(Parent, related_name='children')
Child.parent is a ForwardManyToOneDescriptor instance.
Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example::
class Child(Model):
parent = ForeignKey(Parent, related_name='children')
Child.parent is a ForwardManyToOneDescriptor instance.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
Inherited Members
The requested object does not exist
The query returned multiple objects when only one was expected.
169class AppleNonce(InternallyManagedMixin, ExpiringModel): 170 nonce = models.TextField() 171 device_token = models.ForeignKey(DeviceToken, on_delete=models.CASCADE) 172 173 class Meta(ExpiringModel.Meta): 174 verbose_name = _("Apple Nonce") 175 verbose_name_plural = _("Apple Nonces")
AppleNonce(id, expires, expiring, nonce, device_token)
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example::
class Child(Model):
parent = ForeignKey(Parent, related_name='children')
Child.parent is a ForwardManyToOneDescriptor instance.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
Inherited Members
The requested object does not exist
The query returned multiple objects when only one was expected.