feat(openvpn-pki): add JWT identity preparation workflow
OpenVPN Ansible / Ansible Lint (push) Successful in 1m7s
OpenVPN Ansible / Ansible Syntax Check (push) Successful in 48s
OpenVPN Ansible / Deploy VPN Networking and OpenVPN (push) Successful in 1m50s
OpenVPN Ansible / Generate SBOM (push) Successful in 55s
OpenVPN Ansible / Scan SBOM with Trivy (push) Successful in 21s
OpenVPN Ansible / Ansible Lint (push) Successful in 1m7s
OpenVPN Ansible / Ansible Syntax Check (push) Successful in 48s
OpenVPN Ansible / Deploy VPN Networking and OpenVPN (push) Successful in 1m50s
OpenVPN Ansible / Generate SBOM (push) Successful in 55s
OpenVPN Ansible / Scan SBOM with Trivy (push) Successful in 21s
- Add dedicated Ansible playbook and role for VPN server JWT identities - Generate and securely store per-server RSA key pairs - Export public keys as workflow artifacts for manual OpenBao registration - Add community.crypto collection dependency
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
# OpenVPN PKI JWT identity preparation
|
||||
|
||||
This role prepares one local JWT RSA identity per VPN server so an administrator
|
||||
can register each public key with the existing OpenBao JWT configuration. It
|
||||
does not configure OpenBao or request certificates.
|
||||
|
||||
## Prepare an identity
|
||||
|
||||
Run the dedicated playbook, limiting it to the new VPN server when appropriate:
|
||||
|
||||
```bash
|
||||
ansible-playbook \
|
||||
-i inventories/prod/hosts.ini \
|
||||
playbooks/openvpn-pki-identity.yml \
|
||||
--limit vpn01-test
|
||||
```
|
||||
|
||||
The playbook targets `vpn_nodes` and uses privilege escalation. It creates the
|
||||
identity on the selected server; it does not deploy certificates or alter the
|
||||
OpenVPN service.
|
||||
|
||||
## Key locations and retrieval
|
||||
|
||||
The server stores its root-owned identity in `/etc/vault-jwt/` by default:
|
||||
|
||||
- `private.pem`: RSA 3072-bit private key, mode `0600`.
|
||||
- `public.pem`: corresponding PEM public key, mode `0644`.
|
||||
|
||||
Only `public.pem` is fetched to the controller, as
|
||||
`artifacts/openvpn-pki-public-keys/<inventory_hostname>.pem`. The artifacts
|
||||
directory is ignored by Git. The private key is generated on the VPN server
|
||||
with `community.crypto.openssl_privatekey`; it is never fetched.
|
||||
|
||||
## Register the public key in OpenBao
|
||||
|
||||
Provide the fetched PEM public key to the OpenBao administrator using the
|
||||
approved secure process. The administrator should combine the new PEM public
|
||||
key with all currently registered PEM public keys into a bundle, then update
|
||||
the existing JWT authentication configuration with that complete bundle. The
|
||||
update must preserve every previously registered key; replacing the configured
|
||||
key set with only the new key would invalidate identities already in use.
|
||||
Public-key registration is a manual administrator operation and is not
|
||||
performed by this role.
|
||||
|
||||
## Existing identity behavior
|
||||
|
||||
The role creates a missing identity only when both key files are absent. If
|
||||
both already exist, it leaves them unchanged and fetches the existing public
|
||||
key again. If exactly one key file exists, the role fails rather than
|
||||
replacing or silently repairing the identity. Investigate and recover the
|
||||
matching pair deliberately before rerunning. Do not delete or replace the
|
||||
private key as a routine way to resolve errors: OpenBao registrations depend
|
||||
on the corresponding public key.
|
||||
|
||||
The private key must remain on its VPN server because it is the credential
|
||||
used to prove that server's identity. Copying it to the controller or
|
||||
registering it with OpenBao would defeat the separation between private key
|
||||
custody and public-key registration.
|
||||
|
||||
## Requirements
|
||||
|
||||
Install the `community.crypto` collection on the Ansible controller. It is not
|
||||
currently listed in the repository's `requirements.yml`.
|
||||
@@ -0,0 +1,6 @@
|
||||
---
|
||||
openvpn_pki_jwt_directory: /etc/vault-jwt
|
||||
openvpn_pki_jwt_private_key_path: "{{ openvpn_pki_jwt_directory }}/private.pem"
|
||||
openvpn_pki_jwt_public_key_path: "{{ openvpn_pki_jwt_directory }}/public.pem"
|
||||
openvpn_pki_jwt_rsa_bits: 3072
|
||||
openvpn_pki_public_key_artifact_directory: "{{ playbook_dir }}/../artifacts/openvpn-pki-public-keys"
|
||||
@@ -0,0 +1,62 @@
|
||||
---
|
||||
- name: Create JWT identity directory
|
||||
ansible.builtin.file:
|
||||
path: "{{ openvpn_pki_jwt_directory }}"
|
||||
state: directory
|
||||
owner: root
|
||||
group: root
|
||||
mode: "0700"
|
||||
|
||||
- name: Check for existing JWT private key
|
||||
ansible.builtin.stat:
|
||||
path: "{{ openvpn_pki_jwt_private_key_path }}"
|
||||
register: openvpn_pki_jwt_private_key_stat
|
||||
|
||||
- name: Check for existing JWT public key
|
||||
ansible.builtin.stat:
|
||||
path: "{{ openvpn_pki_jwt_public_key_path }}"
|
||||
register: openvpn_pki_jwt_public_key_stat
|
||||
|
||||
- name: Refuse incomplete JWT identity
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- openvpn_pki_jwt_private_key_stat.stat.exists == openvpn_pki_jwt_public_key_stat.stat.exists
|
||||
fail_msg: >-
|
||||
Only one JWT key file exists. Refusing to replace or repair an existing
|
||||
identity automatically. Inspect the files and recover the matching key
|
||||
pair deliberately before rerunning this playbook.
|
||||
|
||||
- name: Generate JWT RSA private key
|
||||
community.crypto.openssl_privatekey:
|
||||
path: "{{ openvpn_pki_jwt_private_key_path }}"
|
||||
type: RSA
|
||||
size: "{{ openvpn_pki_jwt_rsa_bits }}"
|
||||
owner: root
|
||||
group: root
|
||||
mode: "0600"
|
||||
when: not openvpn_pki_jwt_private_key_stat.stat.exists
|
||||
|
||||
- name: Generate JWT public key from existing private key
|
||||
community.crypto.openssl_publickey:
|
||||
path: "{{ openvpn_pki_jwt_public_key_path }}"
|
||||
privatekey_path: "{{ openvpn_pki_jwt_private_key_path }}"
|
||||
format: PEM
|
||||
owner: root
|
||||
group: root
|
||||
mode: "0644"
|
||||
when: not openvpn_pki_jwt_public_key_stat.stat.exists
|
||||
|
||||
- name: Create public key artifact directory on controller
|
||||
ansible.builtin.file:
|
||||
path: "{{ openvpn_pki_public_key_artifact_directory }}"
|
||||
state: directory
|
||||
mode: "0700"
|
||||
delegate_to: localhost
|
||||
become: false
|
||||
|
||||
- name: Fetch JWT public key to controller
|
||||
ansible.builtin.fetch:
|
||||
src: "{{ openvpn_pki_jwt_public_key_path }}"
|
||||
dest: "{{ openvpn_pki_public_key_artifact_directory }}/{{ inventory_hostname }}.pem"
|
||||
flat: true
|
||||
validate_checksum: true
|
||||
@@ -0,0 +1,3 @@
|
||||
---
|
||||
- name: Import JWT identity preparation tasks
|
||||
ansible.builtin.import_tasks: identity.yml
|
||||
Reference in New Issue
Block a user