HOME


Mini Shell 1.0
Redirecting to https://devs.lapieza.net/iniciar-sesion Redirecting to https://devs.lapieza.net/iniciar-sesion.
DIR: /proc/self/root/usr/lib/python3/dist-packages/cloudinit/config/__pycache__/
Upload File :
Current File : //proc/self/root/usr/lib/python3/dist-packages/cloudinit/config/__pycache__/cc_ssh.cpython-311.pyc
�

܍~c�7�� �UdZddlZddlZddlZddlZddlmZddlmZddl	m
Z
mZmZddl
mZmZmZddlmZddlmZdd	lmZmZdd
lmZmZddlmZdZd
ddeegeed��ggd�Zeed<ee��Zgd�Z ej!d��Z"dZ#dZ$dgZ%iZ&iZ'e D]FZ(e&�)e(�d�e#e(zdfe(�d�e#e(z�d�dfe(�d�e#e(z�d�dfi��e(�d�e'e(�d�<�GdZ*de+d ed!ed"ed#e,d$dfd%�Z-d&�Z.d)d'eee+fd(�Z/dS)*zSSH: Configure SSH and SSH keys�N)�Logger)�dedent)�List�Optional�Sequence)�ssh_util�subp�util)�Cloud)�Config)�
MetaSchema�get_meta_doc)�ALL_DISTROS�ug_util)�PER_INSTANCEa�This module handles most configuration for SSH and both host and authorized SSH
keys.

Authorized Keys
^^^^^^^^^^^^^^^

Authorized keys are a list of public SSH keys that are allowed to connect to
a user account on a system. They are stored in `.ssh/authorized_keys` in that
account's home directory. Authorized keys for the default user defined in
``users`` can be specified using ``ssh_authorized_keys``. Keys
should be specified as a list of public keys.

.. note::
    see the ``cc_set_passwords`` module documentation to enable/disable SSH
    password authentication

Root login can be enabled/disabled using the ``disable_root`` config key. Root
login options can be manually specified with ``disable_root_opts``.

Supported public key types for the ``ssh_authorized_keys`` are:

    - dsa
    - rsa
    - ecdsa
    - ed25519
    - ecdsa-sha2-nistp256-cert-v01@openssh.com
    - ecdsa-sha2-nistp256
    - ecdsa-sha2-nistp384-cert-v01@openssh.com
    - ecdsa-sha2-nistp384
    - ecdsa-sha2-nistp521-cert-v01@openssh.com
    - ecdsa-sha2-nistp521
    - sk-ecdsa-sha2-nistp256-cert-v01@openssh.com
    - sk-ecdsa-sha2-nistp256@openssh.com
    - sk-ssh-ed25519-cert-v01@openssh.com
    - sk-ssh-ed25519@openssh.com
    - ssh-dss-cert-v01@openssh.com
    - ssh-dss
    - ssh-ed25519-cert-v01@openssh.com
    - ssh-ed25519
    - ssh-rsa-cert-v01@openssh.com
    - ssh-rsa
    - ssh-xmss-cert-v01@openssh.com
    - ssh-xmss@openssh.com

.. note::
    this list has been filtered out from the supported keytypes of
    `OpenSSH`_ source, where the sigonly keys are removed. Please see
    ``ssh_util`` for more information.

    ``dsa``, ``rsa``, ``ecdsa`` and ``ed25519`` are added for legacy,
    as they are valid public keys in some old distros. They can possibly
    be removed in the future when support for the older distros are dropped

.. _OpenSSH: https://github.com/openssh/openssh-portable/blob/master/sshkey.c

Host Keys
^^^^^^^^^

Host keys are for authenticating a specific instance. Many images have default
host SSH keys, which can be removed using ``ssh_deletekeys``.

Host keys can be added using the ``ssh_keys`` configuration key.

When host keys are generated the output of the ssh-keygen command(s) can be
displayed on the console using the ``ssh_quiet_keygen`` configuration key.

.. note::
    when specifying private host keys in cloud-config, care should be taken to
    ensure that the communication between the data source and the instance is
    secure


