← Start of tutorial

WIUNIX ACADEMY

OpenVPN MFA with client certificates and Google Authenticator

Page 3 of 5. Review the earlier steps and prerequisites before continuing.

YOUR SYSTEM. YOUR STEPS.

Where are you working?

Choose your OS and version. The prerequisites, commands and troubleshooting follow your environment.

AlmaLinux 10.2Reviewed against official documentation ·

USE YOUR OWN VALUES

Configure this tutorial

Set the example values for your environment; related explanations and copy panels update together. Never enter passwords, private keys or tokens. Values stay in this tab and are not sent to the server or share links. Check actual DNS, certificates and network policy before running commands.

Different IP addresses, domains or ports? Open the settings below, change the values and select “Apply to tutorial”, then copy the updated commands.

Set values for my environment7 editable values
10

LET’S BUILD

Create the pilot server configuration

Save the following complete file. Do not merge it into the production listener. Startup verifies the key/certificate match; a failed start must remain stopped while investigated. Current AEAD data ciphers and TLS1.2 minimum are used, with no compression or obsolete BF-CBC/cipher fallback. DCO is disabled in this small conventional-TUN pilot for consistent diagnostics.

bash

Dedicated pilot VM; private terminal for enrollment

set -eu
sudo sh -c 'umask 077; set -C; : > "/srv/academy-openvpn-mfa/server.conf"'
sudo nano '/srv/academy-openvpn-mfa/server.conf'
How do I know it worked?

A new private pilot configuration is ready to edit.

11

LET’S BUILD

Require both verifiers and retain certificate names

The main daemon drops to academy-openvpn while the packaged PAM helper remains privileged. The one-hour renegotiation interval does not guarantee session lifetime; test actual clients after reconnect, renegotiation and suspend. No credential logging, management listener, duplicate-CN mode or optional authentication is enabled.

text · /srv/academy-openvpn-mfa/server.conf

Dedicated pilot VM; private terminal for enrollment

local 192.0.2.40
port 11940
proto udp4
dev tun-mfa
dev-type tun
topology subnet
server 10.93.0.0 255.255.255.0
ca /srv/academy-openvpn-mfa/pki/ca.crt
cert /srv/academy-openvpn-mfa/pki/server.crt
key /srv/academy-openvpn-mfa/pki/server.key
dh none
crl-verify /srv/academy-openvpn-mfa/pki/crl.pem
tls-crypt /srv/academy-openvpn-mfa/pki/tls-crypt.key
verify-client-cert require
remote-cert-tls client
tls-version-min 1.2
data-ciphers AES-256-GCM:AES-128-GCM:CHACHA20-POLY1305
allow-compression no
disable-dco
plugin /srv/academy-openvpn-mfa/auth-pam.so "academy-mfa login USERNAME Verification PASSWORD"
script-security 2
auth-user-pass-verify /srv/academy-openvpn-mfa/bind-cn.py via-file
tmp-dir /srv/academy-openvpn-mfa/auth-tmp
user academy-openvpn
group academy-openvpn
persist-key
persist-tun
keepalive 10 60
reneg-sec 3600
verb 3
How do I know it worked?

The complete candidate requires verified client certificates, OTP PAM and exact CN binding.

12

LET’S BUILD

Prepare a dedicated systemd unit

The unit is deliberately separate from distribution auto-discovery directories and existing VPN units. It starts as root so the packaged PAM helper can initialize; the OpenVPN configuration then drops the main daemon. Do not add systemd User=nobody, NoNewPrivileges or filesystem restrictions without testing their effect on PAM identity switching and state writes. The scoped unit is not a complete hardening profile.

bash

Dedicated pilot VM; private terminal for enrollment

set -eu
sudo sh -c 'umask 022; set -C; : > "/etc/systemd/system/academy-mfa.service"'
sudo nano '/etc/systemd/system/academy-mfa.service'
How do I know it worked?

A fresh isolated unit file is ready; no existing unit is overwritten.

13

LET’S BUILD

Run only the reviewed pilot

The unit starts as root, reads protected configuration/key and lets OpenVPN reduce the main daemon UID. Personal seed state stays user-owned 0600. Restart=no leaves a failed pilot stopped for diagnosis. Boot enablement stays off until real positive/negative client checks and operational review pass.

ini · /etc/systemd/system/academy-mfa.service

Dedicated pilot VM; private terminal for enrollment

