File manager - Edit - /opt/saltstack/salt/lib/python3.10/site-packages/salt/runners/__pycache__/nacl.cpython-310.pyc
Back
o ;j� � @ sj d Z ddlZdZdd� Zddd�Zdd � Zdd d�Zdd � Zddd�Z dd� Z dd� Zdd� Zdd� Z dS )a� This module helps include encrypted passwords in pillars, grains and salt state files. :depends: PyNaCl, https://github.com/pyca/pynacl This is often useful if you wish to store your pillars in source control or share your pillar data with others that you trust. I don't advise making your pillars public regardless if they are encrypted or not. :configuration: The following configuration defaults can be define (pillar or config files) Avoid storing private keys in pillars! Ensure master does not have `pillar_opts=True`: .. code-block:: python # cat /etc/salt/master.d/nacl.conf nacl.config: # NOTE: `key` and `key_file` have been renamed to `sk`, `sk_file` # also `box_type` default changed from secretbox to sealedbox. box_type: sealedbox (default) sk_file: /etc/salt/pki/master/nacl (default) pk_file: /etc/salt/pki/master/nacl.pub (default) sk: None pk: None Usage can override the config defaults: .. code-block:: bash salt-run nacl.enc sk_file=/etc/salt/pki/master/nacl pk_file=/etc/salt/pki/master/nacl.pub The nacl lib uses 32byte keys, these keys are base64 encoded to make your life more simple. To generate your `sk_file` and `pk_file` use: .. code-block:: bash salt-run nacl.keygen sk_file=/etc/salt/pki/master/nacl # or if you want to work without files. salt-run nacl.keygen local: ---------- pk: /kfGX7PbWeu099702PBbKWLpG/9p06IQRswkdWHCDk0= sk: SVWut5SqNpuPeNzb1b9y6b2eXg2PLIog43GBzp48Sow= Now with your keypair, you can encrypt data: You have two option, `sealedbox` or `secretbox`. SecretBox is data encrypted using private key `pk`. Sealedbox is encrypted using public key `pk`. Recommend using Sealedbox because the one way encryption permits developers to encrypt data for source control but not decrypt. Sealedbox only has one key that is for both encryption and decryption. .. code-block:: bash salt-run nacl.enc asecretpass pk=/kfGX7PbWeu099702PBbKWLpG/9p06IQRswkdWHCDk0= tqXzeIJnTAM9Xf0mdLcpEdklMbfBGPj2oTKmlgrm3S1DTVVHNnh9h8mU1GKllGq/+cYsk6m5WhGdk58= To decrypt the data: .. code-block:: bash salt-run nacl.dec data='tqXzeIJnTAM9Xf0mdLcpEdklMbfBGPj2oTKmlgrm3S1DTVVHNnh9h8mU1GKllGq/+cYsk6m5WhGdk58=' sk='SVWut5SqNpuPeNzb1b9y6b2eXg2PLIog43GBzp48Sow=' When the keys are defined in the master config you can use them from the nacl runner without extra parameters: .. code-block:: python # cat /etc/salt/master.d/nacl.conf nacl.config: sk_file: /etc/salt/pki/master/nacl pk: 'cTIqXwnUiD1ulg4kXsbeCE7/NoeKEzd4nLeYcCFpd9k=' .. code-block:: bash salt-run nacl.enc 'asecretpass' salt-run nacl.dec data='tqXzeIJnTAM9Xf0mdLcpEdklMbfBGPj2oTKmlgrm3S1DTVVHNnh9h8mU1GKllGq/+cYsk6m5WhGdk58=' .. code-block:: yaml # a salt developers minion could have pillar data that includes a nacl public key nacl.config: pk: '/kfGX7PbWeu099702PBbKWLpG/9p06IQRswkdWHCDk0=' The developer can then use a less-secure system to encrypt data. .. code-block:: bash salt-run nacl.enc apassword Pillar files can include protected data that the salt master decrypts: .. code-block:: jinja pillarexample: user: root password1: {{salt.nacl.dec('DRB7Q6/X5gGSRCTpZyxS6hlbWj0llUA+uaVyvou3vJ4=')|json}} cert_key: {{salt.nacl.dec_file('/srv/salt/certs/example.com/key.nacl')|json}} cert_key2: {{salt.nacl.dec_file('salt:///certs/example.com/key.nacl')|json}} Larger files like certificates can be encrypted with: .. code-block:: bash salt-run nacl.enc_file /tmp/cert.crt out=/tmp/cert.nacl � N�naclc C s t d du rdS tjj�� S )NZ fips_modeT)Fz&nacl runner not available in FIPS mode)�__opts__�salt�utilsr Zcheck_requirements� r r �E/opt/saltstack/salt/lib/python3.10/site-packages/salt/runners/nacl.py�__virtual__w s r c K � t |d<