If no host keys are specified using ``ssh_keys``, then keys will be generated
using ``ssh-keygen``. By default one public/private pair of each supported
host key type will be generated. The key types to generate can be specified
using the ``ssh_genkeytypes`` config flag, which accepts a list of host key
types to use. For each host key type for which this module has been instructed
to create a keypair, if a key of the same type is already present on the
system (i.e. if ``ssh_deletekeys`` was false), no key will be generated.

Supported host key types for the ``ssh_keys`` and the ``ssh_genkeytypes``
config flags are:

    - dsa
    - ecdsa
    - ed25519
    - rsa

Unsupported host key types for the ``ssh_keys`` and the ``ssh_genkeytypes``
config flags are:

    - ecdsa-sk
    - ed25519-sk
�cc_ssh�SSHzConfigure SSH and SSH keysa�            ssh_keys:
              rsa_private: |
                -----BEGIN RSA PRIVATE KEY-----
                MIIBxwIBAAJhAKD0YSHy73nUgysO13XsJmd4fHiFyQ+00R7VVu2iV9Qco
                ...
                -----END RSA PRIVATE KEY-----
              rsa_public: ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAGEAoPRhIfLvedSDKw7Xd ...
              rsa_certificate: |
                ssh-rsa-cert-v01@openssh.com AAAAIHNzaC1lZDI1NTE5LWNlcnQt ...
              dsa_private: |
                -----BEGIN DSA PRIVATE KEY-----
                MIIBxwIBAAJhAKD0YSHy73nUgysO13XsJmd4fHiFyQ+00R7VVu2iV9Qco
                ...
                -----END DSA PRIVATE KEY-----
              dsa_public: ssh-dsa AAAAB3NzaC1yc2EAAAABIwAAAGEAoPRhIfLvedSDKw7Xd ...
              dsa_certificate: |
                ssh-dsa-cert-v01@openssh.com AAAAIHNzaC1lZDI1NTE5LWNlcnQt ...
            ssh_authorized_keys:
              - ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAGEA3FSyQwBI6Z+nCSjUU ...
              - ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA3I7VUf2l5gSn5uavROsc5HRDpZ ...
            ssh_deletekeys: true
            ssh_genkeytypes: [rsa, dsa, ecdsa, ed25519]
            disable_root: true
            disable_root_opts: no-port-forwarding,no-agent-forwarding,no-X11-forwarding
            allow_public_ssh_keys: true
            ssh_quiet_keygen: true
            ssh_publish_hostkeys:
              enabled: true
              blacklist: [dsa]
            )�id�name�title�description�distros�	frequency�examples�activate_by_schema_keys�meta)�rsa�dsa�ecdsa�ed25519z4^(ecdsa-sk|ed25519-sk)_(private|public|certificate)$z/etc/ssh/ssh_host_%s_keyTr�_privatei��_public�.pub�_certificatez	-cert.pubz;o=$(ssh-keygen -yf "%s") && echo "$o" root@localhost > "%s"r�cfg�cloud�log�args�returnc	�X�|�dd��rrtj�dd��}t	j|��D]=}	tj|���#t$rtj|d|��Y�:wxYwd|v�r�|d�	��D]�\}}|tvr7t�|��rd}	nd}	|�
