File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/__pycache__/x509_v2.cpython-310.pyc
o
�N�gC, � @ s� d Z ddlZddlZddlZddlZddlZddlZddlZddl m Z m
Z
mZ zddlm
Z ddlmZmZ ddlm m
Z dZW n eyN dZY nw ddlZddlZddlZddlmZmZ ddlmZ e� e!�Z"d Z#d
d� Z$ dZd
d�Z% d[dd�Z& d\dd�Z' d]dd�Z( d^dd�Z)d_dd�Z* d`dd�Z+d_dd�Z, dadd �Z- dbd!d"�Z.dcd#d$�Z/d%d&� Z0d'd(� Z1ddd)d*�Z2ddd+d,�Z3d[d-d.�Z4ddd/d0�Z5d1d2� Z6d3d4� Z7d5d6� Z8d7d8� Z9 ded9d:�Z:ded;d<�Z;d=d>� Z<ddd?d@�Z= d[dAdB�Z>dCdD� Z?dfdEdF�Z@dGdH� ZAdddIdJ�ZBdgdKdL�ZCdMdN� ZDdOdP� ZEdhdRdS�ZFdTdU� ZGdVdW� ZHdXdY� ZIdS )ia<
Manage X.509 certificates
=========================
:depends: cryptography
.. versionadded:: 3006.0
This module represents a complete rewrite of the original ``x509`` modules
and is named ``x509_v2`` since it introduces breaking changes.
.. note::
* PKCS12-related operations require at least cryptography release 36.
* PKCS12-related operations with Edwards-curve keys require at least cryptography release 37.
* PKCS7-related operations require at least cryptography release 37.
Configuration
-------------
Explicit activation
~~~~~~~~~~~~~~~~~~~
Since this module uses the same virtualname as the previous ``x509`` modules,
but is incompatible with them, it needs to be explicitly activated on each
minion by including the following line in the minion configuration:
.. code-block:: yaml
# /etc/salt/minion.d/x509.conf
features:
x509_v2: true
Peer communication
~~~~~~~~~~~~~~~~~~
To be able to remotely sign certificates, it is required to configure the Salt
master to allow :term:`Peer Communication`:
.. code-block:: yaml
# /etc/salt/master.d/peer.conf
peer:
.*:
- x509.sign_remote_certificate
In order for the :term:`Compound Matcher` to work with restricting signing
policies to a subset of minions, in addition calls to :py:func:`match.compound <salt.modules.match.compound>`
by the minion acting as the CA must be permitted:
.. code-block:: yaml
# /etc/salt/master.d/peer.conf
peer:
.*:
- x509.sign_remote_certificate
ca_server:
- match.compound
.. note::
Compound matching in signing policies currently has security tradeoffs since the
CA server queries the requesting minion itself if it matches, not the Salt master.
It is recommended to rely on glob matching only.
Signing policies
~~~~~~~~~~~~~~~~
In addition, the minion representing the CA needs to have at least one
signing policy configured, remote calls not referencing one are always
rejected.
The parameters specified in this signing policy override any
parameters passed from the minion requesting the certificate. It can be
configured in the CA minion's pillar, which takes precedence, or any
location :py:func:`config.get <salt.modules.config.get>` looks up in.
Signing policies are defined under ``x509_signing_policies``.
You can restrict which minions can request a certificate under a configured
signing policy by specifying a matcher in ``minions``. This can be a glob
or compound matcher (for the latter, see the notes above).
.. code-block:: yaml
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, cRLSign, keyCertSign"
- subjectKeyIdentifier: hash
- authorityKeyIdentifier: keyid,issuer:always
- days_valid: 90
- copypath: /etc/pki/issued_certs/
.. note::
The following semantics are applied regarding the order of preference
for specifying the subject name:
* If neither ``subject`` nor any name attributes (like ``CN``) are part of the policy,
issued certificates can contain any requested ones.
* If any name attributes are specified in the signing policy, ``subject`` contained
in requests is ignored.
* If ``subject`` is specified in the signing policy, any name attributes are ignored.
If the request contains the same data type for ``subject`` as the signing policy
(for dicts and lists, and only then), merging is performed, otherwise ``subject``
is taken from the signing policy. Dicts are merged and list items are appended,
with the items taken from the signing policy having priority.
Breaking changes versus the previous ``x509`` modules
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* The output format has changed for all ``read_*`` functions as well as the state return dict.
* The formatting of some extension definitions might have changed, but should
be stable for most basic use cases.
* The default ordering of RDNs/Name Attributes in the subject's Distinguished Name
has been adapted to industry standards. This might cause a reissuance
during the first state run.
* For ``x509.private_key_managed``, the file mode defaults to ``0400``. This should
be considered a bug fix because writing private keys with world-readable
permissions by default is a security issue.
Note that when a ``ca_server`` is involved, both peers must use the updated module version.
.. _x509-setup:
� N)�datetime� timedelta�timezone)�hashes�
serializationTF)�CommandExecutionError�SaltInvocationError)�OrderedDict�x509c C s"