%PDF- %PDF-
Direktori : /lib/python2.7/site-packages/salt/states/ |
Current File : //lib/python2.7/site-packages/salt/states/x509.pyo |
� ���^c @@ s* d Z d d l m Z m Z m Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l m Z y d d l m Z Wn e k r� n Xd � Z d � Z d � Z d d e e d � Z d d d e e e d � Z d � Z d d d d � Z d d d d d d e d � Z e d � Z d S( um Manage X509 Certificates .. versionadded:: 2015.8.0 :depends: M2Crypto This module can enable managing a complete PKI infrastructure including creating private keys, CA's, 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 salt-minion: service.running: - enable: True - listen: - file: /etc/salt/minion.d/signing_policies.conf /etc/salt/minion.d/signing_policies.conf: file.managed: - source: salt://signing_policies.conf /etc/pki: file.directory /etc/pki/issued_certs: file.directory /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 - managed_private_key: name: /etc/pki/ca.key bits: 4096 backup: True - require: - file: /etc/pki mine.send: module.run: - func: x509.get_pem_entries - kwargs: glob_path: /etc/pki/ca.crt - onchanges: - x509: /etc/pki/ca.crt The signing policy defines properties that override any property requested or included in a CRL. It also can define a restricted list of minons which are allowed to remotely invoke this signing policy. /srv/salt/signing_policies.conf .. 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 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.certificate_managed: - ca_server: ca - signing_policy: www - public_key: /etc/pki/www.key - CN: www.example.com - days_remaining: 30 - backup: True - managed_private_key: name: /etc/pki/www.key bits: 4096 backup: True i ( t absolute_importt unicode_literalst print_functionN( t six( t RSAErrorc C@ s d t k r d St d f Sd S( uO only load this module if the corresponding execution module is loaded u x509.get_pem_entryu x509u/ Could not load x509 state: m2crypto unavailableN( t __salt__t False( ( ( s4 /usr/lib/python2.7/site-packages/salt/states/x509.pyt __virtual__� s c C@ s� g } x� | D]� } x� t j | � D]~ \ } } i } x\ | D]T } xK t j | � D]: \ } } t | t j � r� | j d � } n | | | <qR Wq<