File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/states/__pycache__/ssh_auth.cpython-310.pyc
o
�N�gUN � @ sj d Z ddlZddlZdd� Zdd� Z dd
d�Z ddd
�Z ddd�ZdS )aC
Control of entries in SSH authorized_key files
==============================================
The information stored in a user's SSH authorized key file can be easily
controlled via the ssh_auth state. Defaults can be set by the enc, options,
and comment keys. These defaults can be overridden by including them in the
name.
Since the YAML specification limits the length of simple keys to 1024
characters, and since SSH keys are often longer than that, you may have
to use a YAML 'explicit key', as demonstrated in the second example below.
.. code-block:: yaml
AAAAB3NzaC1kc3MAAACBAL0sQ9fJ5bYTEyY==:
ssh_auth.present:
- user: root
- enc: ssh-dss
? AAAAB3NzaC1kc3MAAACBAL0sQ9fJ5bYTEyY==...
:
ssh_auth.present:
- user: root
- enc: ssh-dss
thatch:
ssh_auth.present:
- user: root
- source: salt://ssh_keys/thatch.id_rsa.pub
- config: '%h/.ssh/authorized_keys'
sshkeys:
ssh_auth.present:
- user: root
- enc: ssh-rsa
- options:
- option1="value1"
- option2="value2 flag2"
- comment: myuser
- names:
- AAAAB3NzaC1kc3MAAACBAL0sQ9fJ5bYTEyY==
- ssh-dss AAAAB3NzaCL0sQ9fJ5bYTEyY== user@domain
- option3="value3" ssh-dss AAAAB3NzaC1kcQ9J5bYTEyY== other@testdomain
- AAAAB3NzaC1kcQ9fJFF435bYTEyY== newcomment
sshkeys:
ssh_auth.manage:
- user: root
- enc: ssh-rsa
- options:
- option1="value1"
- option2="value2 flag2"
- comment: myuser
- ssh_keys:
- AAAAB3NzaC1kc3MAAACBAL0sQ9fJ5bYTEyY==
- ssh-dss AAAAB3NzaCL0sQ9fJ5bYTEyY== user@domain
- option3="value3" ssh-dss AAAAB3NzaC1kcQ9J5bYTEyY== other@testdomain
- AAAAB3NzaC1kcQ9fJFF435bYTEyY== newcomment
� Nc C s� d}|rMt d | ||t|d�} | r2d}| �� D ]\}
}|dkr q|d|� d|
� d�7 }q|r2||fS tjt d j j�d
d�}|rEd|fS dd
|� d�fS t� d�}
|
�
|�}|sl|�� }|d }t|�dkrk|d }n&|�
d�ry|�
d��d�}|�
d��� }|d }|d }t|�dkr�|d }t d | ||||||d�}|dkr�d|� d| � d�}||fS |dkr�d|� d| � d�}||fS |dkr�d}d�|| �}||fS )z"
Run checks for "present"
N�ssh.check_key_file��saltenv�fingerprint_hash_type� �existszSet to z: �
� test.ping�ssh_auth.errorFT�All host keys in file z are already present�,^(.*?)\s?((?:sk-)?(?:ssh\-|ecds)[\w-]+\s.+)$r � � �,� �
ssh.check_key��configr �update�Key �
for user z is set to be updated�addz is set to be added�9The authorized host key {} is already present for user {})�__salt__�__env__�items�sys�modules�
__module__�__context__�pop�re�compile�search�split�len�group�format��user�name�enc�comment�options�sourcer r �result�keys�key�status�err�sshre�fullkey�key_and_comment�comps�check� r9 �H/opt/saltstack/salt/lib/python3.10/site-packages/salt/states/ssh_auth.py�
_present_testB sz ��
�
�
� ���r; c C sv d}|rLt d | ||t|d�} | r1d}t| �� �D ]\}
}|dkr"q|d|
� d�7 }q|r1||fS tjt d j j�d d�}|rDd
|fS dd|� d
�fS t �
d�}
|
�|�}|sk|�� }|d }t
|�dkrj|d }n&|�d�rx|�d��d�}|�d��� }|d }|d }t
|�dkr�|d }t d | ||||||d�}|dks�|dkr�d|� d| � d�}||fS d}d}||fS )z!
Run checks for "absent"
Nr r r r zSet to remove: r r r
FTr z are already absentr r r
r r r r r r r r r z is set for removalzKey is already absent)r r �listr r r r r r r! r"