HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/auth/__pycache__/django.cpython-310.pyc
o

�N�g��
@s�dZddlZddlZddlZzddlZddlmZdZWney0Z	zdZWYdZ	[	ndZ	[	wwda
e�e�Z
dZdd�Zd	d
�Zdd�Zd
d�Zdd�ZdS)a�
Provide authentication using Django Web Framework

:depends:   - Django Web Framework

Django authentication depends on the presence of the django framework in the
``PYTHONPATH``, the Django project's ``settings.py`` file being in the
``PYTHONPATH`` and accessible via the ``DJANGO_SETTINGS_MODULE`` environment
variable.

Django auth can be defined like any other eauth module:

.. code-block:: yaml

    external_auth:
      django:
        fred:
          - .*
          - '@runner'

This will authenticate Fred via Django and allow him to run any execution
module and all runners.

The authorization details can optionally be located inside the Django database.
The relevant entry in the ``models.py`` file would look like this:

.. code-block:: python

    class SaltExternalAuthModel(models.Model):
        user_fk = models.ForeignKey(User, on_delete=models.CASCADE)
        minion_or_fn_matcher = models.CharField(max_length=255)
        minion_fn = models.CharField(max_length=255)

The :conf_master:`external_auth` clause in the master config would then look
like this:

.. code-block:: yaml

    external_auth:
      django:
        ^model: <fully-qualified reference to model class>

When a user attempts to authenticate via Django, Salt will import the package
indicated via the keyword ``^model``.  That model must have the fields
indicated above, though the model DOES NOT have to be named
'SaltExternalAuthModel'.
�N)�
connectionTF�djangocCstrtSdS)NF)�
HAS_DJANGO�__virtualname__�rr�D/opt/saltstack/salt/lib/python3.10/site-packages/salt/auth/django.py�__virtual__IsrcCs&ztj��WdStyYdSw)NFT)rZping�	Exceptionrrrr�is_connection_usableOs��r
cCs�tjdkr	t��tdurdSdtddvrFtddd}|�d�d}d�|�d�dd��}t|t�t	�d	�}d
|��}t
|�adSdS)zG
    Prepare the connection to the Django authentication framework
    )��Nz^modelZ
external_authr�.���rZSaltExternalAuthModelzdjango_auth_module.)r�VERSION�setup�DJANGO_AUTH_CLASS�__opts__�split�join�
__import__�globals�locals�eval)Zdjango_model_fullnameZdjango_model_nameZdjango_module_nameZdjango_auth_moduleZDJANGO_AUTH_CLASS_strrrr�__django_auth_setupXs
�
�rcCs�td}|tjvrtj�|�tj�dtd�t�t�s"t	�
�ddl}|jj
j||d�}|durD|jr=t�d�dSt�d	�dSt�d
�dS)z
    Simple Django auth
    �django_auth_pathZDJANGO_SETTINGS_MODULEZdjango_auth_settingsrN)�username�passwordz Django authentication successfulTzIDjango authentication: the password is valid but the account is disabled.zDjango authentication failed.F)r�sys�path�append�os�environ�
setdefaultrr
r�closeZdjango.contrib.authZcontrib�authZauthenticateZ	is_active�log�debug)rrrr�userrrrr$vs&

�
�r$cCs
t�|dur
tj��}ntjj|d�}i}|D]d}|jj|vr&g||jj<|js7|jr7||jj�	|j�q|jrH|jsH||jj�	|j�qd}||jjD]}t
|t�rk|j|vrk||jj|j�	|j�d}qP|s|||jj�	|j|jgi�qt�
d|�|S)a�

    :param username: Username to filter for
    :return: Dictionary that can be slotted into the ``__opts__`` structure for
        eauth that designates the user associated ACL

    Database records such as:

    ===========  ====================     =========
    username     minion_or_fn_matcher     minion_fn
    ===========  ====================     =========
    fred                                  test.ping
    fred         server1                  network.interfaces
    fred         server1                  raid.list
    fred         server2                  .*
    guru         .*
    smartadmin   server1                  .*
    ===========  ====================     =========

    Should result in an eauth config such as:

    .. code-block:: yaml

        fred:
          - test.ping
          - server1:
              - network.interfaces
              - raid.list
          - server2:
              - .*
        guru:
          - .*
        smartadmin:
          - server1:
            - .*

    N)Zuser_fk__usernameFTzdjango auth_dict is %s)rrZobjects�all�filterZuser_fkrZminion_or_fn_matcherZ	minion_fnr�
isinstance�dictr%r&)rZ
db_recordsZ	auth_dict�a�found�drrr�acl�s8&

����r/)�__doc__�loggingr rrZ	django.dbrrr	�excr�	getLogger�__name__r%rrr
rr$r/rrrr�<module>s(0��