refactor(vpn): split JWT identity and OpenVPN certificate lifecycle
OpenVPN Ansible / Ansible Syntax Check (push) Successful in 43s
OpenVPN Ansible / Ansible Lint (push) Successful in 1m8s
OpenVPN Ansible / Deploy VPN Networking and OpenVPN (push) Successful in 3m32s
OpenVPN Ansible / Generate SBOM (push) Successful in 55s
OpenVPN Ansible / Scan SBOM with Trivy (push) Successful in 18s
OpenVPN Ansible / Ansible Syntax Check (push) Successful in 43s
OpenVPN Ansible / Ansible Lint (push) Successful in 1m8s
OpenVPN Ansible / Deploy VPN Networking and OpenVPN (push) Successful in 3m32s
OpenVPN Ansible / Generate SBOM (push) Successful in 55s
OpenVPN Ansible / Scan SBOM with Trivy (push) Successful in 18s
- Add a dedicated role and workflow to generate VPN JWT identities and export public keys - Run identity preparation automatically for VPN nodes awaiting OpenBao registration - Gate OpenVPN and PKI setup until each node is registered - Split PKI setup into runtime, configuration, service, and initial certificate tasks - Restore TAP and bridge attachment after OpenVPN restarts - Remove bundled server certificate and private key
This commit is contained in:
+43
-54
@@ -1,63 +1,52 @@
|
||||
# OpenVPN PKI JWT identity preparation
|
||||
# OpenVPN PKI certificate lifecycle
|
||||
|
||||
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.
|
||||
This role manages the OpenVPN server certificate through the configured
|
||||
OpenBao PKI signing endpoint. JWT identity management belongs to the separate
|
||||
`openvpn_jwt` role, which runs before this role in `playbooks/openvpn.yml`.
|
||||
|
||||
## Prepare an identity
|
||||
## Task layout
|
||||
|
||||
Run the dedicated playbook, limiting it to the new VPN server when appropriate:
|
||||
`tasks/main.yml` delegates to focused stages:
|
||||
|
||||
```bash
|
||||
ansible-playbook \
|
||||
-i inventories/prod/hosts.ini \
|
||||
playbooks/openvpn-pki-identity.yml \
|
||||
--limit vpn01-test
|
||||
- `runtime.yml`: OpenBao CLI, runtime packages, and company VPN CA fingerprint.
|
||||
- `setup.yml`: certificate directories, OpenBao API CA, and lifecycle scripts.
|
||||
- `service.yml`: protected configuration and systemd service/timer.
|
||||
- `initial_certificate.yml`: initial issuance only when `server.crt` is absent.
|
||||
|
||||
Subsequent Ansible deployments do not renew an existing certificate. The
|
||||
daily systemd timer invokes the lifecycle script, which decides whether the
|
||||
certificate needs renewal.
|
||||
|
||||
On initial setup, the certificate is issued before OpenVPN is restarted or
|
||||
started. Ansible then flushes the restart handler, which restarts OpenVPN and
|
||||
waits for TAP before bringing it up and attaching it to the bridge. A separate
|
||||
start/TAP task runs only when no restart handler ran. The daily timer is enabled
|
||||
after the initial issuance attempt.
|
||||
|
||||
## CA configuration
|
||||
|
||||
The OpenBao API CA is deployed to `/root/openbao-ca.crt` and is used only for
|
||||
OpenBao API TLS. The company VPN Root CA deployed by the `openvpn` role at
|
||||
`/etc/openvpn/certs/ca.crt` anchors OpenVPN server certificate validation.
|
||||
The role calculates that certificate's SHA-256 fingerprint on the VPN node.
|
||||
|
||||
## Certificate configuration
|
||||
|
||||
Configure node-specific names in inventory. For example:
|
||||
|
||||
```yaml
|
||||
openvpn_pki_certificate_common_name: "{{ inventory_hostname }}"
|
||||
openvpn_pki_certificate_dns_sans:
|
||||
- "{{ inventory_hostname }}"
|
||||
```
|
||||
|
||||
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.
|
||||
Set `openvpn_pki_bao_addr`, `openvpn_pki_bao_cacert`, and
|
||||
`openvpn_pki_sign_endpoint` to match the OpenBao deployment. The lifecycle
|
||||
script runs as root from `/usr/local/libexec/openvpn-pki/`, using the
|
||||
protected configuration at `/etc/openvpn/openbao-vpn.conf`. It uses the same
|
||||
`flock` lock for initial issuance and timer runs.
|
||||
|
||||
## Requirements
|
||||
|
||||
Install the `community.crypto` collection on the Ansible controller. It is not
|
||||
currently listed in the repository's `requirements.yml`.
|
||||
Install the collections listed in the repository's `requirements.yml`,
|
||||
including `community.crypto` for the `openvpn_jwt` role.
|
||||
|
||||
Reference in New Issue
Block a user