d	|	|���Et|d
}
t|d}tj|
||��d|vrd
|
i}tj|����t"�	��D]�\}
}||dvs
|
|dvr�t|
d
t|d
}}ddt$||fzg}	tjdd���5t)j|d���ddd��n#1swxYwY|�d|�d|������#t$rtj|d|�d|����Y��wxYw�n>tj|dt.��}tj���}d|d<|D�]�}t4|z}tj�|��r�-tjtj�|����dd|ddd|g}tjdd���5	t)j|d|���\}}tj|d d��s1t>j �!tj"|����tj#d��}|d!krCtj$|d!|��tj%|d"��tj%|d#zd$��n�#t(j&$r�}tj"|j'���(��}|j)dkr>|�(���*d%��r|�d&|��ntj|d'||��Yd}~nd}~wwxYwddd��n#1swxYwY���d(|vrCtj|d(d)tV��}tj|d(d*tX��}ntV}tX}|rQt[|�+��}	|j.�/|��n%#t$rtj|d,��YnwxYw	taj1||j2��\}}taj3|��\}} tj|d-d��}!tj4|d.tj5��}"g}#tj|d/d��r|�6��pg}#n|�d0��d1|vr|d1}$|#�7|$��tq|#||!|"��dS#t$rtj|d2��YdSwxYw)3N�ssh_deletekeysTz	/etc/ssh/zssh_host_*key*zFailed deleting key file %s�ssh_keys�unsupported�unrecognizedz Skipping %s ssh_keys entry: "%s"r�r$�HostCertificate�shz-xcz/etc/ssh)�	recursiveF)�capturezGenerated a key for z from zFailed generating a key for �ssh_genkeytypes�C�LANGz
ssh-keygenz-tz-N�z-f)r3�env�ssh_quiet_keygen���i�r#i�zunknown keyz!ssh-keygen: unknown key type '%s'z(Failed generating key type %s to file %s�ssh_publish_hostkeys�	blacklist�enabled)r<zPublishing host keys failed!�disable_root�disable_root_opts�allow_public_ssh_keyszSSkipping import of publish SSH keys per config setting: allow_public_ssh_keys=False�ssh_authorized_keysz Applying SSH credentials failed!)9�get�os�path�join�globr
�del_file�	Exception�logexc�items�CONFIG_KEY_TO_FILE�pattern_unsupported_config_keys�match�warning�
write_filer�update_ssh_config�PRIV_TO_PUB�KEY_GEN_TPL�SeLinuxGuardr	�debug�get_cfg_option_list�GENERATE_KEY_NAMES�environ�copy�KEY_FILE_TPL�exists�
ensure_dir�dirname�get_cfg_option_bool�sys�stdout�write�
decode_binary�get_group_id�chown�chmod�ProcessExecutionError�stderr�lower�	exit_code�
startswith�HOST_KEY_PUBLISH_BLACKLIST�PUBLISH_HOST_KEYS�get_public_host_keys�
datasource�publish_host_keysr�normalize_users_groups�distro�extract_default�get_cfg_option_str�DISABLE_USER_OPTS�get_public_ssh_keys�extend�apply_credentials)%rr%r&r'r(�key_pth�f�key�val�reason�tgt_fn�	tgt_perms�cert_config�private_type�public_type�private_file�public_file�cmd�genkeys�lang_c�keytype�keyfile�out�err�gid�e�host_key_blacklist�publish_hostkeys�hostkeys�users�_groups�user�_user_configr>r?�keys�cfgkeyss%                                     �9/usr/lib/python3/dist-packages/cloudinit/config/cc_ssh.py�handler��sp��
�w�w���&�&�C��'�,�,�{�,<�=�=����7�#�#�	C�	C�A�
C��
�a� � � � ���
C�
C�
C���C�!>��B�B�B�B�B�
C�����S����j�/�/�/�1�1�	8�	8�J�S�#��,�,�,�2�8�8��=�=�,�*�F�F�+�F����>���L�L�L��'��,�Q�/�F�*�3�/��2�I��O�F�C��3�3�3���$�$�0�&�9���*�;�7�7�7��)4�):�):�)<�)<�	�	�%�L�+��s�:��.�.��s�:��6�6��"�<�0��3�"�;�/��2�&�L����|�[�.I� I�J�C�
��&�z�T�B�B�B�2�2��I�c�5�1�1�1�1�2�2�2�2�2�2�2�2�2�2�2����2�2�2�2��	�	�L�;�L�L�l�L�L�������
�
�
����9�"�9�9�*6�9�9������
����%	�4�*��"�$6�
�
������"�"����v���"	�"	�G�"�g�.�G��w�~�~�g�&�&�
���O�B�G�O�O�G�4�4�5�5�5���w��b�$��H�C��"�:��>�>�>�
�
��#�y��d��G�G�G�H�C���3��/����B��
�(�(��);�C�)@�)@�A�A�A��+�J�7�7�C��b�y�y����"�c�2�2�2����%�0�0�0����6�!1�5�9�9�9����1�����,�Q�X�6�6�<�<�>�>�C��{�a�'�'�C�I�I�K�K�,B�,B�%�-�-�'��	�	�"E�w�O�O�O�O����F�#�#�	����������������
�
�
�
�
�
�
�
�
�
�
����
�
�
�
��8��$�$�!�5��&�'��&�
�
��
 �3��&�'��4E�
