|
| 1 | +================== |
| 2 | +Encrypting secrets |
| 3 | +================== |
| 4 | + |
| 5 | +This document describes the supported operations for encrypting secrets and explains how to perform them using the appropriate tooling. |
| 6 | + |
| 7 | +Ansible-Vault |
| 8 | +============= |
| 9 | + |
| 10 | +OpenStack-Ansible provides tooling to encrypt and rotate secret files and keypairs using Ansible Vault. |
| 11 | + |
| 12 | +Role Defaults |
| 13 | +------------- |
| 14 | + |
| 15 | +.. literalinclude:: ../../encrypt_secrets/roles/ansible_vault/defaults/main.yml |
| 16 | + :language: yaml |
| 17 | + :start-after: under the License. |
| 18 | + |
| 19 | +Installing the Collection |
| 20 | +------------------------- |
| 21 | + |
| 22 | +To install the collection, define it in your region deployment configuration file, located at `/etc/openstack_deploy/user-collection-requirements.yml`, as shown below: |
| 23 | + |
| 24 | +.. code-block:: yaml |
| 25 | +
|
| 26 | + - name: osa_ops.encrypt_secrets |
| 27 | + type: git |
| 28 | + version: master |
| 29 | + source: https://opendev.org/openstack/openstack-ansible-ops#/encrypt_secrets |
| 30 | +
|
| 31 | +Then, run `./scripts/bootstrap-ansible.sh` to install the collection. |
| 32 | + |
| 33 | +Initial Encryption of Secret Files |
| 34 | +---------------------------------- |
| 35 | + |
| 36 | +When initializing a region for the first time, you should encrypt secrets and generated private keys before storing them in Git. You can perform this process locally or on the deployment host. |
| 37 | + |
| 38 | +.. NOTE:: |
| 39 | + |
| 40 | + You must re-run the encryption process whenever new services or keypairs are generated, which may occur at later deployment stages. |
| 41 | + |
| 42 | +Encrypting Secrets Locally |
| 43 | +~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 44 | + |
| 45 | +The process for encrypting secrets locally is similar to running it on the deploy host, but some context-specific variables required by OpenStack-Ansible may be unavailable and must be supplied manually. |
| 46 | + |
| 47 | +Ensure you have a Python virtual environment with Ansible installed before proceeding. |
| 48 | + |
| 49 | +1. Generate a password for the Ansible Vault and store it securely: |
| 50 | + |
| 51 | +.. code-block:: bash |
| 52 | +
|
| 53 | + pwgen 36 1 > /tmp/vault.secret |
| 54 | +
|
| 55 | +2. Run the encryption playbook: |
| 56 | + |
| 57 | +.. code-block:: bash |
| 58 | +
|
| 59 | + ansible-playbook osa_ops.encrypt_secrets.ansible_vault -e ansible_vault_region=${REGION_NAME} -e ansible_vault_pw=/tmp/vault.secret |
| 60 | +
|
| 61 | +3. Copy the contents of `/tmp/vault.secret` to the deployment host, for example to `/etc/openstack/vault.secret`. |
| 62 | +4. Define the vault secret path in `/etc/openstack_deploy/user.rc`: |
| 63 | + |
| 64 | +.. code-block:: bash |
| 65 | +
|
| 66 | + export ANSIBLE_VAULT_PASSWORD_FILE=/etc/openstack/vault.secret |
| 67 | +
|
| 68 | +5. Store the password securely in your preferred password manager. |
| 69 | +6. Push the changes to your Git repository. |
| 70 | +7. Ensure that the deploy host decrypts any required secrets. |
| 71 | + |
| 72 | +Encrypting Secrets on the Deployment Host |
| 73 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 74 | + |
| 75 | +Follow these steps to encrypt secrets directly on the deployment host: |
| 76 | + |
| 77 | +1. Generate a password and store it securely: |
| 78 | + |
| 79 | +.. code-block:: bash |
| 80 | +
|
| 81 | + pwgen 36 1 > /etc/openstack/vault.secret |
| 82 | +
|
| 83 | +2. Define the vault secret path in `/etc/openstack_deploy/user.rc`: |
| 84 | + |
| 85 | +.. code-block:: bash |
| 86 | +
|
| 87 | + export ANSIBLE_VAULT_PASSWORD_FILE=/etc/openstack/vault.secret |
| 88 | +
|
| 89 | +3. Run the encryption playbook: |
| 90 | + |
| 91 | +.. code-block:: bash |
| 92 | +
|
| 93 | + openstack-ansible osa_ops.encrypt_secrets.ansible_vault |
| 94 | +
|
| 95 | +4. Commit and push changes to `/etc/openstack_deploy` in your Git repository. |
| 96 | +5. Save the vault password (`/etc/openstack/vault.secret`) in a secure password manager. |
| 97 | +6. Decrypt any necessary secrets before running OpenStack playbooks. |
| 98 | + |
| 99 | + |
| 100 | +Decrypting Keypairs on the Deploy Host |
| 101 | +-------------------------------------- |
| 102 | + |
| 103 | +The OpenStack-Ansible PKI role does not support storing private keys in encrypted format on the deployment host. Instead, configure a pipeline that decrypts the keys after placing them on the deploy host. |
| 104 | + |
| 105 | +Encrypted keypairs should be committed to the Git repository, but stored unencrypted on the deployment host. |
| 106 | + |
| 107 | +To decrypt them, run the following playbook: |
| 108 | + |
| 109 | +.. code-block:: bash |
| 110 | +
|
| 111 | + openstack-ansible osa_ops.encrypt_secrets.ansible_vault -e ansible_vault_action=decrypt |
| 112 | +
|
| 113 | +
|
| 114 | +Rotating the Ansible Vault Secret |
| 115 | +--------------------------------- |
| 116 | + |
| 117 | +Rotating the Ansible Vault password requires re-encrypting all secrets in the repository. Assuming the original password is stored in `/tmp/vault.secret`, follow these steps: |
| 118 | + |
| 119 | +1. Generate a new vault password/encryption key: |
| 120 | + |
| 121 | +.. code-block:: bash |
| 122 | +
|
| 123 | + pwgen 45 1 > /tmp/vault.secret.new |
| 124 | +
|
| 125 | +2. Re-encrypt all secrets using the new password: |
| 126 | + |
| 127 | +.. code-block:: bash |
| 128 | +
|
| 129 | + ANSIBLE_VAULT_PASSWORD_FILE=/tmp/vault.secret ansible-playbook osa_ops.encrypt_secrets.ansible_vault -e ansible_vault_action=rotate |
| 130 | +
|
| 131 | +3. Transfer the new password to the deployment host and store it securely in a password manager. |
0 commit comments