Compare commits
26
Commits
34a18374a5
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
787cbd9e96 | ||
|
|
b6a5ab00b2 | ||
|
|
a4596d76b0 | ||
|
|
4b8e7f3592 | ||
|
|
36d2845a3a | ||
|
|
0edc2c531f | ||
|
|
99ada6fab7 | ||
|
|
299397f4f9 | ||
|
|
acb5c4ba82 | ||
|
|
746e37f077 | ||
|
|
6c86e1bf08 | ||
|
|
86c47eec4f | ||
|
|
853e852753 | ||
|
|
76c82f83c1 | ||
|
|
c23ff11194 | ||
|
|
82d44662b4 | ||
|
|
22394db088 | ||
|
|
3f4899c73a | ||
|
|
4403bc0f4e | ||
|
|
cd65d6aea1 | ||
|
|
31f785b2b8 | ||
|
|
d0b149fbe0 | ||
|
|
ec57d3575b | ||
|
|
b5d5a460b8 | ||
|
|
132c29e3ef | ||
|
|
138acbe08e |
@@ -0,0 +1,4 @@
|
|||||||
|
exclude_paths:
|
||||||
|
- .gitea/
|
||||||
|
skip_list:
|
||||||
|
- partial-become
|
||||||
@@ -0,0 +1,181 @@
|
|||||||
|
name: OpenVPN Ansible
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
|
||||||
|
ansible-lint:
|
||||||
|
name: Ansible Lint
|
||||||
|
runs-on: hetzner-ubuntu-latest
|
||||||
|
|
||||||
|
container:
|
||||||
|
image: gitea.infrastructure.helmholz.cloud/gitea_admin/ansible-utilities:latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Run ansible-lint
|
||||||
|
env:
|
||||||
|
ANSIBLE_CONFIG: ${{ github.workspace }}/ansible.cfg
|
||||||
|
run: |
|
||||||
|
ansible-galaxy collection install -r requirements.yml
|
||||||
|
ansible-lint
|
||||||
|
|
||||||
|
|
||||||
|
syntax-check:
|
||||||
|
name: Ansible Syntax Check
|
||||||
|
runs-on: hetzner-ubuntu-latest
|
||||||
|
|
||||||
|
container:
|
||||||
|
image: gitea.infrastructure.helmholz.cloud/gitea_admin/ansible-utilities:latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Syntax check
|
||||||
|
env:
|
||||||
|
ANSIBLE_CONFIG: ${{ github.workspace }}/ansible.cfg
|
||||||
|
run: |
|
||||||
|
ansible-galaxy collection install -r requirements.yml
|
||||||
|
ansible-inventory --list > /dev/null
|
||||||
|
for playbook in playbooks/*.yml; do
|
||||||
|
echo "Syntax checking ${playbook}"
|
||||||
|
ansible-playbook --syntax-check "$playbook"
|
||||||
|
done
|
||||||
|
|
||||||
|
|
||||||
|
deploy-prod:
|
||||||
|
name: Deploy VPN Networking and OpenVPN
|
||||||
|
runs-on: hetzner-ubuntu-latest
|
||||||
|
|
||||||
|
needs:
|
||||||
|
- ansible-lint
|
||||||
|
- syntax-check
|
||||||
|
|
||||||
|
container:
|
||||||
|
image: gitea.infrastructure.helmholz.cloud/gitea_admin/ansible-utilities:latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Setup SSH
|
||||||
|
run: |
|
||||||
|
echo "Setting up SSH ..."
|
||||||
|
mkdir -p ~/.ssh
|
||||||
|
printf '%s\n' '${{ secrets.SSH_PRIVATE_KEY }}' > ~/.ssh/id_ed25519
|
||||||
|
chmod 600 ~/.ssh/id_ed25519
|
||||||
|
ssh-keygen -y -f ~/.ssh/id_ed25519 > /dev/null
|
||||||
|
echo "SSH key configured successfully"
|
||||||
|
|
||||||
|
- name: Deploy
|
||||||
|
env:
|
||||||
|
ANSIBLE_CONFIG: ${{ github.workspace }}/ansible.cfg
|
||||||
|
run: |
|
||||||
|
ansible-galaxy collection install -r requirements.yml
|
||||||
|
ansible-playbook playbooks/nat-gateway.yml --limit nat_gateways
|
||||||
|
ansible-playbook playbooks/private-vpn-routing.yml --limit vpn_nodes
|
||||||
|
ansible-playbook playbooks/openvpn.yml
|
||||||
|
ansible-playbook playbooks/monitoring-exporter.yml
|
||||||
|
|
||||||
|
|
||||||
|
sbom:
|
||||||
|
name: Generate SBOM
|
||||||
|
runs-on: hetzner-ubuntu-latest
|
||||||
|
|
||||||
|
needs:
|
||||||
|
- deploy-prod
|
||||||
|
|
||||||
|
container:
|
||||||
|
image: gitea.infrastructure.helmholz.cloud/gitea_admin/ansible-utilities:latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Setup SSH
|
||||||
|
run: |
|
||||||
|
echo "Setting up SSH ..."
|
||||||
|
mkdir -p ~/.ssh
|
||||||
|
printf '%s\n' '${{ secrets.SSH_PRIVATE_KEY }}' > ~/.ssh/id_ed25519
|
||||||
|
chmod 600 ~/.ssh/id_ed25519
|
||||||
|
ssh-keygen -y -f ~/.ssh/id_ed25519 > /dev/null
|
||||||
|
echo "SSH key configured successfully"
|
||||||
|
|
||||||
|
- name: Generate SBOM
|
||||||
|
env:
|
||||||
|
ANSIBLE_CONFIG: ${{ github.workspace }}/ansible.cfg
|
||||||
|
run: |
|
||||||
|
ansible-playbook playbooks/sbom.yml
|
||||||
|
|
||||||
|
- name: Upload SBOM
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: sbom
|
||||||
|
path: reports/sbom/
|
||||||
|
retention-days: 365
|
||||||
|
|
||||||
|
|
||||||
|
trivy-sbom:
|
||||||
|
name: Scan SBOM with Trivy
|
||||||
|
runs-on: hetzner-ubuntu-latest
|
||||||
|
|
||||||
|
needs:
|
||||||
|
- sbom
|
||||||
|
|
||||||
|
container:
|
||||||
|
image: gitea.infrastructure.helmholz.cloud/gitea_admin/ansible-utilities:latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Download SBOM
|
||||||
|
uses: actions/download-artifact@v4
|
||||||
|
with:
|
||||||
|
name: sbom
|
||||||
|
path: reports/sbom/
|
||||||
|
|
||||||
|
- name: Scan SBOMs
|
||||||
|
run: |
|
||||||
|
ls -R reports || true
|
||||||
|
|
||||||
|
mkdir -p reports/trivy
|
||||||
|
|
||||||
|
if compgen -G "reports/sbom/*.json" > /dev/null; then
|
||||||
|
|
||||||
|
for sbom in reports/sbom/*.json; do
|
||||||
|
filename=$(basename "$sbom" .json)
|
||||||
|
|
||||||
|
echo "Scanning $sbom"
|
||||||
|
|
||||||
|
trivy sbom \
|
||||||
|
--format json \
|
||||||
|
--output "reports/trivy/${filename}-trivy.json" \
|
||||||
|
--exit-code 0 \
|
||||||
|
"$sbom"
|
||||||
|
|
||||||
|
trivy sbom \
|
||||||
|
--format table \
|
||||||
|
--output "reports/trivy/${filename}-trivy.txt" \
|
||||||
|
--exit-code 0 \
|
||||||
|
"$sbom"
|
||||||
|
done
|
||||||
|
|
||||||
|
else
|
||||||
|
echo "No SBOM files found."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Upload Trivy reports
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: trivy-reports
|
||||||
|
path: reports/trivy/
|
||||||
|
retention-days: 365
|
||||||
@@ -0,0 +1,91 @@
|
|||||||
|
name: OpenVPN JWT Identity Preparation
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_run:
|
||||||
|
workflows:
|
||||||
|
- OpenVPN Ansible
|
||||||
|
types:
|
||||||
|
- completed
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
prepare-identities:
|
||||||
|
name: Prepare unregistered VPN identities
|
||||||
|
runs-on: hetzner-ubuntu-latest
|
||||||
|
if: >-
|
||||||
|
github.event.workflow_run.conclusion == 'success' &&
|
||||||
|
github.event.workflow_run.head_branch == 'main'
|
||||||
|
|
||||||
|
container:
|
||||||
|
image: gitea.infrastructure.helmholz.cloud/gitea_admin/ansible-utilities:latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
ref: ${{ github.event.workflow_run.head_sha }}
|
||||||
|
|
||||||
|
- name: Find VPN nodes awaiting JWT registration
|
||||||
|
id: pending
|
||||||
|
run: |
|
||||||
|
set -eu
|
||||||
|
ansible-inventory -i inventories/prod/hosts.ini --list |
|
||||||
|
python3 -c '
|
||||||
|
import json
|
||||||
|
import sys
|
||||||
|
|
||||||
|
inventory = json.load(sys.stdin)
|
||||||
|
vpn_hosts = inventory.get("vpn_nodes", {}).get("hosts", [])
|
||||||
|
hostvars = inventory.get("_meta", {}).get("hostvars", {})
|
||||||
|
pending = []
|
||||||
|
for hostname in vpn_hosts:
|
||||||
|
registered = hostvars.get(hostname, {}).get("openvpn_jwt_registered", False)
|
||||||
|
if str(registered).strip().lower() not in {"true", "yes", "1", "on"}:
|
||||||
|
pending.append(hostname)
|
||||||
|
|
||||||
|
print(",".join(pending))
|
||||||
|
' > /tmp/openvpn-jwt-pending-hosts
|
||||||
|
pending_hosts=$(cat /tmp/openvpn-jwt-pending-hosts)
|
||||||
|
if [ -n "$pending_hosts" ]; then
|
||||||
|
echo "has_hosts=true" >> "$GITHUB_OUTPUT"
|
||||||
|
echo "hosts=$pending_hosts" >> "$GITHUB_OUTPUT"
|
||||||
|
echo "Preparing JWT identities for: $pending_hosts"
|
||||||
|
else
|
||||||
|
echo "has_hosts=false" >> "$GITHUB_OUTPUT"
|
||||||
|
echo "No VPN nodes are awaiting JWT registration."
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Setup SSH
|
||||||
|
if: steps.pending.outputs.has_hosts == 'true'
|
||||||
|
env:
|
||||||
|
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
|
||||||
|
run: |
|
||||||
|
set -eu
|
||||||
|
mkdir -p ~/.ssh
|
||||||
|
printf '%s\n' "$SSH_PRIVATE_KEY" > ~/.ssh/id_ed25519
|
||||||
|
chmod 600 ~/.ssh/id_ed25519
|
||||||
|
ssh-keygen -y -f ~/.ssh/id_ed25519 > /dev/null
|
||||||
|
|
||||||
|
- name: Install Ansible collections
|
||||||
|
if: steps.pending.outputs.has_hosts == 'true'
|
||||||
|
run: ansible-galaxy collection install -r requirements.yml
|
||||||
|
|
||||||
|
- name: Prepare JWT identities
|
||||||
|
if: steps.pending.outputs.has_hosts == 'true'
|
||||||
|
env:
|
||||||
|
ANSIBLE_CONFIG: ${{ github.workspace }}/ansible.cfg
|
||||||
|
PENDING_HOSTS: ${{ steps.pending.outputs.hosts }}
|
||||||
|
run: |
|
||||||
|
set -eu
|
||||||
|
ansible-playbook \
|
||||||
|
-i inventories/prod/hosts.ini \
|
||||||
|
playbooks/openvpn-jwt-identity.yml \
|
||||||
|
--limit "$PENDING_HOSTS"
|
||||||
|
|
||||||
|
- name: Upload public JWT keys
|
||||||
|
if: steps.pending.outputs.has_hosts == 'true'
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: openvpn-jwt-public-keys
|
||||||
|
path: artifacts/openvpn-jwt-public-keys/*.pem
|
||||||
|
if-no-files-found: error
|
||||||
|
retention-days: 7
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
/artifacts/openvpn-jwt-public-keys/
|
||||||
+104
-60
@@ -7,74 +7,118 @@ stages:
|
|||||||
- deploy
|
- deploy
|
||||||
- security
|
- security
|
||||||
|
|
||||||
before_script:
|
include:
|
||||||
- echo "Setting up ssh ..."
|
- project: 'next-gen-portal/ci-templates'
|
||||||
- mkdir -p ~/.ssh
|
ref: 'main'
|
||||||
- cat "$SSH_PRIVATE_KEY_FILE" > ~/.ssh/id_ed25519
|
file: '/templates/openbao/with-secret.yml'
|
||||||
- chmod 600 ~/.ssh/id_ed25519
|
|
||||||
- cat "$SSH_PUBLIC_KEY_FILE" > ~/.ssh/id_ed25519.pub
|
|
||||||
- chmod 600 ~/.ssh/id_ed25519.pub
|
|
||||||
- export ANSIBLE_CONFIG=$CI_PROJECT_DIR/ansible.cfg
|
|
||||||
|
|
||||||
ansible-lint:
|
ansible-lint:
|
||||||
stage: validate
|
stage: validate
|
||||||
script:
|
script:
|
||||||
|
- export ANSIBLE_CONFIG=$CI_PROJECT_DIR/ansible.cfg
|
||||||
|
- ansible-galaxy collection install -r requirements.yml
|
||||||
- ansible-lint
|
- ansible-lint
|
||||||
|
|
||||||
syntax-check:
|
syntax-check:
|
||||||
stage: validate
|
stage: validate
|
||||||
script:
|
script:
|
||||||
- ansible-playbook --syntax-check playbooks/openvpn.yml
|
- export ANSIBLE_CONFIG=$CI_PROJECT_DIR/ansible.cfg
|
||||||
|
- ansible-galaxy collection install -r requirements.yml
|
||||||
deploy-prod:
|
- ansible-inventory --list > /dev/null
|
||||||
stage: deploy
|
|
||||||
script:
|
|
||||||
- ansible-playbook playbooks/openvpn.yml
|
|
||||||
|
|
||||||
sbom:
|
|
||||||
stage: security
|
|
||||||
needs:
|
|
||||||
- deploy-prod
|
|
||||||
script:
|
|
||||||
- ansible-playbook playbooks/sbom.yml
|
|
||||||
artifacts:
|
|
||||||
when: always
|
|
||||||
paths:
|
|
||||||
- reports/sbom/
|
|
||||||
expire_in: 365 days
|
|
||||||
|
|
||||||
trivy:sbom:
|
|
||||||
stage: security
|
|
||||||
needs:
|
|
||||||
- job: sbom
|
|
||||||
artifacts: true
|
|
||||||
script:
|
|
||||||
- ls -R reports || true
|
|
||||||
- mkdir -p reports/trivy
|
|
||||||
- |
|
- |
|
||||||
if compgen -G "reports/sbom/*.json" > /dev/null; then
|
set -eu
|
||||||
for sbom in reports/sbom/*.json; do
|
for playbook in playbooks/*.yml; do
|
||||||
filename=$(basename "$sbom" .json)
|
echo "Syntax checking ${playbook}"
|
||||||
|
ansible-playbook --syntax-check "$playbook"
|
||||||
echo "Scanning $sbom"
|
|
||||||
|
|
||||||
trivy sbom \
|
|
||||||
--format json \
|
|
||||||
--output "reports/trivy/${filename}-trivy.json" \
|
|
||||||
--exit-code 0 \
|
|
||||||
"$sbom"
|
|
||||||
trivy sbom \
|
|
||||||
--format table \
|
|
||||||
--output "reports/trivy/${filename}-trivy.txt" \
|
|
||||||
--exit-code 0 \
|
|
||||||
"$sbom"
|
|
||||||
done
|
done
|
||||||
else
|
|
||||||
echo "No SBOM files found."
|
# deploy-prod:
|
||||||
exit 1
|
# extends: .openbao-with-secrets
|
||||||
fi
|
# stage: deploy
|
||||||
artifacts:
|
|
||||||
when: always
|
# id_tokens:
|
||||||
expire_in: 365 days
|
# OPENBAO_ID_TOKEN:
|
||||||
paths:
|
# aud: "https://openbao.helmholz.local:8200"
|
||||||
- reports/trivy/
|
|
||||||
|
# variables:
|
||||||
|
# OPENBAO_SECRET_REQUESTS_FILE: "secrets.json"
|
||||||
|
# script:
|
||||||
|
# - |
|
||||||
|
# set -eu
|
||||||
|
|
||||||
|
# echo "Setting up SSH..."
|
||||||
|
# mkdir -p ~/.ssh
|
||||||
|
|
||||||
|
# printf '%s\n' "$VPN_ADMIN_PRIVATE_KEY" > ~/.ssh/id_ed25519
|
||||||
|
# chmod 600 ~/.ssh/id_ed25519
|
||||||
|
# export ANSIBLE_CONFIG="$CI_PROJECT_DIR/ansible.cfg"
|
||||||
|
# ansible-galaxy collection install -r requirements.yml
|
||||||
|
# ansible-playbook playbooks/nat-gateway.yml --limit nat_gateways
|
||||||
|
# ansible-playbook playbooks/private-vpn-routing.yml --limit vpn_nodes
|
||||||
|
# ansible-playbook playbooks/openvpn.yml
|
||||||
|
# when: manual
|
||||||
|
|
||||||
|
# sbom:
|
||||||
|
# extends: .openbao-with-secrets
|
||||||
|
# stage: security
|
||||||
|
|
||||||
|
# id_tokens:
|
||||||
|
# OPENBAO_ID_TOKEN:
|
||||||
|
# aud: "https://openbao.helmholz.local:8200"
|
||||||
|
|
||||||
|
# variables:
|
||||||
|
# OPENBAO_SECRET_REQUESTS_FILE: "secrets.json"
|
||||||
|
# needs:
|
||||||
|
# - deploy-prod
|
||||||
|
# script:
|
||||||
|
# - |
|
||||||
|
# set -eu
|
||||||
|
|
||||||
|
# echo "Setting up SSH..."
|
||||||
|
# mkdir -p ~/.ssh
|
||||||
|
|
||||||
|
# printf '%s\n' "$VPN_ADMIN_PRIVATE_KEY" > ~/.ssh/id_ed25519
|
||||||
|
# chmod 600 ~/.ssh/id_ed25519
|
||||||
|
# export ANSIBLE_CONFIG="$CI_PROJECT_DIR/ansible.cfg"
|
||||||
|
# ansible-playbook playbooks/sbom.yml
|
||||||
|
# artifacts:
|
||||||
|
# when: always
|
||||||
|
# paths:
|
||||||
|
# - reports/sbom/
|
||||||
|
# expire_in: 365 days
|
||||||
|
|
||||||
|
# trivy:sbom:
|
||||||
|
# stage: security
|
||||||
|
# needs:
|
||||||
|
# - job: sbom
|
||||||
|
# artifacts: true
|
||||||
|
# script:
|
||||||
|
# - ls -R reports || true
|
||||||
|
# - mkdir -p reports/trivy
|
||||||
|
# - |
|
||||||
|
# if compgen -G "reports/sbom/*.json" > /dev/null; then
|
||||||
|
# for sbom in reports/sbom/*.json; do
|
||||||
|
# filename=$(basename "$sbom" .json)
|
||||||
|
|
||||||
|
# echo "Scanning $sbom"
|
||||||
|
|
||||||
|
# trivy sbom \
|
||||||
|
# --format json \
|
||||||
|
# --output "reports/trivy/${filename}-trivy.json" \
|
||||||
|
# --exit-code 0 \
|
||||||
|
# "$sbom"
|
||||||
|
# trivy sbom \
|
||||||
|
# --format table \
|
||||||
|
# --output "reports/trivy/${filename}-trivy.txt" \
|
||||||
|
# --exit-code 0 \
|
||||||
|
# "$sbom"
|
||||||
|
# done
|
||||||
|
# else
|
||||||
|
# echo "No SBOM files found."
|
||||||
|
# exit 1
|
||||||
|
# fi
|
||||||
|
# artifacts:
|
||||||
|
# when: always
|
||||||
|
# expire_in: 365 days
|
||||||
|
# paths:
|
||||||
|
# - reports/trivy/
|
||||||
|
|||||||
@@ -1,93 +1,109 @@
|
|||||||
# vpn-node-config
|
# VPN node configuration
|
||||||
|
|
||||||
|
Ansible configuration for Ubuntu 24.04 VPN nodes. Host packages are installed
|
||||||
|
through Ubuntu's package manager, so package architecture selection is
|
||||||
|
automatic.
|
||||||
|
|
||||||
|
## Supported platforms
|
||||||
|
|
||||||
## Getting started
|
- `linux/amd64` (`x86_64`)
|
||||||
|
- `linux/arm64` (`aarch64`)
|
||||||
|
|
||||||
To make it easy for you to get started with GitLab, here's a list of recommended next steps.
|
The common role checks the Ubuntu release and architecture before
|
||||||
|
making changes. Networking sysctl configuration uses the interfaces reported
|
||||||
|
by Ansible rather than assuming a particular NIC name. The OpenVPN RADIUS
|
||||||
|
plugin path is discovered after package installation, including Debian's
|
||||||
|
architecture-specific library directories.
|
||||||
|
|
||||||
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
|
## Run
|
||||||
|
|
||||||
## Add your files
|
Configure inventory in `inventories/prod/hosts.ini`, then run:
|
||||||
|
|
||||||
- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
|
```sh
|
||||||
- [ ] [Add files using the command line](https://docs.gitlab.com/topics/git/add_files/#add-files-to-a-git-repository) or push an existing Git repository with the following command:
|
ansible-playbook playbooks/openvpn.yml
|
||||||
|
|
||||||
```
|
|
||||||
cd existing_repo
|
|
||||||
git remote add origin https://gitlab/next-gen-portal/ansible/vpn-node-config.git
|
|
||||||
git branch -M main
|
|
||||||
git push -uf origin main
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Integrate with your tools
|
The target hosts must run Ubuntu 24.04 and Ansible must gather facts.
|
||||||
|
|
||||||
- [ ] [Set up project integrations](https://gitlab/next-gen-portal/ansible/vpn-node-config/-/settings/integrations)
|
## Private VM internet access
|
||||||
|
|
||||||
## Collaborate with your team
|
The `vpn-gateway` VM provides NAT for private VPN nodes. A private VM sends
|
||||||
|
internet-bound traffic to the Hetzner private-network router (`10.0.0.1`). The
|
||||||
|
Hetzner network route for `0.0.0.0/0` then delivers it to the gateway's private
|
||||||
|
address (`10.100.0.4`), where iptables masquerades it out `eth0`. The route in
|
||||||
|
Hetzner's network and the operating-system default route on each private VM are
|
||||||
|
separate settings: both must exist. The gateway itself keeps its public default
|
||||||
|
route through `eth0`.
|
||||||
|
|
||||||
- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
|
`vpn_nodes` contains private VPN nodes and `nat_gateways` contains only the
|
||||||
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
|
gateway. Add new private VMs to `vpn_nodes` with their management address and
|
||||||
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
|
private address, and set the private routing role variables in host/group vars
|
||||||
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
|
if their interface or gateway differs. Do not add a gateway to `vpn_nodes`.
|
||||||
- [ ] [Set auto-merge](https://docs.gitlab.com/user/project/merge_requests/auto_merge/)
|
The routing role detects Netplan or systemd-networkd and adds only a route
|
||||||
|
fragment; review the host's existing route metrics and manager before rollout.
|
||||||
|
The Netplan fragment adds a metric 100 default route. Internal destinations
|
||||||
|
continue to use more-specific routes; validate the FreeRADIUS NodePort path on
|
||||||
|
each host.
|
||||||
|
|
||||||
## Test and Deploy
|
Install required collections with `ansible-galaxy collection install -r
|
||||||
|
requirements.yml`, then check syntax and deploy independently:
|
||||||
|
|
||||||
Use the built-in continuous integration in GitLab.
|
```sh
|
||||||
|
ansible-playbook --syntax-check playbooks/nat-gateway.yml
|
||||||
|
ansible-playbook --syntax-check playbooks/private-vpn-routing.yml
|
||||||
|
ansible-playbook --check playbooks/nat-gateway.yml --limit nat_gateways
|
||||||
|
ansible-playbook playbooks/nat-gateway.yml --limit nat_gateways
|
||||||
|
ansible-playbook --check playbooks/private-vpn-routing.yml --limit vpn_nodes
|
||||||
|
ansible-playbook playbooks/private-vpn-routing.yml --limit vpn_nodes
|
||||||
|
```
|
||||||
|
|
||||||
- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/)
|
Check mode cannot validate actual kernel routes or persistence and may report
|
||||||
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing (SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
|
handlers without applying them. `netplan apply` and restarting
|
||||||
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
|
systemd-networkd can briefly interrupt remote connectivity; schedule route
|
||||||
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
|
rollout with console access or a maintenance window. Do not reboot automatically.
|
||||||
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
|
|
||||||
|
|
||||||
***
|
Verify the gateway after deployment (and separately after a planned reboot):
|
||||||
|
|
||||||
# Editing this README
|
```sh
|
||||||
|
sysctl net.ipv4.ip_forward
|
||||||
|
iptables -t nat -S POSTROUTING
|
||||||
|
iptables -S FORWARD
|
||||||
|
systemctl is-enabled nat-gateway-firewall.service
|
||||||
|
systemctl status nat-gateway-firewall.service --no-pager
|
||||||
|
ip -4 route show default
|
||||||
|
```
|
||||||
|
|
||||||
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thanks to [makeareadme.com](https://www.makeareadme.com/) for this template.
|
Expect forwarding value `1`, the subnet-specific MASQUERADE and two narrow
|
||||||
|
FORWARD rules, an enabled firewall persistence service, and the gateway public
|
||||||
|
default via `eth0`. The service re-adds only these scoped rules at boot and
|
||||||
|
does not save or flush the full firewall ruleset. On each private VM:
|
||||||
|
|
||||||
## Suggestions for a good README
|
```sh
|
||||||
|
ip -4 route show default
|
||||||
|
ip -4 route get 8.8.8.8
|
||||||
|
getent hosts google.com
|
||||||
|
curl -I --max-time 10 https://google.com
|
||||||
|
```
|
||||||
|
|
||||||
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
|
Also connect to the existing FreeRADIUS NodePort endpoint using its configured
|
||||||
|
address and port. DNS and NodePort checks require live network access. The
|
||||||
|
inventory gateway IP/interface values are taken from the supplied task; verify
|
||||||
|
them against the live Hetzner VM before applying.
|
||||||
|
|
||||||
## Name
|
## Monitoring exporter
|
||||||
Choose a self-explaining name for your project.
|
|
||||||
|
|
||||||
## Description
|
Run `playbooks/monitoring-exporter.yml` for the VPN nodes and NAT gateway.
|
||||||
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
|
Set `monitoring_vm_ip` in `inventories/prod/group_vars/all.yml` to the monitoring
|
||||||
|
VM's address on the `10.100.0.x` private network. It is the only allowed source
|
||||||
|
to TCP port 9100. The identical `node_exporter` role defaults to port 9100,
|
||||||
|
binds to `private_ip` then `keepalived_src_ip` then `ansible_host`, and uses
|
||||||
|
`monitoring_vm_ip` as its firewall source. It creates the root-owned,
|
||||||
|
world-readable `/var/lib/node_exporter/textfile` directory and enables
|
||||||
|
systemd, conntrack, filesystem, netdev, textfile, time, and timex collectors;
|
||||||
|
`node_exporter_systemd_unit_filter` restricts unit metrics.
|
||||||
|
|
||||||
## Badges
|
On the NAT gateway, `nat_gateway_node_exporter_port` defaults to 9100 and
|
||||||
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
|
`nat_gateway_node_exporter_allowed_source` uses `monitoring_vm_ip`. Both the
|
||||||
|
ACCEPT for that source and DROP for all other sources on the port are written
|
||||||
## Visuals
|
into `ensure-nat-gateway-firewall.j2`, so the gateway firewall persistence
|
||||||
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
|
service owns them.
|
||||||
|
|
||||||
## Installation
|
|
||||||
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
|
|
||||||
|
|
||||||
## Support
|
|
||||||
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
|
|
||||||
|
|
||||||
## Roadmap
|
|
||||||
If you have ideas for releases in the future, it is a good idea to list them in the README.
|
|
||||||
|
|
||||||
## Contributing
|
|
||||||
State if you are open to contributions and what your requirements are for accepting them.
|
|
||||||
|
|
||||||
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
|
|
||||||
|
|
||||||
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
|
|
||||||
|
|
||||||
## Authors and acknowledgment
|
|
||||||
Show your appreciation to those who have contributed to the project.
|
|
||||||
|
|
||||||
## License
|
|
||||||
For open source projects, say how it is licensed.
|
|
||||||
|
|
||||||
## Project status
|
|
||||||
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
|
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
timezone: Europe/Berlin
|
timezone: Europe/Berlin
|
||||||
|
# Required: monitoring VM private address on the 10.100.0.x private network.
|
||||||
|
monitoring_vm_ip: "10.100.0.30"
|
||||||
common_packages:
|
common_packages:
|
||||||
- vim
|
- vim
|
||||||
- curl
|
- curl
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
[vpn_nodes]
|
[vpn_nodes]
|
||||||
vpn01 ansible_host=65.108.95.144 private_ip=10.100.0.1
|
# vpn01 ansible_host=65.108.95.144 private_ip=10.100.0.1
|
||||||
# vpn01-test ansible_host=65.108.95.144 private_ip=10.100.0.2
|
# vpn01-test ansible_host=10.100.0.2 private_ip=10.100.0.2 openvpn_jwt_registered=false
|
||||||
|
vpn02-test ansible_host=10.100.0.5 private_ip=10.100.0.5 openvpn_jwt_registered=true
|
||||||
# vpn01-bmw ansible_host=65.108.93.171 private_ip=10.100.0.3
|
# vpn01-bmw ansible_host=65.108.93.171 private_ip=10.100.0.3
|
||||||
|
|
||||||
|
[nat_gateways]
|
||||||
|
vpn-gateway ansible_host=178.104.249.28 private_ip=10.100.0.4
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
---
|
||||||
|
- name: Configure node exporter on VPN nodes
|
||||||
|
hosts: vpn_nodes
|
||||||
|
become: true
|
||||||
|
roles:
|
||||||
|
- role: node_exporter
|
||||||
|
tags: [monitoring]
|
||||||
|
|
||||||
|
- name: Configure node exporter and firewall on NAT gateway
|
||||||
|
hosts: nat_gateways
|
||||||
|
become: true
|
||||||
|
roles:
|
||||||
|
- role: nat_gateway
|
||||||
|
- role: node_exporter
|
||||||
|
vars:
|
||||||
|
node_exporter_manage_firewall: false
|
||||||
|
tags: [monitoring]
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
- name: Configure NAT gateway
|
||||||
|
hosts: nat_gateways
|
||||||
|
become: true
|
||||||
|
roles: [nat_gateway]
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
---
|
||||||
|
- name: Prepare OpenVPN JWT identities
|
||||||
|
hosts: vpn_nodes
|
||||||
|
become: true
|
||||||
|
|
||||||
|
roles:
|
||||||
|
- openvpn_jwt
|
||||||
+20
-1
@@ -7,4 +7,23 @@
|
|||||||
- common
|
- common
|
||||||
- networking
|
- networking
|
||||||
- radius_nat
|
- radius_nat
|
||||||
- openvpn
|
- role: openvpn
|
||||||
|
when: openvpn_jwt_registered | default(false) | bool
|
||||||
|
- role: openvpn_jwt
|
||||||
|
when: openvpn_jwt_registered | default(false) | bool
|
||||||
|
vars:
|
||||||
|
openvpn_jwt_export_public_key: false
|
||||||
|
- role: openvpn_pki
|
||||||
|
when: openvpn_jwt_registered | default(false) | bool
|
||||||
|
|
||||||
|
tasks:
|
||||||
|
- name: Run pending OpenVPN restart handlers after certificate issuance
|
||||||
|
ansible.builtin.meta: flush_handlers
|
||||||
|
|
||||||
|
- name: Start OpenVPN and attach TAP interface after certificate setup
|
||||||
|
ansible.builtin.import_role:
|
||||||
|
name: openvpn
|
||||||
|
tasks_from: bridge-tap.yml
|
||||||
|
when:
|
||||||
|
- openvpn_jwt_registered | default(false) | bool
|
||||||
|
- openvpn_restart_result is not defined
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
- name: Configure private VPN node default routes
|
||||||
|
hosts: vpn_nodes
|
||||||
|
become: true
|
||||||
|
roles: [private_routing]
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
collections:
|
||||||
|
- name: ansible.posix
|
||||||
|
- name: community.general
|
||||||
|
- name: community.crypto
|
||||||
@@ -1,8 +1,21 @@
|
|||||||
---
|
---
|
||||||
|
- name: Validate supported operating system and CPU architecture
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that:
|
||||||
|
- ansible_distribution == 'Ubuntu'
|
||||||
|
- ansible_distribution_version == '24.04'
|
||||||
|
- ansible_architecture in ['x86_64', 'aarch64']
|
||||||
|
fail_msg: >-
|
||||||
|
vpn-node-config supports Debian-family hosts on linux/amd64 (x86_64) and
|
||||||
|
linux/arm64 (aarch64); detected {{ ansible_os_family }} /
|
||||||
|
{{ ansible_architecture }}.
|
||||||
|
|
||||||
- name: Update apt cache
|
- name: Update apt cache
|
||||||
ansible.builtin.apt:
|
ansible.builtin.apt:
|
||||||
update_cache: true
|
update_cache: true
|
||||||
cache_valid_time: 3600
|
cache_valid_time: 3600
|
||||||
|
update_cache_retries: 5
|
||||||
|
update_cache_retry_max_delay: 12
|
||||||
|
|
||||||
- name: Upgrade packages
|
- name: Upgrade packages
|
||||||
ansible.builtin.apt:
|
ansible.builtin.apt:
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
---
|
||||||
|
nat_gateway_private_cidr: 10.100.0.0/16
|
||||||
|
nat_gateway_private_interface: enp7s0
|
||||||
|
nat_gateway_public_interface: eth0
|
||||||
|
nat_gateway_firewall_script: /usr/local/sbin/ensure-nat-gateway-firewall
|
||||||
|
# Exporter firewall accepts this private source and drops all others on its port.
|
||||||
|
nat_gateway_node_exporter_port: 9100
|
||||||
|
nat_gateway_node_exporter_allowed_source: "{{ monitoring_vm_ip }}"
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
---
|
||||||
|
- name: Apply NAT gateway sysctl
|
||||||
|
ansible.builtin.command: sysctl --system
|
||||||
|
changed_when: false
|
||||||
|
- name: Restart NAT gateway firewall persistence
|
||||||
|
ansible.builtin.systemd:
|
||||||
|
name: nat-gateway-firewall.service
|
||||||
|
enabled: true
|
||||||
|
daemon_reload: true
|
||||||
|
state: restarted
|
||||||
@@ -0,0 +1,91 @@
|
|||||||
|
---
|
||||||
|
- name: Install iptables tools
|
||||||
|
ansible.builtin.apt:
|
||||||
|
name: [iptables, prometheus-node-exporter]
|
||||||
|
state: present
|
||||||
|
|
||||||
|
- name: Install idempotent NAT firewall restore script
|
||||||
|
ansible.builtin.template:
|
||||||
|
src: ensure-nat-gateway-firewall.j2
|
||||||
|
dest: "{{ nat_gateway_firewall_script }}"
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: "0750"
|
||||||
|
notify: Restart NAT gateway firewall persistence
|
||||||
|
|
||||||
|
- name: Install NAT firewall persistence unit
|
||||||
|
ansible.builtin.template:
|
||||||
|
src: nat-gateway-firewall.service.j2
|
||||||
|
dest: /etc/systemd/system/nat-gateway-firewall.service
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: "0644"
|
||||||
|
notify: Restart NAT gateway firewall persistence
|
||||||
|
|
||||||
|
- name: Enable NAT firewall persistence at boot
|
||||||
|
ansible.builtin.systemd:
|
||||||
|
name: nat-gateway-firewall.service
|
||||||
|
enabled: true
|
||||||
|
daemon_reload: true
|
||||||
|
state: started
|
||||||
|
|
||||||
|
- name: Configure persistent IPv4 forwarding
|
||||||
|
ansible.builtin.copy:
|
||||||
|
dest: /etc/sysctl.d/99-nat-gateway.conf
|
||||||
|
content: "net.ipv4.ip_forward=1\n"
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: "0644"
|
||||||
|
notify: Apply NAT gateway sysctl
|
||||||
|
|
||||||
|
- name: Enable IPv4 forwarding immediately
|
||||||
|
ansible.posix.sysctl:
|
||||||
|
name: net.ipv4.ip_forward
|
||||||
|
value: "1"
|
||||||
|
sysctl_file: /etc/sysctl.d/99-nat-gateway.conf
|
||||||
|
reload: true
|
||||||
|
|
||||||
|
- name: Create node exporter textfile directory
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: /var/lib/node_exporter/textfile
|
||||||
|
state: directory
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: "0755"
|
||||||
|
|
||||||
|
- name: Allow private subnet outbound through public interface
|
||||||
|
ansible.builtin.iptables:
|
||||||
|
table: nat
|
||||||
|
chain: POSTROUTING
|
||||||
|
source: "{{ nat_gateway_private_cidr }}"
|
||||||
|
out_interface: "{{ nat_gateway_public_interface }}"
|
||||||
|
jump: MASQUERADE
|
||||||
|
state: present
|
||||||
|
notify: Restart NAT gateway firewall persistence
|
||||||
|
|
||||||
|
- name: Allow private subnet forwarding to public interface
|
||||||
|
ansible.builtin.iptables:
|
||||||
|
chain: FORWARD
|
||||||
|
in_interface: "{{ nat_gateway_private_interface }}"
|
||||||
|
out_interface: "{{ nat_gateway_public_interface }}"
|
||||||
|
source: "{{ nat_gateway_private_cidr }}"
|
||||||
|
jump: ACCEPT
|
||||||
|
state: present
|
||||||
|
notify: Restart NAT gateway firewall persistence
|
||||||
|
|
||||||
|
- name: Allow established return traffic to private subnet
|
||||||
|
ansible.builtin.iptables:
|
||||||
|
chain: FORWARD
|
||||||
|
in_interface: "{{ nat_gateway_public_interface }}"
|
||||||
|
out_interface: "{{ nat_gateway_private_interface }}"
|
||||||
|
destination: "{{ nat_gateway_private_cidr }}"
|
||||||
|
ctstate: [ESTABLISHED, RELATED]
|
||||||
|
jump: ACCEPT
|
||||||
|
state: present
|
||||||
|
notify: Restart NAT gateway firewall persistence
|
||||||
|
|
||||||
|
- name: Assert gateway retains public default route
|
||||||
|
ansible.builtin.command: ip -4 route show default
|
||||||
|
register: nat_gateway_default_route
|
||||||
|
changed_when: false
|
||||||
|
failed_when: nat_gateway_public_interface not in nat_gateway_default_route.stdout
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
iptables -t nat -C POSTROUTING -s {{ nat_gateway_private_cidr }} -o {{ nat_gateway_public_interface }} -j MASQUERADE 2>/dev/null || \
|
||||||
|
iptables -t nat -A POSTROUTING -s {{ nat_gateway_private_cidr }} -o {{ nat_gateway_public_interface }} -j MASQUERADE
|
||||||
|
|
||||||
|
iptables -C FORWARD -i {{ nat_gateway_private_interface }} -o {{ nat_gateway_public_interface }} -s {{ nat_gateway_private_cidr }} -j ACCEPT 2>/dev/null || \
|
||||||
|
iptables -A FORWARD -i {{ nat_gateway_private_interface }} -o {{ nat_gateway_public_interface }} -s {{ nat_gateway_private_cidr }} -j ACCEPT
|
||||||
|
|
||||||
|
iptables -C FORWARD -i {{ nat_gateway_public_interface }} -o {{ nat_gateway_private_interface }} -d {{ nat_gateway_private_cidr }} -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT 2>/dev/null || \
|
||||||
|
iptables -A FORWARD -i {{ nat_gateway_public_interface }} -o {{ nat_gateway_private_interface }} -d {{ nat_gateway_private_cidr }} -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
|
||||||
|
|
||||||
|
iptables -C INPUT -p tcp -s {{ nat_gateway_node_exporter_allowed_source }} --dport {{ nat_gateway_node_exporter_port }} -j ACCEPT 2>/dev/null || \
|
||||||
|
iptables -I INPUT 1 -p tcp -s {{ nat_gateway_node_exporter_allowed_source }} --dport {{ nat_gateway_node_exporter_port }} -j ACCEPT
|
||||||
|
|
||||||
|
iptables -C INPUT -p tcp --dport {{ nat_gateway_node_exporter_port }} -j DROP 2>/dev/null || \
|
||||||
|
iptables -I INPUT 2 -p tcp --dport {{ nat_gateway_node_exporter_port }} -j DROP
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Ensure scoped NAT gateway firewall rules are present
|
||||||
|
Wants=network-online.target
|
||||||
|
After=network-online.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=oneshot
|
||||||
|
ExecStart={{ nat_gateway_firewall_script }}
|
||||||
|
RemainAfterExit=yes
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
@@ -3,4 +3,6 @@ net.ipv4.ip_forward=1
|
|||||||
net.ipv4.conf.all.rp_filter=0
|
net.ipv4.conf.all.rp_filter=0
|
||||||
net.ipv4.conf.default.rp_filter=0
|
net.ipv4.conf.default.rp_filter=0
|
||||||
|
|
||||||
net.ipv4.conf.enp7s0.rp_filter=0
|
{% for interface in ansible_interfaces | default([]) if interface not in ['lo', 'br-main-vpn', 'tap0'] %}
|
||||||
|
net.ipv4.conf.{{ interface }}.rp_filter=0
|
||||||
|
{% endfor %}
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
---
|
||||||
|
# Bind to private_ip, then the LB keepalived source IP, and use public ansible_host
|
||||||
|
# only if neither private address is configured.
|
||||||
|
node_exporter_listen_address: "{{ private_ip | default(keepalived_src_ip | default(ansible_host)) }}"
|
||||||
|
# TCP listener port for node_exporter.
|
||||||
|
node_exporter_port: 9100
|
||||||
|
# Required: set to monitoring_vm_ip in inventory/group_vars.
|
||||||
|
node_exporter_allowed_source: "{{ monitoring_vm_ip }}"
|
||||||
|
# Root-owned, world-readable textfile collector directory.
|
||||||
|
node_exporter_textfile_dir: /var/lib/node_exporter/textfile
|
||||||
|
# Restrict systemd collector output to relevant service units.
|
||||||
|
node_exporter_systemd_unit_filter: "^(openvpn.*|squid@.*|keepalived.service|nat-gateway-firewall.service)$"
|
||||||
|
# Collect systemd, connection tracking, filesystem, network, textfile, time, and timex metrics.
|
||||||
|
node_exporter_collectors:
|
||||||
|
- systemd
|
||||||
|
- conntrack
|
||||||
|
- filesystem
|
||||||
|
- netdev
|
||||||
|
- textfile
|
||||||
|
- time
|
||||||
|
- timex
|
||||||
|
# Use iptables allow/drop rules locally; NAT gateway disables this because its
|
||||||
|
# firewall script owns those rules.
|
||||||
|
node_exporter_manage_firewall: true
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
- name: Restart node exporter
|
||||||
|
ansible.builtin.systemd:
|
||||||
|
name: prometheus-node-exporter
|
||||||
|
state: restarted
|
||||||
@@ -0,0 +1,91 @@
|
|||||||
|
---
|
||||||
|
- name: Require the monitoring VM private source address
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that:
|
||||||
|
- monitoring_vm_ip is defined
|
||||||
|
- monitoring_vm_ip | length > 0
|
||||||
|
fail_msg: Set monitoring_vm_ip to the monitoring VM's 10.100.0.x address.
|
||||||
|
tags: [monitoring]
|
||||||
|
|
||||||
|
- name: Install node exporter package
|
||||||
|
ansible.builtin.apt:
|
||||||
|
name: prometheus-node-exporter
|
||||||
|
state: present
|
||||||
|
update_cache: true
|
||||||
|
cache_valid_time: 3600
|
||||||
|
tags: [monitoring]
|
||||||
|
|
||||||
|
- name: Install iptables persistence packages
|
||||||
|
ansible.builtin.apt:
|
||||||
|
name: [iptables, iptables-persistent]
|
||||||
|
state: present
|
||||||
|
update_cache: true
|
||||||
|
cache_valid_time: 3600
|
||||||
|
environment:
|
||||||
|
DEBIAN_FRONTEND: noninteractive
|
||||||
|
tags: [monitoring]
|
||||||
|
|
||||||
|
- name: Create node exporter textfile directory
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: "{{ node_exporter_textfile_dir }}"
|
||||||
|
state: directory
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: "0755"
|
||||||
|
tags: [monitoring]
|
||||||
|
|
||||||
|
- name: Configure node exporter arguments
|
||||||
|
ansible.builtin.copy:
|
||||||
|
dest: /etc/default/prometheus-node-exporter
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: "0644"
|
||||||
|
content: >-
|
||||||
|
ARGS="--web.listen-address={{ node_exporter_listen_address }}:{{ node_exporter_port }}
|
||||||
|
{% for collector in node_exporter_collectors %}--collector.{{ collector }} {% endfor %}
|
||||||
|
--collector.systemd.unit-include={{ node_exporter_systemd_unit_filter }}
|
||||||
|
--collector.textfile.directory={{ node_exporter_textfile_dir }}"
|
||||||
|
notify: Restart node exporter
|
||||||
|
tags: [monitoring]
|
||||||
|
|
||||||
|
- name: Allow monitoring VM to access node exporter
|
||||||
|
ansible.builtin.iptables:
|
||||||
|
chain: INPUT
|
||||||
|
protocol: tcp
|
||||||
|
destination_port: "{{ node_exporter_port }}"
|
||||||
|
source: "{{ node_exporter_allowed_source }}"
|
||||||
|
jump: ACCEPT
|
||||||
|
comment: Allow monitoring VM node exporter
|
||||||
|
action: insert
|
||||||
|
rule_num: 1
|
||||||
|
register: node_exporter_allow_rule
|
||||||
|
tags: [monitoring]
|
||||||
|
when: node_exporter_manage_firewall
|
||||||
|
|
||||||
|
- name: Drop other node exporter access
|
||||||
|
ansible.builtin.iptables:
|
||||||
|
chain: INPUT
|
||||||
|
protocol: tcp
|
||||||
|
destination_port: "{{ node_exporter_port }}"
|
||||||
|
jump: DROP
|
||||||
|
comment: Drop other node exporter access
|
||||||
|
action: insert
|
||||||
|
rule_num: 2
|
||||||
|
register: node_exporter_drop_rule
|
||||||
|
tags: [monitoring]
|
||||||
|
when: node_exporter_manage_firewall
|
||||||
|
|
||||||
|
- name: Persist node exporter firewall rules
|
||||||
|
ansible.builtin.command: netfilter-persistent save
|
||||||
|
when:
|
||||||
|
- node_exporter_manage_firewall
|
||||||
|
- node_exporter_allow_rule is changed or node_exporter_drop_rule is changed
|
||||||
|
changed_when: true
|
||||||
|
tags: [monitoring]
|
||||||
|
|
||||||
|
- name: Enable and start node exporter
|
||||||
|
ansible.builtin.systemd:
|
||||||
|
name: prometheus-node-exporter
|
||||||
|
state: started
|
||||||
|
enabled: true
|
||||||
|
tags: [monitoring]
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
---
|
||||||
|
openbao_cli_version: "2.7.0"
|
||||||
|
openbao_cli_binary_path: /usr/bin/bao
|
||||||
|
openbao_cli_architecture_map:
|
||||||
|
x86_64: amd64
|
||||||
|
aarch64: arm64
|
||||||
|
openbao_cli_verify_checksum_signature: true
|
||||||
|
openbao_cli_gpg_key_url: https://openbao.org/assets/openbao-gpg-pub-20240618.asc
|
||||||
|
openbao_cli_gpg_primary_fingerprint: 66D15FDD87287219C8E15478D200CD702853E6D0
|
||||||
@@ -0,0 +1,168 @@
|
|||||||
|
---
|
||||||
|
- name: Validate OpenBao CLI platform
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that:
|
||||||
|
- ansible_facts.distribution in ['Debian', 'Ubuntu']
|
||||||
|
- ansible_facts.architecture in openbao_cli_architecture_map
|
||||||
|
fail_msg: >-
|
||||||
|
OpenBao CLI installation supports Debian and Ubuntu amd64 and arm64 only;
|
||||||
|
detected {{ ansible_facts.distribution }} {{ ansible_facts.architecture }}.
|
||||||
|
|
||||||
|
- name: Set OpenBao release package facts
|
||||||
|
ansible.builtin.set_fact:
|
||||||
|
openbao_cli_package_name: "openbao_{{ openbao_cli_version }}_linux_{{ openbao_cli_architecture_map[ansible_facts.architecture] }}.deb"
|
||||||
|
openbao_cli_release_url: "https://github.com/openbao/openbao/releases/download/v{{ openbao_cli_version }}"
|
||||||
|
|
||||||
|
- name: Read currently installed OpenBao CLI version
|
||||||
|
ansible.builtin.command:
|
||||||
|
argv:
|
||||||
|
- "{{ openbao_cli_binary_path }}"
|
||||||
|
- version
|
||||||
|
register: openbao_cli_current_version
|
||||||
|
changed_when: false
|
||||||
|
failed_when: false
|
||||||
|
when: ansible_facts.pkg_mgr == 'apt'
|
||||||
|
|
||||||
|
- name: Set OpenBao CLI installation requirement using the reported version
|
||||||
|
ansible.builtin.set_fact:
|
||||||
|
openbao_cli_install_required: >-
|
||||||
|
{{ not ((openbao_cli_current_version.stdout | default('') | trim) |
|
||||||
|
regex_search('^OpenBao v' ~ (openbao_cli_version | regex_escape) ~ '( |$)')) }}
|
||||||
|
|
||||||
|
- name: Install pinned OpenBao CLI from the official release
|
||||||
|
when: openbao_cli_install_required
|
||||||
|
block:
|
||||||
|
- name: Create OpenBao CLI temporary directory
|
||||||
|
ansible.builtin.tempfile:
|
||||||
|
state: directory
|
||||||
|
suffix: openbao-cli
|
||||||
|
register: openbao_cli_tmp
|
||||||
|
|
||||||
|
- name: Install GnuPG for mandatory checksum signature verification
|
||||||
|
ansible.builtin.apt:
|
||||||
|
name: gnupg
|
||||||
|
state: present
|
||||||
|
when: openbao_cli_verify_checksum_signature | bool
|
||||||
|
|
||||||
|
- name: Download official OpenBao release checksums
|
||||||
|
ansible.builtin.get_url:
|
||||||
|
url: "{{ openbao_cli_release_url }}/checksums.txt"
|
||||||
|
dest: "{{ openbao_cli_tmp.path }}/checksums.txt"
|
||||||
|
mode: "0600"
|
||||||
|
|
||||||
|
- name: Download signature for official OpenBao checksums
|
||||||
|
ansible.builtin.get_url:
|
||||||
|
url: "{{ openbao_cli_release_url }}/checksums.txt.gpgsig"
|
||||||
|
dest: "{{ openbao_cli_tmp.path }}/checksums.txt.gpgsig"
|
||||||
|
mode: "0600"
|
||||||
|
when: openbao_cli_verify_checksum_signature | bool
|
||||||
|
|
||||||
|
- name: Download OpenBao signing public key
|
||||||
|
ansible.builtin.get_url:
|
||||||
|
url: "{{ openbao_cli_gpg_key_url }}"
|
||||||
|
dest: "{{ openbao_cli_tmp.path }}/openbao-gpg-key.asc"
|
||||||
|
mode: "0600"
|
||||||
|
when: openbao_cli_verify_checksum_signature | bool
|
||||||
|
|
||||||
|
- name: Create isolated GnuPG home
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: "{{ openbao_cli_tmp.path }}/gnupg"
|
||||||
|
state: directory
|
||||||
|
mode: "0700"
|
||||||
|
when: openbao_cli_verify_checksum_signature | bool
|
||||||
|
|
||||||
|
- name: Import OpenBao signing key into isolated keyring
|
||||||
|
ansible.builtin.command:
|
||||||
|
argv:
|
||||||
|
- gpg
|
||||||
|
- --batch
|
||||||
|
- --homedir
|
||||||
|
- "{{ openbao_cli_tmp.path }}/gnupg"
|
||||||
|
- --import
|
||||||
|
- "{{ openbao_cli_tmp.path }}/openbao-gpg-key.asc"
|
||||||
|
register: openbao_cli_gpg_import
|
||||||
|
changed_when: false
|
||||||
|
when: openbao_cli_verify_checksum_signature | bool
|
||||||
|
|
||||||
|
- name: Read imported signing-key fingerprints
|
||||||
|
ansible.builtin.command:
|
||||||
|
argv:
|
||||||
|
- gpg
|
||||||
|
- --batch
|
||||||
|
- --homedir
|
||||||
|
- "{{ openbao_cli_tmp.path }}/gnupg"
|
||||||
|
- --with-colons
|
||||||
|
- --fingerprint
|
||||||
|
- --list-keys
|
||||||
|
register: openbao_cli_gpg_fingerprints
|
||||||
|
changed_when: false
|
||||||
|
when: openbao_cli_verify_checksum_signature | bool
|
||||||
|
|
||||||
|
- name: Require the documented OpenBao primary key fingerprint
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that:
|
||||||
|
- openbao_cli_gpg_fingerprints.stdout | regex_findall('(?m)^pub:') | length == 1
|
||||||
|
- >-
|
||||||
|
openbao_cli_gpg_fingerprints.stdout | regex_findall('(?m)^fpr:.*$') |
|
||||||
|
map('regex_search', '[A-F0-9]{40}') |
|
||||||
|
select('equalto', openbao_cli_gpg_primary_fingerprint) | list | length == 1
|
||||||
|
fail_msg: The imported OpenBao signing key did not match the pinned primary fingerprint.
|
||||||
|
when: openbao_cli_verify_checksum_signature | bool
|
||||||
|
|
||||||
|
- name: Verify official checksums.txt signature
|
||||||
|
ansible.builtin.command:
|
||||||
|
argv:
|
||||||
|
- gpg
|
||||||
|
- --batch
|
||||||
|
- --homedir
|
||||||
|
- "{{ openbao_cli_tmp.path }}/gnupg"
|
||||||
|
- --verify
|
||||||
|
- "{{ openbao_cli_tmp.path }}/checksums.txt.gpgsig"
|
||||||
|
- "{{ openbao_cli_tmp.path }}/checksums.txt"
|
||||||
|
register: openbao_cli_gpg_verify
|
||||||
|
changed_when: false
|
||||||
|
when: openbao_cli_verify_checksum_signature | bool
|
||||||
|
|
||||||
|
- name: Find checksum for the requested Debian package
|
||||||
|
ansible.builtin.command:
|
||||||
|
argv:
|
||||||
|
- awk
|
||||||
|
- "$2 == \"{{ openbao_cli_package_name }}\" {print $1}"
|
||||||
|
- "{{ openbao_cli_tmp.path }}/checksums.txt"
|
||||||
|
register: openbao_cli_expected_checksum
|
||||||
|
changed_when: false
|
||||||
|
|
||||||
|
- name: Require a single valid SHA-256 checksum for the package
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that:
|
||||||
|
- openbao_cli_expected_checksum.stdout | trim is match('^[a-fA-F0-9]{64}$')
|
||||||
|
fail_msg: "No unique valid checksum for {{ openbao_cli_package_name }} in official release checksums."
|
||||||
|
|
||||||
|
- name: Download checksummed OpenBao Debian package
|
||||||
|
ansible.builtin.get_url:
|
||||||
|
url: "{{ openbao_cli_release_url }}/{{ openbao_cli_package_name }}"
|
||||||
|
dest: "{{ openbao_cli_tmp.path }}/{{ openbao_cli_package_name }}"
|
||||||
|
checksum: "sha256:{{ openbao_cli_expected_checksum.stdout | trim }}"
|
||||||
|
mode: "0600"
|
||||||
|
|
||||||
|
- name: Install OpenBao CLI Debian package
|
||||||
|
ansible.builtin.apt:
|
||||||
|
deb: "{{ openbao_cli_tmp.path }}/{{ openbao_cli_package_name }}"
|
||||||
|
state: present
|
||||||
|
always:
|
||||||
|
- name: Remove OpenBao CLI temporary directory after success or failure
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: "{{ openbao_cli_tmp.path }}"
|
||||||
|
state: absent
|
||||||
|
when: openbao_cli_tmp is defined and openbao_cli_tmp.path is defined
|
||||||
|
|
||||||
|
- name: Verify installed OpenBao CLI version matches the pin
|
||||||
|
ansible.builtin.command:
|
||||||
|
argv:
|
||||||
|
- "{{ openbao_cli_binary_path }}"
|
||||||
|
- version
|
||||||
|
register: openbao_cli_installed_version
|
||||||
|
changed_when: false
|
||||||
|
failed_when: >-
|
||||||
|
not ((openbao_cli_installed_version.stdout | trim) |
|
||||||
|
regex_search('^OpenBao v' ~ (openbao_cli_version | regex_escape) ~ '( |$)'))
|
||||||
@@ -7,6 +7,7 @@ openvpn_cert_dir: /etc/openvpn/certs
|
|||||||
|
|
||||||
|
|
||||||
openvpn_service: openvpn@server.service
|
openvpn_service: openvpn@server.service
|
||||||
|
openvpn_radius_plugin_path: ""
|
||||||
|
|
||||||
openvpn_radius_server: 10.1.0.101
|
openvpn_radius_server: 10.1.0.101
|
||||||
openvpn_radius_auth_port: 1812
|
openvpn_radius_auth_port: 1812
|
||||||
|
|||||||
@@ -1,25 +0,0 @@
|
|||||||
-----BEGIN CERTIFICATE-----
|
|
||||||
MIIEIzCCAwugAwIBAgIIXQADw2Y0rCkwDQYJKoZIhvcNAQELBQAwdDELMAkGA1UE
|
|
||||||
BhMCREUxCzAJBgNVBAYTAkRFMRAwDgYDVQQIEwdCYXZhcmlhMQ8wDQYDVQQHEwZN
|
|
||||||
dW5pY2gxEjAQBgNVBAoTCU15Q29tcGFueTEMMAoGA1UECxMDVlBOMRMwEQYDVQQD
|
|
||||||
EwpPcGVuVlBOLUNBMB4XDTI1MTExMTA5MjYwMFoXDTI2MTExMTA5MjYwMFowazEL
|
|
||||||
MAkGA1UEBhMCREUxEDAOBgNVBAgTB0JhdmFyaWExDzANBgNVBAcTBk11bmljaDES
|
|
||||||
MBAGA1UEChMJTXlDb21wYW55MQwwCgYDVQQLEwNWUE4xFzAVBgNVBAMTDjEyOC4x
|
|
||||||
NDAuMzEuMTMwMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAqS+40lrT
|
|
||||||
JnMvpdATIwPkK+tlgRSMP6o7T3lPrEQs5hs3i7cz/7iQyKA+m6aGbBeq9UkjZEn1
|
|
||||||
YBL0B7W+JN5EKQIRB5CSP+dQPX1v29KJpg2pBERoz//q5s0HDDm+cGm7g/eyDoeU
|
|
||||||
mQRq2coJlSCTMxDBIbh5kBzWckA0wI1ttFJgrWkNg8vlC/tMcScUs8dUcq2fD2AK
|
|
||||||
p8MPlj6y2/P91VOcfKHied96tJFZ4AQa9NXgfKVpK/6SvofskorU3rdH9sDXPG1C
|
|
||||||
7uoenZwB9IxAaA7aAbp5vn7e/sQz51OkIYpJ/bmo19Gsr479swzLwiZIN/RTeC56
|
|
||||||
2bkJTfwuECOK3QIDAQABo4HBMIG+MAwGA1UdEwEB/wQCMAAwHQYDVR0OBBYEFBYa
|
|
||||||
XMnt5E8Nm5QcEXoXoioOMRRXMB8GA1UdIwQYMBaAFKKI+gy0SqgucXKV2WDSDAJb
|
|
||||||
pIjiMAsGA1UdDwQEAwID6DATBgNVHSUEDDAKBggrBgEFBQcDATAZBgNVHREEEjAQ
|
|
||||||
gg4xMjguMTQwLjMxLjEzMDARBglghkgBhvhCAQEEBAMCBkAwHgYJYIZIAYb4QgEN
|
|
||||||
BBEWD3hjYSBjZXJ0aWZpY2F0ZTANBgkqhkiG9w0BAQsFAAOCAQEALsvqnSEoO82r
|
|
||||||
YxcH+Zo0+H4CdCYmwondZ7m0SuGaHDF0Sk1SecLVIKLMAZykzSEZPnYY9LancjCv
|
|
||||||
HYy2qtWYUxZxj5EwO1WUvxMzqpg6rCuUvlfZVBdoawjQq7N2FRgsZqA1GvCRo4g1
|
|
||||||
FkH+KDL7EH77tMXQceJroM1/RFLotbwoT+QegENTHYf2pWTFikdMissSlWBzG7P/
|
|
||||||
Vv3qY//LGJBtejvJWdNKE179S/X0Emyj0HWcNJ63ZxTvxbs+xVf4X4qNKY1JyGS2
|
|
||||||
WtWquMJAfgD9hfr9fDptt+fAq4zTiTZ0Xrxs3uYo5xFszNvYevl4900ZvrQwygve
|
|
||||||
ywb75tRo2g==
|
|
||||||
-----END CERTIFICATE-----
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
-----BEGIN RSA PRIVATE KEY-----
|
|
||||||
MIIEowIBAAKCAQEAqS+40lrTJnMvpdATIwPkK+tlgRSMP6o7T3lPrEQs5hs3i7cz
|
|
||||||
/7iQyKA+m6aGbBeq9UkjZEn1YBL0B7W+JN5EKQIRB5CSP+dQPX1v29KJpg2pBERo
|
|
||||||
z//q5s0HDDm+cGm7g/eyDoeUmQRq2coJlSCTMxDBIbh5kBzWckA0wI1ttFJgrWkN
|
|
||||||
g8vlC/tMcScUs8dUcq2fD2AKp8MPlj6y2/P91VOcfKHied96tJFZ4AQa9NXgfKVp
|
|
||||||
K/6SvofskorU3rdH9sDXPG1C7uoenZwB9IxAaA7aAbp5vn7e/sQz51OkIYpJ/bmo
|
|
||||||
19Gsr479swzLwiZIN/RTeC562bkJTfwuECOK3QIDAQABAoIBAACgvUSGJKgF/E1l
|
|
||||||
H4QravjPMyvLIg/kpbsJOI2yjxM1xKYBUNTdke6nWLQi9KHeSYHN+ufBmZ8xxJcx
|
|
||||||
ZrNc/nnDmME/4HBoDXj11lOpFEHr10eEcQh5B3Ls8WyH26oTXCg9jolHfYiwvA/k
|
|
||||||
20gGg3qsCZRX5wjtG1xp2pZ8zFOKp9VQkIBwUbj1uwh6+5zI7+9Lldw9lGm+8K5c
|
|
||||||
/plfXuy91rO0q1y8Uh7nf6DfT3/J0+vHngI/H0+/Bv1iKCSwsAyvwTN/SR6I4DcB
|
|
||||||
gSl8Aex0aA8y8A4UIAsGO2+FXVtu6TSA+RVBtodC6ugfI0sBbq2xLpgdKvkvgmVY
|
|
||||||
jAMtBCECgYEA7N6Weiv8ZCVbvzBc8XAhzPNOag4NOZklXX/kNrEZwwJRV9rao/x4
|
|
||||||
XBRSITgmzteoqIruSYc1Asw89Sk1zpF+LmnFQVfn8f2a1P8oRGLc6Q4VSBOEEd5K
|
|
||||||
aB4AAtciLmxOPuyAfECbe/rph3E8tvyltQeZPMQQrpBrMz8tS8pazzUCgYEAttm/
|
|
||||||
eOjH909Ibr3KZBBt7EvVvvQc6ss7mCgA00IoJ8Kmss8dPx24yKp4qsICGI10KUVa
|
|
||||||
BXlC87mRLfHj90JoYxF1GJwVzNz3QVK7Itum16AHw7KwWXlVqqVNAUHfX5VgU7k1
|
|
||||||
Kj5tu6rSMXM8LD57aTC8jmGRQEconorzWHLHegkCgYEAhM+BO9sx1s0Dlj19v3oJ
|
|
||||||
2aqKSvi5/ZOa2cP9p5TBRxAjn8j8Unoa2jYinrGnQM62qFnNpbiDxp/RhfynSL1X
|
|
||||||
LJrtmOe7C3oQuGCgqUdtadcVo6YdpQ8oVRyNEQqjBbiAXtOobwKiq29SRTj+u/MI
|
|
||||||
zmoGR4X/fIFJOiCwOxCovgkCgYBHSn6s1ZWhhvfmtXjDquQwzSB5YxQjNzn1CSPJ
|
|
||||||
OnINjocQEFCG2z/AfTau3RWUHRK9RJzkpXLFNAS2tSj8rpekiJnvDmwxg7Wjcm4k
|
|
||||||
GR/j0jE0y+aV/Ai6j9iGNPiye7si6YMhBVYjZWaugQ9k8LeNO8NIgCHxvczIg8R9
|
|
||||||
J8M+gQKBgCa8WFdvu4mwjfX+rkOyVpkY/rmktgMot1YRarC9xSDaOydS5C1D++UU
|
|
||||||
NxPRDwb7Ci1GNPAEHofOXXDLFVwlqJFg8meoYET4tP5L5dKb0MlQfb2dWyCITsNf
|
|
||||||
WVBGoDNIW3jbOD5/hPS8TfFvAVsRggMQTPSiMr5Z+pLrIoj45VkO
|
|
||||||
-----END RSA PRIVATE KEY-----
|
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
-----BEGIN OpenVPN Static key V1-----
|
||||||
|
50233c0e81ad6e32db57614c6475e318
|
||||||
|
3b89cc7d5955d14d86ecb94574f2c813
|
||||||
|
0de8f6ee461eedd7c7c8dc412f3ef5da
|
||||||
|
08fbff0d8216b05c9c8b288ba05b4262
|
||||||
|
3b6869c97763ccb5c871edf274ce2631
|
||||||
|
eaf92c23c2eb200d5296cdb7194ea366
|
||||||
|
21556274bc5b26e584c6e44b28d2d0e7
|
||||||
|
bb1b31b5a3ea115ec87f519a70543746
|
||||||
|
1e26900f527c3e6e2a2c8b4ae34127e1
|
||||||
|
7f85b059a7d88198b9b6a659958db81e
|
||||||
|
238b1257805a97509d47b53b697721d0
|
||||||
|
a54044df487f4441a95e41e39118fda5
|
||||||
|
3040f9a3ea581f4b43875b36b17a4566
|
||||||
|
5f968e0d3262a0eb1b56c03acac7cf40
|
||||||
|
f5d8111f55b51aa00926948f282af910
|
||||||
|
51c00fd604de92af7612823a560a6c2c
|
||||||
|
-----END OpenVPN Static key V1-----
|
||||||
@@ -3,9 +3,10 @@
|
|||||||
ansible.builtin.systemd:
|
ansible.builtin.systemd:
|
||||||
name: "{{ openvpn_service }}"
|
name: "{{ openvpn_service }}"
|
||||||
state: restarted
|
state: restarted
|
||||||
|
register: openvpn_restart_result
|
||||||
listen: Restart openvpn
|
listen: Restart openvpn
|
||||||
|
|
||||||
- name: Wait for tap0
|
- name: Wait for tap0 after OpenVPN restart
|
||||||
ansible.builtin.command: ip link show tap0
|
ansible.builtin.command: ip link show tap0
|
||||||
register: openvpn_tap_check
|
register: openvpn_tap_check
|
||||||
retries: 10
|
retries: 10
|
||||||
@@ -14,12 +15,12 @@
|
|||||||
changed_when: false
|
changed_when: false
|
||||||
listen: Restart openvpn
|
listen: Restart openvpn
|
||||||
|
|
||||||
- name: Bring tap0 up
|
- name: Bring tap0 up after OpenVPN restart
|
||||||
ansible.builtin.command: ip link set tap0 up
|
ansible.builtin.command: ip link set tap0 up
|
||||||
changed_when: false
|
changed_when: false
|
||||||
listen: Restart openvpn
|
listen: Restart openvpn
|
||||||
|
|
||||||
- name: Attach tap0 to bridge
|
- name: Attach tap0 to bridge after OpenVPN restart
|
||||||
ansible.builtin.command: ip link set tap0 master br-main-vpn
|
ansible.builtin.command: ip link set tap0 master br-main-vpn
|
||||||
changed_when: false
|
changed_when: false
|
||||||
listen: Restart openvpn
|
listen: Restart openvpn
|
||||||
|
|||||||
@@ -15,18 +15,11 @@
|
|||||||
group: root
|
group: root
|
||||||
mode: "0644"
|
mode: "0644"
|
||||||
|
|
||||||
- name: Deploy server certificate
|
- name: Deploy tls-crypt key
|
||||||
ansible.builtin.copy:
|
ansible.builtin.copy:
|
||||||
src: certs/server.crt
|
src: certs/tls-crypt.key
|
||||||
dest: "{{ openvpn_cert_dir }}/server.crt"
|
dest: "{{ openvpn_cert_dir }}/tls-crypt.key"
|
||||||
owner: root
|
|
||||||
group: root
|
|
||||||
mode: "0644"
|
|
||||||
|
|
||||||
- name: Deploy server private key
|
|
||||||
ansible.builtin.copy:
|
|
||||||
src: certs/server.key
|
|
||||||
dest: "{{ openvpn_cert_dir }}/server.key"
|
|
||||||
owner: root
|
owner: root
|
||||||
group: root
|
group: root
|
||||||
mode: "0600"
|
mode: "0600"
|
||||||
|
notify: Restart openvpn
|
||||||
|
|||||||
@@ -7,6 +7,32 @@
|
|||||||
state: present
|
state: present
|
||||||
update_cache: true
|
update_cache: true
|
||||||
|
|
||||||
|
- name: Locate RADIUS authentication plugin
|
||||||
|
ansible.builtin.find:
|
||||||
|
paths:
|
||||||
|
- /usr/lib
|
||||||
|
- /usr/lib/{{ ansible_architecture }}-linux-gnu
|
||||||
|
- /usr/lib/aarch64-linux-gnu
|
||||||
|
- /usr/lib/x86_64-linux-gnu
|
||||||
|
patterns: radiusplugin.so
|
||||||
|
recurse: true
|
||||||
|
file_type: file
|
||||||
|
register: openvpn_radius_plugin_candidates
|
||||||
|
|
||||||
|
- name: Configure RADIUS authentication plugin path
|
||||||
|
ansible.builtin.set_fact:
|
||||||
|
openvpn_radius_plugin_path: "{{ (openvpn_radius_plugin_candidates.files | sort(attribute='path') | first).path }}"
|
||||||
|
when: openvpn_radius_plugin_candidates.matched | int > 0
|
||||||
|
|
||||||
|
- name: Ensure RADIUS authentication plugin was found
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that:
|
||||||
|
- openvpn_radius_plugin_candidates.matched | int > 0
|
||||||
|
fail_msg: >-
|
||||||
|
The openvpn-auth-radius package is installed but radiusplugin.so was not
|
||||||
|
found. Set openvpn_radius_plugin_path to its installed path for this
|
||||||
|
distribution and architecture.
|
||||||
|
|
||||||
- name: Create OpenVPN directories
|
- name: Create OpenVPN directories
|
||||||
ansible.builtin.file:
|
ansible.builtin.file:
|
||||||
path: "{{ item }}"
|
path: "{{ item }}"
|
||||||
|
|||||||
@@ -5,5 +5,3 @@
|
|||||||
ansible.builtin.import_tasks: certs.yml
|
ansible.builtin.import_tasks: certs.yml
|
||||||
- name: Import OpenVPN configuration tasks
|
- name: Import OpenVPN configuration tasks
|
||||||
ansible.builtin.import_tasks: config.yml
|
ansible.builtin.import_tasks: config.yml
|
||||||
- name: Import OpenVPN bridge-tap tasks
|
|
||||||
ansible.builtin.import_tasks: bridge-tap.yml
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ mode server
|
|||||||
|
|
||||||
vlan-tagging
|
vlan-tagging
|
||||||
|
|
||||||
plugin /usr/lib/openvpn/radiusplugin.so /etc/openvpn/radiusplugin.cnf
|
plugin {{ openvpn_radius_plugin_path }} /etc/openvpn/radiusplugin.cnf
|
||||||
|
|
||||||
verify-client-cert none
|
verify-client-cert none
|
||||||
username-as-common-name
|
username-as-common-name
|
||||||
@@ -28,6 +28,7 @@ client-connect /etc/openvpn/scripts/client-connect.sh
|
|||||||
ca {{ openvpn_cert_dir }}/ca.crt
|
ca {{ openvpn_cert_dir }}/ca.crt
|
||||||
cert {{ openvpn_cert_dir }}/server.crt
|
cert {{ openvpn_cert_dir }}/server.crt
|
||||||
key {{ openvpn_cert_dir }}/server.key
|
key {{ openvpn_cert_dir }}/server.key
|
||||||
|
tls-crypt {{ openvpn_cert_dir }}/tls-crypt.key
|
||||||
|
|
||||||
dh none
|
dh none
|
||||||
ecdh-curve prime256v1
|
ecdh-curve prime256v1
|
||||||
|
|||||||
@@ -0,0 +1,54 @@
|
|||||||
|
# OpenVPN JWT identity
|
||||||
|
|
||||||
|
This role manages each VPN node's local RSA identity and JWT generator. It is
|
||||||
|
separate from `openvpn_pki`, which manages the OpenVPN server certificate.
|
||||||
|
|
||||||
|
`tasks/main.yml` delegates to three focused task files:
|
||||||
|
|
||||||
|
- `generator.yml` installs the configured generator and checks its Python
|
||||||
|
interpreter and dependencies.
|
||||||
|
- `keys.yml` creates or validates the RSA private/public key pair.
|
||||||
|
- `public_key.yml` fetches only the public key to the controller.
|
||||||
|
|
||||||
|
Run the dedicated identity playbook for selected nodes:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
ansible-playbook \
|
||||||
|
-i inventories/prod/hosts.ini \
|
||||||
|
playbooks/openvpn-jwt-identity.yml \
|
||||||
|
--limit vpn01-test
|
||||||
|
```
|
||||||
|
|
||||||
|
The Gitea workflow `.gitea/workflows/openvpn-jwt-identity.yml` runs after the
|
||||||
|
main OpenVPN workflow succeeds. It selects every
|
||||||
|
`vpn_nodes` host whose
|
||||||
|
`openvpn_jwt_registered` value is false or missing. It uploads the resulting
|
||||||
|
PEM files as the `openvpn-jwt-public-keys` artifact. An administrator adds
|
||||||
|
each new public key to OpenBao's existing trusted-key bundle while preserving
|
||||||
|
the other keys. After registration is confirmed, set that host's
|
||||||
|
`openvpn_jwt_registered` value to `true`; the regular OpenVPN deployment can
|
||||||
|
then proceed for that VM.
|
||||||
|
|
||||||
|
The regular `openvpn.yml` deployment skips the `openvpn`, `openvpn_jwt`, and
|
||||||
|
`openvpn_pki` roles when the flag is false or absent. Shared base roles still
|
||||||
|
run.
|
||||||
|
|
||||||
|
The private key remains on the VPN node at `/etc/vault-jwt/private.pem` by
|
||||||
|
default, with root ownership and mode `0600`.
|
||||||
|
Only the public key is copied to
|
||||||
|
`artifacts/openvpn-jwt-public-keys/<inventory_hostname>.pem` for manual
|
||||||
|
registration with OpenBao. The role does not configure OpenBao.
|
||||||
|
|
||||||
|
Existing keys must be a matching RSA pair at the configured size. The role
|
||||||
|
fails without replacing an incomplete, invalid, wrong-size, or mismatched
|
||||||
|
identity.
|
||||||
|
|
||||||
|
Install the collections in `requirements.yml`, including
|
||||||
|
`community.crypto`, on the Ansible controller before running this role.
|
||||||
|
|
||||||
|
The role creates the Python virtual environment and installs the pinned
|
||||||
|
`PyJWT[crypto]` dependency. Override `openvpn_jwt_virtualenv` to change the
|
||||||
|
environment location. If you also override `openvpn_jwt_python`, point it to
|
||||||
|
an interpreter inside that same environment.
|
||||||
|
`openvpn_jwt_role` and `openvpn_jwt_generator_args` configure the generator
|
||||||
|
invocation used by the certificate lifecycle script.
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
openvpn_jwt_directory: /etc/vault-jwt
|
||||||
|
openvpn_jwt_private_key_path: "{{ openvpn_jwt_directory }}/private.pem"
|
||||||
|
openvpn_jwt_public_key_path: "{{ openvpn_jwt_directory }}/public.pem"
|
||||||
|
openvpn_jwt_rsa_bits: 3072
|
||||||
|
openvpn_jwt_public_key_artifact_directory: "{{ playbook_dir }}/../artifacts/openvpn-jwt-public-keys"
|
||||||
|
|
||||||
|
openvpn_jwt_generator_script: /usr/local/bin/generate-vault-jwt.py
|
||||||
|
openvpn_jwt_virtualenv: /opt/vault-jwt/venv
|
||||||
|
openvpn_jwt_python: "{{ openvpn_jwt_virtualenv }}/bin/python"
|
||||||
|
openvpn_jwt_pyjwt_version: "2.15.1"
|
||||||
|
openvpn_jwt_role: vpn-servers
|
||||||
|
openvpn_jwt_auth_mount: jwt-vpn
|
||||||
|
# The generator must write only the JWT to stdout.
|
||||||
|
openvpn_jwt_generator_args: []
|
||||||
|
openvpn_jwt_export_public_key: true
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
---
|
||||||
|
- name: Create JWT identity directory
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: "{{ openvpn_jwt_directory }}"
|
||||||
|
state: directory
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: "0700"
|
||||||
|
|
||||||
|
- name: Deploy JWT generator script
|
||||||
|
ansible.builtin.template:
|
||||||
|
src: generate-vault-jwt.py.j2
|
||||||
|
dest: "{{ openvpn_jwt_generator_script }}"
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: "0750"
|
||||||
|
|
||||||
|
- name: Check JWT generator script
|
||||||
|
ansible.builtin.stat:
|
||||||
|
path: "{{ openvpn_jwt_generator_script }}"
|
||||||
|
register: openvpn_jwt_generator_stat
|
||||||
|
|
||||||
|
- name: Require executable JWT generator
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that:
|
||||||
|
- openvpn_jwt_generator_stat.stat.isreg | default(false)
|
||||||
|
- openvpn_jwt_generator_stat.stat.executable | default(false)
|
||||||
|
fail_msg: >-
|
||||||
|
JWT generator is missing or not executable:
|
||||||
|
{{ openvpn_jwt_generator_script }}
|
||||||
|
|
||||||
|
- name: Check JWT Python interpreter
|
||||||
|
ansible.builtin.stat:
|
||||||
|
path: "{{ openvpn_jwt_python }}"
|
||||||
|
register: openvpn_jwt_python_stat
|
||||||
|
|
||||||
|
- name: Require JWT Python interpreter
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that:
|
||||||
|
- openvpn_jwt_python_stat.stat.exists
|
||||||
|
- openvpn_jwt_python_stat.stat.executable | default(false)
|
||||||
|
fail_msg: >-
|
||||||
|
JWT Python interpreter is missing or not executable:
|
||||||
|
{{ openvpn_jwt_python }}
|
||||||
|
|
||||||
|
- name: Validate JWT Python dependencies
|
||||||
|
ansible.builtin.command:
|
||||||
|
argv:
|
||||||
|
- "{{ openvpn_jwt_python }}"
|
||||||
|
- -c
|
||||||
|
- "import jwt; import cryptography; assert hasattr(jwt, 'encode')"
|
||||||
|
changed_when: false
|
||||||
@@ -0,0 +1,154 @@
|
|||||||
|
---
|
||||||
|
- name: Check for existing JWT private key
|
||||||
|
ansible.builtin.stat:
|
||||||
|
path: "{{ openvpn_jwt_private_key_path }}"
|
||||||
|
register: openvpn_jwt_private_key_stat
|
||||||
|
|
||||||
|
- name: Check for existing JWT public key
|
||||||
|
ansible.builtin.stat:
|
||||||
|
path: "{{ openvpn_jwt_public_key_path }}"
|
||||||
|
register: openvpn_jwt_public_key_stat
|
||||||
|
|
||||||
|
- name: Refuse incomplete JWT identity
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that:
|
||||||
|
- openvpn_jwt_private_key_stat.stat.exists == openvpn_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_jwt_private_key_path }}"
|
||||||
|
type: RSA
|
||||||
|
size: "{{ openvpn_jwt_rsa_bits }}"
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: "0600"
|
||||||
|
when: not openvpn_jwt_private_key_stat.stat.exists
|
||||||
|
|
||||||
|
- name: Generate JWT public key from existing private key
|
||||||
|
community.crypto.openssl_publickey:
|
||||||
|
path: "{{ openvpn_jwt_public_key_path }}"
|
||||||
|
privatekey_path: "{{ openvpn_jwt_private_key_path }}"
|
||||||
|
format: PEM
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: "0644"
|
||||||
|
when: not openvpn_jwt_public_key_stat.stat.exists
|
||||||
|
|
||||||
|
- name: Validate existing JWT private key
|
||||||
|
ansible.builtin.command:
|
||||||
|
argv:
|
||||||
|
- openssl
|
||||||
|
- pkey
|
||||||
|
- -in
|
||||||
|
- "{{ openvpn_jwt_private_key_path }}"
|
||||||
|
- -check
|
||||||
|
- -noout
|
||||||
|
register: openvpn_jwt_private_key_validation
|
||||||
|
changed_when: false
|
||||||
|
failed_when: false
|
||||||
|
when: openvpn_jwt_private_key_stat.stat.exists
|
||||||
|
|
||||||
|
- name: Validate existing JWT public key
|
||||||
|
ansible.builtin.command:
|
||||||
|
argv:
|
||||||
|
- openssl
|
||||||
|
- pkey
|
||||||
|
- -pubin
|
||||||
|
- -in
|
||||||
|
- "{{ openvpn_jwt_public_key_path }}"
|
||||||
|
- -pubcheck
|
||||||
|
- -noout
|
||||||
|
register: openvpn_jwt_public_key_validation
|
||||||
|
changed_when: false
|
||||||
|
failed_when: false
|
||||||
|
when: openvpn_jwt_public_key_stat.stat.exists
|
||||||
|
|
||||||
|
- name: Fail clearly for invalid existing JWT identity keys
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that:
|
||||||
|
- openvpn_jwt_private_key_validation.rc == 0
|
||||||
|
- openvpn_jwt_public_key_validation.rc == 0
|
||||||
|
fail_msg: Existing JWT identity contains an invalid private or public key. The identity was not replaced.
|
||||||
|
when: openvpn_jwt_private_key_stat.stat.exists
|
||||||
|
|
||||||
|
- name: Read existing JWT private key type and size
|
||||||
|
ansible.builtin.command:
|
||||||
|
argv: [openssl, pkey, -in, "{{ openvpn_jwt_private_key_path }}", -text, -noout]
|
||||||
|
register: openvpn_jwt_private_key_details
|
||||||
|
changed_when: false
|
||||||
|
when: openvpn_jwt_private_key_stat.stat.exists
|
||||||
|
no_log: true
|
||||||
|
|
||||||
|
- name: Read existing JWT public key type and size
|
||||||
|
ansible.builtin.command:
|
||||||
|
argv: [openssl, pkey, -pubin, -in, "{{ openvpn_jwt_public_key_path }}", -text, -noout]
|
||||||
|
register: openvpn_jwt_public_key_details
|
||||||
|
changed_when: false
|
||||||
|
when: openvpn_jwt_public_key_stat.stat.exists
|
||||||
|
no_log: true
|
||||||
|
|
||||||
|
- name: Require existing JWT identity to be configured-size RSA
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that:
|
||||||
|
- "('Private-Key: (' ~ (openvpn_jwt_rsa_bits | string) ~ ' bit') in openvpn_jwt_private_key_details.stdout"
|
||||||
|
- "('Public-Key: (' ~ (openvpn_jwt_rsa_bits | string) ~ ' bit') in openvpn_jwt_public_key_details.stdout"
|
||||||
|
- "'modulus:' in openvpn_jwt_private_key_details.stdout"
|
||||||
|
- "'Modulus:' in openvpn_jwt_public_key_details.stdout"
|
||||||
|
fail_msg: Existing JWT identity must be an RSA key pair of the configured size. The identity was not replaced.
|
||||||
|
when: openvpn_jwt_private_key_stat.stat.exists
|
||||||
|
no_log: true
|
||||||
|
|
||||||
|
- name: Derive public key from existing JWT private key
|
||||||
|
ansible.builtin.command:
|
||||||
|
argv:
|
||||||
|
- openssl
|
||||||
|
- pkey
|
||||||
|
- -in
|
||||||
|
- "{{ openvpn_jwt_private_key_path }}"
|
||||||
|
- -pubout
|
||||||
|
register: openvpn_jwt_derived_public_key
|
||||||
|
changed_when: false
|
||||||
|
when: openvpn_jwt_private_key_stat.stat.exists
|
||||||
|
|
||||||
|
- name: Read stored JWT public key
|
||||||
|
ansible.builtin.command:
|
||||||
|
argv:
|
||||||
|
- openssl
|
||||||
|
- pkey
|
||||||
|
- -pubin
|
||||||
|
- -in
|
||||||
|
- "{{ openvpn_jwt_public_key_path }}"
|
||||||
|
- -pubout
|
||||||
|
register: openvpn_jwt_stored_public_key
|
||||||
|
changed_when: false
|
||||||
|
when: openvpn_jwt_public_key_stat.stat.exists
|
||||||
|
no_log: true
|
||||||
|
|
||||||
|
- name: Refuse mismatched existing JWT identity
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that:
|
||||||
|
- openvpn_jwt_derived_public_key.stdout == openvpn_jwt_stored_public_key.stdout
|
||||||
|
fail_msg: Existing JWT public key does not match its private key. The identity was not replaced.
|
||||||
|
when: openvpn_jwt_private_key_stat.stat.exists
|
||||||
|
|
||||||
|
- name: Enforce JWT private key ownership and permissions
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: "{{ openvpn_jwt_private_key_path }}"
|
||||||
|
state: file
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: "0600"
|
||||||
|
when: openvpn_jwt_private_key_stat.stat.exists
|
||||||
|
|
||||||
|
- name: Enforce JWT public key ownership and permissions
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: "{{ openvpn_jwt_public_key_path }}"
|
||||||
|
state: file
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: "0644"
|
||||||
|
when: openvpn_jwt_public_key_stat.stat.exists
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
---
|
||||||
|
- name: Provision the JWT Python environment
|
||||||
|
ansible.builtin.import_tasks: python_environment.yml
|
||||||
|
|
||||||
|
- name: Configure the JWT generator and runtime
|
||||||
|
ansible.builtin.import_tasks: generator.yml
|
||||||
|
|
||||||
|
- name: Create or validate the local JWT key pair
|
||||||
|
ansible.builtin.import_tasks: keys.yml
|
||||||
|
|
||||||
|
- name: Export the JWT public key for registration
|
||||||
|
ansible.builtin.import_tasks: public_key.yml
|
||||||
|
when: openvpn_jwt_export_public_key | bool
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
---
|
||||||
|
- name: Create public key artifact directory on controller
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: "{{ openvpn_jwt_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_jwt_public_key_path }}"
|
||||||
|
dest: "{{ openvpn_jwt_public_key_artifact_directory }}/{{ inventory_hostname }}.pem"
|
||||||
|
flat: true
|
||||||
|
validate_checksum: true
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
---
|
||||||
|
- name: Install Python virtual environment support
|
||||||
|
ansible.builtin.apt:
|
||||||
|
name: python3-venv
|
||||||
|
state: present
|
||||||
|
update_cache: true
|
||||||
|
cache_valid_time: 3600
|
||||||
|
|
||||||
|
- name: Install PyJWT and cryptography in the JWT virtual environment
|
||||||
|
ansible.builtin.pip:
|
||||||
|
name: "PyJWT[crypto]=={{ openvpn_jwt_pyjwt_version }}"
|
||||||
|
virtualenv: "{{ openvpn_jwt_virtualenv }}"
|
||||||
|
virtualenv_command: /usr/bin/python3 -m venv
|
||||||
|
state: present
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import time
|
||||||
|
import uuid
|
||||||
|
import jwt
|
||||||
|
|
||||||
|
PRIVATE_KEY = "{{ openvpn_jwt_private_key_path }}"
|
||||||
|
|
||||||
|
now = int(time.time())
|
||||||
|
|
||||||
|
payload = {
|
||||||
|
"iss": "helmholz-server-identity",
|
||||||
|
"sub": "{{ inventory_hostname }}",
|
||||||
|
"aud": "vault-pki",
|
||||||
|
"iat": now,
|
||||||
|
"nbf": now,
|
||||||
|
"exp": now + 600,
|
||||||
|
"jti": str(uuid.uuid4())
|
||||||
|
}
|
||||||
|
|
||||||
|
with open(PRIVATE_KEY, "r") as f:
|
||||||
|
private_key = f.read()
|
||||||
|
|
||||||
|
token = jwt.encode(
|
||||||
|
payload,
|
||||||
|
private_key,
|
||||||
|
algorithm="RS256"
|
||||||
|
)
|
||||||
|
|
||||||
|
print(token)
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
# OpenVPN PKI certificate lifecycle
|
||||||
|
|
||||||
|
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`.
|
||||||
|
|
||||||
|
## Task layout
|
||||||
|
|
||||||
|
`tasks/main.yml` delegates to focused stages:
|
||||||
|
|
||||||
|
- `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 }}"
|
||||||
|
```
|
||||||
|
|
||||||
|
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 collections listed in the repository's `requirements.yml`,
|
||||||
|
including `community.crypto` for the `openvpn_jwt` role.
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
---
|
||||||
|
|
||||||
|
openvpn_pki_bao_addr: "https://10.1.0.101:30200"
|
||||||
|
openvpn_pki_bao_cacert: /root/openbao-ca.crt
|
||||||
|
openvpn_pki_deployed_ca_source: "{{ openvpn_pki_certificate_dir }}/ca.crt"
|
||||||
|
openvpn_pki_sign_endpoint: vpn-Intermediate-pki/sign/vpn-servers
|
||||||
|
openvpn_pki_certificate_ttl: 1128h
|
||||||
|
openvpn_pki_certificate_dir: "{{ openvpn_cert_dir | default('/etc/openvpn/certs') }}"
|
||||||
|
openvpn_pki_certificate_common_name: "{{ inventory_hostname }}"
|
||||||
|
openvpn_pki_certificate_dns_sans: []
|
||||||
|
openvpn_pki_certificate_rsa_bits: 4096
|
||||||
|
openvpn_pki_expected_issuer: ""
|
||||||
|
openvpn_pki_require_server_auth_eku: true
|
||||||
|
openvpn_pki_renew_before_days: 15
|
||||||
|
openvpn_pki_working_directory: "{{ openvpn_pki_certificate_dir }}/.pki-work"
|
||||||
|
openvpn_pki_script_directory: /usr/local/libexec/openvpn-pki
|
||||||
|
openvpn_pki_config_path: /etc/openvpn/openbao-vpn.conf
|
||||||
|
openvpn_pki_service: "{{ openvpn_service | default('openvpn@server.service') }}"
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
-----BEGIN CERTIFICATE-----
|
||||||
|
MIIBbTCCARSgAwIBAgIUVIlalnN+qp4SnO6TeCnyhOej4tAwCgYIKoZIzj0EAwIw
|
||||||
|
FTETMBEGA1UEAxMKb3BlbmJhby1jYTAeFw0yNjExMjAxNzA4NDBaFw0zNjExMTcx
|
||||||
|
NzA4NDBaMBUxEzARBgNVBAMTCm9wZW5iYW8tY2EwWTATBgcqhkjOPQIBBggqhkjO
|
||||||
|
PQMBBwNCAAS29w4pGpvGF4MvRhJ4Nzw6E2WWQ8w1XaNE/CiKOLZNdiZsx6Q6IY6j
|
||||||
|
MReHV/N133Mf2UUUSbVHdWn307aC2U46o0IwQDAOBgNVHQ8BAf8EBAMCAqQwDwYD
|
||||||
|
VR0TAQH/BAUwAwEB/zAdBgNVHQ4EFgQU80e1lro0vF072OBJBm3Droxp+6gwCgYI
|
||||||
|
KoZIzj0EAwIDRwAwRAIgIc+d06gwSKl9rIiVBbii3Yg+SC/sxdSYto/0EPJ/SvMC
|
||||||
|
IEHFRvZ171ouXOL521avaBDq+eQOlXLVjGeYpJOi7oQk
|
||||||
|
-----END CERTIFICATE-----
|
||||||
@@ -0,0 +1,310 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -Eeuo pipefail
|
||||||
|
umask 077
|
||||||
|
|
||||||
|
log() { printf '[openvpn-pki] %s\n' "$*" >&2; }
|
||||||
|
die() { log "ERROR: $*"; exit 1; }
|
||||||
|
|
||||||
|
[[ $# -le 2 ]] || die "Usage: openbao-vpn-cert.sh [CONFIG_FILE] [--skip-openvpn-restart]"
|
||||||
|
CONFIG_FILE=${1:-/etc/openvpn/openbao-vpn.conf}
|
||||||
|
skip_openvpn_restart=false
|
||||||
|
if [[ ${2:-} == --skip-openvpn-restart ]]; then
|
||||||
|
skip_openvpn_restart=true
|
||||||
|
elif [[ $# -gt 1 ]]; then
|
||||||
|
die "Usage: openbao-vpn-cert.sh [CONFIG_FILE] [--skip-openvpn-restart]"
|
||||||
|
fi
|
||||||
|
[[ -r "$CONFIG_FILE" ]] || die "Configuration file is not readable"
|
||||||
|
|
||||||
|
# This is a root-owned Ansible template, with every value shell-quoted.
|
||||||
|
set -a
|
||||||
|
# shellcheck disable=SC1090
|
||||||
|
source "$CONFIG_FILE"
|
||||||
|
set +a
|
||||||
|
|
||||||
|
required_vars=(BAO_ADDR BAO_CACERT OPENVPN_CA_CERT OPENVPN_CA_FINGERPRINT BAO_BINARY JWT_PRIVATE_KEY JWT_SCRIPT JWT_PYTHON JWT_ROLE JWT_AUTH_PATH JWT_GENERATOR_ARGS_JSON PKI_SIGN_PATH CERT_TTL CERT_DIR WORKING_DIR CERT_NAME REQUIRE_SERVER_AUTH_EKU CERT_ALT_NAMES_JSON RSA_KEY_BITS RENEW_BEFORE_DAYS OPENVPN_SERVICE)
|
||||||
|
for name in "${required_vars[@]}"; do
|
||||||
|
[[ -n "${!name:-}" ]] || die "Required configuration value $name is empty"
|
||||||
|
done
|
||||||
|
|
||||||
|
for dependency in openssl jq mktemp install mv cp rm cmp cat chmod awk sed grep tr sort systemctl flock ip stat; do
|
||||||
|
command -v "$dependency" >/dev/null 2>&1 || die "Required executable is missing: $dependency"
|
||||||
|
done
|
||||||
|
[[ -x "$BAO_BINARY" ]] || die "OpenBao CLI is not executable: $BAO_BINARY"
|
||||||
|
[[ -x "$JWT_PYTHON" ]] || die "JWT Python interpreter is not executable: $JWT_PYTHON"
|
||||||
|
[[ -r "$JWT_SCRIPT" ]] || die "JWT generator script is not readable"
|
||||||
|
[[ -r "$JWT_PRIVATE_KEY" ]] || die "JWT private key is not readable"
|
||||||
|
[[ -r "$BAO_CACERT" ]] || die "OpenBao CA trust certificate is not readable"
|
||||||
|
[[ -r "$OPENVPN_CA_CERT" ]] || die "Deployed OpenVPN Root CA trust certificate is missing or unreadable"
|
||||||
|
[[ -d "$CERT_DIR" && -w "$CERT_DIR" ]] || die "Certificate directory is missing or not writable"
|
||||||
|
[[ -d "$WORKING_DIR" && -w "$WORKING_DIR" ]] || die "Staging directory is missing or not writable"
|
||||||
|
[[ "$RSA_KEY_BITS" =~ ^[0-9]+$ ]] && (( RSA_KEY_BITS >= 2048 )) || die "RSA_KEY_BITS must be at least 2048"
|
||||||
|
[[ "$RENEW_BEFORE_DAYS" =~ ^[0-9]+$ ]] || die "RENEW_BEFORE_DAYS must be a non-negative integer"
|
||||||
|
[[ "$REQUIRE_SERVER_AUTH_EKU" == true || "$REQUIRE_SERVER_AUTH_EKU" == false ]] || die "REQUIRE_SERVER_AUTH_EKU must be true or false"
|
||||||
|
|
||||||
|
certificate_fingerprint() {
|
||||||
|
openssl x509 -in "$1" -noout -fingerprint -sha256 |
|
||||||
|
sed 's/.*=//' | tr -d ':' | tr '[:lower:]' '[:upper:]'
|
||||||
|
}
|
||||||
|
|
||||||
|
restart_openvpn() {
|
||||||
|
local attempt
|
||||||
|
if [[ "$skip_openvpn_restart" == true ]]; then
|
||||||
|
log "Deferring OpenVPN restart to the Ansible handler"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
systemctl restart "$OPENVPN_SERVICE"
|
||||||
|
for attempt in {1..10}; do
|
||||||
|
if ip link show tap0 >/dev/null 2>&1; then
|
||||||
|
ip link set tap0 up
|
||||||
|
ip link set tap0 master br-main-vpn
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
sleep 10
|
||||||
|
done
|
||||||
|
log "OpenVPN restarted but tap0 did not become available"
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
root_fingerprint=$(certificate_fingerprint "$OPENVPN_CA_CERT") || die "Deployed company VPN Root CA is invalid"
|
||||||
|
expected_root_fingerprint=$(printf '%s' "$OPENVPN_CA_FINGERPRINT" | tr -d ':' | tr '[:lower:]' '[:upper:]')
|
||||||
|
[[ "$root_fingerprint" == "$expected_root_fingerprint" ]] || die "Configured company VPN Root CA fingerprint differs from its deployed certificate"
|
||||||
|
|
||||||
|
valid_dns_name() {
|
||||||
|
local value=$1 label
|
||||||
|
local -a labels=()
|
||||||
|
[[ ${#value} -le 253 && "$value" != *..* ]] || return 1
|
||||||
|
IFS=. read -r -a labels <<<"$value"
|
||||||
|
for label in "${labels[@]}"; do
|
||||||
|
[[ ${#label} -le 63 && "$label" =~ ^[A-Za-z0-9]([A-Za-z0-9-]*[A-Za-z0-9])?$ ]] || return 1
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
valid_dns_name "$CERT_NAME" || die "Certificate common name is not a valid DNS name"
|
||||||
|
jq -e 'type == "array" and all(.[]; type == "string")' <<<"$CERT_ALT_NAMES_JSON" >/dev/null || die "Certificate DNS SANs must be a JSON string array"
|
||||||
|
mapfile -t ALT_NAMES < <(jq -r '.[]' <<<"$CERT_ALT_NAMES_JSON")
|
||||||
|
((${#ALT_NAMES[@]} > 0)) || die "At least one DNS SAN is required"
|
||||||
|
declare -A seen_names=()
|
||||||
|
for name in "${ALT_NAMES[@]}"; do
|
||||||
|
valid_dns_name "$name" || die "Invalid DNS SAN configured"
|
||||||
|
seen_names["$name"]=1
|
||||||
|
done
|
||||||
|
[[ -n "${seen_names[$CERT_NAME]:-}" ]] || die "Certificate SAN list must include the common name"
|
||||||
|
|
||||||
|
workdir=$(mktemp -d "$WORKING_DIR/.openvpn-pki.XXXXXX") || die "Could not create staging directory"
|
||||||
|
cert_device=$(stat -c '%d' "$CERT_DIR") || die "Could not identify certificate filesystem"
|
||||||
|
work_device=$(stat -c '%d' "$workdir") || die "Could not identify staging filesystem"
|
||||||
|
[[ "$cert_device" == "$work_device" ]] || die "Staging directory must be on the certificate filesystem"
|
||||||
|
old_key_present=false
|
||||||
|
old_cert_present=false
|
||||||
|
replacement_started=false
|
||||||
|
preserve_workdir=false
|
||||||
|
|
||||||
|
cleanup() {
|
||||||
|
local status=$?
|
||||||
|
trap - EXIT
|
||||||
|
if [[ "$replacement_started" == true && $status -ne 0 ]]; then
|
||||||
|
log "Installation failed; restoring the previous certificate and key"
|
||||||
|
local rollback_failed=false
|
||||||
|
if [[ "$old_key_present" == true ]]; then
|
||||||
|
cp -p -- "$workdir/old-server.key" "$CERT_DIR/.server.key.rollback" || rollback_failed=true
|
||||||
|
mv -f -- "$CERT_DIR/.server.key.rollback" "$CERT_DIR/server.key" || rollback_failed=true
|
||||||
|
else
|
||||||
|
rm -f -- "$CERT_DIR/server.key" || rollback_failed=true
|
||||||
|
fi
|
||||||
|
if [[ "$old_cert_present" == true ]]; then
|
||||||
|
cp -p -- "$workdir/old-server.crt" "$CERT_DIR/.server.crt.rollback" || rollback_failed=true
|
||||||
|
mv -f -- "$CERT_DIR/.server.crt.rollback" "$CERT_DIR/server.crt" || rollback_failed=true
|
||||||
|
else
|
||||||
|
rm -f -- "$CERT_DIR/server.crt" || rollback_failed=true
|
||||||
|
fi
|
||||||
|
if [[ "$rollback_failed" != true ]]; then
|
||||||
|
restart_openvpn || rollback_failed=true
|
||||||
|
fi
|
||||||
|
if [[ "$rollback_failed" == true ]]; then
|
||||||
|
preserve_workdir=true
|
||||||
|
log "CRITICAL: rollback was incomplete; backups remain at $workdir"
|
||||||
|
status=1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
if [[ "$preserve_workdir" != true ]]; then
|
||||||
|
rm -rf -- "$workdir"
|
||||||
|
else
|
||||||
|
log "Staging data was retained for manual recovery"
|
||||||
|
fi
|
||||||
|
exit "$status"
|
||||||
|
}
|
||||||
|
trap cleanup EXIT
|
||||||
|
|
||||||
|
existing_certificate_is_valid() {
|
||||||
|
local current_dir="$workdir/current"
|
||||||
|
local subject actual_sans expected_sans
|
||||||
|
[[ -s "$CERT_DIR/server.crt" && -s "$CERT_DIR/server.key" ]] || return 1
|
||||||
|
mkdir -m 0700 "$current_dir" || return 1
|
||||||
|
/usr/bin/python3 "$(dirname "$0")/split-pem-chain.py" \
|
||||||
|
"$CERT_DIR/server.crt" "$current_dir" "$OPENVPN_CA_CERT" >/dev/null 2>&1 || return 1
|
||||||
|
openssl verify -CAfile "$OPENVPN_CA_CERT" -untrusted "$current_dir/intermediates.pem" \
|
||||||
|
"$current_dir/leaf.pem" >/dev/null 2>&1 || return 1
|
||||||
|
openssl x509 -in "$current_dir/leaf.pem" -checkend "$((RENEW_BEFORE_DAYS * 86400))" -noout >/dev/null 2>&1 || return 1
|
||||||
|
subject=$(openssl x509 -in "$current_dir/leaf.pem" -noout -subject -nameopt RFC2253 2>/dev/null) || return 1
|
||||||
|
subject=${subject#subject=}
|
||||||
|
[[ "$subject" =~ (^|,)CN=([^,]+) ]] && [[ "${BASH_REMATCH[2]}" == "$CERT_NAME" ]] || return 1
|
||||||
|
if [[ -n "${EXPECTED_ISSUER:-}" ]]; then
|
||||||
|
local issuer
|
||||||
|
issuer=$(openssl x509 -in "$current_dir/leaf.pem" -noout -issuer -nameopt RFC2253 2>/dev/null) || return 1
|
||||||
|
[[ "${issuer#issuer=}" == "$EXPECTED_ISSUER" ]] || return 1
|
||||||
|
fi
|
||||||
|
for name in "${ALT_NAMES[@]}"; do
|
||||||
|
openssl x509 -in "$current_dir/leaf.pem" -checkhost "$name" -noout >/dev/null 2>&1 || return 1
|
||||||
|
done
|
||||||
|
openssl x509 -in "$current_dir/leaf.pem" -noout -ext subjectAltName 2>/dev/null |
|
||||||
|
awk '/X509v3 Subject Alternative Name:/ {in_san=1; next} in_san {gsub(/^[[:space:]]+/, ""); printf "%s ", $0}' |
|
||||||
|
tr ',' '\n' | sed -n 's/^[[:space:]]*DNS:[[:space:]]*//p' | tr '[:upper:]' '[:lower:]' | sort -u >"$current_dir/actual-dns-sans" || return 1
|
||||||
|
printf '%s\n' "${ALT_NAMES[@]}" | tr '[:upper:]' '[:lower:]' | sort -u >"$current_dir/expected-dns-sans" || return 1
|
||||||
|
cmp -s "$current_dir/actual-dns-sans" "$current_dir/expected-dns-sans" || return 1
|
||||||
|
openssl x509 -in "$current_dir/leaf.pem" -pubkey -noout >"$current_dir/cert.pub" 2>/dev/null || return 1
|
||||||
|
openssl pkey -in "$CERT_DIR/server.key" -pubout >"$current_dir/key.pub" 2>/dev/null || return 1
|
||||||
|
cmp -s "$current_dir/cert.pub" "$current_dir/key.pub" || return 1
|
||||||
|
openssl rsa -pubin -in "$current_dir/cert.pub" -text -noout >"$current_dir/rsa-details" 2>/dev/null || return 1
|
||||||
|
grep -Fq "Public-Key: ($RSA_KEY_BITS bit)" "$current_dir/rsa-details" || return 1
|
||||||
|
if [[ "$REQUIRE_SERVER_AUTH_EKU" == true ]]; then
|
||||||
|
openssl x509 -in "$current_dir/leaf.pem" -noout -ext extendedKeyUsage >"$current_dir/eku" 2>/dev/null || return 1
|
||||||
|
grep -Eiq 'TLS Web Server Authentication|1\.3\.6\.1\.5\.5\.7\.3\.1' "$current_dir/eku" || return 1
|
||||||
|
fi
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
if existing_certificate_is_valid; then
|
||||||
|
log "Existing certificate is valid and outside the renewal window; no action required"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
login_json="$workdir/login.json"
|
||||||
|
issue_json="$workdir/issue.json"
|
||||||
|
log "Generating a local RSA key and CSR for $CERT_NAME"
|
||||||
|
openssl genpkey -algorithm RSA -pkeyopt "rsa_keygen_bits:$RSA_KEY_BITS" -out "$workdir/server.key" 2>/dev/null
|
||||||
|
chmod 0600 "$workdir/server.key"
|
||||||
|
|
||||||
|
{
|
||||||
|
printf '[req]\ndistinguished_name=dn\nreq_extensions=req_ext\nprompt=no\n[dn]\n'
|
||||||
|
printf 'CN=%s\n[req_ext]\nsubjectAltName=@alt_names\n[alt_names]\n' "$CERT_NAME"
|
||||||
|
index=1
|
||||||
|
declare -A emitted_names=()
|
||||||
|
for name in "${ALT_NAMES[@]}"; do
|
||||||
|
if [[ -n "${emitted_names[$name]:-}" ]]; then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
printf 'DNS.%d=%s\n' "$index" "$name"
|
||||||
|
index=$((index + 1))
|
||||||
|
emitted_names["$name"]=1
|
||||||
|
done
|
||||||
|
} >"$workdir/req.cnf"
|
||||||
|
openssl req -new -key "$workdir/server.key" -out "$workdir/server.csr" -config "$workdir/req.cnf"
|
||||||
|
|
||||||
|
log "Creating short-lived JWT and authenticating to OpenBao"
|
||||||
|
generator_args=()
|
||||||
|
mapfile -t generator_args < <(jq -r '.[]' <<<"$JWT_GENERATOR_ARGS_JSON")
|
||||||
|
if ! JWT_PRIVATE_KEY="$JWT_PRIVATE_KEY" JWT_ROLE="$JWT_ROLE" \
|
||||||
|
"$JWT_PYTHON" "$JWT_SCRIPT" "${generator_args[@]}" >"$workdir/jwt" 2>"$workdir/jwt-generator.err"; then
|
||||||
|
die "JWT generation failed (details suppressed to protect credentials)"
|
||||||
|
fi
|
||||||
|
[[ -s "$workdir/jwt" ]] || die "JWT generator returned an empty token"
|
||||||
|
tr -d '\r\n' <"$workdir/jwt" >"$workdir/jwt-clean"
|
||||||
|
mv -f -- "$workdir/jwt-clean" "$workdir/jwt"
|
||||||
|
[[ -s "$workdir/jwt" ]] || die "JWT generator returned an empty token"
|
||||||
|
chmod 0600 "$workdir/jwt"
|
||||||
|
if ! BAO_ADDR="$BAO_ADDR" BAO_CACERT="$BAO_CACERT" \
|
||||||
|
"$BAO_BINARY" write -format=json "auth/$JWT_AUTH_PATH/login" \
|
||||||
|
"role=$JWT_ROLE" "jwt=@$workdir/jwt" >"$login_json" 2>"$workdir/bao-login.err"; then
|
||||||
|
die "OpenBao JWT authentication failed (details suppressed)"
|
||||||
|
fi
|
||||||
|
token=$(jq -er '.auth.client_token' "$login_json" 2>/dev/null) || die "OpenBao authentication response was invalid"
|
||||||
|
rm -f -- "$workdir/jwt" "$workdir/jwt-generator.err" "$workdir/bao-login.err" "$login_json"
|
||||||
|
|
||||||
|
log "Requesting certificate from the configured PKI endpoint"
|
||||||
|
alt_names_csv=$(IFS=,; printf '%s' "${ALT_NAMES[*]}")
|
||||||
|
if ! BAO_ADDR="$BAO_ADDR" BAO_CACERT="$BAO_CACERT" BAO_TOKEN="$token" \
|
||||||
|
"$BAO_BINARY" write -format=json "$PKI_SIGN_PATH" \
|
||||||
|
"csr=@$workdir/server.csr" "ttl=$CERT_TTL" "common_name=$CERT_NAME" "alt_names=$alt_names_csv" \
|
||||||
|
>"$issue_json" 2>"$workdir/bao-issue.err"; then
|
||||||
|
unset token
|
||||||
|
die "OpenBao certificate signing failed (details suppressed)"
|
||||||
|
fi
|
||||||
|
unset token
|
||||||
|
jq -er '.data.certificate' "$issue_json" >"$workdir/leaf.crt" 2>/dev/null || die "OpenBao response did not contain a leaf certificate"
|
||||||
|
jq -er '.data.ca_chain[]' "$issue_json" >"$workdir/ca-chain-all.pem" 2>/dev/null || die "OpenBao response did not contain a CA chain"
|
||||||
|
|
||||||
|
root_fingerprint=$(certificate_fingerprint "$OPENVPN_CA_CERT")
|
||||||
|
: >"$workdir/intermediates.pem"
|
||||||
|
first_intermediate=""
|
||||||
|
awk -v dir="$workdir" '
|
||||||
|
/-----BEGIN CERTIFICATE-----/ {
|
||||||
|
n++
|
||||||
|
file=sprintf("%s/chain-%04d.pem", dir, n)
|
||||||
|
}
|
||||||
|
n > 0 { print > file }
|
||||||
|
/-----END CERTIFICATE-----/ { close(file); n=0 }
|
||||||
|
' "$workdir/ca-chain-all.pem"
|
||||||
|
shopt -s nullglob
|
||||||
|
chain_files=("$workdir"/chain-*.pem)
|
||||||
|
((${#chain_files[@]} > 0)) || die "OpenBao returned no parseable CA certificates"
|
||||||
|
for chain_cert in "${chain_files[@]}"; do
|
||||||
|
fingerprint=$(certificate_fingerprint "$chain_cert") || die "OpenBao returned an invalid CA certificate"
|
||||||
|
if [[ "$fingerprint" != "$root_fingerprint" ]]; then
|
||||||
|
[[ -n "$first_intermediate" ]] || first_intermediate=$chain_cert
|
||||||
|
cat "$chain_cert" >>"$workdir/intermediates.pem"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
[[ -s "$workdir/intermediates.pem" ]] || die "OpenBao returned no intermediate certificate"
|
||||||
|
|
||||||
|
log "Validating certificate chain, validity, identity, SANs and private-key match"
|
||||||
|
openssl verify -CAfile "$OPENVPN_CA_CERT" -untrusted "$workdir/intermediates.pem" "$workdir/leaf.crt" >/dev/null
|
||||||
|
openssl x509 -in "$workdir/leaf.crt" -checkend 0 -noout >/dev/null
|
||||||
|
subject=$(openssl x509 -in "$workdir/leaf.crt" -noout -subject -nameopt RFC2253 | sed 's/^subject=//')
|
||||||
|
[[ "$subject" =~ (^|,)CN=([^,]+) ]] || die "Issued certificate has no common name"
|
||||||
|
[[ "${BASH_REMATCH[2]}" == "$CERT_NAME" ]] || die "Issued certificate common name did not match configuration"
|
||||||
|
issuer=$(openssl x509 -in "$workdir/leaf.crt" -noout -issuer -nameopt RFC2253 | sed 's/^issuer=//')
|
||||||
|
if [[ -n "${EXPECTED_ISSUER:-}" ]]; then
|
||||||
|
[[ "$issuer" == "$EXPECTED_ISSUER" ]] || die "Issued certificate issuer did not match configured issuer"
|
||||||
|
else
|
||||||
|
[[ -n "$first_intermediate" ]] || die "No issuing intermediate certificate was returned"
|
||||||
|
intermediate_subject=$(openssl x509 -in "$first_intermediate" -noout -subject -nameopt RFC2253 | sed 's/^subject=//')
|
||||||
|
[[ "$issuer" == "$intermediate_subject" ]] || die "Issued certificate issuer did not match the returned intermediate"
|
||||||
|
fi
|
||||||
|
for name in "${ALT_NAMES[@]}"; do
|
||||||
|
openssl x509 -in "$workdir/leaf.crt" -checkhost "$name" -noout >/dev/null || die "Issued certificate is missing configured DNS identity"
|
||||||
|
done
|
||||||
|
openssl x509 -in "$workdir/leaf.crt" -noout -ext subjectAltName |
|
||||||
|
awk '/X509v3 Subject Alternative Name:/ {in_san=1; next} in_san {gsub(/^[[:space:]]+/, ""); printf "%s ", $0}' |
|
||||||
|
tr ',' '\n' | sed -n 's/^[[:space:]]*DNS:[[:space:]]*//p' | tr '[:upper:]' '[:lower:]' | sort -u >"$workdir/actual-dns-sans"
|
||||||
|
printf '%s\n' "${ALT_NAMES[@]}" | tr '[:upper:]' '[:lower:]' | sort -u >"$workdir/expected-dns-sans"
|
||||||
|
cmp -s "$workdir/actual-dns-sans" "$workdir/expected-dns-sans" || die "Issued certificate DNS SAN set did not exactly match configuration"
|
||||||
|
if [[ "$REQUIRE_SERVER_AUTH_EKU" == true ]]; then
|
||||||
|
openssl x509 -in "$workdir/leaf.crt" -noout -ext extendedKeyUsage >"$workdir/eku"
|
||||||
|
grep -Eiq 'TLS Web Server Authentication|1\.3\.6\.1\.5\.5\.7\.3\.1' "$workdir/eku" || die "Issued certificate lacks required serverAuth EKU"
|
||||||
|
fi
|
||||||
|
openssl x509 -in "$workdir/leaf.crt" -pubkey -noout >"$workdir/cert.pub"
|
||||||
|
openssl pkey -in "$workdir/server.key" -pubout >"$workdir/key.pub"
|
||||||
|
cmp -s "$workdir/cert.pub" "$workdir/key.pub" || die "Issued certificate does not match its private key"
|
||||||
|
openssl rsa -pubin -in "$workdir/cert.pub" -text -noout >"$workdir/rsa-details" 2>/dev/null || die "Issued certificate public key is not RSA"
|
||||||
|
grep -Fq "Public-Key: ($RSA_KEY_BITS bit)" "$workdir/rsa-details" || die "Issued certificate RSA key size did not match configuration"
|
||||||
|
cat "$workdir/leaf.crt" "$workdir/intermediates.pem" >"$workdir/server.crt"
|
||||||
|
install -o root -g root -m 0600 "$workdir/server.key" "$workdir/new-server.key"
|
||||||
|
install -o root -g root -m 0644 "$workdir/server.crt" "$workdir/new-server.crt"
|
||||||
|
|
||||||
|
if [[ -e "$CERT_DIR/server.key" ]]; then
|
||||||
|
cp -p -- "$CERT_DIR/server.key" "$workdir/old-server.key"
|
||||||
|
old_key_present=true
|
||||||
|
fi
|
||||||
|
if [[ -e "$CERT_DIR/server.crt" ]]; then
|
||||||
|
cp -p -- "$CERT_DIR/server.crt" "$workdir/old-server.crt"
|
||||||
|
old_cert_present=true
|
||||||
|
fi
|
||||||
|
replacement_started=true
|
||||||
|
install -o root -g root -m 0600 "$workdir/new-server.key" "$CERT_DIR/.server.key.new"
|
||||||
|
install -o root -g root -m 0644 "$workdir/new-server.crt" "$CERT_DIR/.server.crt.new"
|
||||||
|
mv -f -- "$CERT_DIR/.server.key.new" "$CERT_DIR/server.key"
|
||||||
|
mv -f -- "$CERT_DIR/.server.crt.new" "$CERT_DIR/server.crt"
|
||||||
|
restart_openvpn
|
||||||
|
log "Certificate and private key installed successfully"
|
||||||
|
printf 'CERTIFICATE_INSTALLED\n'
|
||||||
|
replacement_started=false
|
||||||
@@ -0,0 +1,105 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""Extract the first certificate and the remaining certificates in a PEM chain."""
|
||||||
|
|
||||||
|
import os
|
||||||
|
import re
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
from typing import Tuple
|
||||||
|
from pathlib import Path
|
||||||
|
from typing import NoReturn
|
||||||
|
|
||||||
|
|
||||||
|
def fail(message: str) -> "NoReturn":
|
||||||
|
print(message, file=sys.stderr)
|
||||||
|
raise SystemExit(1)
|
||||||
|
|
||||||
|
|
||||||
|
if len(sys.argv) != 4:
|
||||||
|
fail("Usage: split-pem-chain.py FULL_CHAIN OUTPUT_DIRECTORY ROOT_CA")
|
||||||
|
|
||||||
|
source = Path(sys.argv[1])
|
||||||
|
output_dir = Path(sys.argv[2])
|
||||||
|
root_ca = Path(sys.argv[3])
|
||||||
|
try:
|
||||||
|
data = source.read_bytes()
|
||||||
|
except OSError as exc:
|
||||||
|
fail(f"Could not read certificate chain: {exc}")
|
||||||
|
|
||||||
|
blocks = re.findall(
|
||||||
|
br"-----BEGIN CERTIFICATE-----\s*.*?-----END CERTIFICATE-----",
|
||||||
|
data,
|
||||||
|
flags=re.DOTALL,
|
||||||
|
)
|
||||||
|
if not blocks:
|
||||||
|
fail("Full-chain file contains no PEM certificates")
|
||||||
|
|
||||||
|
certificate_pattern = re.compile(
|
||||||
|
br"-----BEGIN CERTIFICATE-----\s*.*?-----END CERTIFICATE-----", re.DOTALL
|
||||||
|
)
|
||||||
|
if len(certificate_pattern.findall(data)) != len(blocks):
|
||||||
|
fail("Full-chain file contains malformed or nested PEM certificate blocks")
|
||||||
|
|
||||||
|
remaining = re.sub(
|
||||||
|
br"-----BEGIN CERTIFICATE-----\s*.*?-----END CERTIFICATE-----",
|
||||||
|
b"",
|
||||||
|
data,
|
||||||
|
flags=re.DOTALL,
|
||||||
|
)
|
||||||
|
if remaining.strip():
|
||||||
|
fail("Full-chain file contains data outside PEM certificate blocks")
|
||||||
|
|
||||||
|
try:
|
||||||
|
def inspect_certificate(block: bytes, description: str) -> Tuple[bytes, bool]:
|
||||||
|
pem = block.decode("ascii")
|
||||||
|
fingerprint = subprocess.check_output(
|
||||||
|
["openssl", "x509", "-noout", "-fingerprint", "-sha256"],
|
||||||
|
input=pem,
|
||||||
|
text=True,
|
||||||
|
stderr=subprocess.DEVNULL,
|
||||||
|
).strip()
|
||||||
|
basic_constraints = subprocess.run(
|
||||||
|
["openssl", "x509", "-noout", "-ext", "basicConstraints"],
|
||||||
|
input=pem,
|
||||||
|
text=True,
|
||||||
|
stdout=subprocess.PIPE,
|
||||||
|
stderr=subprocess.DEVNULL,
|
||||||
|
check=False,
|
||||||
|
)
|
||||||
|
is_ca = basic_constraints.returncode == 0 and re.search(
|
||||||
|
r"CA\s*:\s*TRUE", basic_constraints.stdout, re.IGNORECASE
|
||||||
|
) is not None
|
||||||
|
if basic_constraints.returncode not in (0, 1):
|
||||||
|
fail(f"Could not inspect {description} Basic Constraints")
|
||||||
|
return fingerprint.encode(), is_ca
|
||||||
|
|
||||||
|
root_fingerprint = subprocess.check_output(
|
||||||
|
["openssl", "x509", "-in", str(root_ca), "-noout", "-fingerprint", "-sha256"],
|
||||||
|
text=True,
|
||||||
|
stderr=subprocess.DEVNULL,
|
||||||
|
).strip()
|
||||||
|
_, leaf_is_ca = inspect_certificate(blocks[0], "leaf certificate")
|
||||||
|
if leaf_is_ca:
|
||||||
|
fail("First certificate in full-chain file is a CA certificate, not a leaf")
|
||||||
|
|
||||||
|
intermediate_blocks = []
|
||||||
|
for index, block in enumerate(blocks[1:], start=2):
|
||||||
|
fingerprint, is_ca = inspect_certificate(block, f"chain certificate {index}")
|
||||||
|
if not is_ca:
|
||||||
|
fail(f"Chain certificate {index} is not a CA certificate")
|
||||||
|
if fingerprint != root_fingerprint:
|
||||||
|
intermediate_blocks.append(block)
|
||||||
|
except (OSError, subprocess.CalledProcessError, UnicodeDecodeError) as exc:
|
||||||
|
fail(f"Could not inspect certificates in the existing chain: {exc}")
|
||||||
|
|
||||||
|
try:
|
||||||
|
leaf = output_dir / "leaf.pem"
|
||||||
|
intermediates = output_dir / "intermediates.pem"
|
||||||
|
leaf.write_bytes(blocks[0] + b"\n")
|
||||||
|
intermediates.write_bytes(b"\n".join(block + b"\n" for block in intermediate_blocks))
|
||||||
|
os.chmod(leaf, 0o600)
|
||||||
|
os.chmod(intermediates, 0o600)
|
||||||
|
except OSError as exc:
|
||||||
|
fail(f"Could not write extracted certificate chain: {exc}")
|
||||||
|
|
||||||
|
print(f"CHAIN_SPLIT_OK {len(intermediate_blocks)}")
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
---
|
||||||
|
- name: Check whether the OpenVPN server certificate exists
|
||||||
|
ansible.builtin.stat:
|
||||||
|
path: "{{ openvpn_pki_certificate_dir }}/server.crt"
|
||||||
|
register: openvpn_pki_server_certificate
|
||||||
|
|
||||||
|
|
||||||
|
- name: Issue the initial OpenVPN server certificate
|
||||||
|
ansible.builtin.command:
|
||||||
|
argv:
|
||||||
|
- /usr/bin/flock
|
||||||
|
- -n
|
||||||
|
- /run/lock/openbao-vpn-cert.lock
|
||||||
|
- "{{ openvpn_pki_script_directory }}/openbao-vpn-cert.sh"
|
||||||
|
- "{{ openvpn_pki_config_path }}"
|
||||||
|
- --skip-openvpn-restart
|
||||||
|
when: not openvpn_pki_server_certificate.stat.exists
|
||||||
|
register: openvpn_pki_initial_certificate
|
||||||
|
changed_when: "'CERTIFICATE_INSTALLED' in openvpn_pki_initial_certificate.stdout"
|
||||||
|
notify: Restart openvpn
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
---
|
||||||
|
- name: Install OpenVPN PKI runtime
|
||||||
|
ansible.builtin.import_tasks: runtime.yml
|
||||||
|
|
||||||
|
- name: Prepare certificate files and OpenBao configuration
|
||||||
|
ansible.builtin.import_tasks: setup.yml
|
||||||
|
|
||||||
|
- name: Install certificate lifecycle service and timer units
|
||||||
|
ansible.builtin.import_tasks: service.yml
|
||||||
|
|
||||||
|
- name: Issue certificate only when it is absent
|
||||||
|
ansible.builtin.import_tasks: initial_certificate.yml
|
||||||
|
|
||||||
|
- name: Enable and start daily certificate lifecycle timer
|
||||||
|
ansible.builtin.systemd:
|
||||||
|
name: openbao-vpn-cert.timer
|
||||||
|
enabled: true
|
||||||
|
state: started
|
||||||
|
daemon_reload: true
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
---
|
||||||
|
- name: Install OpenBao CLI
|
||||||
|
ansible.builtin.import_role:
|
||||||
|
name: openbao_cli
|
||||||
|
- name: Install OpenVPN PKI runtime dependencies
|
||||||
|
ansible.builtin.apt:
|
||||||
|
name:
|
||||||
|
- openssl
|
||||||
|
- jq
|
||||||
|
- python3
|
||||||
|
- util-linux
|
||||||
|
state: present
|
||||||
|
update_cache: true
|
||||||
|
cache_valid_time: 3600
|
||||||
|
- name: Calculate deployed company VPN Root CA fingerprint
|
||||||
|
ansible.builtin.command:
|
||||||
|
argv:
|
||||||
|
- openssl
|
||||||
|
- x509
|
||||||
|
- -in
|
||||||
|
- "{{ openvpn_pki_deployed_ca_source }}"
|
||||||
|
- -noout
|
||||||
|
- -fingerprint
|
||||||
|
- -sha256
|
||||||
|
register: openvpn_pki_company_ca_fingerprint
|
||||||
|
changed_when: false
|
||||||
|
- name: Normalize deployed company VPN Root CA fingerprint
|
||||||
|
ansible.builtin.set_fact:
|
||||||
|
openvpn_pki_company_ca_fingerprint_value: "{{ openvpn_pki_company_ca_fingerprint.stdout | regex_replace('^.*=', '') | replace(':', '') | upper }}"
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
---
|
||||||
|
- name: Deploy lifecycle script configuration
|
||||||
|
ansible.builtin.template:
|
||||||
|
src: openbao-vpn.conf.j2
|
||||||
|
dest: "{{ openvpn_pki_config_path }}"
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: "0600"
|
||||||
|
|
||||||
|
- name: Deploy certificate lifecycle service
|
||||||
|
ansible.builtin.template:
|
||||||
|
src: openbao-vpn-cert.service.j2
|
||||||
|
dest: /etc/systemd/system/openbao-vpn-cert.service
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: "0644"
|
||||||
|
|
||||||
|
- name: Deploy daily certificate lifecycle timer
|
||||||
|
ansible.builtin.template:
|
||||||
|
src: openbao-vpn-cert.timer.j2
|
||||||
|
dest: /etc/systemd/system/openbao-vpn-cert.timer
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: "0644"
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
---
|
||||||
|
- name: Create OpenVPN PKI directories
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: "{{ item.path }}"
|
||||||
|
state: directory
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: "{{ item.mode }}"
|
||||||
|
loop:
|
||||||
|
- { path: "{{ openvpn_pki_certificate_dir }}", mode: "0755" }
|
||||||
|
- { path: "{{ openvpn_pki_working_directory }}", mode: "0700" }
|
||||||
|
- { path: "{{ openvpn_pki_script_directory }}", mode: "0755" }
|
||||||
|
- { path: "{{ openvpn_pki_config_path | dirname }}", mode: "0755" }
|
||||||
|
|
||||||
|
|
||||||
|
- name: Require certificate staging directory on certificate filesystem
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that:
|
||||||
|
- openvpn_pki_working_directory == openvpn_pki_certificate_dir or openvpn_pki_working_directory.startswith(openvpn_pki_certificate_dir ~ '/')
|
||||||
|
fail_msg: >-
|
||||||
|
openvpn_pki_working_directory must be inside openvpn_pki_certificate_dir
|
||||||
|
so certificate and key replacement stays on one filesystem.
|
||||||
|
|
||||||
|
|
||||||
|
- name: Install OpenBao API CA certificate
|
||||||
|
ansible.builtin.copy:
|
||||||
|
src: certs/openbao-ca.crt
|
||||||
|
dest: "{{ openvpn_pki_bao_cacert }}"
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: "0644"
|
||||||
|
|
||||||
|
|
||||||
|
- name: Validate OpenBao API CA certificate
|
||||||
|
ansible.builtin.command:
|
||||||
|
argv:
|
||||||
|
- openssl
|
||||||
|
- x509
|
||||||
|
- -in
|
||||||
|
- "{{ openvpn_pki_bao_cacert }}"
|
||||||
|
- -noout
|
||||||
|
- -checkend
|
||||||
|
- "0"
|
||||||
|
changed_when: false
|
||||||
|
|
||||||
|
|
||||||
|
- name: Deploy OpenVPN certificate lifecycle script
|
||||||
|
ansible.builtin.copy:
|
||||||
|
src: scripts/openbao-vpn-cert.sh
|
||||||
|
dest: "{{ openvpn_pki_script_directory }}/openbao-vpn-cert.sh"
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: "0750"
|
||||||
|
|
||||||
|
|
||||||
|
- name: Deploy PEM chain helper
|
||||||
|
ansible.builtin.copy:
|
||||||
|
src: scripts/split-pem-chain.py
|
||||||
|
dest: "{{ openvpn_pki_script_directory }}/split-pem-chain.py"
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: "0750"
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=OpenVPN certificate lifecycle
|
||||||
|
After=network-online.target
|
||||||
|
Wants=network-online.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=oneshot
|
||||||
|
User=root
|
||||||
|
Group=root
|
||||||
|
ExecStart=/usr/bin/flock -n /run/lock/openbao-vpn-cert.lock {{ openvpn_pki_script_directory }}/openbao-vpn-cert.sh {{ openvpn_pki_config_path }}
|
||||||
|
TimeoutStartSec=5min
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Daily OpenVPN certificate lifecycle check
|
||||||
|
|
||||||
|
[Timer]
|
||||||
|
OnCalendar=daily
|
||||||
|
Persistent=true
|
||||||
|
Unit=openbao-vpn-cert.service
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=timers.target
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
BAO_ADDR={{ openvpn_pki_bao_addr | quote }}
|
||||||
|
BAO_CACERT={{ openvpn_pki_bao_cacert | quote }}
|
||||||
|
OPENVPN_CA_CERT={{ (openvpn_pki_certificate_dir ~ '/ca.crt') | quote }}
|
||||||
|
OPENVPN_CA_FINGERPRINT={{ openvpn_pki_company_ca_fingerprint_value | quote }}
|
||||||
|
BAO_BINARY={{ openbao_cli_binary_path | default('/usr/bin/bao') | quote }}
|
||||||
|
JWT_PRIVATE_KEY={{ openvpn_jwt_private_key_path | quote }}
|
||||||
|
JWT_SCRIPT={{ openvpn_jwt_generator_script | quote }}
|
||||||
|
JWT_PYTHON={{ openvpn_jwt_python | quote }}
|
||||||
|
JWT_ROLE={{ openvpn_jwt_role | quote }}
|
||||||
|
JWT_AUTH_PATH={{ openvpn_jwt_auth_mount | quote }}
|
||||||
|
JWT_GENERATOR_ARGS_JSON={{ openvpn_jwt_generator_args | to_json | quote }}
|
||||||
|
PKI_SIGN_PATH={{ openvpn_pki_sign_endpoint | quote }}
|
||||||
|
CERT_TTL={{ openvpn_pki_certificate_ttl | quote }}
|
||||||
|
CERT_DIR={{ openvpn_pki_certificate_dir | quote }}
|
||||||
|
WORKING_DIR={{ openvpn_pki_working_directory | quote }}
|
||||||
|
CERT_NAME={{ openvpn_pki_certificate_common_name | quote }}
|
||||||
|
EXPECTED_ISSUER={{ openvpn_pki_expected_issuer | quote }}
|
||||||
|
REQUIRE_SERVER_AUTH_EKU={{ openvpn_pki_require_server_auth_eku | bool | ternary('true', 'false') | quote }}
|
||||||
|
CERT_ALT_NAMES_JSON={{ (openvpn_pki_certificate_dns_sans + [openvpn_pki_certificate_common_name]) | unique | to_json | quote }}
|
||||||
|
RSA_KEY_BITS={{ openvpn_pki_certificate_rsa_bits | int }}
|
||||||
|
RENEW_BEFORE_DAYS={{ openvpn_pki_renew_before_days | int }}
|
||||||
|
OPENVPN_SERVICE={{ openvpn_pki_service | quote }}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
---
|
||||||
|
private_routing_interface: enp7s0
|
||||||
|
private_routing_gateway: 10.0.0.1
|
||||||
|
private_routing_metric: 100
|
||||||
|
private_routing_nameservers:
|
||||||
|
- 1.1.1.1
|
||||||
|
- 9.9.9.9
|
||||||
@@ -0,0 +1,93 @@
|
|||||||
|
---
|
||||||
|
- name: Find Netplan configuration files
|
||||||
|
ansible.builtin.find:
|
||||||
|
paths: /etc/netplan
|
||||||
|
patterns: "*.yaml,*.yml"
|
||||||
|
file_type: file
|
||||||
|
register: private_routing_netplan_files
|
||||||
|
failed_when: false
|
||||||
|
|
||||||
|
- name: Determine whether systemd-networkd manages the interface
|
||||||
|
ansible.builtin.command: networkctl status "{{ private_routing_interface }}"
|
||||||
|
register: private_routing_networkctl
|
||||||
|
changed_when: false
|
||||||
|
failed_when: false
|
||||||
|
when: private_routing_netplan_files.matched | default(0) == 0
|
||||||
|
|
||||||
|
- name: Refuse unknown network manager rather than overwrite network settings
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that:
|
||||||
|
- (private_routing_netplan_files.matched | default(0) > 0) or
|
||||||
|
(private_routing_networkctl.rc | default(1) == 0)
|
||||||
|
fail_msg: >-
|
||||||
|
No Netplan configuration or active systemd-networkd interface found for
|
||||||
|
{{ private_routing_interface }}; refusing to change network configuration.
|
||||||
|
|
||||||
|
# ---- Netplan path ----
|
||||||
|
- name: Install Netplan route drop-in
|
||||||
|
ansible.builtin.copy:
|
||||||
|
dest: /etc/netplan/99-private-vpn-default-route.yaml
|
||||||
|
content: |
|
||||||
|
network:
|
||||||
|
version: 2
|
||||||
|
ethernets:
|
||||||
|
{{ private_routing_interface }}:
|
||||||
|
routes:
|
||||||
|
- to: default
|
||||||
|
via: {{ private_routing_gateway }}
|
||||||
|
metric: {{ private_routing_metric }}
|
||||||
|
nameservers:
|
||||||
|
addresses: {{ private_routing_nameservers | to_json }}
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: "0600"
|
||||||
|
validate: python3 -c "import yaml,sys; yaml.safe_load(open(sys.argv[1]))" %s
|
||||||
|
when: private_routing_netplan_files.matched | default(0) > 0
|
||||||
|
|
||||||
|
- name: Apply Netplan route configuration
|
||||||
|
ansible.builtin.command: netplan apply
|
||||||
|
changed_when: false
|
||||||
|
when: private_routing_netplan_files.matched | default(0) > 0
|
||||||
|
|
||||||
|
# ---- systemd-networkd path ----
|
||||||
|
- name: Install systemd-networkd route drop-in
|
||||||
|
ansible.builtin.copy:
|
||||||
|
dest: "/etc/systemd/network/90-{{ private_routing_interface }}-private-vpn-route.network"
|
||||||
|
content: |
|
||||||
|
[Match]
|
||||||
|
Name={{ private_routing_interface }}
|
||||||
|
|
||||||
|
[Network]
|
||||||
|
{% for ns in private_routing_nameservers %}
|
||||||
|
DNS={{ ns }}
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
[Route]
|
||||||
|
Destination=0.0.0.0/0
|
||||||
|
Gateway={{ private_routing_gateway }}
|
||||||
|
Metric={{ private_routing_metric }}
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: "0644"
|
||||||
|
when: private_routing_netplan_files.matched | default(0) == 0
|
||||||
|
|
||||||
|
- name: Apply systemd-networkd route configuration
|
||||||
|
ansible.builtin.systemd:
|
||||||
|
name: systemd-networkd
|
||||||
|
state: restarted
|
||||||
|
when: private_routing_netplan_files.matched | default(0) == 0
|
||||||
|
|
||||||
|
# ---- Verification (both paths) ----
|
||||||
|
- name: Verify selected route to internet
|
||||||
|
ansible.builtin.command: ip -4 route get 8.8.8.8
|
||||||
|
register: private_routing_route_get
|
||||||
|
changed_when: false
|
||||||
|
failed_when: private_routing_gateway not in private_routing_route_get.stdout or private_routing_interface not in private_routing_route_get.stdout
|
||||||
|
|
||||||
|
- name: Verify DNS resolution through the gateway
|
||||||
|
ansible.builtin.command: getent hosts archive.ubuntu.com
|
||||||
|
register: private_routing_dns_check
|
||||||
|
changed_when: false
|
||||||
|
retries: 5
|
||||||
|
delay: 3
|
||||||
|
until: private_routing_dns_check.rc == 0
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
---
|
---
|
||||||
- name: Check if Syft is installed
|
- name: Check if Syft is installed
|
||||||
ansible.builtin.command: syft version
|
ansible.builtin.command: syft version
|
||||||
register: syft_check
|
register: sbom_syft_check
|
||||||
failed_when: false
|
failed_when: false
|
||||||
changed_when: false
|
changed_when: false
|
||||||
|
|
||||||
@@ -10,12 +10,12 @@
|
|||||||
url: https://raw.githubusercontent.com/anchore/syft/main/install.sh
|
url: https://raw.githubusercontent.com/anchore/syft/main/install.sh
|
||||||
dest: /tmp/install-syft.sh
|
dest: /tmp/install-syft.sh
|
||||||
mode: "0755"
|
mode: "0755"
|
||||||
when: syft_check.rc != 0
|
when: sbom_syft_check.rc != 0
|
||||||
|
|
||||||
- name: Install Syft
|
- name: Install Syft
|
||||||
ansible.builtin.command:
|
ansible.builtin.command:
|
||||||
cmd: /tmp/install-syft.sh -b /usr/local/bin
|
cmd: /tmp/install-syft.sh -b /usr/local/bin
|
||||||
when: syft_check.rc != 0
|
when: sbom_syft_check.rc != 0
|
||||||
changed_when: true
|
changed_when: true
|
||||||
|
|
||||||
- name: Create report directory
|
- name: Create report directory
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"namespace": "infrastructure",
|
||||||
|
"role": "gitlab-vpn-node-config",
|
||||||
|
"mount": "ssh",
|
||||||
|
"path": "vpn-admin",
|
||||||
|
"field": "private_key",
|
||||||
|
"variable": "VPN_ADMIN_PRIVATE_KEY"
|
||||||
|
}
|
||||||
|
]
|
||||||
Reference in New Issue
Block a user