�
���8��,���=�'�2D�E�E�E��	=���.�.�x�8�8�8�8���	=�	=�	=��K��;�<�<�<�<�<�	=����=�"�9�#�u�|�L�L����&�6�u�=�=���|��/��^�T�J�J�� �3��$�h�&@�
�
�����#�C�)@�$�G�G�	��,�,�.�.�4�"�D�D��I�I�>�
�
�
�
!�C�'�'��/�0�G��K�K�� � � ��$��l�4E�F�F�F�F�F���=�=�=���C�;�<�<�<�<�<�<�=���s��A#�# B�B�/H�G(�H�(G,	�,H�/G,	�0H�%H7�6H7�9Q-�;B>N:�9Q-�:Q�	BQ�Q-�Q�Q-�-Q1	�4Q1	�"S=�=T�T�#C!X�X)�(X)c���t|��}|rtj||��|r1|sd}|�d|��}|�dd��}nd}tj|d|���dS)N�NONEz$USERz
$DISABLE_USER�rootr7)�options)�setr�setup_user_keys�replace)r�r�r>r?�
key_prefixs     r�rvrvWs����t�9�9�D��-�� ��t�,�,�,����	��D�&�.�.�w��=�=�
��'�'���@�@�
�
��
���T�6�:�>�>�>�>�>�>�r<c�d���t�d��g}g�|r�fd�|D����fd�tj�dz��D��}|D]i}tj|��}|���}|r=t|��dkr*|�t|dd������j|S)aRead host keys from /etc/ssh/*.pub files and return them as a list.

    @param blacklist: List of key types to ignore. e.g. ['dsa', 'rsa']
    @returns: List of keys, each formatted as a two-element tuple.
        e.g. [('ssh-rsa', 'AAAAB3Nz...'), ('ssh-ed25519', 'AAAAC3Nx...')]
    r#c���g|]}�|fz��	S�r�)�.0�key_type�public_key_file_tmpls  �r��
<listcomp>z(get_public_host_keys.<locals>.<listcomp>us.���
�
�
�3;� �H�;�.�
�
�
r�c���g|]}|�v�|��	Sr�r�)r��hostfile�blacklist_filess  �r�r�z(get_public_host_keys.<locals>.<listcomp>ys.��������?�*�*�	�*�*�*r�)�*r/N�)rYrFr
�	load_file�split�len�append�tuple)r<�key_list�	file_list�	file_name�
file_contents�key_datar�r�s      @@r�rlrlhs�����(4�|�|�5���H��O��
�
�
�
�
�?H�
�
�
�������	�"6��"?�@�@����I��1�1�	���y�1�1�
� �&�&�(�(���	1��H�
�
��)�)��O�O�E�(�2�A�2�,�/�/�0�0�0���Or�)N)0�__doc__rFrC�rer^�loggingr�textwrapr�typingrrr�	cloudinitrr	r
�cloudinit.cloudr�cloudinit.configr�cloudinit.config.schemar
r�cloudinit.distrosrr�cloudinit.settingsr�MODULE_DESCRIPTIONr�__annotations__rV�compilerLrYrkrjrKrQ�k�updaterR�str�listr�rvrlr�r�r��<module>r�s���&�%�%�����	�	�	�	�	�	�	�	�
�
�
�
�������������+�+�+�+�+�+�+�+�+�+�*�*�*�*�*�*�*�*�*�*�!�!�!�!�!�!�#�#�#�#�#�#�<�<�<�<�<�<�<�<�2�2�2�2�2�2�2�2�+�+�+�+�+�+�^��N��
)�%��}����
� 	
� 	
�"�F "�U+�+��j�+�+�+�Z�,�t�
�
��7�7�7��",�"�*�:�#�#��*����$�W������	�0�0�A�����N�N�N�\�A�-�u�5��M�M�M�|�a�/�5�5�5�u�=�����L�1�$4�!?�!?�!?�� G�	
����&'�-�-�-�K�1������K��M=�

�M=��M=�#(�M=�/5�M=�=A�M=�	�M=�M=�M=�M=�`?�?�?�"��H�X�c�]�$;������r