[Unit]
Description=WIUNIX Academy certificate and TOTP pilot
Wants=network-online.target
After=network-online.target

[Service]
Type=simple
ExecStart=/usr/sbin/openvpn --config /srv/academy-openvpn-mfa/server.conf
Restart=no
UMask=0077

[Install]
WantedBy=multi-user.target
How do I know it worked?

The unit invokes only this dedicated configuration; automatic boot start remains off.

14

LET’S BUILD

Review host security policy before starting

Keep SELinux enforcing. Map only this pilot tree to openvpn_etc_t, personal seed state to openvpn_var_lib_t and credential temp files to openvpn_var_run_t; map the dedicated UDP port to openvpn_port_t. Record each successful exact local mapping privately; stop for errors or pre-existing mappings, never overwrite them.

These paths use native policy; actual service-domain PAM/hook behavior still needs positive/negative tests and AVC review. Correct UID is not proof of SELinux permission; do not use unchecked audit2allow. Review the actual firewalld zone, broad existing rules and upstream ACL: allow UDP only from approved client sources and tunnel INPUT only to the approved service, not a global openvpn-service allow.

bash

Pilot VM before first service start

sudo python3 - <<'PY'
import pathlib,subprocess,re,os,json
r=pathlib.Path('/srv/academy-openvpn-mfa'); receipt=r/'selinux-local.json'
if os.path.lexists(receipt): raise SystemExit('Existing SELinux receipt; inspect, do not overwrite')
if subprocess.check_output(['getenforce'],text=True).strip()!='Enforcing':
    raise SystemExit('Use enforcing documented path; do not disable SELinux')
patterns=[(re.escape(str(r))+'(/.*)?','openvpn_etc_t'),(re.escape(str(r/'users'))+'(/.*)?','openvpn_var_lib_t'),(re.escape(str(r/'auth-tmp'))+'(/.*)?','openvpn_var_run_t')]
fd=os.open(receipt,os.O_WRONLY|os.O_CREAT|os.O_EXCL,0o600)
with os.fdopen(fd,'w',encoding='utf-8') as out: json.dump({'patterns':[],'port_added':False},out)
done={'patterns':[],'port_added':False}
for pattern,kind in patterns:
    subprocess.run(['semanage','fcontext','-a','-t',kind,pattern],check=True)
    done['patterns'].append(pattern);receipt.write_text(json.dumps(done),encoding='utf-8')
subprocess.run(['semanage','port','-a','-t','openvpn_port_t','-p','udp','11940'],check=True)
done['port_added']=True;receipt.write_text(json.dumps(done),encoding='utf-8')
subprocess.run(['restorecon','-RFv',str(r)],check=True)
subprocess.run(['restorecon','-v','/etc/pam.d/academy-mfa','/etc/systemd/system/academy-mfa.service'],check=True)
print('Exact lab labels and UDP port mapping recorded; SELinux stays enforcing')
PY
sudo ls -Zd '/srv/academy-openvpn-mfa' '/srv/academy-openvpn-mfa/users/academyvpn' '/srv/academy-openvpn-mfa/auth-tmp'
sudo ausearch -m AVC,USER_AVC -ts recent
How do I know it worked?

The actual policy permits only the intended pilot; ready for real service and denial checks.

15

LET’S BUILD

Validate the unit and start with the console open

Run this on the dedicated VM with the independent console still open. OpenVPN has no general full-config dry-run flag; systemd-analyze checks unit syntax, not TLS/auth correctness. A real bounded startup is the configuration check here. Read the journal privately and stop for any plugin, CRL, key, TUN or permission failure. Never add insecure options to make startup succeed.

bash

Dedicated pilot VM; private terminal for enrollment

set -eu
sudo systemd-analyze verify '/etc/systemd/system/academy-mfa.service'
sudo systemctl daemon-reload
sudo systemctl start 'academy-mfa.service'
sudo systemctl is-active 'academy-mfa.service'
sudo journalctl -u 'academy-mfa.service' -n 60 --no-pager
ip -br address show dev 'tun-mfa'
sudo ss -lunp
ps -eo user,pid,ppid,args | grep '[o]penvpn'
How do I know it worked?

The pilot listens on its dedicated UDP port, the new TUN has 10.93.0.1/24 and the main daemon runs as academy-openvpn; the packaged PAM helper remains privileged. Authentication/application checks follow.

Explore all tutorials ↗