Skip to content
This repository has been archived by the owner on Jun 4, 2021. It is now read-only.

Commit

Permalink
Control OpenVPN and ocserv access via /etc/allowed_vpn_certs (#1470)
Browse files Browse the repository at this point in the history
Just because you have a certificate (you can authenticate) doesn't mean that you are *authorized* to use a service. Create `/etc/allowed_vpn_certs`, with the name of one client cert per line. To disable ocserv and OpenVPN access, comment out the cert's line.

* ocserv properly uses PAM, and `/etc/pam.d/ocserv` configures it to check the list.

* OpenVPN theoretically can use PAM, but in practice does not seem to call it correctly. However, it ships with a script that can authorize certs.
  • Loading branch information
nopdotcom authored Mar 15, 2019
1 parent 59430d1 commit 0b901f7
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 0 deletions.
8 changes: 8 additions & 0 deletions playbooks/roles/certificates/tasks/client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,11 @@
loop_control:
loop_var: "client_name"
label: "{{ client_name.item }}"

- name: Authorize certificates via /etc/allowed_vpn_certs
template:
src: allowed_vpn_certs.j2
dest: /etc/allowed_vpn_certs
owner: root
group: root
mode: 0644
6 changes: 6 additions & 0 deletions playbooks/roles/certificates/templates/allowed_vpn_certs.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# This file lists all the enabled VPN certificate names. Note that
# it does not affect WireGuard.

{% for client in vpn_client_names.results -%}
{{ client.stdout }}
{% endfor %}
10 changes: 10 additions & 0 deletions playbooks/roles/openconnect/files/ocserv-pam
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
account required pam_listfile.so \
sense=allow item=user file=/etc/allowed_vpn_certs

auth required pam_listfile.so \
sense=allow item=user file=/etc/allowed_vpn_certs

password required pam_deny.so
session required pam_deny.so

other required pam_deny.so
8 changes: 8 additions & 0 deletions playbooks/roles/openconnect/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
# Download, compile and install ocserv and its dependencies
- import_tasks: install.yml

- name: Create ocserv's PAM control
copy:
src: ocserv-pam
dest: /etc/pam.d/ocserv
owner: root
group: root
mode: 0644

- name: Create the ocserv configuration directory
file:
path: "{{ ocserv_path }}"
Expand Down
2 changes: 2 additions & 0 deletions playbooks/roles/openconnect/templates/config.j2
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,5 @@ tunnel-all-dns = true
{% for item in upstream_dns_servers %}
dns = {{ item }}
{% endfor %}

acct = pam
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,6 @@ group nogroup
persist-key
persist-tun
verb 0

script-security 2
tls-verify "/usr/share/openvpn/verify-cn /etc/allowed_vpn_certs"

0 comments on commit 0b901f7

Please sign in to comment.