File manager - Edit - /opt/saltstack/salt/lib/python3.10/site-packages/salt/states/__pycache__/x509.cpython-310.pyc
Back
o ;j*o � @ s� d Z ddlZddlZddlZddlZddlZddlZddlZzddl m Z W n ey/ Y nw e�e �Zdd� Zdd� Zdd � Zd&dd �Z d'dd�Zdd� Zd(dd�Zdd� Zdd� Zdd� Zd)dd�Z ! d*d"d#�Zd(d$d%�ZdS )+a" Manage X509 Certificates .. versionadded:: 2015.8.0 :depends: M2Crypto .. deprecated:: 3006.0 .. warning:: This module has been deprecated and will be removed in Salt 3009 (Potassium). Please migrate to the replacement modules. For breaking changes between both versions, you can refer to the :ref:`x509_v2 execution module docs <x509-setup>`. They will become the default ``x509`` modules in Salt 3008 (Argon). You can explicitly switch to the new modules before that release by setting ``features: {x509_v2: true}`` in your minion configuration. This module can enable managing a complete PKI infrastructure including creating private keys, CAs, certificates and CRLs. It includes the ability to generate a private key on a server, and have the corresponding public key sent to a remote CA to create a CA signed certificate. This can be done in a secure manner, where private keys are always generated locally and never moved across the network. Here is a simple example scenario. In this example ``ca`` is the ca server, and ``www`` is a web server that needs a certificate signed by ``ca``. For remote signing, peers must be permitted to remotely call the :mod:`sign_remote_certificate <salt.modules.x509.sign_remote_certificate>` function. /etc/salt/master.d/peer.conf .. code-block:: yaml peer: .*: - x509.sign_remote_certificate /srv/salt/top.sls .. code-block:: yaml base: '*': - cert 'ca': - ca 'www': - www This state creates the CA key, certificate and signing policy. It also publishes the certificate to the mine where it can be easily retrieved by other minions. /srv/salt/ca.sls .. code-block:: yaml /etc/salt/minion.d/x509.conf: file.managed: - source: salt://x509.conf restart-salt-minion: cmd.run: - name: 'salt-call service.restart salt-minion' - bg: True - onchanges: - file: /etc/salt/minion.d/x509.conf /etc/pki: file.directory /etc/pki/issued_certs: file.directory /etc/pki/ca.key: x509.private_key_managed: - bits: 4096 - backup: True /etc/pki/ca.crt: x509.certificate_managed: - signing_private_key: /etc/pki/ca.key - CN: ca.example.com - C: US - ST: Utah - L: Salt Lake City - basicConstraints: "critical CA:true" - keyUsage: "critical cRLSign, keyCertSign" - subjectKeyIdentifier: hash - authorityKeyIdentifier: keyid,issuer:always - days_valid: 3650 - days_remaining: 0 - backup: True - require: - file: /etc/pki The signing policy defines properties that override any property requested or included in a CRL. It also can define a restricted list of minions which are allowed to remotely invoke this signing policy. /srv/salt/x509.conf .. code-block:: yaml mine_functions: x509.get_pem_entries: [/etc/pki/ca.crt] x509_signing_policies: www: - minions: 'www' - signing_private_key: /etc/pki/ca.key - signing_cert: /etc/pki/ca.crt - C: US - ST: Utah - L: Salt Lake City - basicConstraints: "critical CA:false" - keyUsage: "critical keyEncipherment" - subjectKeyIdentifier: hash - authorityKeyIdentifier: keyid,issuer:always - days_valid: 90 - copypath: /etc/pki/issued_certs/ This state will instruct all minions to trust certificates signed by our new CA. Using Jinja to strip newlines from the text avoids dealing with newlines in the rendered YAML, and the :mod:`sign_remote_certificate <salt.states.x509.sign_remote_certificate>` state will handle properly formatting the text before writing the output. /srv/salt/cert.sls .. code-block:: jinja /usr/local/share/ca-certificates: file.directory /usr/local/share/ca-certificates/intca.crt: x509.pem_managed: - text: {{ salt['mine.get']('ca', 'x509.get_pem_entries')['ca']['/etc/pki/ca.crt']|replace('\n', '') }} This state creates a private key then requests a certificate signed by ca according to the www policy. /srv/salt/www.sls .. code-block:: yaml /etc/pki/www.crt: x509.private_key_managed: - name: /etc/pki/www.key - bits: 4096 - backup: True /etc/pki/www.crt: x509.certificate_managed: - ca_server: ca - signing_policy: www - public_key: /etc/pki/www.key - CN: www.example.com - days_remaining: 30 - backup: True This other state creates a private key then requests a certificate signed by ca according to the www policy but adds a strict date range for the certificate to be considered valid. /srv/salt/www-time-limited.sls .. code-block:: yaml /etc/pki/www-time-limited.crt: x509.certificate_managed: - ca_server: ca - signing_policy: www - public_key: /etc/pki/www-time-limited.key - CN: www.example.com - not_before: 2019-05-05 00:00:00 - not_after: 2020-05-05 14:30:00 - backup: True � N)�RSAErrorc C s2 t d �d�r dS dtv rtjj�dd� dS dS ) zO only load this module if the corresponding execution module is loaded ZfeaturesZx509_v2)FzSuperseded, using x509_v2�x509.get_pem_entryZ Potassiumz�The x509 modules are deprecated. Please migrate to the replacement modules (x509_v2). They are the default from Salt 3008 (Argon) onwards.Zx509)Fz/Could not load x509 state: m2crypto unavailable)�__opts__�get�__salt__�salt�utilsZversionsZ warn_until� r r �D/opt/saltstack/salt/lib/python3.10/site-packages/salt/states/x509.py�__virtual__� s �r c C sh g }| D ]-}|� � D ]&}i }|D ]}|�� D ]\}}t|tj�r%|�d�}|||<