├── playbooks
├── group_vars
│ └── README.md
├── roles
│ ├── openvpn
│ │ ├── templates
│ │ │ ├── etc_tmpfiles.d_openvpn.conf
│ │ │ ├── group_vars_all.yml.j2
│ │ │ ├── group_vars_openvpn-vpn.yml.j2
│ │ │ ├── etc_openvpn_server.conf.j2
│ │ │ ├── etc_iptables_rules.v4.j2
│ │ │ ├── etc_systemd_system_openvpn@.service.d_override.conf.j2
│ │ │ ├── etc_openvpn_easyrsa_easyrsa3_vars.j2
│ │ │ └── etc_dnsmasq.conf.j2
│ │ ├── files
│ │ │ ├── 10periodic
│ │ │ └── 50unattended-upgrades
│ │ ├── tasks
│ │ │ ├── harden_umask.yml
│ │ │ ├── harden_kernel.yml
│ │ │ ├── firewall.yml
│ │ │ ├── dns.yml
│ │ │ ├── harden_services.yml
│ │ │ ├── main.yml
│ │ │ ├── harden_aide.yml
│ │ │ ├── harden_sysctl.yml
│ │ │ ├── harden_users.yml
│ │ │ ├── harden_sshd.yml
│ │ │ ├── packages.yml
│ │ │ ├── openvpn.yml
│ │ │ ├── harden_misc.yml
│ │ │ ├── pki.yml
│ │ │ ├── harden_password.yml
│ │ │ └── harden_auditd.yml
│ │ ├── vars
│ │ │ ├── RedHat.yml
│ │ │ └── Debian.yml
│ │ ├── handlers
│ │ │ └── main.yml
│ │ └── defaults
│ │ │ └── main.yml
│ ├── add_clients
│ │ ├── templates
│ │ │ ├── client_pkcs12.ovpn.j2
│ │ │ ├── client_pki_files.ovpn.j2
│ │ │ ├── client_pki_embedded.ovpn.j2
│ │ │ └── client_common.ovpn.j2
│ │ └── tasks
│ │ │ ├── main.yml
│ │ │ ├── add_via_csr.yml
│ │ │ └── add_gen_key.yml
│ ├── audit
│ │ ├── tasks
│ │ │ ├── tiger.yml
│ │ │ ├── main.yml
│ │ │ ├── lynis.yml
│ │ │ └── openscap.yml
│ │ └── vars
│ │ │ ├── Debian-8.yml
│ │ │ ├── Ubuntu-16.04.yml
│ │ │ └── RedHat.yml
│ └── revoke_client
│ │ └── tasks
│ │ └── main.yml
├── audit.yml
├── revoke_client.yml
├── add_clients.yml
└── install.yml
├── .gitignore
├── ansible.cfg
├── test
├── docker-inventory
├── Dockerfile.debian-8.7
├── Dockerfile.centos-7
└── Dockerfile.ubuntu-16.04
├── inventory.example
├── .travis.yml
├── README.md
└── LICENSE
/playbooks/group_vars/README.md:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | fetched_creds
2 | *.retry
3 | /inventory
4 |
--------------------------------------------------------------------------------
/playbooks/roles/openvpn/templates/etc_tmpfiles.d_openvpn.conf:
--------------------------------------------------------------------------------
1 | #Type Path Mode UID GID Age Argument
2 | d /run/openvpn 0755 openvpn openvpn
3 |
--------------------------------------------------------------------------------
/playbooks/roles/openvpn/templates/group_vars_all.yml.j2:
--------------------------------------------------------------------------------
1 | ---
2 | # Generated by pki.yml task
3 | ca_password: {{ ca_password_result.stdout }}
4 |
--------------------------------------------------------------------------------
/playbooks/roles/add_clients/templates/client_pkcs12.ovpn.j2:
--------------------------------------------------------------------------------
1 | {% include "client_common.ovpn.j2" %}
2 |
3 | pkcs12 {{ item }}@{{ openvpn_server_common_name }}.p12
4 |
--------------------------------------------------------------------------------
/ansible.cfg:
--------------------------------------------------------------------------------
1 | [defaults]
2 | inventory = inventory
3 |
4 | # Workaround for https://github.com/ansible/ansible/issues/13401
5 | scp_if_ssh=True
6 |
7 | [ssh_connection]
8 | pipelining = True
9 |
--------------------------------------------------------------------------------
/test/docker-inventory:
--------------------------------------------------------------------------------
1 | [localhost]
2 | 127.0.0.1 ansible_python_interpreter=python
3 |
4 | [openvpn-internet]
5 | 172.17.0.2 ansible_user=docker ansible_become=yes ansible_become_pass=password
6 |
--------------------------------------------------------------------------------
/playbooks/roles/openvpn/files/10periodic:
--------------------------------------------------------------------------------
1 | APT::Periodic::Update-Package-Lists "1";
2 | APT::Periodic::Download-Upgradeable-Packages "1";
3 | APT::Periodic::AutocleanInterval "7";
4 | APT::Periodic::Unattended-Upgrade "1";
5 |
--------------------------------------------------------------------------------
/playbooks/roles/openvpn/templates/group_vars_openvpn-vpn.yml.j2:
--------------------------------------------------------------------------------
1 | ---
2 | # Generated by harden_users.yml
3 | ansible_user: {{ sudo_username }}
4 | ansible_become: yes
5 | ansible_become_pass: {{ sudo_user_password.stdout }}
6 |
--------------------------------------------------------------------------------
/playbooks/roles/add_clients/templates/client_pki_files.ovpn.j2:
--------------------------------------------------------------------------------
1 | {% include "client_common.ovpn.j2" %}
2 |
3 | ca ca.crt
4 | cert {{ item }}@{{ openvpn_server_common_name }}.crt
5 | key {{ item }}@{{ openvpn_server_common_name }}.key
6 |
--------------------------------------------------------------------------------
/playbooks/audit.yml:
--------------------------------------------------------------------------------
1 | - name: Audit Server
2 | # ========================================================
3 | # Allows caller to override hosts using '-e cmd_hosts='
4 | hosts: "{{ cmd_hosts | default('openvpn-vpn') }}"
5 |
6 | roles:
7 | - audit
8 |
--------------------------------------------------------------------------------
/playbooks/revoke_client.yml:
--------------------------------------------------------------------------------
1 | - name: Revoke client access
2 | # ========================================================
3 | # Allows caller to override hosts using '-e cmd_hosts='
4 | hosts: "{{ cmd_hosts | default('openvpn-vpn') }}"
5 |
6 | roles:
7 | - revoke_client
8 |
--------------------------------------------------------------------------------
/playbooks/add_clients.yml:
--------------------------------------------------------------------------------
1 | - name: Add clients to OpenVPN's PKI
2 | # ========================================================
3 | # Allows caller to override hosts using '-e cmd_hosts='
4 | hosts: "{{ cmd_hosts | default('openvpn-vpn') }}"
5 |
6 | roles:
7 | - add_clients
8 |
--------------------------------------------------------------------------------
/playbooks/roles/add_clients/templates/client_pki_embedded.ovpn.j2:
--------------------------------------------------------------------------------
1 | {% include "client_common.ovpn.j2" %}
2 |
3 |
4 | {{ openvpn_ca_contents.stdout }}
5 |
6 |
7 |
8 | {{ item[1].stdout }}
9 |
10 |
11 |
12 | {{ item[2].stdout }}
13 |
14 |
--------------------------------------------------------------------------------
/playbooks/roles/openvpn/tasks/harden_umask.yml:
--------------------------------------------------------------------------------
1 | ---
2 | - name: OpenVPN | Harden | Set default umask in {{ item.dest }}
3 | lineinfile:
4 | dest: "{{ item.dest }}"
5 | regexp: "{{ item.regexp }}"
6 | line: "{{ item.line }}"
7 | state: present
8 | with_items: "{{ umask_files }}"
9 |
--------------------------------------------------------------------------------
/playbooks/roles/openvpn/tasks/harden_kernel.yml:
--------------------------------------------------------------------------------
1 | ---
2 | - name: OpenVPN | Harden Kernel | Disable various kernel modules
3 | copy:
4 | content: "install {{ item }} /bin/false"
5 | dest: /etc/modprobe.d/{{ item }}.conf
6 | with_items:
7 | - cramfs
8 | - freevxfs
9 | - jffs2
10 | - hfs
11 | - hfsplus
12 | - squashfs
13 | - udf
14 | - dccp
15 | - sctp
16 | - rds
17 | - tipc
18 | - firewire-core
19 | - usb-storage
20 | - net-pf-31
21 | - bluetooth
22 |
--------------------------------------------------------------------------------
/playbooks/roles/openvpn/tasks/firewall.yml:
--------------------------------------------------------------------------------
1 | ---
2 | - name: OpenVPN | Firewall | Reread ansible_default_ipv4
3 | setup:
4 | filter: ansible_default_ipv4*
5 |
6 | - name: OpenVPN | Firewall | Write persistent iptables rules
7 | template:
8 | src: etc_iptables_rules.v4.j2
9 | dest: "{{ path_persistent_iptables_rules }}"
10 | owner: root
11 | group: root
12 | mode: 0744
13 |
14 | - name: OpenVPN | Firewall | Enable iptables service
15 | service:
16 | name: iptables
17 | enabled: true
18 | when: ansible_os_family == "RedHat"
19 |
--------------------------------------------------------------------------------
/playbooks/roles/add_clients/templates/client_common.ovpn.j2:
--------------------------------------------------------------------------------
1 | client
2 |
3 | {% for instance in openvpn_instances %}
4 | remote {{ openvpn_server }} {{ instance.port }} {{ instance.proto }}
5 | {% endfor %}
6 |
7 | dev tun
8 | cipher {{ openvpn_cipher }}
9 | auth {{ openvpn_auth_digest }}
10 | resolv-retry infinite
11 | nobind
12 | persist-key
13 | persist-tun
14 | remote-cert-tls server
15 | verify-x509-name server@{{ openvpn_server_common_name }} name
16 | tls-version-min 1.2
17 | comp-lzo
18 | key-direction 1
19 | verb 3
20 |
21 |
22 | {{ openvpn_hmac_firewall_contents.stdout }}
23 |
24 |
--------------------------------------------------------------------------------
/playbooks/roles/openvpn/tasks/dns.yml:
--------------------------------------------------------------------------------
1 | ---
2 | - name: OpenVPN | dns | Create {{ dns_group }} group
3 | group:
4 | name: "{{ dns_group }}"
5 |
6 | - name: OpenVPN | dns | Create {{ dns_user }} user
7 | user:
8 | name: "{{ dns_user }}"
9 | group: "{{ dns_group }}"
10 | shell: /usr/sbin/nologin
11 | createhome: no
12 |
13 | - name: OpenVPN | dns | Generate dnsmasq configuration file
14 | template:
15 | src: etc_dnsmasq.conf.j2
16 | dest: /etc/dnsmasq.conf
17 | notify:
18 | - start dnsmasq
19 |
20 | - name: OpenVPN | dns | systemd - enable service
21 | service:
22 | name: dnsmasq
23 | enabled: true
24 |
--------------------------------------------------------------------------------
/playbooks/roles/openvpn/tasks/harden_services.yml:
--------------------------------------------------------------------------------
1 | ---
2 | - name: OpenVPN | Harden Services | cron.allow
3 | copy:
4 | content: "root"
5 | dest: "/etc/cron.allow"
6 | owner: root
7 | group: root
8 | mode: 0644
9 |
10 | # Note aide package on debian requires parts of exim, so can't uninstall it. just disable.
11 | - name: OpenVPN | Harden Services | Disable mail services
12 | service:
13 | name: "{{ item }}"
14 | enabled: false
15 | register: unused_disable
16 | #If the service doesn't exist, no need to disable -> not a failure
17 | failed_when: "unused_disable|failed and ('find' not in unused_disable.msg and 'found' not in unused_disable.msg)"
18 | with_items:
19 | - exim4
20 | - postfix
21 |
--------------------------------------------------------------------------------
/playbooks/roles/add_clients/tasks/main.yml:
--------------------------------------------------------------------------------
1 | ---
2 | - name: OpenVPN | Add Clients | Set variables
3 | include_vars: ../../openvpn/defaults/main.yml
4 |
5 | - name: OpenVPN | Add Clients | Register the OpenVPN server common name
6 | command: cat {{ openvpn_server_common_name_file }}
7 | no_log: true
8 | register: openvpn_server_common_name_result
9 | changed_when: false
10 |
11 | - name: OpenVPN | Add Clients | Set server common name variable
12 | set_fact:
13 | openvpn_server_common_name: "{{ openvpn_server_common_name_result.stdout }}"
14 |
15 | - name: OpenVPN | Add Clients | Add clients and generate keys
16 | include: add_gen_key.yml
17 | when: clients_to_add is defined
18 |
19 | - name: OpenVPN | Add Clients | Add via CSR
20 | include: add_via_csr.yml
21 | when: csr_path is defined
22 |
--------------------------------------------------------------------------------
/playbooks/roles/openvpn/templates/etc_openvpn_server.conf.j2:
--------------------------------------------------------------------------------
1 | dev tun-{{ item.proto }}-{{ item.port }}
2 | server {{ item.mask }}
3 | push "dhcp-option DNS {{ item.gateway }}"
4 | proto {{ item.proto }}
5 | port {{ item.port }}
6 |
7 | ca {{ openvpn_ca_cert }}
8 | cert {{ path_server_cert }}
9 | key {{ path_server_key }}
10 | dh {{ dhparams_location }}
11 | crl-verify {{ openvpn_crl }}
12 | push "redirect-gateway def1"
13 |
14 | # Fix for the Windows 10 DNS leak described here:
15 | # https://community.openvpn.net/openvpn/ticket/605
16 | push block-outside-dns
17 |
18 | remote-cert-tls client
19 | keepalive 10 120
20 | tls-auth {{ openvpn_hmac_firewall }} 0
21 | cipher {{ openvpn_cipher }}
22 | tls-cipher {{ openvpn_tls_cipher }}
23 | auth {{ openvpn_auth_digest }}
24 | tls-version-min 1.2
25 | comp-lzo
26 | persist-key
27 | persist-tun
28 | verb 0
29 |
--------------------------------------------------------------------------------
/playbooks/roles/audit/tasks/tiger.yml:
--------------------------------------------------------------------------------
1 | ---
2 | - name: Audit | tiger | Install
3 | package:
4 | name: "tiger"
5 |
6 | # TODO Maybe add '-H' to get an HTML report instead
7 | - name: Audit | tiger | Run
8 | shell: tiger -e
9 | changed_when: false
10 | tags:
11 | - skip_ansible_lint
12 |
13 | - name: Audit | tiger | Make local destination
14 | local_action: file path="{{ local_creds_folder }}/" state=directory
15 | become: False
16 |
17 | - name: Audit | tiger | Get report name
18 | find:
19 | path: /var/log/tiger/
20 | get_checksum: true
21 | register: tiger_report_path
22 | changed_when: false
23 |
24 | - name: Audit | tiger | Get report
25 | fetch:
26 | src: "{{ item.path }}"
27 | dest: "{{ local_creds_folder }}/tiger_report-{{ item.checksum }}.txt"
28 | flat: yes
29 | with_items:
30 | - "{{ tiger_report_path.files }}"
31 |
--------------------------------------------------------------------------------
/playbooks/roles/audit/vars/Debian-8.yml:
--------------------------------------------------------------------------------
1 | ---
2 | audit_oscap_packages:
3 | - libopenscap8
4 | - unzip
5 | - git
6 | oscap_ssg_version: 0.1.32
7 | oscap_ssg_archive: "scap-security-guide-{{ oscap_ssg_version }}.zip"
8 | oscap_ssg_url: "https://github.com/OpenSCAP/scap-security-guide/releases/download/v{{ oscap_ssg_version }}/{{ oscap_ssg_archive }}"
9 |
10 | oscap_policy_parent: "/usr/local"
11 | oscap_policy_base: "{{ oscap_policy_parent }}/scap-security-guide-{{ oscap_ssg_version }}"
12 |
13 | oscap_reports:
14 | - { name: default,
15 | profile: xccdf_org.ssgproject.content_profile_common,
16 | policy: "{{ oscap_policy_base }}/ssg-debian8-ds.xml",
17 | extra: "" }
18 | - { name: high,
19 | profile: xccdf_org.ssgproject.content_profile_anssi_np_nt28_high,
20 | policy: "{{ oscap_policy_base }}/ssg-debian8-ds.xml",
21 | extra: "" }
22 |
--------------------------------------------------------------------------------
/playbooks/roles/audit/vars/Ubuntu-16.04.yml:
--------------------------------------------------------------------------------
1 | ---
2 | audit_oscap_packages:
3 | - libopenscap8
4 | - unzip
5 | - git
6 | oscap_ssg_version: 0.1.32
7 | oscap_ssg_archive: "scap-security-guide-{{ oscap_ssg_version }}.zip"
8 | oscap_ssg_url: "https://github.com/OpenSCAP/scap-security-guide/releases/download/v{{ oscap_ssg_version }}/{{ oscap_ssg_archive }}"
9 |
10 | oscap_policy_parent: "/usr/local"
11 | oscap_policy_base: "{{ oscap_policy_parent }}/scap-security-guide-{{ oscap_ssg_version }}"
12 |
13 | oscap_reports:
14 | - { name: default,
15 | profile: xccdf_org.ssgproject.content_profile_common,
16 | policy: "{{ oscap_policy_base }}/ssg-ubuntu1604-ds.xml",
17 | extra: "" }
18 | - { name: high,
19 | profile: xccdf_org.ssgproject.content_profile_anssi_np_nt28_high,
20 | policy: "{{ oscap_policy_base }}/ssg-ubuntu1604-ds.xml",
21 | extra: "" }
22 |
--------------------------------------------------------------------------------
/playbooks/roles/audit/tasks/main.yml:
--------------------------------------------------------------------------------
1 | ---
2 | - name: OpenVPN | Audit | Set variables
3 | include_vars: ../../openvpn/defaults/main.yml
4 |
5 | - name: OpenVPN | Audit | Set Distro/Version specific variables
6 | include_vars: "{{ item }}"
7 | with_first_found:
8 | - "../vars/{{ ansible_distribution }}-{{ ansible_distribution_version}}.yml"
9 | - "../vars/{{ ansible_distribution }}-{{ ansible_distribution_major_version }}.yml"
10 | - "../vars/{{ ansible_os_family }}.yml"
11 | #- "../vars/default.yml"
12 |
13 | - include: openscap.yml
14 | #For now skip debian since it's version of oscap is so old it won't support new definitions. Revisit for Debian 9
15 | when: ansible_distribution not in ['Debian']
16 | - include: lynis.yml
17 | # No package for CentOS, RHEL, etc. Maybe pull from src in the future?
18 | - include: tiger.yml
19 | when: ansible_os_family == "Debian"
20 |
--------------------------------------------------------------------------------
/test/Dockerfile.debian-8.7:
--------------------------------------------------------------------------------
1 | FROM debian:8.7
2 | ENV container docker
3 |
4 | RUN apt-get update; apt-get -y upgrade
5 |
6 | RUN DEBIAN_FRONTEND=noninteractive apt-get -q -y install systemd openssh-server sudo openssh-client
7 |
8 | RUN systemctl mask dev-mqueue.mount dev-hugepages.mount \
9 | sys-kernel-debug.mount sys-fs-fuse-connections.mount \
10 | display-manager.service graphical.target systemd-logind.service
11 |
12 | RUN useradd -m -G sudo -s /bin/bash docker
13 | RUN echo 'docker:password' | chpasswd
14 |
15 | RUN mkdir /home/docker/.ssh
16 | ADD test/id_rsa.pub /home/docker/.ssh/authorized_keys
17 | RUN chown -R docker:docker /home/docker/.ssh/
18 | RUN chmod 701 /home/docker
19 | RUN chmod 700 /home/docker/.ssh
20 | RUN chmod 600 /home/docker/.ssh/authorized_keys
21 |
22 | VOLUME [ "/sys/fs/cgroup" ]
23 | VOLUME ["/run"]
24 |
25 | EXPOSE 22
26 | EXPOSE 1194
27 |
28 | CMD ["/bin/systemd"]
29 |
--------------------------------------------------------------------------------
/playbooks/roles/openvpn/tasks/main.yml:
--------------------------------------------------------------------------------
1 | ---
2 | - name: OpenVPN | Install | Set Distro/Version specific variables
3 | include_vars: "{{ item }}"
4 | with_first_found:
5 | #- "../vars/{{ ansible_distribution }}-{{ ansible_distribution_major_version | int}}.yml"
6 | #- "../vars/{{ ansible_distribution }}.yml"
7 | - "../vars/{{ ansible_os_family }}.yml"
8 | #- "../vars/default.yml"
9 | notify:
10 | - clear history
11 |
12 | - include: packages.yml
13 | - include: pki.yml
14 | - include: openvpn.yml
15 | - include: dns.yml
16 | - include: harden_sysctl.yml
17 | when: ansible_virtualization_type != "docker"
18 | - include: harden_umask.yml
19 | - include: harden_services.yml
20 | - include: harden_kernel.yml
21 | when: ansible_virtualization_type != "docker"
22 | - include: harden_misc.yml
23 | - include: harden_auditd.yml
24 |
25 | - include: firewall.yml
26 | - include: harden_password.yml
27 | - include: harden_users.yml
28 | - include: harden_sshd.yml
29 | - include: harden_aide.yml
30 |
--------------------------------------------------------------------------------
/playbooks/roles/openvpn/vars/RedHat.yml:
--------------------------------------------------------------------------------
1 | ---
2 |
3 | package_name_words: words
4 | package_name_auditd: audit
5 |
6 | path_bin_ip: /usr/sbin/ip
7 | path_bin_aide: /usr/sbin/aide
8 | path_persistent_iptables_rules: /etc/sysconfig/iptables
9 | path_dict: /usr/share/dict/words
10 | path_pam_system_auth: /etc/pam.d/system-auth
11 | path_pam_password_auth: /etc/pam.d/system-auth
12 | path_mac_config: /etc/selinux/
13 | path_auditd_rules: /etc/audit/rules.d/audit.rules
14 | path_aide_db: /var/lib/aide/aide.db.gz
15 |
16 | sudo_group: wheel
17 | path_grub_cfg: /boot/grub2/grub.cfg
18 | grub_mkconfig: grub2-mkconfig
19 |
20 | umask_files:
21 | - { dest: "/etc/profile", regexp: "^umask", line: "umask 077" }
22 |
23 | deny_failed_login_auth_files:
24 | - "{{ path_pam_system_auth }}"
25 | - '/etc/pam.d/password-auth'
26 |
27 | deny_failed_login_account_files: "{{ deny_failed_login_auth_files }}"
28 |
29 |
30 | os_family_specific_pre:
31 | - epel-release
32 | - yum-cron
33 | - yum-utils
34 | - iptables-services
35 |
36 |
--------------------------------------------------------------------------------
/playbooks/roles/audit/tasks/lynis.yml:
--------------------------------------------------------------------------------
1 | ---
2 | - name: Audit | lynis | Install lynis
3 | git:
4 | repo: https://github.com/CISOfy/lynis.git
5 | accept_hostkey: True
6 | remote: github
7 | version: master
8 | dest: "/usr/local/lynis"
9 |
10 | - name: Audit | lynis | chown dirs
11 | file:
12 | path: /usr/local/lynis
13 | owner: root
14 | group: root
15 | recurse: true
16 |
17 | - name: Audit | lynis | Run lynis
18 | shell: ./lynis audit system --cronjob > ~/lynis_report.txt
19 | args:
20 | chdir: /usr/local/lynis
21 | changed_when: false
22 |
23 | - name: Audit | lynis | Make local destination
24 | local_action: file path="{{ local_creds_folder }}/" state=directory
25 | become: False
26 |
27 | - name: Audit | lynis | Get report
28 | fetch:
29 | src: "~/lynis_report.txt"
30 | dest: "{{ local_creds_folder }}/lynis_report.txt"
31 | flat: yes
32 |
33 | - name: Audit | lynis | Get log
34 | fetch:
35 | src: "/var/log/lynis.log"
36 | dest: "{{ local_creds_folder }}/lynis_log.txt"
37 | flat: yes
38 |
--------------------------------------------------------------------------------
/playbooks/roles/openvpn/tasks/harden_aide.yml:
--------------------------------------------------------------------------------
1 | ---
2 | - name: OpenVPN | AIDE | Check for DB
3 | stat:
4 | path: "{{ path_aide_db }}"
5 | register: aide_db_check
6 |
7 | - name: OpenVPN | AIDE | Initialize AIDE DB
8 | shell: aideinit
9 | changed_when: false
10 | when: ansible_os_family == "Debian" and aide_db_check.stat.exists == false
11 | tags:
12 | - skip_ansible_lint
13 |
14 | - name: OpenVPN | AIDE | Initialize AIDE DB
15 | shell: aide --init
16 | changed_when: false
17 | when: ansible_os_family == "RedHat" and aide_db_check.stat.exists == false
18 | tags:
19 | - skip_ansible_lint
20 |
21 | - name: OpenVPN | AIDE | Copy initialized DB
22 | copy:
23 | remote_src: true
24 | src: /var/lib/aide/aide.db.new.gz
25 | dest: "{{ path_aide_db }}"
26 | when: ansible_os_family == "RedHat" and aide_db_check.stat.exists == false
27 |
28 | - name: OpenVPN | AIDE | Delete old DB
29 | file:
30 | path: /var/lib/aide/aide.db.new.gz
31 | state: absent
32 | when: ansible_os_family == "RedHat" and aide_db_check.stat.exists == false
33 |
--------------------------------------------------------------------------------
/inventory.example:
--------------------------------------------------------------------------------
1 | [localhost]
2 | 127.0.0.1 ansible_python_interpreter=python
3 |
4 | # This group is used by the install.yml playbook. Only one host should be defined in the group
5 | [openvpn-internet]
6 | # Typical Digital Ocean config w/ root user and pub/priv key authentication
7 | #255.255.255.255 ansible_user=root
8 | # Typical azure config w/ ssh authentication
9 | #255.255.255.255 ansible_user=vpnuser ansible_become=yes
10 | # Config for a machine with pub/priv key and password
11 | #255.255.255.255 ansible_user=vpnuser ansible_become=yes ansible_become_pass=password
12 | # No example provided for using just password authentication.
13 | # It's obvious given the example above but I'm not going to help you too much
14 | # with that bush league shit. Use a pub/priv key pair.
15 |
16 | # This group is used by the audit.yml, add_clients.yml and revoke_client.yml playbooks
17 | # You must be connected to the VPN to run these playbooks.
18 | # ansible_user, ansible_become_pass, etc are defined in group_vars/openvpn-vpn.yml
19 | # which is generated by the install.yml playbook.
20 | [openvpn-vpn]
21 | 10.9.0.1
22 |
--------------------------------------------------------------------------------
/playbooks/install.yml:
--------------------------------------------------------------------------------
1 | - name: Install required software, configure and harden
2 | # ========================================================
3 | hosts: openvpn-internet
4 |
5 | # You need a python 2 interpreter first, so skip gathering facts, then use
6 | # 'setup:' to get them after the python 2 interpreter has been installed.
7 | # See 'pre_tasks' below
8 | gather_facts: no
9 | pre_tasks:
10 | # If python doesn't exist on path (type returns non-zero), install python
11 | - name: OpenVPN | install | Install python2 if necessary
12 | raw: 'type python >/dev/null 2>&1 || apt-get -y install python-minimal'
13 | changed_when: false
14 |
15 | - name: OpenVPN | install | Gather facts after python2 is available
16 | setup:
17 |
18 | roles:
19 | - openvpn
20 | - {role: add_clients, clients_to_add: "{{ openvpn_clients }}"}
21 | - {role: audit, when: do_audit is defined and do_audit }
22 |
23 | post_tasks:
24 | - name: OpenVPN | install | Restart system after setup
25 | shell: sleep 2 && shutdown -r now "Restart for OpenVPN install"
26 | async: 1
27 | poll: 0
28 | ignore_errors: true
29 | changed_when: false
30 | when: ansible_virtualization_type != "docker"
31 |
--------------------------------------------------------------------------------
/playbooks/roles/revoke_client/tasks/main.yml:
--------------------------------------------------------------------------------
1 | ---
2 | - name: OpenVPN | Revoke Client | Set variables
3 | include_vars: ../../openvpn/defaults/main.yml
4 |
5 | - name: OpenVPN | Revoke Client | Register the OpenVPN server common name
6 | command: cat {{ openvpn_server_common_name_file }}
7 | no_log: true
8 | register: openvpn_server_common_name_result
9 | changed_when: false
10 |
11 | - name: OpenVPN | Revoke Client | Set the server common name
12 | set_fact:
13 | openvpn_server_common_name: "{{ openvpn_server_common_name_result.stdout }}"
14 |
15 | - name: OpenVPN | Revoke Client | Revoke access for {{ client }}
16 | expect:
17 | command: ./easyrsa revoke {{ client }}@{{ openvpn_server_common_name }}
18 | responses:
19 | 'Enter pass phrase for .*?:$': "{{ ca_password }}"
20 | chdir: "{{ openvpn_path_easyrsa }}"
21 | no_log: true
22 |
23 | - name: OpenVPN | Revoke Client | Rebuild CRL
24 | expect:
25 | command: ./easyrsa gen-crl
26 | responses:
27 | 'Enter pass phrase for .*?:$': "{{ ca_password }}"
28 | chdir: "{{ openvpn_path_easyrsa }}"
29 |
30 | - name: OpenVPN | Directories | Fix CRL Permissions
31 | file:
32 | path: "{{ item }}"
33 | state: file
34 | group: openvpn
35 | mode: g+r
36 | with_items:
37 | - "{{ openvpn_crl }}"
38 |
--------------------------------------------------------------------------------
/playbooks/roles/audit/vars/RedHat.yml:
--------------------------------------------------------------------------------
1 | ---
2 | audit_oscap_packages:
3 | - openscap-scanner
4 | - scap-security-guide
5 |
6 | oscap_policy_base: "/usr/share/xml/scap/ssg/content/"
7 |
8 | # Available profiles in ssg-centos7-ds.xml:
9 | # content_profile_standard
10 | # content_profile_pci-dss
11 | # content_profile_rht-ccp
12 | # content_profile_common
13 | # content_profile_stig-rhel7-server-upstream
14 |
15 | oscap_reports:
16 | - { name: stig,
17 | profile: xccdf_org.ssgproject.content_profile_stig-rhel7-server-upstream,
18 | policy: "{{ oscap_policy_base }}ssg-centos7-ds.xml",
19 | extra: "" }
20 | - { name: dss,
21 | profile: xccdf_org.ssgproject.content_profile_pci-dss,
22 | policy: "{{ oscap_policy_base }}ssg-centos7-ds.xml",
23 | extra: "" }
24 | # - { name: standard,
25 | # profile: xccdf_org.ssgproject.content_profile_standard,
26 | # policy: "{{ oscap_policy_base }}ssg-centos7-ds.xml",
27 | # extra: "" }
28 | - { name: rht-ccp,
29 | profile: xccdf_org.ssgproject.content_profile_rht-ccp,
30 | policy: "{{ oscap_policy_base }}ssg-centos7-ds.xml",
31 | extra: "" }
32 | # - { name: common,
33 | # profile: xccdf_org.ssgproject.content_profile_common,
34 | # policy: "{{ oscap_policy_base }}ssg-centos7-ds.xml",
35 | # extra: "" }
36 |
--------------------------------------------------------------------------------
/playbooks/roles/openvpn/handlers/main.yml:
--------------------------------------------------------------------------------
1 | ---
2 | - name: clear history
3 | shell: cat /dev/null > ~/.bash_history && history -c
4 | args:
5 | executable: /bin/bash
6 | changed_when: false
7 |
8 | - name: systemd tmpfiles
9 | shell: systemd-tmpfiles --remove --create
10 | changed_when: false
11 | tags:
12 | - skip_ansible_lint
13 |
14 | # TODO try to get Ubuntu docker container working
15 | - name: start openvpn
16 | service:
17 | name: "openvpn@{{ item.proto }}-{{ item.port }}.service"
18 | state: started
19 | with_items: "{{ openvpn_instances }}"
20 | when: (ansible_virtualization_type != "docker") or
21 | (ansible_virtualization_type == "docker" and ansible_distribution not in ['Ubuntu'])
22 |
23 | # TODO try to get Ubuntu docker container working
24 | - name: start dnsmasq
25 | service:
26 | name: dnsmasq
27 | state: started
28 | when: (ansible_virtualization_type != "docker") or
29 | (ansible_virtualization_type == "docker" and ansible_distribution not in ['Ubuntu'])
30 |
31 | - name: New Sudo User Creds
32 | local_action: template src=group_vars_openvpn-vpn.yml.j2 dest={{ playbook_dir }}/group_vars/openvpn-vpn.yml
33 | become: False
34 |
35 | - name: start auditd
36 | service:
37 | name: auditd
38 | state: started
39 | when: ansible_virtualization_type != "docker"
40 |
--------------------------------------------------------------------------------
/test/Dockerfile.centos-7:
--------------------------------------------------------------------------------
1 | FROM centos:centos7
2 | ENV container docker
3 |
4 | RUN yum -y update; yum clean all
5 |
6 | RUN yum -y swap -- remove systemd-container systemd-container-libs -- install systemd systemd-libs
7 |
8 | RUN systemctl mask dev-mqueue.mount dev-hugepages.mount \
9 | systemd-remount-fs.service sys-kernel-config.mount \
10 | sys-kernel-debug.mount sys-fs-fuse-connections.mount \
11 | display-manager.service graphical.target systemd-logind.service
12 |
13 | RUN yum -y install openssh-server sudo openssh-clients
14 | RUN ssh-keygen -q -f /etc/ssh/ssh_host_rsa_key -N '' -t rsa && \
15 | ssh-keygen -q -f /etc/ssh/ssh_host_ecdsa_key -N '' -t ecdsa && \
16 | ssh-keygen -q -f /etc/ssh/ssh_host_ed25519_key -N '' -t ed25519
17 |
18 | RUN useradd -m -G wheel -s /bin/bash docker
19 | RUN echo 'docker:password' | chpasswd
20 |
21 | RUN mkdir /home/docker/.ssh
22 | ADD test/id_rsa.pub /home/docker/.ssh/authorized_keys
23 | RUN chown -R docker:docker /home/docker/.ssh/
24 | RUN chmod 701 /home/docker
25 | RUN chmod 700 /home/docker/.ssh
26 | RUN chmod 600 /home/docker/.ssh/authorized_keys
27 |
28 | RUN bash -c 'echo "Defaults:docker !requiretty" | (EDITOR="tee -a" visudo)'
29 | RUN cat /etc/sudoers
30 |
31 | RUN systemctl enable sshd.service
32 |
33 | VOLUME [ "/sys/fs/cgroup" ]
34 | VOLUME ["/run"]
35 |
36 | EXPOSE 22
37 | EXPOSE 1194
38 |
39 | CMD ["/usr/sbin/init"]
40 |
--------------------------------------------------------------------------------
/playbooks/roles/add_clients/tasks/add_via_csr.yml:
--------------------------------------------------------------------------------
1 | ---
2 | # Vars
3 | # cn -
4 | # csr_path -
5 |
6 | # openssl genrsa -out ./test.key 2048
7 | # openssl req -new -sha256 -key test.key -out test.csr
8 | # openssl x509 -in CERTIFICATE_FILE -fingerprint -noout
9 |
10 | - name: OpenVPN | Add via CSR | Upload CSR
11 | copy:
12 | src: "{{ csr_path }}"
13 | dest: "{{ openvpn_path_reqs }}/{{ cn }}.req"
14 |
15 | - name: OpenVPN | Add via CSR | Sign CSR
16 | expect:
17 | command: ./easyrsa sign-req client {{ cn }}
18 | responses:
19 | 'Enter pass phrase for .*?:$': "{{ ca_password }}"
20 | chdir: "{{ openvpn_path_easyrsa }}"
21 | creates: "{{ openvpn_path_certs }}/{{ cn }}.crt"
22 |
23 | - name: OpenVPN | Add via CSR | Get client CA cert
24 | fetch:
25 | src: "{{ openvpn_ca_cert }}"
26 | dest: "{{ local_creds_folder }}/{{ cn }}/"
27 | flat: yes
28 |
29 | - name: OpenVPN | Add via CSR | Get client cert
30 | fetch:
31 | src: "{{ openvpn_path_certs }}/{{ cn }}.crt"
32 | dest: "{{ local_creds_folder }}/{{ cn }}/"
33 | flat: yes
34 |
35 | - name: OpenVPN | Add via CSR | Register HMAC firewall key contents
36 | command: cat {{ openvpn_hmac_firewall }}
37 | no_log: true
38 | register: openvpn_hmac_firewall_contents
39 | changed_when: false
40 |
41 | - name: OpenVPN | Add via CSR | Write OpenVPN client config
42 | template:
43 | src: client_common.ovpn.j2
44 | dest: "{{ local_creds_folder }}/{{ cn }}/{{ cn }}.ovpn"
45 | delegate_to: 127.0.0.1
46 |
--------------------------------------------------------------------------------
/test/Dockerfile.ubuntu-16.04:
--------------------------------------------------------------------------------
1 | FROM ubuntu:16.04
2 | ENV container docker
3 |
4 | RUN apt-get update; apt-get -y upgrade
5 |
6 | RUN DEBIAN_FRONTEND=noninteractive apt-get -q -y install systemd dbus openssh-server sudo openssh-client locales
7 |
8 | # Uncomment to speed up local tests by pre-installing most required packages
9 | #RUN DEBIAN_FRONTEND=noninteractive apt-get -q -y install aptitude iptables-persistent apt-transport-https ca-certificates python-software-properties unattended-upgrades debsums debsecan apt-listchanges libpam-pwquality aide-common
10 | #RUN DEBIAN_FRONTEND=noninteractive apt-get -q -y install sudo python-pip python-virtualenv git gnupg iptables aide openssl dnsmasq auditd
11 |
12 | RUN systemctl mask dev-mqueue.mount dev-hugepages.mount \
13 | sys-kernel-debug.mount sys-fs-fuse-connections.mount \
14 | display-manager.service graphical.target systemd-logind.service
15 |
16 | RUN useradd -m -G sudo -s /bin/bash docker
17 | RUN echo 'docker:password' | chpasswd
18 |
19 | RUN mkdir /home/docker/.ssh
20 | ADD test/id_rsa.pub /home/docker/.ssh/authorized_keys
21 | RUN chown -R docker:docker /home/docker/.ssh/
22 | RUN chmod 701 /home/docker
23 | RUN chmod 700 /home/docker/.ssh
24 | RUN chmod 600 /home/docker/.ssh/authorized_keys
25 |
26 | RUN systemctl enable ssh.service
27 |
28 | VOLUME [ "/sys/fs/cgroup" ]
29 | VOLUME ["/run"]
30 |
31 | EXPOSE 22
32 | EXPOSE 1194
33 |
34 | RUN locale-gen en_US.UTF-8
35 | ENV LANG en_US.UTF-8
36 | ENV LANGUAGE en_US:en
37 | ENV LC_ALL en_US.UTF-8
38 |
39 | CMD ["/bin/systemd"]
40 |
--------------------------------------------------------------------------------
/playbooks/roles/openvpn/files/50unattended-upgrades:
--------------------------------------------------------------------------------
1 | // Automatically upgrade packages from these (origin, archive) pairs
2 | Unattended-Upgrade::Allowed-Origins {
3 | // ${distro_id} and ${distro_codename} will be automatically expanded
4 | "${distro_id} stable";
5 | "${distro_id} ${distro_codename}-security";
6 |
7 | // Auto-update OpenVPN
8 | "Freight:${distro_codename}";
9 |
10 | // "${distro_id} ${distro_codename}-updates";
11 | // "${distro_id} ${distro_codename}-proposed-updates";
12 | };
13 |
14 | // List of packages to not update
15 | Unattended-Upgrade::Package-Blacklist {
16 | // "vim";
17 | // "libc6";
18 | // "libc6-dev";
19 | // "libc6-i686";
20 | };
21 |
22 | // Send email to this address for problems or packages upgrades
23 | // If empty or unset then no email is sent, make sure that you
24 | // have a working mail setup on your system. The package 'mailx'
25 | // must be installed or anything that provides /usr/bin/mail.
26 | //Unattended-Upgrade::Mail "root@localhost";
27 |
28 | // Do automatic removal of new unused dependencies after the upgrade
29 | // (equivalent to apt-get autoremove)
30 | Unattended-Upgrade::Remove-Unused-Dependencies "true";
31 |
32 | // Automatically reboot *WITHOUT CONFIRMATION* if a
33 | // the file /var/run/reboot-required is found after the upgrade
34 | Unattended-Upgrade::Automatic-Reboot "true";
35 |
36 | // If automatic reboot is enabled and needed, reboot at the specific
37 | // time instead of immediately
38 | // Default: "now"
39 | Unattended-Upgrade::Automatic-Reboot-Time "00:00";
40 |
--------------------------------------------------------------------------------
/playbooks/roles/openvpn/templates/etc_iptables_rules.v4.j2:
--------------------------------------------------------------------------------
1 | # Generated by ansible
2 | *filter
3 | # By default, drop incoming packets
4 | :INPUT DROP [0:0]
5 | :FORWARD ACCEPT [0:0]
6 | :OUTPUT ACCEPT [0:0]
7 | # Allow all incoming connections to loopback
8 | -A INPUT -i lo -j ACCEPT
9 | -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
10 | # Allow SSH connections on the VPN
11 | {% for instance in openvpn_instances %}
12 | -A INPUT -p tcp -d {{ instance.cidr }} --dport 22 -j ACCEPT
13 | {% endfor %}
14 |
15 | # Ansible ssh_on_vpn_only set to: {{ ssh_on_vpn_only }}
16 | # {% if ssh_on_vpn_only == true %}Uncomment to {% endif %}Allow SSH connections on the default interface
17 | {% if ssh_on_vpn_only == true %}#{% endif %}-A INPUT -p tcp -i {{ ansible_default_ipv4.interface }} --dport 22 -j ACCEPT
18 |
19 | # Allow VPN connections to dnsmasq
20 | {% for instance in openvpn_instances %}
21 | -A INPUT -p udp -d {{ instance.gateway }} --dport 53 -j ACCEPT
22 | {% endfor %}
23 | # Allow connections to the VPN
24 | {% for instance in openvpn_instances %}
25 | -A INPUT -p {{ instance.proto }} --dport {{ instance.port }} -j ACCEPT
26 | {% endfor %}
27 | -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT
28 | {% for instance in openvpn_instances %}
29 | -A FORWARD -s {{ instance.cidr }} -j ACCEPT
30 | {% endfor %}
31 | COMMIT
32 | *nat
33 | :PREROUTING ACCEPT [0:0]
34 | :POSTROUTING ACCEPT [0:0]
35 | :OUTPUT ACCEPT [0:0]
36 | {% for instance in openvpn_instances %}
37 | -A POSTROUTING -s {{ instance.cidr }} -o {{ ansible_default_ipv4.interface }} -j MASQUERADE
38 | {% endfor %}
39 | COMMIT
40 |
--------------------------------------------------------------------------------
/playbooks/roles/openvpn/vars/Debian.yml:
--------------------------------------------------------------------------------
1 | ---
2 |
3 | package_name_words: wamerican-huge
4 | package_name_auditd: auditd
5 |
6 | path_bin_ip: /bin/ip
7 | path_bin_aide: /usr/bin/aide
8 | path_persistent_iptables_rules: /etc/iptables/rules.v4
9 | path_dict: /usr/share/dict/american-english-huge
10 | path_pam_system_auth: /etc/pam.d/common-auth
11 | path_pam_password_auth: /etc/pam.d/common-password
12 | path_mac_config: /etc/apparmor/
13 | path_auditd_rules: /etc/audit/audit.rules
14 | path_aide_db: /var/lib/aide/aide.db
15 |
16 | sudo_group: sudo
17 | path_grub_cfg: /boot/grub/grub.cfg
18 | grub_mkconfig: grub-mkconfig
19 |
20 | umask_files:
21 | - { dest: "/etc/login.defs", regexp: "^UMASK", line: "UMASK\t\t077" }
22 | - { dest: "/etc/init.d/rc", regexp: "^umask", line: "umask 077" }
23 |
24 | deny_failed_login_auth_files:
25 | - "{{ path_pam_system_auth }}"
26 |
27 | deny_failed_login_account_files:
28 | - "/etc/pam.d/common-account"
29 |
30 |
31 | os_family_specific_pre:
32 | # Needed for ansible module apt: upgrade
33 | - aptitude
34 | # Make firewall rules persistent across reboots
35 | - iptables-persistent
36 | # Make sure https repos can be added (needed for OpenVPN repo)
37 | - apt-transport-https
38 | - ca-certificates
39 | # Required for the apt_repository module
40 | - python-software-properties
41 | # Used for automatically installing security updates
42 | - unattended-upgrades
43 | # File integrity
44 | - debsums
45 | - debsecan
46 | # Package management
47 | - apt-listchanges
48 | # Password policy
49 | - libpam-pwquality
50 | - aide-common
51 |
52 |
--------------------------------------------------------------------------------
/playbooks/roles/audit/tasks/openscap.yml:
--------------------------------------------------------------------------------
1 | ---
2 | - name: Audit | OpenSCAP | Install
3 | package:
4 | name: "{{ item }}"
5 | with_items: "{{ audit_oscap_packages }}"
6 |
7 | - name: Audit | OpenSCAP | Get SSGs from OpenSCAP github
8 | get_url:
9 | url: "{{ oscap_ssg_url }}"
10 | dest: "~/"
11 | when: ansible_os_family == "Debian"
12 |
13 | - name: Audit | OpenSCAP | Unarchive OpenSCAP SSGs
14 | unarchive:
15 | src: "~/{{ oscap_ssg_archive }}"
16 | dest: "{{ oscap_policy_parent }}"
17 | remote_src: True
18 | when: ansible_os_family == "Debian"
19 |
20 | - name: Audit | OpenSCAP | Run
21 | shell: >
22 | oscap xccdf eval
23 | --profile {{ item.profile }}
24 | --check-engine-results --oval-results
25 | --results ~/oscap_results_{{ item.name }}.xml
26 | --report ~/oscap_report_{{ item.name }}.html
27 | {{ item.extra }}
28 | {{ item.policy }}
29 | ignore_errors: true
30 | with_items: "{{ oscap_reports }}"
31 | register: openscap_results
32 | changed_when: false
33 | failed_when: false
34 | tags:
35 | - skip_ansible_lint
36 |
37 | - name: Audit | OpenSCAP | Check Run Results
38 | fail:
39 | msg: "Error occurred. See stdout:\n{{ item.stdout }}"
40 | no_log: True
41 | when: item.stdout.find('OpenSCAP Error') == 1
42 | with_items: "{{ openscap_results.results }}"
43 |
44 | - name: Audit | OpenSCAP | Make local destination
45 | local_action: file path="{{ local_creds_folder }}/" state=directory
46 | become: False
47 |
48 | - name: Audit | OpenSCAP | Get report
49 | fetch:
50 | src: "~/oscap_report_{{ item.name }}.html"
51 | dest: "{{ local_creds_folder }}/oscap_report_{{ item.name }}.html"
52 | flat: yes
53 | with_items: "{{ oscap_reports }}"
54 |
--------------------------------------------------------------------------------
/playbooks/roles/openvpn/tasks/harden_sysctl.yml:
--------------------------------------------------------------------------------
1 | ---
2 | - name: OpenVPN | Harden | sysctl configuration
3 | sysctl:
4 | name: "{{ item.name }}"
5 | value: "{{ item.value }}"
6 | with_items:
7 | - { name: 'net.ipv4.conf.all.send_redirects', value: 0 }
8 | - { name: 'net.ipv4.conf.default.send_redirects', value: 0 }
9 | - { name: 'net.ipv4.conf.all.accept_redirects', value: 0 }
10 | - { name: 'net.ipv4.conf.default.accept_redirects', value: 0 }
11 | - { name: 'net.ipv6.conf.all.accept_redirects', value: 0 }
12 | - { name: 'net.ipv6.conf.default.accept_redirects', value: 0 }
13 | - { name: 'net.ipv4.conf.all.secure_redirects', value: 0 }
14 | - { name: 'net.ipv4.conf.default.secure_redirects', value: 0 }
15 | - { name: 'net.ipv4.icmp_echo_ignore_all', value: 1 }
16 | - { name: 'net.ipv4.icmp_echo_ignore_broadcasts', value: 1 }
17 | - { name: 'net.ipv4.icmp_ignore_bogus_error_responses', value: 1 }
18 | - { name: 'net.ipv4.tcp_syncookies', value: 1 }
19 | - { name: 'net.ipv4.conf.all.rp_filter', value: 1 }
20 | - { name: 'net.ipv4.conf.default.rp_filter', value: 1 }
21 | - { name: 'kernel.core_uses_pid', value: 1 }
22 | - { name: 'kernel.sysrq', value: 0 }
23 | - { name: 'kernel.randomize_va_space', value: 2 }
24 | - { name: 'net.ipv4.conf.all.log_martians', value: 1 }
25 | - { name: 'net.ipv4.conf.default.log_martians', value: 1 }
26 | - { name: 'net.ipv4.conf.all.accept_source_route', value: 0 }
27 | - { name: 'net.ipv4.conf.default.accept_source_route', value: 0 }
28 | - { name: 'net.ipv4.tcp_timestamps', value: 0 }
29 | - { name: 'net.ipv6.conf.all.disable_ipv6', value: 1 }
30 | - { name: 'net.ipv6.conf.default.disable_ipv6', value: 1 }
31 | - { name: 'net.ipv6.conf.lo.disable_ipv6', value: 1 }
32 | - { name: 'net.ipv6.conf.default.accept_ra', value: 0 }
33 | - { name: 'fs.suid_dumpable', value: 0 }
34 |
--------------------------------------------------------------------------------
/playbooks/roles/openvpn/templates/etc_systemd_system_openvpn@.service.d_override.conf.j2:
--------------------------------------------------------------------------------
1 | [Unit]
2 | After=network.target systemd-tmpfiles-setup.service
3 | Before=dnsmasq.service
4 | # Need systemd-tmpfiles for /run/openvpn directory which contains PID and status files
5 | Wants=systemd-tmpfiles-setup.service
6 | Requires=network.target
7 |
8 | [Service]
9 | User=openvpn
10 | Group=openvpn
11 | # Only apply user and group to ExecStart. ExecStartPre/Post need root to manage devices
12 | PermissionsStartOnly=true
13 | ExecStartPre=/usr/sbin/openvpn --mktun --dev tun-%i --dev-type tun --user openvpn --group openvpn
14 | # Annoying race condition, openvpn doesn't create the pid file fast enough for
15 | # systemd. The sleep makes systemd wait before checking for the pid file
16 | ExecStartPost=/bin/sleep 0.1
17 | ExecStopPost=/usr/sbin/openvpn --rmtun --dev tun-%i
18 | {% if ansible_distribution in ['Ubuntu', 'Debian'] %}
19 | {#
20 | Clearing doesn't seem to be okay on Debian 8.5 (systemd 215) or CentOS 7.2 (systemd 219)
21 | But it's okay on Ubuntu 16.04 (systemd 229) and Debian 8.5 w/ backports (systemd 230)
22 | TODO Maybe key off of systemd version instead? custom 'set_fact' step on start?
23 | #}
24 | CapabilityBoundingSet=
25 | {% endif %}
26 | CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE
27 | ProtectSystem=full
28 | ProtectHome=true
29 | # Need access to /usr/sbin/openvpn and /bin/ip
30 | # Root directory; handle /bin, /usr, /var, /lib and /sbin separately
31 | InaccessibleDirectories=/boot /home /lost+found /media /mnt /opt /root /snap /srv /sys
32 | # Leave /usr/sbin accessible
33 | InaccessibleDirectories=/usr/bin /usr/games /usr/include /usr/local /usr/share /usr/src
34 | # Leave /var/run accessible
35 | InaccessibleDirectories=/var/backups /var/cache /var/lib /var/local /var/log /var/mail /var/opt /var/spool
36 | {% if ansible_distribution in ['Ubuntu'] and ansible_distribution_version in ['16.04'] %}
37 | {#
38 | These dirs only exist on ubuntu
39 | TODO Maybe build list of directories
40 | #}
41 | InaccessibleDirectories=/var/crash /var/snap
42 | {% endif %}
43 | ReadOnlyDirectories=/lib /lib64 /usr/lib
44 |
--------------------------------------------------------------------------------
/playbooks/roles/openvpn/defaults/main.yml:
--------------------------------------------------------------------------------
1 | ---
2 | ssh_on_vpn_only: true
3 |
4 | openvpn_key_country: "US"
5 | openvpn_key_province: "California"
6 | openvpn_key_city: "Beverly Hills"
7 | openvpn_key_org: "ACME CORPORATION"
8 | openvpn_key_ou: "Anvil Department"
9 | openvpn_key_email: "user@box.com"
10 | openvpn_clients:
11 | - laptop
12 | - phone
13 |
14 | openvpn_key_size: "2048"
15 | openvpn_cipher: "AES-256-CBC"
16 | openvpn_auth_digest: "SHA256"
17 | # For all available ciphers use: openvpn --show-tls
18 | # For all available PFS ciphers (without eliptic curve cryptography) use: openvpn --show-tls | grep -e "-DHE-"
19 | # Configuration here just uses PFS ciphers leveraging AES256 and at least SHA256
20 | openvpn_tls_cipher: "TLS-DHE-DSS-WITH-AES-256-GCM-SHA384:TLS-DHE-RSA-WITH-AES-256-GCM-SHA384:TLS-DHE-RSA-WITH-AES-256-CBC-SHA256:TLS-DHE-DSS-WITH-AES-256-CBC-SHA256"
21 |
22 | ## lock easyrsa git checkout to pull in openssl fix
23 | ## https://github.com/OpenVPN/easy-rsa/issues/132
24 | openvpn_easyrsa_version: a138c0d83b0ff1feed385c5d2d7a1c25422fe04d
25 |
26 | openvpn_instances:
27 | - {
28 | proto: udp,
29 | port: 1194,
30 | mask: "10.9.0.0 255.255.255.0",
31 | cidr: "10.9.0.0/24",
32 | gateway: "10.9.0.1",
33 | }
34 | # Uncomment below to listen on TCP 443. This will look like normal SSL/TLS traffic
35 | # and will be more likely to get through restrictive firewalls.
36 | # - {
37 | # proto: tcp,
38 | # port: 443,
39 | # mask: "10.8.0.0 255.255.255.0",
40 | # cidr: "10.8.0.0/24",
41 | # gateway: "10.8.0.1",
42 | # }
43 |
44 | dns_user: dns
45 | dns_group: dns
46 |
47 | upstream_dns_servers:
48 | - 8.8.8.8
49 | - 8.8.4.4
50 |
51 | openvpn_path: "/etc/openvpn"
52 | openvpn_path_pki: "{{ openvpn_path }}/pki"
53 | openvpn_path_keys: "{{ openvpn_path_pki }}/private"
54 | openvpn_path_certs: "{{ openvpn_path_pki }}/issued"
55 | openvpn_path_reqs: "{{ openvpn_path_pki }}/reqs"
56 | openvpn_hmac_firewall: "{{ openvpn_path_pki }}/ta.key"
57 | openvpn_ca_cert: "{{ openvpn_path_pki }}/ca.crt"
58 | openvpn_path_easyrsa: "{{ openvpn_path }}/easyrsa/easyrsa3"
59 | dhparams_size: "{{ openvpn_key_size }}"
60 | dhparams_location: "{{ openvpn_path_pki }}/dh.pem"
61 | openvpn_crl: "{{ openvpn_path_pki }}/crl.pem"
62 | openvpn_server_common_name_file: "{{ openvpn_path }}/openvpn_server_common_name"
63 |
64 | openvpn_server: "{{ inventory_hostname }}"
65 |
66 | local_creds_folder: "{{ playbook_dir }}/../fetched_creds/{{ openvpn_server }}"
67 |
68 | required_packages:
69 | - sudo
70 | # Required for ansible 'expect' module
71 | #- python-pexpect
72 | - python-pip
73 | - python-virtualenv
74 | # Required for easy-rsa install in PKI tasks and audit tasks
75 | - git
76 | # Used to verify GPG signatures for mirrored packages
77 | - gnupg
78 | # Used to configure firewall rules
79 | - iptables
80 | # Word List dictionary used by several roles to generate random data
81 | - "{{ package_name_words }}"
82 | - "{{ package_name_auditd }}"
83 | - aide
84 | - openssl
85 | - openvpn
86 | - dnsmasq
87 | - rsyslog
88 | - logrotate
89 |
90 | unwanted_packages:
91 | - bind9-host
92 | - libbind9-140
93 | - at
94 | - lxcfs
95 | - rpcbind
96 | - nfs-common
97 |
--------------------------------------------------------------------------------
/playbooks/roles/openvpn/tasks/harden_users.yml:
--------------------------------------------------------------------------------
1 | ---
2 | - name: OpenVPN | Harden | Set sudo user comment variable
3 | set_fact:
4 | sudo_user_comment: "ansible-openvpn-hardened sudo user"
5 |
6 | - name: OpenVPN | Harden | Check for existing user
7 | shell: "grep \"{{ sudo_user_comment }}\" /etc/passwd | awk -F: '{print $1}'"
8 | changed_when: false
9 | register: sudo_user_check
10 | failed_when: false
11 |
12 | - name: OpenVPN | Harden | Generate sudo username
13 | shell: grep -v -P "[\x80-\xFF]" {{ path_dict }} | sed -e "s/'//" | shuf -n 1 | xargs | sed -e 's/ /-/g'
14 | register: generated_sudo_username
15 | when: sudo_user_check.stdout == ""
16 |
17 | - name: OpenVPN | Harden | Set sudo username variable
18 | set_fact:
19 | sudo_username: "{{ sudo_user_check.stdout }}"
20 | when: sudo_user_check.stdout != ""
21 |
22 | - name: OpenVPN | Harden | Set sudo username variable
23 | set_fact:
24 | sudo_username: "{{ generated_sudo_username.stdout }}"
25 | when: sudo_user_check.stdout == ""
26 |
27 | # This is complicated to ensure the PAM password requirements set in harden_password.yml are met
28 | - name: OpenVPN | Harden | Generate sudo user password
29 | shell: echo "$(head /dev/urandom | tr -dc A-Z | head -c2)$(head /dev/urandom | tr -dc a-z | head -c2)$(head /dev/urandom | tr -dc 0-9 | head -c2)$(head /dev/urandom | tr -dc '@#$%^&*()' | head -c2)$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c8)"
30 | register: sudo_user_password
31 | changed_when: false
32 |
33 | - name: OpenVPN | Harden | Create {{ sudo_username }} group
34 | group:
35 | name: "{{ sudo_username }}"
36 |
37 | - name: OpenVPN | Harden | Create sudo user, '{{ sudo_username }}'
38 | user:
39 | name: "{{ sudo_username }}"
40 | password: "{{ sudo_user_password.stdout | password_hash('sha512') }}"
41 | update_password: on_create
42 | shell: "/bin/bash"
43 | groups: "{{ sudo_username }},{{ sudo_group }}"
44 | comment: "{{ sudo_user_comment }}"
45 | notify:
46 | - New Sudo User Creds
47 |
48 | # As recommended by https://help.ubuntu.com/lts/serverguide/user-management.html
49 | - name: OpenVPN | Harden | Remove world readable home directory permissions
50 | file:
51 | path: "/home/{{ sudo_username }}"
52 | state: directory
53 | mode: 0750
54 |
55 | - name: OpenVPN | Harden | Add or update authorized key
56 | action: authorized_key user={{ sudo_username }} key="{{ lookup('file', '~/.ssh/id_rsa.pub') }}"
57 |
58 | # Password setting used here is similar to running 'passwd -l root' which just
59 | # prefixes the hashed password in /etc/shadow with an '!', making it an invalid hash
60 | # The supplied password is expected to already be hashed and the supplied value is
61 | # put directly into /etc/shadow so the result is an /etc/shadow that looks like:
62 | # ...
63 | # root:!:...
64 | # ...
65 | # This both clears and disables any existing password for the root account.
66 | - name: OpenVPN | Harden | Disable root login
67 | user:
68 | name: root
69 | shell: /usr/sbin/nologin
70 | password: '!'
71 |
72 | # As recommended by LinEnum.
73 | - name: OpenVPN | Harden | Only root can read root's .bash_history
74 | file:
75 | path: /root/.bash_history
76 | mode: 0600
77 | state: touch
78 | changed_when: false
79 |
80 | - name: OpenVPN | Harden | Disable root tty access
81 | copy:
82 | content: ""
83 | dest: /etc/securetty
84 |
--------------------------------------------------------------------------------
/playbooks/roles/openvpn/tasks/harden_sshd.yml:
--------------------------------------------------------------------------------
1 | ---
2 | - name: OpenVPN | Harden | Set allowed SSH users
3 | set_fact:
4 | allowed_ssh_users: "{{ sudo_username }}"
5 | when: ssh_on_vpn_only == true
6 |
7 | - name: OpenVPN | Harden | Set allowed SSH users for test
8 | set_fact:
9 | allowed_ssh_users: "{{ sudo_username }} {{ ansible_env.SUDO_USER }}"
10 | when: ssh_on_vpn_only != true
11 | tags:
12 | - ci_test
13 |
14 | - name: OpenVPN | Harden | sshd configuration
15 | lineinfile:
16 | dest: /etc/ssh/sshd_config
17 | regexp: "{{ item.reg }}"
18 | line: "{{ item.line }}"
19 | state: present
20 | validate: '/usr/sbin/sshd -T -f %s'
21 | with_items:
22 | - { reg: '^(#)?PasswordAuthentication', line: 'PasswordAuthentication no'}
23 | # V-38613 - The ssh daemon must not permit root logins
24 | - { reg: '^(#)?PermitRootLogin', line: 'PermitRootLogin no'}
25 | - { reg: '^(#)?AllowTcpForwarding', line: 'AllowTcpForwarding no'}
26 | - { reg: '^(#)?Compression', line: 'Compression no'}
27 | - { reg: '^(#)?LogLevel', line: 'LogLevel VERBOSE'}
28 | - { reg: '^(#)?MaxAuthTries', line: 'MaxAuthTries 1'}
29 | - { reg: '^(#)?MaxSessions', line: 'MaxSessions 2'}
30 | - { reg: '^(#)?TCPKeepAlive', line: 'TCPKeepAlive no'}
31 | - { reg: '^(#)?UsePrivilegeSeparation', line: 'UsePrivilegeSeparation SANDBOX'}
32 | - { reg: '^(#)?X11Forwarding', line: 'X11Forwarding no'}
33 | - { reg: '^(#)?AllowUsers', line: 'AllowUsers {{ allowed_ssh_users }}'}
34 | # V-38607 - The SSH daemon must be configured to use only the SSHv2 protocol
35 | - { reg: '^(#)?PrintLastLog', line: 'PrintLastLog yes'}
36 | # V-38607 - The SSH daemon must be configured to use only the SSHv2 protocol
37 | - { reg: '^(#)?Protocol \d', line: 'Protocol 2'}
38 | # V-38614 - The SSH daemon must not allow authentication using an empty password
39 | - { reg: '^(#)?PermitEmptyPasswords', line: 'PermitEmptyPasswords no'}
40 | # V-38612 - The SSH daemon must not allow host-based authentication
41 | - { reg: '^(#)?HostbasedAuthentication', line: 'HostbasedAuthentication no'}
42 | # V-38608 - Set a timeout interval for idle ssh sessions
43 | - { reg: '^(#)?ClientAliveInterval', line: 'ClientAliveInterval 300'}
44 | # V-38610 - Set a timeout count on idle ssh sessions
45 | # OpenSCAP report - CCP profile suggested value of 0
46 | - { reg: '^(#)?ClientAliveCountMax', line: 'ClientAliveCountMax 0'}
47 | # V-38611 - The sshd daemon must ignore .rhosts files
48 | - { reg: '^(#)?IgnoreRhosts', line: 'IgnoreRhosts yes'}
49 | # V-38616 - The ssh daemon must not permit user environment settings
50 | - { reg: '^(#)?PermitUserEnvironment', line: 'PermitUserEnvironment no'}
51 | # V-38617 - The ssh daemon must be configured to use approved ciphers
52 | - { reg: '^(#)?Ciphers', line: 'Ciphers aes256-ctr,aes256-cbc'}
53 | # OpenSCAP report - CCP profile suggested referencing warning banner
54 | - { reg: '^(#)?Banner', line: 'Banner /etc/issue'}
55 | # Suggested by lynis audit
56 | - { reg: '^(#)?UseDNS', line: 'UseDNS no'}
57 | - { reg: '^(#)?AllowAgentForwarding', line: 'AllowAgentForwarding no'}
58 |
59 | - name: OpenVPN | Harden | Add VPN interfaces using 'ListenAddress' to /etc/ssh/sshd_config
60 | lineinfile:
61 | dest: /etc/ssh/sshd_config
62 | line: 'ListenAddress {{ item.gateway }}'
63 | with_items: "{{ openvpn_instances }}"
64 | when: ssh_on_vpn_only == true
65 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | ---
2 | language: python
3 |
4 | cache: pip
5 |
6 | sudo: required
7 |
8 | env:
9 | matrix:
10 | - distribution: centos
11 | version: 7
12 | init: /usr/lib/systemd/systemd
13 | run_opts: "'--detach --privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup'"
14 | ssh: sshd
15 | - distribution: ubuntu
16 | version: 16.04
17 | init: /sbin/init
18 | #--volume=\"/tmp/$(mktemp -d):/run\"
19 | run_opts: "'--detach --privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup'"
20 | ssh: ssh
21 | - distribution: debian
22 | version: 8.7
23 | init: /bin/systemd
24 | run_opts: "'--detach --privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup'"
25 | ssh: ssh
26 |
27 | services:
28 | - docker
29 |
30 | before_install:
31 | # Pull container
32 | - sudo docker pull ${distribution}:${version}
33 | - ssh-keygen -t rsa -f /home/travis/.ssh/id_rsa -q -N ""
34 | - cp /home/travis/.ssh/id_rsa.pub test/id_rsa.pub
35 | # Customize container
36 | - sudo docker build --rm=true --file=test/Dockerfile.${distribution}-${version} --tag=${distribution}-${version}:ansible .
37 | # Run container in detached state
38 | - sudo docker run ${run_opts} ${distribution}-${version}:ansible "${init}"
39 |
40 | install:
41 | - sudo -H pip install ansible ansible-lint
42 | - sudo apt-get -y install openssl
43 |
44 | script:
45 | - container_id=$(mktemp)
46 | - container_ip=$(mktemp)
47 |
48 | - sudo docker ps -q > "${container_id}"
49 |
50 | - sudo docker exec $(cat ${container_id}) /bin/systemctl status ${ssh}.service
51 |
52 | # Ansible syntax check.
53 | - ansible-lint playbooks/install.yml
54 | - ansible-lint playbooks/add_clients.yml
55 | - ansible-lint playbooks/revoke_client.yml
56 | - ansible-lint playbooks/audit.yml
57 |
58 | # Get the IP of the container and add it to the inventory
59 | - sudo docker inspect --format '{{ .NetworkSettings.IPAddress }}' $(cat ${container_id}) > "${container_ip}"
60 | - sed -i -e 's/172\.17\.0\.2/'"$(cat ${container_ip})"'/' test/docker-inventory
61 |
62 | # Verify ssh connection
63 | - ssh-keyscan -H $(cat ${container_ip}) >> ~/.ssh/known_hosts
64 | # - ssh -vvv docker@$(cat ${container_ip}) /bin/true
65 |
66 | # Test role.
67 | - ansible-playbook -i test/docker-inventory --diff playbooks/install.yml
68 |
69 | # Test role idempotence.
70 | - >
71 | ansible-playbook -i test/docker-inventory playbooks/install.yml
72 | | grep -q 'changed=0.*failed=0'
73 | && (echo 'Idempotence test: pass' && exit 0)
74 | || (echo 'Idempotence test: fail' && exit 1)
75 |
76 | # Test adding a client
77 | - ansible-playbook -i test/docker-inventory -e "cmd_hosts=openvpn-internet clients_to_add=cool_client" playbooks/add_clients.yml
78 |
79 | # Test removing a client
80 | - ansible-playbook -i test/docker-inventory -e "cmd_hosts=openvpn-internet client=cool_client" playbooks/revoke_client.yml
81 |
82 | # Test adding a client using a CSR
83 | - openssl genrsa -out ~/test.key 2048
84 | - openssl req -new -sha256 -key ~/test.key -out ~/test.csr -batch -subj "/CN=test@domain.com"
85 | - ansible-playbook -i test/docker-inventory -e "cmd_hosts=openvpn-internet csr_path=~/test.csr cn=test@domain.com" playbooks/add_clients.yml
86 |
87 | # Test audit
88 | - ansible-playbook -i test/docker-inventory -e "cmd_hosts=openvpn-internet" playbooks/audit.yml
89 |
90 | after_script:
91 | # Clean up
92 | - 'sudo docker stop "$(cat ${container_id})"'
93 |
--------------------------------------------------------------------------------
/playbooks/roles/openvpn/tasks/packages.yml:
--------------------------------------------------------------------------------
1 | ---
2 | - name: OpenVPN | package | Ensure the APT cache is up to date
3 | apt:
4 | update_cache: yes
5 | changed_when: False
6 | when: ansible_os_family == "Debian"
7 |
8 | - name: OpenVPN | package | Remove non-required packages
9 | package:
10 | name: "{{ item }}"
11 | state: absent
12 | with_items: "{{ unwanted_packages }}"
13 |
14 | - name: OpenVPN | package | Install {{ ansible_os_family }} specific packages
15 | package:
16 | name: "{{ item }}"
17 | with_items: "{{ os_family_specific_pre }}"
18 | register: install_specific_result
19 | until: install_specific_result | success
20 | retries: 5
21 | delay: 5
22 |
23 | - name: OpenVPN | package | Get official OpenVPN APT key
24 | # Work around for ansible issue https://github.com/ansible/ansible/issues/22647
25 | get_url:
26 | url: https://swupdate.openvpn.net/repos/repo-public.gpg
27 | dest: ~/openvpn.gpg
28 | when: ansible_os_family == "Debian"
29 |
30 | - name: OpenVPN | package | Add the official OpenVPN APT key
31 | # Work around for ansible issue https://github.com/ansible/ansible/issues/22647
32 | apt_key:
33 | file: ~/openvpn.gpg
34 | state: present
35 | when: ansible_os_family == "Debian"
36 |
37 | - name: OpenVPN | package | Reread ansible_lsb facts
38 | setup: filter=ansible_lsb*
39 |
40 | - name: OpenVPN | package | Add the official OpenVPN repository
41 | apt_repository:
42 | repo: 'deb https://build.openvpn.net/debian/openvpn/stable {{ ansible_lsb.codename }} main'
43 | state: present
44 | update_cache: yes
45 | when: ansible_os_family == "Debian"
46 |
47 | - name: OpenVPN | package | Add debian backports
48 | apt_repository:
49 | repo: 'deb http://ftp.debian.org/debian {{ ansible_lsb.codename }}-backports main'
50 | state: present
51 | update_cache: yes
52 | when: ansible_distribution in ['Debian']
53 |
54 | - name: OpenVPN | package | Upgrade systemd on debian
55 | apt:
56 | name: systemd
57 | state: latest
58 | default_release: "{{ ansible_lsb.codename }}-backports"
59 | when: ansible_distribution in ['Debian']
60 | tags:
61 | # Need latest, systemd v215 is really old and a pain to support alongside newer versions
62 | - skip_ansible_lint
63 |
64 | - name: OpenVPN | package | Install required packages
65 | package:
66 | name: "{{ item }}"
67 | with_items: "{{ required_packages }}"
68 | register: install_required_result
69 | until: install_required_result | success
70 | retries: 5
71 | delay: 5
72 | tags:
73 | - skip_ansible_lint
74 |
75 | - name: OpenVPN | package | apt - upgrade any out of date packages
76 | apt:
77 | upgrade: safe
78 | when: ansible_os_family == "Debian"
79 |
80 | - name: OpenVPN | package | yum - upgrade any out of date packages
81 | yum:
82 | name: '*'
83 | state: latest
84 | update_cache: yes
85 | when: ansible_os_family == "RedHat"
86 | tags:
87 | - skip_ansible_lint
88 |
89 | - name: OpenVPN | package | Copy the unattended-upgrades templates to enable automatic security updates
90 | copy:
91 | src: "{{ item.src }}"
92 | dest: "{{ item.dest }}"
93 | owner: root
94 | group: root
95 | mode: 0644
96 | with_items:
97 | - { src: "10periodic", dest: "/etc/apt/apt.conf.d" }
98 | - { src: "50unattended-upgrades", dest: "/etc/apt/apt.conf.d" }
99 | when: ansible_os_family == "Debian"
100 |
101 | - name: OpenVPN | package | Configure yum-cron
102 | lineinfile:
103 | regexp: "{{ item.regexp }}"
104 | line: "{{ item.line }}"
105 | dest: /etc/yum/yum-cron.conf
106 | state: present
107 | with_items:
108 | - {regexp: '^update_cmd\s*=\s*', line: "update_cmd = security"}
109 | - {regexp: '^apply_updates\s*=\s*', line: "apply_updates = yes"}
110 | when: ansible_os_family == "RedHat"
111 |
112 | - name: OpenVPN | package | Install pexpect via pip
113 | pip:
114 | name: "pexpect"
115 | version: "3.3"
116 |
--------------------------------------------------------------------------------
/playbooks/roles/openvpn/tasks/openvpn.yml:
--------------------------------------------------------------------------------
1 | ---
2 | - name: OpenVPN | sysctl | Enable IPv4 traffic forwarding
3 | sysctl:
4 | name: net.ipv4.ip_forward
5 | value: 1
6 |
7 | - name: OpenVPN | Configuration | Copy OpenVPN server configuration files into place
8 | template:
9 | src: etc_openvpn_server.conf.j2
10 | dest: "{{ openvpn_path }}/{{ item.proto }}-{{ item.port }}.conf"
11 | with_items: "{{ openvpn_instances }}"
12 | notify:
13 | - start openvpn
14 |
15 | # TODO make openvpn_user/group a variable referenced here and systemd (openvpn and tmpfiles conf)
16 | #Harden - Run as unprivileged user
17 | # See: https://community.openvpn.net/openvpn/wiki/UnprivilegedUser
18 | - name: OpenVPN | Users | Create openvpn group
19 | group:
20 | name: openvpn
21 |
22 | - name: OpenVPN | Users | Create openvpn user
23 | user:
24 | name: openvpn
25 | group: openvpn
26 | shell: /usr/sbin/nologin
27 | home: /var/lib/openvpn
28 |
29 | - name: OpenVPN | Directories | Set the proper permissions {{ openvpn_path }}
30 | file:
31 | path: "{{ openvpn_path }}"
32 | recurse: no
33 | state: directory
34 | owner: root
35 | group: openvpn
36 | mode: 0750
37 |
38 | - name: OpenVPN | Directories | Allow openvpn user access to pki files
39 | file:
40 | path: "{{ item }}"
41 | recurse: no
42 | state: directory
43 | group: openvpn
44 | mode: g+rx
45 | with_items:
46 | - "{{ openvpn_path }}/easyrsa"
47 | - "{{ openvpn_path }}/easyrsa/easyrsa3"
48 | - "{{ openvpn_path }}/easyrsa/easyrsa3/pki"
49 | - "{{ openvpn_path }}/easyrsa/easyrsa3/pki/private"
50 | - "{{ openvpn_path }}/easyrsa/easyrsa3/pki/issued"
51 |
52 | - name: OpenVPN | Directories | Allow openvpn user to read required PKI files
53 | file:
54 | path: "{{ item }}"
55 | state: file
56 | group: openvpn
57 | mode: g+r
58 | with_items:
59 | - "{{ openvpn_ca_cert }}"
60 | - "{{ dhparams_location }}"
61 | - "{{ openvpn_crl }}"
62 |
63 | - name: OpenVPN | Directories | Allow openvpn user to read required PKI files
64 | file:
65 | path: "{{ item }}"
66 | state: file
67 | owner: openvpn
68 | group: openvpn
69 | with_items:
70 | - "{{ path_server_cert }}"
71 | - "{{ path_server_key }}"
72 | - "{{ openvpn_hmac_firewall }}"
73 |
74 | - name: OpenVPN | setcap | Ensure only root and openvpn user can run 'ip' and 'openvpn'
75 | file:
76 | path: "{{ item }}"
77 | group: openvpn
78 | mode: 0750
79 | with_items:
80 | - "{{ path_bin_ip }}"
81 | - "/usr/sbin/openvpn"
82 |
83 | - name: OpenVPN | setcap | Set capabilities to allow /usr/sbin/openvpn to bind to reserved (0-1024) ports
84 | capabilities:
85 | path: /usr/sbin/openvpn
86 | capability: '{{ item }}'
87 | with_items:
88 | - "cap_net_admin+eip"
89 | - "cap_net_bind_service+eip"
90 |
91 | - name: OpenVPN | setcap | Set capabilities to allow "{{ path_bin_ip }}" perform network admin tasks
92 | capabilities:
93 | path: "{{ path_bin_ip }}"
94 | capability: 'cap_net_admin+eip'
95 |
96 | - name: OpenVPN | systemd | Make override directories
97 | file:
98 | path: "{{ item }}"
99 | state: directory
100 | with_items:
101 | - "/etc/systemd/system/openvpn@.service.d"
102 |
103 | - name: OpenVPN | systemd | Use override file to better sandbox OpenVPN and run as openvpn user
104 | template:
105 | src: etc_systemd_system_openvpn@.service.d_override.conf.j2
106 | dest: /etc/systemd/system/openvpn@.service.d/override.conf
107 | notify:
108 | - start openvpn
109 |
110 | - name: OpenVPN | systemd | Use systemd-tmpfiles to create /run/openvpn on startup
111 | template:
112 | src: etc_tmpfiles.d_openvpn.conf
113 | dest: /etc/tmpfiles.d/openvpn.conf
114 | notify:
115 | - systemd tmpfiles
116 |
117 | - name: OpenVPN | systemd | Enable services
118 | service:
119 | name: "openvpn@{{ item.proto }}-{{ item.port }}.service"
120 | enabled: true
121 | with_items: "{{ openvpn_instances }}"
122 | notify:
123 | - start openvpn
124 |
--------------------------------------------------------------------------------
/playbooks/roles/openvpn/tasks/harden_misc.yml:
--------------------------------------------------------------------------------
1 | ---
2 | - name: OpenVPN | Harden Misc | Disable core dumps for all users
3 | lineinfile:
4 | line: "* hard core 0"
5 | dest: /etc/security/limits.conf
6 | regexp: ^[\s]*\*[\s]+hard[\s]+core[\s]+([\d]+)
7 | state: present
8 |
9 | - name: OpenVPN | Harden Misc | Filter out links from path directories
10 | stat:
11 | path: "{{ item }}"
12 | register: path_dirs
13 | with_items: "{{ ansible_env['PATH'].split(':') }}"
14 |
15 | - name: OpenVPN | Harden Misc | No group or other writable permissions on path
16 | file:
17 | path: "{{ item.stat.path }}"
18 | mode: "go-w"
19 | state: directory
20 | when: "item.stat.exists == true and item.stat.islnk == false"
21 | with_items: "{{ path_dirs.results }}"
22 |
23 | - name: OpenVPN | Harden Misc | Add legal banner
24 | lineinfile:
25 | line: "Unauthorized access to this machine is prohibited."
26 | dest: "{{ item }}"
27 | state: present
28 | with_items:
29 | - /etc/issue
30 | - /etc/issue.net
31 |
32 | - name: OpenVPN | Harden Misc | Check for cloud-init.conf
33 | stat: path=/usr/lib/tmpfiles.d/cloud-init.conf
34 | register: tmpfiles_cloud
35 |
36 | # Found on CentOS 7.2 digital ocean image. Should be a nop if these don't exist
37 | - name: OpenVPN | Harden Misc | Shared Library Permissions
38 | file:
39 | path: "{{ item }}"
40 | mode: "go-w"
41 | state: file
42 | with_items:
43 | - "/usr/lib/tmpfiles.d/cloud-init.conf"
44 | - "/lib/tmpfiles.d/cloud-init.conf"
45 | when: tmpfiles_cloud.stat.exists
46 |
47 | # TODO check if this file is created elsewhere (/etc/crontab, /etc/cron.daily, etc)
48 | # Ubuntu/Debian creates a cron job in /etc/cron.daily
49 | - name: OpenVPN | Harden Misc | Periodic run of AIDE via cron @ 04:05:00
50 | copy:
51 | content: "05 4 * * * root {{ path_bin_aide }} --check"
52 | dest: /etc/cron.d/aide
53 | when: ansible_os_family == "RedHat"
54 |
55 | - name: OpenVPN | Harden Misc | Ensure AIDE is run via cron
56 | stat: path=/etc/cron.daily/aide
57 | register: aide_cron
58 | when: ansible_os_family == "Debian"
59 |
60 | - name: OpenVPN | Harden Misc | Check for AIDE cron job
61 | fail: msg="No daily cron job for running AIDE"
62 | when: ansible_os_family == "Debian" and aide_cron.stat.exists == false
63 |
64 | # Necessary for Azure, this line seems to be missing in the 16.04 image.
65 | # Absense of this line causes sudo to hang
66 | # Since using backrefs, if no match -> no change. This prevents adding {{ ansible_hostname }} everytime
67 | - name: OpenVPN | Harden Misc | Ensure hostname is in /etc/hosts
68 | lineinfile:
69 | dest: "/etc/hosts"
70 | regexp: (127\.0\.0\.1)\s+((?!.*\s*{{ ansible_hostname }}\s*.*).*)
71 | line: \1 \2 {{ ansible_hostname }}
72 | state: present
73 | backrefs: true
74 | when: ansible_virtualization_type != "docker"
75 |
76 | # Since using backrefs, if no match -> no change. This prevents adding audit=1 everytime
77 | - name: OpenVPN | Harden Misc | grub - Turn on auditing before auditd starts
78 | lineinfile:
79 | dest: "/etc/default/grub"
80 | regexp: (GRUB_CMDLINE_LINUX=)"((?!.*audit=1.*).*)"
81 | line: \1"\2 audit=1"
82 | state: present
83 | backrefs: true
84 | register: updated_grub_cfg
85 | when: ansible_virtualization_type != "docker"
86 |
87 | - name: OpenVPN | Harden Misc | grub - Regenerate grub.cfg
88 | shell: "{{ grub_mkconfig }} -o {{ path_grub_cfg }}"
89 | when: updated_grub_cfg.changed
90 | tags:
91 | - skip_ansible_lint
92 |
93 | - name: OpenVPN | Harden Misc | Grub permissions
94 | file:
95 | path: "{{ path_grub_cfg }}"
96 | mode: "0600"
97 | state: file
98 | when: ansible_virtualization_type != "docker"
99 |
100 | - name: OpenVPN | Harden Misc | Disable prelinking
101 | lineinfile:
102 | dest: "/etc/sysconfig/prelink"
103 | regexp: ^PRELINKING=
104 | line: PRELINKING=no
105 | state: present
106 | create: true
107 |
108 | - name: OpenVPN | Harden Misc | Restrict access to compilers
109 | file:
110 | path: "{{ item }}"
111 | mode: "go-rx"
112 | state: file
113 | follow: true
114 | with_items:
115 | - /usr/bin/as
116 |
--------------------------------------------------------------------------------
/playbooks/roles/openvpn/tasks/pki.yml:
--------------------------------------------------------------------------------
1 | ---
2 | - name: OpenVPN | PKI | EasyRSA Checkout
3 | git:
4 | repo: https://github.com/OpenVPN/easy-rsa.git
5 | accept_hostkey: True
6 | remote: github
7 | version: "{{ openvpn_easyrsa_version }}"
8 | dest: "{{ openvpn_path }}/easyrsa"
9 |
10 | - name: OpenVPN | PKI | Make local destination folder
11 | local_action: file path={{ local_creds_folder }}/ state=directory
12 | become: False
13 |
14 | - name: OpenVPN | PKI | Generate a random server common name
15 | shell: grep -v -P "[\x80-\xFF]" {{ path_dict }} | sed -e "s/'//" | shuf -n 2 | xargs | sed -e 's/ /./g' | cut -c 1-64 > {{ openvpn_server_common_name_file }}
16 | args:
17 | creates: "{{ openvpn_server_common_name_file }}"
18 |
19 | - name: OpenVPN | PKI | Register the OpenVPN server common name
20 | command: cat {{ openvpn_server_common_name_file }}
21 | register: openvpn_server_common_name_result
22 | changed_when: false
23 |
24 | - name: OpenVPN | PKI | Generate CA password
25 | shell: echo "$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c15)"
26 | no_log: true
27 | register: ca_password_result
28 | when: ca_password is not defined
29 |
30 | - name: OpenVPN | PKI | Store CA password
31 | local_action: template src=group_vars_all.yml.j2 dest={{ playbook_dir }}/group_vars/all.yml
32 | become: False
33 | when: ca_password is not defined
34 |
35 | - name: OpenVPN | PKI | Set CA password variable
36 | set_fact:
37 | ca_password: "{{ ca_password_result.stdout }}"
38 | when: ca_password is not defined
39 |
40 | - name: OpenVPN | PKI | Set common name variable
41 | set_fact:
42 | openvpn_server_common_name: "{{ openvpn_server_common_name_result.stdout }}"
43 |
44 | - name: OpenVPN | PKI | Set server key and cert path variables
45 | set_fact:
46 | path_server_key: "{{ openvpn_path_keys }}/server@{{ openvpn_server_common_name }}.key"
47 | path_server_cert: "{{ openvpn_path_certs }}/server@{{ openvpn_server_common_name }}.crt"
48 |
49 | - name: OpenVPN | PKI | EasyRSA Link project
50 | file:
51 | src: ./easyrsa/easyrsa3/pki
52 | dest: "{{ openvpn_path_pki }}"
53 | owner: root
54 | group: root
55 | force: yes
56 | state: link
57 |
58 | - name: OpenVPN | PKI | Deploy vars configuration
59 | template:
60 | src: etc_openvpn_easyrsa_easyrsa3_vars.j2
61 | dest: "{{ openvpn_path_easyrsa }}/vars"
62 | owner: root
63 | group: root
64 | mode: 0600
65 |
66 | - name: OpenVPN | PKI | Intialize PKI
67 | shell: echo 'yes' | ./easyrsa init-pki
68 | args:
69 | chdir: "{{ openvpn_path_easyrsa }}"
70 | creates: "{{ openvpn_path_keys }}"
71 |
72 | - name: OpenVPN | PKI | Build CA
73 | expect:
74 | command: ./easyrsa build-ca --req-cn ca@{{ openvpn_server_common_name }}
75 | responses:
76 | 'Enter PEM pass phrase:$': "{{ ca_password }}"
77 | 'Verifying - Enter PEM pass phrase:$': "{{ ca_password }}"
78 | chdir: "{{ openvpn_path_easyrsa }}"
79 | creates: "{{ openvpn_path_easyrsa }}/pki/private/ca.key"
80 |
81 | - name: OpenVPN | PKI | Build CRL
82 | expect:
83 | command: ./easyrsa gen-crl
84 | responses:
85 | 'Enter pass phrase for .*?:$': "{{ ca_password }}"
86 | chdir: "{{ openvpn_path_easyrsa }}"
87 | creates: "{{ openvpn_crl }}"
88 |
89 | - name: OpenVPN | PKI | Add server
90 | expect:
91 | command: ./easyrsa build-server-full server@{{ openvpn_server_common_name }} nopass --req-cn server@{{ openvpn_server_common_name }}
92 | responses:
93 | 'Enter pass phrase for .*?:$': "{{ ca_password }}"
94 | chdir: "{{ openvpn_path_easyrsa }}"
95 | creates: "{{ path_server_key }}"
96 |
97 | - name: OpenVPN | PKI | Build ta.key
98 | shell: openvpn --genkey --secret ta.key
99 | args:
100 | chdir: "{{ openvpn_path_easyrsa }}/pki"
101 | creates: "{{ openvpn_hmac_firewall }}"
102 | tags:
103 | - skip_ansible_lint
104 |
105 | - name: OpenVPN | PKI | Build dh.pem
106 | shell: ./easyrsa gen-dh
107 | args:
108 | chdir: "{{ openvpn_path_easyrsa }}"
109 | creates: "{{ dhparams_location }}"
110 | tags:
111 | - skip_ansible_lint
112 |
113 | - name: OpenVPN | Add Clients | Get CA cert
114 | fetch:
115 | src: "{{ openvpn_ca_cert }}"
116 | dest: "{{ local_creds_folder }}/ca@{{openvpn_server_common_name}}.crt"
117 | flat: yes
118 |
--------------------------------------------------------------------------------
/playbooks/roles/openvpn/tasks/harden_password.yml:
--------------------------------------------------------------------------------
1 | ---
2 | - name: OpenVPN | Harden Password | Set minimum password length
3 | set_fact:
4 | password_min_length: 15
5 |
6 | - name: OpenVPN | Harden | Disable login with empty passwords
7 | replace:
8 | regexp: 'nullok_secure'
9 | replace: ''
10 | dest: "{{ path_pam_system_auth }}"
11 |
12 | - name: OpenVPN | Harden | Disable login with empty passwords
13 | replace:
14 | regexp: 'nullok'
15 | replace: ''
16 | dest: "{{ path_pam_system_auth }}"
17 |
18 | - name: OpenVPN | Harden Password | Configure pwquality.conf
19 | lineinfile:
20 | dest: /etc/security/pwquality.conf
21 | regexp: "{{ item.reg }}"
22 | line: "{{ item.line }}"
23 | state: present
24 | with_items:
25 | - {reg: '^dcredit[\s]*=[\s]*(-?\d+)(?:[\s]|$)', line: 'dcredit = -1'}
26 | - {reg: '^minlen[\s]*=[\s]*(-?\d+)(?:[\s]|$)', line: 'minlen = {{ password_min_length }}'}
27 | - {reg: '^ucredit[s\]*=[\s]*(-?\d+)(?:[\s]|$)', line: 'ucredit = -2'}
28 | - {reg: '^ocredit[\s]*=[\s]*(-?\d+)(?:[\s]|$)', line: 'ocredit = -2'}
29 | - {reg: '^lcredit[\s]*=[\s]*(-?\d+)(?:[\s]|$)', line: 'lcredit = -2'}
30 | - {reg: '^difok[\s]*=[\s]*(\d+)(?:[\s]|$)', line: 'difok = 15'}
31 |
32 | - name: OpenVPN | Harden Password | Set minimum password length in login.defs
33 | lineinfile:
34 | dest: /etc/login.defs
35 | regexp: ^PASS_MIN_LEN\s+
36 | line: "PASS_MIN_LEN {{ password_min_length }}"
37 | state: present
38 |
39 | - name: OpenVPN | Harden Password | Set hashing algorithm to SHA512
40 | lineinfile:
41 | dest: "{{ path_pam_password_auth }}"
42 | regexp: (^\s*password\s+(?:(?:sufficient)|(?:required)|(?:\[.*\]))\s+pam_unix\.so)\s+(.*)(md5|bigcrypt|sha256|blowfish)(.*)
43 | line: \1 \2 sha512 \4
44 | state: present
45 | backrefs: true
46 |
47 | - name: OpenVPN | Harden Password | Set hashing algorithm to SHA512
48 | lineinfile:
49 | dest: /etc/login.defs
50 | regexp: ^ENCRYPT_METHOD\s+
51 | line: ENCRYPT_METHOD SHA512
52 | state: present
53 |
54 | - name: OpenVPN | Harden Password | Check for libuser.conf
55 | stat:
56 | path: /etc/libuser.conf
57 | register: libuser_conf
58 |
59 | - name: OpenVPN | Harden Password | Set hashing algorithm to SHA512
60 | lineinfile:
61 | dest: /etc/libuser.conf
62 | regexp: ^crypt_style\s*=
63 | line: crypt_style = sha512
64 | state: present
65 | when: libuser_conf.stat.exists
66 |
67 | # - name: OpenVPN | Harden Password | Limit password reuse
68 | # lineinfile:
69 | # dest: "{{ path_pam_password_auth }}"
70 | # regexp: (^\s*password\s+(?:(?:sufficient)|(?:required)|(?:\[.*\]))\s+pam_unix\.so)\s+((?!.*\s+remember=5\s*.*).*)
71 | # line: \1 \2 remember=5
72 | # state: present
73 | # backrefs: true
74 | #
75 | # - name: OpenVPN | Harden Password | Set max/min password age
76 | # lineinfile:
77 | # dest: /etc/login.defs
78 | # regexp: "{{ item.reg }}"
79 | # line: "{{ item.line }}"
80 | # state: present
81 | # with_items:
82 | # - {reg: '^PASS_MIN_DAYS[\s]*', line: 'PASS_MIN_DAYS 1'}
83 | # - {reg: '^PASS_MAX_DAYS[\s]*', line: 'PASS_MAX_DAYS 60'}
84 | #
85 | # - name: OpenVPN | Harden Password | Set deny for failed password attempts
86 | # lineinfile:
87 | # dest: "{{ item }}"
88 | # line: 'auth [default=die] pam_faillock.so authfail deny=3 unlock_time=604800 fail_interval=900'
89 | # insertafter: '^auth[\s]+(?:(?:sufficient)|(?:required)|(?:\[.*\]))\s+pam_unix.so'
90 | # state: present
91 | # with_items: "{{ deny_failed_login_auth_files }}"
92 | #
93 | # - name: OpenVPN | Harden Password | Set deny for failed password attempts
94 | # lineinfile:
95 | # dest: "{{ item }}"
96 | # line: 'auth required pam_faillock.so preauth silent deny=3 unlock_time=604800 fail_interval=900'
97 | # insertbefore: '^auth[\s]+(?:(?:sufficient)|(?:required)|(?:\[.*\]))\s+pam_unix.so'
98 | # state: present
99 | # with_items: "{{ deny_failed_login_auth_files }}"
100 | #
101 | # - name: OpenVPN | Harden Password | Set deny for failed password attempts
102 | # lineinfile:
103 | # dest: "{{ item }}"
104 | # line: 'account required pam_faillock.so'
105 | # insertbefore: '^account[\s]+(?:(?:sufficient)|(?:required)|(?:\[.*\]))\s+pam_unix.so'
106 | # state: present
107 | # with_items: "{{ deny_failed_login_account_files }}"
108 |
--------------------------------------------------------------------------------
/playbooks/roles/add_clients/tasks/add_gen_key.yml:
--------------------------------------------------------------------------------
1 | ---
2 | - name: OpenVPN | Add Clients | Check for existing private key passwords
3 | local_action: stat path={{ local_creds_folder }}/{{ item }}/{{ openvpn_server_common_name }}_pk_pass.txt
4 | become: False
5 | register: client_pk_passwords_local
6 | with_items:
7 | - "{{ clients_to_add }}"
8 |
9 | - name: OpenVPN | Add Clients | Generate private key passwords
10 | shell: echo "$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c15)"
11 | no_log: true
12 | register: client_pk_passwords
13 | with_items: "{{ clients_to_add }}"
14 | when: "client_pk_passwords_local.results[0].stat.exists == False"
15 |
16 | - name: OpenVPN | Add Clients | Make local destination
17 | local_action: file path="{{ local_creds_folder }}/{{ item }}/" state=directory
18 | become: False
19 | with_items:
20 | - "{{ clients_to_add }}"
21 |
22 | - name: OpenVPN | Add Clients | Write private key pass phrases
23 | local_action: copy content={{ item[1].stdout }} dest={{ local_creds_folder }}/{{ item[0] }}/{{ openvpn_server_common_name }}_pk_pass.txt
24 | no_log: true
25 | become: False
26 | with_together:
27 | - "{{ clients_to_add }}"
28 | - "{{ client_pk_passwords.results }}"
29 | when: "client_pk_passwords_local.results[0].stat.exists == False"
30 |
31 | - name: OpenVPN | Add Clients | Read private key pass phrases
32 | local_action: command cat {{ local_creds_folder }}/{{ item }}/{{ openvpn_server_common_name }}_pk_pass.txt
33 | no_log: true
34 | become: False
35 | register: client_pk_passwords
36 | with_items: "{{ clients_to_add }}"
37 | changed_when: false
38 |
39 | - name: OpenVPN | Add Clients | Build Clients
40 | expect:
41 | command: ./easyrsa build-client-full {{ item[0] }}@{{ openvpn_server_common_name }} --req-cn {{ item[0] }}@{{ openvpn_server_common_name }}
42 | responses:
43 | 'Enter PEM pass phrase:$': "{{ item[1].stdout }}"
44 | 'Verifying - Enter PEM pass phrase:$': "{{ item[1].stdout }}"
45 | 'Enter pass phrase for .*?:$': "{{ ca_password }}"
46 | chdir: "{{ openvpn_path_easyrsa }}"
47 | creates: "{{ openvpn_path_keys }}/{{ item[0] }}@{{ openvpn_server_common_name }}.key"
48 | no_log: true
49 | with_together:
50 | - "{{ clients_to_add }}"
51 | - "{{ client_pk_passwords.results }}"
52 |
53 | - name: OpenVPN | Add Clients | Make client configuration directory
54 | file:
55 | path: "{{ openvpn_path_pki }}/ovpn"
56 | mode: 0700
57 | state: directory
58 |
59 | - name: OpenVPN | Add Clients | Register CA certificate contents
60 | command: cat {{ openvpn_ca_cert }}
61 | no_log: true
62 | register: openvpn_ca_contents
63 | changed_when: false
64 |
65 | - name: OpenVPN | Add Clients | Register HMAC firewall key contents
66 | command: cat {{ openvpn_hmac_firewall }}
67 | no_log: true
68 | register: openvpn_hmac_firewall_contents
69 | changed_when: false
70 |
71 | - name: OpenVPN | Add Clients | Register client key contents
72 | command: cat {{ openvpn_path_keys }}/{{ item }}@{{ openvpn_server_common_name }}.key
73 | with_items: "{{ clients_to_add }}"
74 | no_log: true
75 | register: openvpn_client_keys
76 | changed_when: false
77 |
78 | - name: OpenVPN | Add Clients | Register client certificate contents
79 | command: cat {{ openvpn_path_certs }}/{{ item }}@{{ openvpn_server_common_name }}.crt
80 | with_items: "{{ clients_to_add }}"
81 | no_log: true
82 | register: openvpn_client_certs
83 | changed_when: false
84 |
85 | - name: OpenVPN | Add Clients | Build client configs (.ovpn files; pki embedded)
86 | template:
87 | src: client_pki_embedded.ovpn.j2
88 | dest: "{{ openvpn_path_pki }}/ovpn/{{ item[0] }}@{{ openvpn_server_common_name }}-pki-embedded.ovpn"
89 | mode: 0400
90 | no_log: true
91 | with_together:
92 | - "{{ clients_to_add }}"
93 | - "{{ openvpn_client_certs.results }}"
94 | - "{{ openvpn_client_keys.results }}"
95 |
96 | - name: OpenVPN | Add Clients | Build client configs (.ovpn files; pki external files)
97 | template:
98 | src: client_pki_files.ovpn.j2
99 | dest: "{{ openvpn_path_pki }}/ovpn/{{ item }}@{{ openvpn_server_common_name }}-pki-files.ovpn"
100 | mode: 0400
101 | no_log: true
102 | with_items:
103 | - "{{ clients_to_add }}"
104 |
105 | - name: OpenVPN | Add Clients | Build client configs (.ovpn files; external pkcs12)
106 | template:
107 | src: client_pkcs12.ovpn.j2
108 | dest: "{{ openvpn_path_pki }}/ovpn/{{ item }}@{{ openvpn_server_common_name }}-pkcs12.ovpn"
109 | mode: 0400
110 | no_log: true
111 | with_items:
112 | - "{{ clients_to_add }}"
113 |
114 | - name: OpenVPN | Add Clients | Generate PKCS#12
115 | shell: >
116 | openssl pkcs12 -export
117 | -in {{ openvpn_path_certs }}/{{ item[0] }}@{{ openvpn_server_common_name }}.crt
118 | -inkey {{ openvpn_path_keys }}/{{ item[0] }}@{{ openvpn_server_common_name }}.key
119 | -certfile {{ openvpn_ca_cert }}
120 | -name {{ item[0] }}
121 | -out {{ openvpn_path_pki }}/ovpn/{{ item[0] }}@{{ openvpn_server_common_name }}.p12
122 | -passin pass:{{ item[1].stdout }}
123 | -passout pass:{{ item[1].stdout }}
124 | args:
125 | creates: "{{ openvpn_path_pki }}/ovpn/{{ item[0] }}@{{ openvpn_server_common_name }}.p12"
126 | no_log: true
127 | with_together:
128 | - "{{ clients_to_add }}"
129 | - "{{ client_pk_passwords.results }}"
130 | tags:
131 | - skip_ansible_lint
132 |
133 | - name: OpenVPN | Add Clients | Get .ovpn files (*-pki-embedded.ovpn)
134 | fetch:
135 | src: "{{ openvpn_path_pki }}/ovpn/{{ item }}@{{ openvpn_server_common_name }}-pki-embedded.ovpn"
136 | dest: "{{ local_creds_folder }}/{{ item }}/"
137 | flat: yes
138 | with_items:
139 | - "{{ clients_to_add }}"
140 |
141 | - name: OpenVPN | Add Clients | Get .ovpn files (*-pki-files.ovpn)
142 | fetch:
143 | src: "{{ openvpn_path_pki }}/ovpn/{{ item }}@{{ openvpn_server_common_name }}-pki-files.ovpn"
144 | dest: "{{ local_creds_folder }}/{{ item }}/"
145 | flat: yes
146 | with_items:
147 | - "{{ clients_to_add }}"
148 |
149 | - name: OpenVPN | Add Clients | Get .ovpn files (*-pkcs12.ovpn)
150 | fetch:
151 | src: "{{ openvpn_path_pki }}/ovpn/{{ item }}@{{ openvpn_server_common_name }}-pkcs12.ovpn"
152 | dest: "{{ local_creds_folder }}/{{ item }}/"
153 | flat: yes
154 | with_items:
155 | - "{{ clients_to_add }}"
156 |
157 | - name: OpenVPN | Add Clients | Get client PKCS#12 files
158 | fetch:
159 | src: "{{ openvpn_path_pki }}/ovpn/{{ item }}@{{ openvpn_server_common_name }}.p12"
160 | dest: "{{ local_creds_folder }}/{{ item }}/"
161 | flat: yes
162 | with_items:
163 | - "{{ clients_to_add }}"
164 |
165 | - name: OpenVPN | Add Clients | Get client CA cert
166 | fetch:
167 | src: "{{ openvpn_ca_cert }}"
168 | dest: "{{ local_creds_folder }}/{{ item }}/"
169 | flat: yes
170 | with_items:
171 | - "{{ clients_to_add }}"
172 |
173 | - name: OpenVPN | Add Clients | Get client certs
174 | fetch:
175 | src: "{{ openvpn_path_certs }}/{{ item }}@{{ openvpn_server_common_name }}.crt"
176 | dest: "{{ local_creds_folder }}/{{ item }}/"
177 | flat: yes
178 | with_items:
179 | - "{{ clients_to_add }}"
180 |
181 | - name: OpenVPN | Add Clients | Get client keys
182 | fetch:
183 | src: "{{ openvpn_path_keys }}/{{ item }}@{{ openvpn_server_common_name }}.key"
184 | dest: "{{ local_creds_folder }}/{{ item }}/"
185 | flat: yes
186 | with_items:
187 | - "{{ clients_to_add }}"
188 |
189 | - name: OpenVPN | Add Clients | Clear bash history
190 | shell: cat /dev/null > ~/.bash_history && history -c
191 | args:
192 | executable: /bin/bash
193 | ignore_errors: true
194 | changed_when: false
195 |
--------------------------------------------------------------------------------
/playbooks/roles/openvpn/templates/etc_openvpn_easyrsa_easyrsa3_vars.j2:
--------------------------------------------------------------------------------
1 | # Easy-RSA 3 parameter settings
2 |
3 | # NOTE: If you installed Easy-RSA from your distro's package manager, don't edit
4 | # this file in place -- instead, you should copy the entire easy-rsa directory
5 | # to another location so future upgrades don't wipe out your changes.
6 |
7 | # HOW TO USE THIS FILE
8 | #
9 | # vars.example contains built-in examples to Easy-RSA settings. You MUST name
10 | # this file 'vars' if you want it to be used as a configuration file. If you do
11 | # not, it WILL NOT be automatically read when you call easyrsa commands.
12 | #
13 | # It is not necessary to use this config file unless you wish to change
14 | # operational defaults. These defaults should be fine for many uses without the
15 | # need to copy and edit the 'vars' file.
16 | #
17 | # All of the editable settings are shown commented and start with the command
18 | # 'set_var' -- this means any set_var command that is uncommented has been
19 | # modified by the user. If you're happy with a default, there is no need to
20 | # define the value to its default.
21 |
22 | # NOTES FOR WINDOWS USERS
23 | #
24 | # Paths for Windows *MUST* use forward slashes, or optionally double-esscaped
25 | # backslashes (single forward slashes are recommended.) This means your path to
26 | # the openssl binary might look like this:
27 | # "C:/Program Files/OpenSSL-Win32/bin/openssl.exe"
28 |
29 | # A little housekeeping: DON'T EDIT THIS SECTION
30 | #
31 | # Easy-RSA 3.x doesn't source into the environment directly.
32 | # Complain if a user tries to do this:
33 | if [ -z "$EASYRSA_CALLER" ]; then
34 | echo "You appear to be sourcing an Easy-RSA 'vars' file." >&2
35 | echo "This is no longer necessary and is disallowed. See the section called" >&2
36 | echo "'How to use this file' near the top comments for more details." >&2
37 | return 1
38 | fi
39 |
40 | # DO YOUR EDITS BELOW THIS POINT
41 |
42 | # This variable should point to the top level of the easy-rsa tree. By default,
43 | # this is taken to be the directory you are currently in.
44 |
45 | #set_var EASYRSA "$PWD"
46 |
47 | # If your OpenSSL command is not in the system PATH, you will need to define the
48 | # path to it here. Normally this means a full path to the executable, otherwise
49 | # you could have left it undefined here and the shown default would be used.
50 | #
51 | # Windows users, remember to use paths with forward-slashes (or escaped
52 | # back-slashes.) Windows users should declare the full path to the openssl
53 | # binary here if it is not in their system PATH.
54 |
55 | #set_var EASYRSA_OPENSSL "openssl"
56 | #
57 | # This sample is in Windows syntax -- edit it for your path if not using PATH:
58 | #set_var EASYRSA_OPENSSL "C:/Program Files/OpenSSL-Win32/bin/openssl.exe"
59 |
60 | # Edit this variable to point to your soon-to-be-created key directory.
61 | #
62 | # WARNING: init-pki will do a rm -rf on this directory so make sure you define
63 | # it correctly! (Interactive mode will prompt before acting.)
64 |
65 | #set_var EASYRSA_PKI "$EASYRSA/pki"
66 |
67 | # Define X509 DN mode.
68 | # This is used to adjust what elements are included in the Subject field as the DN
69 | # (this is the "Distinguished Name.")
70 | # Note that in cn_only mode the Organizational fields further below aren't used.
71 | #
72 | # Choices are:
73 | # cn_only - use just a CN value
74 | # org - use the "traditional" Country/Province/City/Org/OU/email/CN format
75 |
76 | set_var EASYRSA_DN "org"
77 |
78 | # Organizational fields (used with 'org' mode and ignored in 'cn_only' mode.)
79 | # These are the default values for fields which will be placed in the
80 | # certificate. Don't leave any of these fields blank, although interactively
81 | # you may omit any specific field by typing the "." symbol (not valid for
82 | # email.)
83 |
84 | set_var EASYRSA_REQ_COUNTRY "{{ openvpn_key_country }}"
85 | set_var EASYRSA_REQ_PROVINCE "{{ openvpn_key_province }}"
86 | set_var EASYRSA_REQ_CITY "{{ openvpn_key_city }}"
87 | set_var EASYRSA_REQ_ORG "{{ openvpn_key_org }}"
88 | set_var EASYRSA_REQ_EMAIL "{{ openvpn_key_email }}"
89 | set_var EASYRSA_REQ_OU "{{ openvpn_key_ou }}"
90 |
91 | # Choose a size in bits for your keypairs. The recommended value is 2048. Using
92 | # 2048-bit keys is considered more than sufficient for many years into the
93 | # future. Larger keysizes will slow down TLS negotiation and make key/DH param
94 | # generation take much longer. Values up to 4096 should be accepted by most
95 | # software. Only used when the crypto alg is rsa (see below.)
96 |
97 | set_var EASYRSA_KEY_SIZE {{ dhparams_size }}
98 |
99 | # The default crypto mode is rsa; ec can enable elliptic curve support.
100 | # Note that not all software supports ECC, so use care when enabling it.
101 | # Choices for crypto alg are: (each in lower-case)
102 | # * rsa
103 | # * ec
104 |
105 | #set_var EASYRSA_ALGO rsa
106 |
107 | # Define the named curve, used in ec mode only:
108 |
109 | #set_var EASYRSA_CURVE secp384r1
110 |
111 | # In how many days should the root CA key expire?
112 |
113 | #set_var EASYRSA_CA_EXPIRE 3650
114 |
115 | # In how many days should certificates expire?
116 |
117 | #set_var EASYRSA_CERT_EXPIRE 3650
118 |
119 | # How many days until the next CRL publish date? Note that the CRL can still be
120 | # parsed after this timeframe passes. It is only used for an expected next
121 | # publication date.
122 |
123 | #set_var EASYRSA_CRL_DAYS 180
124 |
125 | # Support deprecated "Netscape" extensions? (choices "yes" or "no".) The default
126 | # is "no" to discourage use of deprecated extensions. If you require this
127 | # feature to use with --ns-cert-type, set this to "yes" here. This support
128 | # should be replaced with the more modern --remote-cert-tls feature. If you do
129 | # not use --ns-cert-type in your configs, it is safe (and recommended) to leave
130 | # this defined to "no". When set to "yes", server-signed certs get the
131 | # nsCertType=server attribute, and also get any NS_COMMENT defined below in the
132 | # nsComment field.
133 |
134 | #set_var EASYRSA_NS_SUPPORT "no"
135 |
136 | # When NS_SUPPORT is set to "yes", this field is added as the nsComment field.
137 | # Set this blank to omit it. With NS_SUPPORT set to "no" this field is ignored.
138 |
139 | #set_var EASYRSA_NS_COMMENT "Easy-RSA Generated Certificate"
140 |
141 | # A temp file used to stage cert extensions during signing. The default should
142 | # be fine for most users; however, some users might want an alternative under a
143 | # RAM-based FS, such as /dev/shm or /tmp on some systems.
144 |
145 | #set_var EASYRSA_TEMP_FILE "$EASYRSA_PKI/extensions.temp"
146 |
147 | # !!
148 | # NOTE: ADVANCED OPTIONS BELOW THIS POINT
149 | # PLAY WITH THEM AT YOUR OWN RISK
150 | # !!
151 |
152 | # Broken shell command aliases: If you have a largely broken shell that is
153 | # missing any of these POSIX-required commands used by Easy-RSA, you will need
154 | # to define an alias to the proper path for the command. The symptom will be
155 | # some form of a 'command not found' error from your shell. This means your
156 | # shell is BROKEN, but you can hack around it here if you really need. These
157 | # shown values are not defaults: it is up to you to know what you're doing if
158 | # you touch these.
159 | #
160 | #alias awk="/alt/bin/awk"
161 | #alias cat="/alt/bin/cat"
162 |
163 | # X509 extensions directory:
164 | # If you want to customize the X509 extensions used, set the directory to look
165 | # for extensions here. Each cert type you sign must have a matching filename,
166 | # and an optional file named 'COMMON' is included first when present. Note that
167 | # when undefined here, default behaviour is to look in $EASYRSA_PKI first, then
168 | # fallback to $EASYRSA for the 'x509-types' dir. You may override this
169 | # detection with an explicit dir here.
170 | #
171 | #set_var EASYRSA_EXT_DIR "$EASYRSA/x509-types"
172 |
173 | # OpenSSL config file:
174 | # If you need to use a specific openssl config file, you can reference it here.
175 | # Normally this file is auto-detected from a file named openssl-1.0.cnf from the
176 | # EASYRSA_PKI or EASYRSA dir (in that order.) NOTE that this file is Easy-RSA
177 | # specific and you cannot just use a standard config file, so this is an
178 | # advanced feature.
179 |
180 | #set_var EASYRSA_SSL_CONF "$EASYRSA/openssl-1.0.cnf"
181 |
182 | # Default CN:
183 | # This is best left alone. Interactively you will set this manually, and BATCH
184 | # callers are expected to set this themselves.
185 |
186 | set_var EASYRSA_REQ_CN "ca@{{ openvpn_server_common_name }}"
187 |
188 | # Cryptographic digest to use.
189 | # Do not change this default unless you understand the security implications.
190 | # Valid choices include: md5, sha1, sha256, sha224, sha384, sha512
191 |
192 | #set_var EASYRSA_DIGEST "sha256"
193 |
194 | # Batch mode. Leave this disabled unless you intend to call Easy-RSA explicitly
195 | # in batch mode without any user input, confirmation on dangerous operations,
196 | # or most output. Setting this to any non-blank string enables batch mode.
197 |
198 | set_var EASYRSA_BATCH "yes"
199 |
--------------------------------------------------------------------------------
/playbooks/roles/openvpn/tasks/harden_auditd.yml:
--------------------------------------------------------------------------------
1 | ---
2 | - name: OpenVPN | Harden auditd | Enable auditd service
3 | service:
4 | name: auditd
5 | enabled: true
6 |
7 | - name: OpenVPN | Harden auditd | Configure
8 | lineinfile:
9 | dest: /etc/audit/auditd.conf
10 | regexp: "{{ item.regexp }}"
11 | line: "{{ item.line }}"
12 | state: present
13 | with_items:
14 | - { regexp: '^(#)?disk_error_action[\s]*=', line: 'disk_error_action = halt'}
15 | - { regexp: '^(#)?disk_full_action[\s]*=', line: 'disk_full_action = halt'}
16 | # Halt the computer if only 75MB is left on disk
17 | - { regexp: '^(#)?space_left[\s]*=', line: 'space_left = 75'}
18 | - { regexp: '^(#)?space_left_action[\s]*=', line: 'space_left_action = halt'}
19 | - { regexp: '^(#)?admin_space_left_action[\s]*=', line: 'admin_space_left_action = halt'}
20 | notify:
21 | - start auditd
22 |
23 | - name: OpenVPN | Harden auditd | Forward auditd records to syslog
24 | lineinfile:
25 | dest: /etc/audisp/plugins.d/syslog.conf
26 | regexp: "^(#)?active"
27 | line: "active = yes"
28 | state: present
29 |
30 | - name: OpenVPN | Harden auditd | Add rules
31 | lineinfile:
32 | dest: "{{ path_auditd_rules }}"
33 | regexp: "{{ item.regexp }}"
34 | line: "{{ item.line }}"
35 | state: present
36 | with_items:
37 | - { regexp: '^[\s]*-a[\s]+always,exit[\s]+-F[\s]+arch=b32.*-S[\s]+adjtimex[\s]+.*-k[\s]+[\S]+[\s]*$',
38 | line: '-a always,exit -F arch=b32 -S adjtimex -k audit_time_rules'}
39 | - { regexp: '^[\s]*-a[\s]+always,exit[\s]+-F[\s]+arch=b64.*-S[\s]+adjtimex[\s]+.*-k[\s]+[\S]+[\s]*$',
40 | line: '-a always,exit -F arch=b64 -S adjtimex -k audit_time_rules'}
41 | - { regexp: '^[\s]*-a[\s]+always,exit[\s]+-F[\s]+arch=b32.*-S[\s]+settimeofday[\s]+.*-k[\s]+[\S]+[\s]*$',
42 | line: '-a always,exit -F arch=b32 -S settimeofday -k audit_time_rules'}
43 | - { regexp: '^[\s]*-a[\s]+always,exit[\s]+-F[\s]+arch=b64.*-S[\s]+settimeofday[\s]+.*-k[\s]+[\S]+[\s]*$',
44 | line: '-a always,exit -F arch=b64 -S settimeofday -k audit_time_rules'}
45 | - { regexp: '^[\s]*-a[\s]+always,exit[\s]+-F[\s]+arch=b32.*-S[\s]+stime[\s]+.*-k[\s]+[\S]+[\s]*$',
46 | line: '-a always,exit -F arch=b32 -S stime -k audit_time_rules'}
47 | - { regexp: '^[\s]*-a[\s]+always,exit[\s]+-F[\s]+arch=b32.*-S[\s]+clock_settime[\s]+.*-k[\s]+[\S]+[\s]*$',
48 | line: '-a always,exit -F arch=b32 -S clock_settime -k audit_time_rules'}
49 | - { regexp: '^[\s]*-a[\s]+always,exit[\s]+-F[\s]+arch=b64.*-S[\s]+clock_settime[\s]+.*-k[\s]+[\S]+[\s]*$',
50 | line: '-a always,exit -F arch=b64 -S clock_settime -k audit_time_rules'}
51 | - { regexp: '^[\s]*-w[\s]+\/etc\/localtime[\s]+-p[\s]+\b([rx]*w[rx]*a[rx]*|[rx]*a[rx]*w[rx]*)\b.*-k[\s]+[\S]+[\s]*$',
52 | line: '-w /etc/localtime -p wa -k audit_time_rules'}
53 | - { regexp: '^[\s]*-a[\s]+always,exit[\s]+(?:.*-F[\s]+arch=b32[\s]+)(?:.*-S[\s]+chmod[\s]+)(?:.*-F\s+auid>=1000[\s]+)(?:.*-F\s+auid!=4294967295[\s]+).*-k[\s]+[\S]+[\s]*$',
54 | line: '-a always,exit -F arch=b32 -S chmod -F auid>=1000 -F auid!=4294967295 -k perm_mod'}
55 | - { regexp: '^[\s]*-a[\s]+always,exit[\s]+(?:.*-F[\s]+arch=b64[\s]+)(?:.*-S[\s]+chmod[\s]+)(?:.*-F\s+auid>=1000[\s]+)(?:.*-F\s+auid!=4294967295[\s]+).*-k[\s]+[\S]+[\s]*$',
56 | line: '-a always,exit -F arch=b64 -S chmod -F auid>=1000 -F auid!=4294967295 -k perm_mod'}
57 | - { regexp: '^[\s]*-a[\s]+always,exit[\s]+(?:.*-F[\s]+arch=b32[\s]+)(?:.*-S[\s]+chown[\s]+)(?:.*-F\s+auid>=1000[\s]+)(?:.*-F\s+auid!=4294967295[\s]+).*-k[\s]+[\S]+[\s]*$',
58 | line: '-a always,exit -F arch=b32 -S chown -F auid>=1000 -F auid!=4294967295 -k perm_mod'}
59 | - { regexp: '^[\s]*-a[\s]+always,exit[\s]+(?:.*-F[\s]+arch=b64[\s]+)(?:.*-S[\s]+chown[\s]+)(?:.*-F\s+auid>=1000[\s]+)(?:.*-F\s+auid!=4294967295[\s]+).*-k[\s]+[\S]+[\s]*$',
60 | line: '-a always,exit -F arch=b64 -S chown -F auid>=1000 -F auid!=4294967295 -k perm_mod'}
61 | - { regexp: '^[\s]*-a[\s]+always,exit[\s]+(?:.*-F[\s]+arch=b32[\s]+)(?:.*-S[\s]+fchmod[\s]+)(?:.*-F\s+auid>=1000[\s]+)(?:.*-F\s+auid!=4294967295[\s]+).*-k[\s]+[\S]+[\s]*$',
62 | line: '-a always,exit -F arch=b32 -S fchmod -F auid>=1000 -F auid!=4294967295 -k perm_mod'}
63 | - { regexp: '^[\s]*-a[\s]+always,exit[\s]+(?:.*-F[\s]+arch=b64[\s]+)(?:.*-S[\s]+fchmod[\s]+)(?:.*-F\s+auid>=1000[\s]+)(?:.*-F\s+auid!=4294967295[\s]+).*-k[\s]+[\S]+[\s]*$',
64 | line: '-a always,exit -F arch=b64 -S fchmod -F auid>=1000 -F auid!=4294967295 -k perm_mod'}
65 | - { regexp: '^[\s]*-a[\s]+always,exit[\s]+(?:.*-F[\s]+arch=b32[\s]+)(?:.*-S[\s]+fchmodat[\s]+)(?:.*-F\s+auid>=1000[\s]+)(?:.*-F\s+auid!=4294967295[\s]+).*-k[\s]+[\S]+[\s]*$',
66 | line: '-a always,exit -F arch=b32 -S fchmodat -F auid>=1000 -F auid!=4294967295 -k perm_mod'}
67 | - { regexp: '^[\s]*-a[\s]+always,exit[\s]+(?:.*-F[\s]+arch=b64[\s]+)(?:.*-S[\s]+fchmodat[\s]+)(?:.*-F\s+auid>=1000[\s]+)(?:.*-F\s+auid!=4294967295[\s]+).*-k[\s]+[\S]+[\s]*$',
68 | line: '-a always,exit -F arch=b64 -S fchmodat -F auid>=1000 -F auid!=4294967295 -k perm_mod'}
69 | - { regexp: '^[\s]*-a[\s]+always,exit[\s]+(?:.*-F[\s]+arch=b32[\s]+)(?:.*-S[\s]+fchown[\s]+)(?:.*-F\s+auid>=1000[\s]+)(?:.*-F\s+auid!=4294967295[\s]+).*-k[\s]+[\S]+[\s]*$',
70 | line: '-a always,exit -F arch=b32 -S fchown -F auid>=1000 -F auid!=4294967295 -k perm_mod'}
71 | - { regexp: '^[\s]*-a[\s]+always,exit[\s]+(?:.*-F[\s]+arch=b64[\s]+)(?:.*-S[\s]+fchown[\s]+)(?:.*-F\s+auid>=1000[\s]+)(?:.*-F\s+auid!=4294967295[\s]+).*-k[\s]+[\S]+[\s]*$',
72 | line: '-a always,exit -F arch=b64 -S fchown -F auid>=1000 -F auid!=4294967295 -k perm_mod'}
73 | - { regexp: '^[\s]*-a[\s]+always,exit[\s]+(?:.*-F[\s]+arch=b32[\s]+)(?:.*-S[\s]+fchownat[\s]+)(?:.*-F\s+auid>=1000[\s]+)(?:.*-F\s+auid!=4294967295[\s]+).*-k[\s]+[\S]+[\s]*$',
74 | line: '-a always,exit -F arch=b32 -S fchownat -F auid>=1000 -F auid!=4294967295 -k perm_mod'}
75 | - { regexp: '^[\s]*-a[\s]+always,exit[\s]+(?:.*-F[\s]+arch=b64[\s]+)(?:.*-S[\s]+fchownat[\s]+)(?:.*-F\s+auid>=1000[\s]+)(?:.*-F\s+auid!=4294967295[\s]+).*-k[\s]+[\S]+[\s]*$',
76 | line: '-a always,exit -F arch=b64 -S fchownat -F auid>=1000 -F auid!=4294967295 -k perm_mod'}
77 | - { regexp: '^[\s]*-a[\s]+always,exit[\s]+(?:.*-F[\s]+arch=b32[\s]+)(?:.*-S[\s]+fremovexattr[\s]+)(?:.*-F\s+auid>=1000[\s]+)(?:.*-F\s+auid!=4294967295[\s]+).*-k[\s]+[\S]+[\s]*$',
78 | line: '-a always,exit -F arch=b32 -S fremovexattr -F auid>=1000 -F auid!=4294967295 -k perm_mod'}
79 | - { regexp: '^[\s]*-a[\s]+always,exit[\s]+(?:.*-F[\s]+arch=b64[\s]+)(?:.*-S[\s]+fremovexattr[\s]+)(?:.*-F\s+auid>=1000[\s]+)(?:.*-F\s+auid!=4294967295[\s]+).*-k[\s]+[\S]+[\s]*$',
80 | line: '-a always,exit -F arch=b64 -S fremovexattr -F auid>=1000 -F auid!=4294967295 -k perm_mod'}
81 | - { regexp: '^[\s]*-a[\s]+always,exit[\s]+(?:.*-F[\s]+arch=b32[\s]+)(?:.*-S[\s]+fsetxattr[\s]+)(?:.*-F\s+auid>=1000[\s]+)(?:.*-F\s+auid!=4294967295[\s]+).*-k[\s]+[\S]+[\s]*$',
82 | line: '-a always,exit -F arch=b32 -S fsetxattr -F auid>=1000 -F auid!=4294967295 -k perm_mod'}
83 | - { regexp: '^[\s]*-a[\s]+always,exit[\s]+(?:.*-F[\s]+arch=b64[\s]+)(?:.*-S[\s]+fsetxattr[\s]+)(?:.*-F\s+auid>=1000[\s]+)(?:.*-F\s+auid!=4294967295[\s]+).*-k[\s]+[\S]+[\s]*$',
84 | line: '-a always,exit -F arch=b64 -S fsetxattr -F auid>=1000 -F auid!=4294967295 -k perm_mod'}
85 | - { regexp: '^[\s]*-a[\s]+always,exit[\s]+(?:.*-F[\s]+arch=b32[\s]+)(?:.*-S[\s]+lchown[\s]+)(?:.*-F\s+auid>=1000[\s]+)(?:.*-F\s+auid!=4294967295[\s]+).*-k[\s]+[\S]+[\s]*$',
86 | line: '-a always,exit -F arch=b32 -S lchown -F auid>=1000 -F auid!=4294967295 -k perm_mod'}
87 | - { regexp: '^[\s]*-a[\s]+always,exit[\s]+(?:.*-F[\s]+arch=b64[\s]+)(?:.*-S[\s]+lchown[\s]+)(?:.*-F\s+auid>=1000[\s]+)(?:.*-F\s+auid!=4294967295[\s]+).*-k[\s]+[\S]+[\s]*$',
88 | line: '-a always,exit -F arch=b64 -S lchown -F auid>=1000 -F auid!=4294967295 -k perm_mod'}
89 | - { regexp: '^[\s]*-a[\s]+always,exit[\s]+(?:.*-F[\s]+arch=b32[\s]+)(?:.*-S[\s]+lremovexattr[\s]+)(?:.*-F\s+auid>=1000[\s]+)(?:.*-F\s+auid!=4294967295[\s]+).*-k[\s]+[\S]+[\s]*$',
90 | line: '-a always,exit -F arch=b32 -S lremovexattr -F auid>=1000 -F auid!=4294967295 -k perm_mod'}
91 | - { regexp: '^[\s]*-a[\s]+always,exit[\s]+(?:.*-F[\s]+arch=b64[\s]+)(?:.*-S[\s]+lremovexattr[\s]+)(?:.*-F\s+auid>=1000[\s]+)(?:.*-F\s+auid!=4294967295[\s]+).*-k[\s]+[\S]+[\s]*$',
92 | line: '-a always,exit -F arch=b64 -S lremovexattr -F auid>=1000 -F auid!=4294967295 -k perm_mod'}
93 | - { regexp: '^[\s]*-a[\s]+always,exit[\s]+(?:.*-F[\s]+arch=b32[\s]+)(?:.*-S[\s]+lsetxattr[\s]+)(?:.*-F\s+auid>=1000[\s]+)(?:.*-F\s+auid!=4294967295[\s]+).*-k[\s]+[\S]+[\s]*$',
94 | line: '-a always,exit -F arch=b32 -S lsetxattr -F auid>=1000 -F auid!=4294967295 -k perm_mod'}
95 | - { regexp: '^[\s]*-a[\s]+always,exit[\s]+(?:.*-F[\s]+arch=b64[\s]+)(?:.*-S[\s]+lsetxattr[\s]+)(?:.*-F\s+auid>=1000[\s]+)(?:.*-F\s+auid!=4294967295[\s]+).*-k[\s]+[\S]+[\s]*$',
96 | line: '-a always,exit -F arch=b64 -S lsetxattr -F auid>=1000 -F auid!=4294967295 -k perm_mod'}
97 | - { regexp: '^[\s]*-a[\s]+always,exit[\s]+(?:.*-F[\s]+arch=b32[\s]+)(?:.*-S[\s]+removexattr[\s]+)(?:.*-F\s+auid>=1000[\s]+)(?:.*-F\s+auid!=4294967295[\s]+).*-k[\s]+[\S]+[\s]*$',
98 | line: '-a always,exit -F arch=b32 -S removexattr -F auid>=1000 -F auid!=4294967295 -k perm_mod'}
99 | - { regexp: '^[\s]*-a[\s]+always,exit[\s]+(?:.*-F[\s]+arch=b64[\s]+)(?:.*-S[\s]+removexattr[\s]+)(?:.*-F\s+auid>=1000[\s]+)(?:.*-F\s+auid!=4294967295[\s]+).*-k[\s]+[\S]+[\s]*$',
100 | line: '-a always,exit -F arch=b64 -S removexattr -F auid>=1000 -F auid!=4294967295 -k perm_mod'}
101 | - { regexp: '^[\s]*-a[\s]+always,exit[\s]+(?:.*-F[\s]+arch=b32[\s]+)(?:.*-S[\s]+setxattr[\s]+)(?:.*-F\s+auid>=1000[\s]+)(?:.*-F\s+auid!=4294967295[\s]+).*-k[\s]+[\S]+[\s]*$',
102 | line: '-a always,exit -F arch=b32 -S setxattr -F auid>=1000 -F auid!=4294967295 -k perm_mod'}
103 | - { regexp: '^[\s]*-a[\s]+always,exit[\s]+(?:.*-F[\s]+arch=b64[\s]+)(?:.*-S[\s]+setxattr[\s]+)(?:.*-F\s+auid>=1000[\s]+)(?:.*-F\s+auid!=4294967295[\s]+).*-k[\s]+[\S]+[\s]*$',
104 | line: '-a always,exit -F arch=b64 -S setxattr -F auid>=1000 -F auid!=4294967295 -k perm_mod'}
105 | - { regexp: '^\-w[\s]+/etc/group[\s]+\-p[\s]+\b([rx]*w[rx]*a[rx]*|[rx]*a[rx]*w[rx]*)\b[\s+]\-k[\s]+\w+[\s]*$',
106 | line: '-w /etc/group -p wa -k audit_rules_usergroup_modification'}
107 | - { regexp: '^\-w[\s]+/etc/passwd[\s]+\-p[\s]+\b([rx]*w[rx]*a[rx]*|[rx]*a[rx]*w[rx]*)\b[\s]+\-k[\s]+\w+[\s]*$',
108 | line: '-w /etc/passwd -p wa -k audit_rules_usergroup_modification'}
109 | - { regexp: '^\-w[\s]+/etc/gshadow[\s]+\-p[\s]+\b([rx]*w[rx]*a[rx]*|[rx]*a[rx]*w[rx]*)\b[\s]+\-k[\s]+\w+[\s]*$',
110 | line: '-w /etc/gshadow -p wa -k audit_rules_usergroup_modification'}
111 | - { regexp: '^\-w[\s]+/etc/shadow[\s]+\-p[\s]+\b([rx]*w[rx]*a[rx]*|[rx]*a[rx]*w[rx]*)\b[\s]+\-k[\s]+\w+[\s]*$',
112 | line: '-w /etc/shadow -p wa -k audit_rules_usergroup_modification'}
113 | - { regexp: '^\-w[\s]+/etc/security/opasswd[\s]+\-p[\s]+\b([rx]*w[rx]*a[rx]*|[rx]*a[rx]*w[rx]*)\b[\s]+\-k[\s]+\w+[\s]*$',
114 | line: '-w /etc/security/opasswd -p wa -k audit_rules_usergroup_modification'}
115 | - { regexp: '^\-a\s+always,exit\s+(\-F\s+arch=(b64|b32)\s+)?\-S\s+sethostname\s+\-S\s+setdomainname\s+\-k\s+[-\w]+\s*$',
116 | line: '-a always,exit -F arch=b64 -S sethostname -S setdomainname -k audit_rules_networkconfig_modification'}
117 | - { regexp: '^\-w[\s]+/etc/issue[\s]+\-p[\s]+\b([rx]*w[rx]*a[rx]*|[rx]*a[rx]*w[rx]*)\b[\s]+\-k[\s]+[-\w]+[\s]*$',
118 | line: '-w /etc/issue -p wa -k audit_rules_networkconfig_modification'}
119 | - { regexp: '^\-w[\s]+/etc/issue\.net[\s]+\-p[\s]+\b([rx]*w[rx]*a[rx]*|[rx]*a[rx]*w[rx]*)\b[\s]+\-k[\s]+[-\w]+[\s]*$',
120 | line: '-w /etc/issue.net -p wa -k audit_rules_networkconfig_modification'}
121 | - { regexp: '^\-w[\s]+/etc/hosts[\s]+\-p[\s]+\b([rx]*w[rx]*a[rx]*|[rx]*a[rx]*w[rx]*)\b[\s]+\-k[\s]+[-\w]+[\s]*$',
122 | line: '-w /etc/hosts -p wa -k audit_rules_networkconfig_modification'}
123 | - { regexp: '^\-w[\s]+/etc/sysconfig/network[\s]+\-p[\s]+\b([rx]*w[rx]*a[rx]*|[rx]*a[rx]*w[rx]*)\b[\s]+\-k[\s]+[-\w]+[\s]*$',
124 | line: '-w /etc/sysconfig/network -p wa -k audit_rules_networkconfig_modification'}
125 | - { regexp: '^\-w[\s]+{{ path_mac_config }}[\s]+\-p[\s]+\b([rx]*w[rx]*a[rx]*|[rx]*a[rx]*w[rx]*)\b[\s]+\-k[\s]+[-\w]+[\s]*$',
126 | line: '-w {{ path_mac_config }} -p wa -k MAC-policy'}
127 | - { regexp: '^\-w\s+/var/run/utmp\s+\-p\s+wa\s+\-k\s+[-\w]+\s*$',
128 | line: '-w /var/run/utmp -p wa -k session'}
129 | - { regexp: '^\-w\s+/var/log/btmp\s+\-p\s+wa\s+\-k\s+[-\w]+\s*$',
130 | line: '-w /var/log/btmp -p wa -k session'}
131 | - { regexp: '^\-w\s+/var/log/wtmp\s+\-p\s+wa\s+\-k\s+[-\w]+\s*$',
132 | line: '-w /var/log/wtmp -p wa -k session'}
133 | - { regexp: '^\-a\s+always,exit\s+\-F\s+arch=b32\s+?\-S\s+creat\s+\-S\s+open\s+\-S\s+openat\s+\-S\s+open_by_handle_at\s+\-S\s+truncate\s+\-S\s+ftruncate\s+\-F\s+exit=\-EACCES\s+\-F\s+auid>=1000\s+\-F\s+auid!=4294967295\s+\-k\s+[-\w]+\s*$',
134 | line: '-a always,exit -F arch=b32 -S creat -S open -S openat -S open_by_handle_at -S truncate -S ftruncate -F exit=-EACCES -F auid>=1000 -F auid!=4294967295 -k access'}
135 | - { regexp: '^\-a\s+always,exit\s+\-F\s+arch=b32\s+?\-S\s+creat\s+\-S\s+open\s+\-S\s+openat\s+\-S\s+open_by_handle_at\s+\-S\s+truncate\s+\-S\s+ftruncate\s+\-F\s+exit=\-EPERM\s+\-F\s+auid>=1000\s+\-F\s+auid!=4294967295\s+\-k\s+[-\w]+\s*$',
136 | line: '-a always,exit -F arch=b32 -S creat -S open -S openat -S open_by_handle_at -S truncate -S ftruncate -F exit=-EPERM -F auid>=1000 -F auid!=4294967295 -k access'}
137 | - { regexp: '^\-a\s+always,exit\s+\-F\s+arch=b64\s+?\-S\s+creat\s+\-S\s+open\s+\-S\s+openat\s+\-S\s+open_by_handle_at\s+\-S\s+truncate\s+\-S\s+ftruncate\s+\-F\s+exit=\-EACCES\s+\-F\s+auid>=1000\s+\-F\s+auid!=4294967295\s+\-k\s+[-\w]+\s*$',
138 | line: '-a always,exit -F arch=b64 -S creat -S open -S openat -S open_by_handle_at -S truncate -S ftruncate -F exit=-EACCES -F auid>=1000 -F auid!=4294967295 -k access'}
139 | - { regexp: '^\-a\s+always,exit\s+\-F\s+arch=b64\s+?\-S\s+creat\s+\-S\s+open\s+\-S\s+openat\s+\-S\s+open_by_handle_at\s+\-S\s+truncate\s+\-S\s+ftruncate\s+\-F\s+exit=\-EPERM\s+\-F\s+auid>=1000\s+\-F\s+auid!=4294967295\s+\-k\s+[-\w]+\s*$',
140 | line: '-a always,exit -F arch=b64 -S creat -S open -S openat -S open_by_handle_at -S truncate -S ftruncate -F exit=-EPERM -F auid>=1000 -F auid!=4294967295 -k access'}
141 | - { regexp: '^\-a\s+always,exit\s+(\-F\s+arch=(b64|b32)\s+)?\-S\s+mount\s+\-F\s+auid>=1000\s+\-F\s+auid!=4294967295\s+\-k\s+[-\w]+\s*$',
142 | line: '-a always,exit -F arch=b64 -S mount -F auid>=1000 -F auid!=4294967295 -k export'}
143 | - { regexp: '^\-a\s+always,exit\s+(\-F\s+arch=(b64|b32)\s+)?\-S\s+rmdir\s+\-S\s+unlink\s+\-S\s+unlinkat\s+\-S\s+rename\s+\-S\s+renameat\s+\-F\s+auid>=1000\s+\-F\s+auid!=4294967295\s+\-k\s+[-\w]+\s*$',
144 | line: '-a always,exit -F arch=b64 -S rmdir -S unlink -S unlinkat -S rename -S renameat -F auid>=1000 -F auid!=4294967295 -k delete'}
145 | - { regexp: '^\-w[\s]+/etc/sudoers[\s]+\-p[\s]+\b([rx]*w[rx]*a[rx]*|[rx]*a[rx]*w[rx]*)\b[\s]+\-k[\s]+[-\w]+[\s]*$',
146 | line: '-w /etc/sudoers -p wa -k actions'}
147 | - { regexp: '^\-w[\s]+/usr/sbin/insmod[\s]+\-p[\s]+\b([raw]*x[raw]*)\b[\s]+\-k[\s]+[-\w]+[\s]*$',
148 | line: '-w /usr/sbin/insmod -p x -k modules'}
149 | - { regexp: '^\-w[\s]+/usr/sbin/rmmod[\s]+\-p[\s]+\b([raw]*x[raw]*)\b[\s]+\-k[\s]+[-\w]+[\s]*$',
150 | line: '-w /usr/sbin/rmmod -p x -k modules'}
151 | - { regexp: '^\-w\s+/usr/sbin/modprobe[\s]+\-p[\s]+\b([raw]*x[raw]*)\b[\s]+\-k[\s]+[-\w]+[\s]*$',
152 | line: '-w /usr/sbin/modprobe -p x -k modules'}
153 | - { regexp: '^\-a\s+always,exit\s+(\-F\s+arch=(b64|b32)\s+)?\-S\s+init_module\s+\-S\s+delete_module\s+\-k\s+[-\w]+\s*$',
154 | line: '-a always,exit -F arch=b64 -S init_module -S delete_module -k modules'}
155 | notify:
156 | - start auditd
157 |
158 | - name: OpenVPN | Harden auditd | Find all setuid/setgid applications
159 | shell: find / -xdev -type f -perm -4000 -o -type f -perm -2000 2>/dev/null
160 | changed_when: false
161 | register: found_setuid_bins
162 | notify:
163 | - start auditd
164 |
165 | - name: OpenVPN | Harden auditd | Monitor all setuid/setgid applications
166 | lineinfile:
167 | dest: /etc/audit/rules.d/audit.rules
168 | line: "-a always,exit -F path={{ item }} -F perm=x -F auid>=1000 -F auid!=4294967295 -k privileged"
169 | regexp: '^\-a\s+always,exit\s+\-F\s+path={{ item }}\s+\-F\s+perm=x\s+\-F\s+auid>=1000\s+\-F\s+auid!=4294967295\s+\-k\s+privileged\s*$'
170 | state: present
171 | with_items: "{{ found_setuid_bins.stdout_lines }}"
172 | notify:
173 | - start auditd
174 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Overview [](https://travis-ci.org/bau-sec/ansible-openvpn-hardened)
2 | *ansible-openvpn-hardened* is an [*Ansible*](http://www.ansible.com/home) playbook written to create and manage a hardened OpenVPN server instance in the cloud or locally. The created instance is configured for use as a tunnel for internet traffic allowing more secure internet access when using public WiFi or other untrusted networks. With this setup you don't have to trust or pay a shady VPN service; you control your data and the security of the VPN.
3 |
4 | Other Ansible playbooks and roles exist to automate the installation of OpenVPN but few, if any, thoroughly harden the OpenVPN server. *ansible-openvpn-hardened* configures the OpenVPN server to:
5 | - run entirely as an unprivileged user [as described in the OpenVPN docs](https://community.openvpn.net/openvpn/wiki/UnprivilegedUser)
6 | - use *systemd* to further sandbox the OpenVPN server process.
7 | - use only TLS ciphers that implement **perfect forward secrecy**
8 | - leverage *easyrsa* for PKI with a CRL and ansible playbooks for easy key management
9 | - produce thorough security audits using independent tools
10 | - And more; see the [Hardening](#hardening) section
11 |
12 | *ansible-openvpn-hardened* includes a playbook to run audits against the created server that independently verify the steps taken to harden the server. The supported auditing tools include [*OpenSCAP*](https://www.open-scap.org/) (with assistance from [*ubuntu-scap*](https://github.com/GovReady/ubuntu-scap) on Debian/Ubuntu), [*lynis*](https://cisofy.com/lynis/) and [*tiger*](http://www.nongnu.org/tiger/). Example output from these tools can be reviewed on the project wiki.
13 |
14 | To learn more about the server hardening read on; to get started immediately, jump to [Quick Start](#quick-start).
15 |
16 | ## Supported Targets
17 |
18 | The intended target is a fresh instantiation of an image running on a cloud provider like [Digital Ocean](https://www.digitalocean.com/?refcode=5ab3eb461bcb) (fair warning: referral link) or Microsoft's [Azure](https://azure.microsoft.com/). Physical boxes or local VMs should work as well assuming they are accessible over SSH, but haven't been tested.
19 |
20 | The following Linux distros are supported:
21 |
22 | - CentOS 7.2 x64 (And by extension RHEL 7.2 should work, but this hasn't been tested)
23 | - Ubuntu 16.04 x64
24 | - Debian 8.7 x64
25 |
26 | Other distros and versions may work but no promises. If support for another distro is desired, submit an issue ticket. Pull requests are always welcome.
27 |
28 | # Hardening
29 | Some of the steps taken to harden the server:
30 | ### General
31 | - OpenVPN both **starts** and runs as the `openvpn` user instead of starting as `root` and dropping privileges
32 | - OpenVPN recommends this as being the most secure way to run on Linux. The OpenVPN wiki [describes how to do this](https://community.openvpn.net/openvpn/wiki/UnprivilegedUser), but those instructions don't work on distros using *systemd*. The ansible tasks defined in this project show how to get this working with *systemd*
33 | - Firewall configured to only allow SSH access on the VPN LAN
34 | - The point of this script is to create a VPN tunnel; why not use that VPN to protect the SSH daemon as well? This not only makes the server more secure, it also eliminates the hundreds of daily log entries created by automated scripts trolling the internet for unsecured SSH ports. This makes the system logs easier to sift through.
35 | - Numerous modifications to `/etc/ssh/sshd_config` for hardening. See [`harden_sshd.yml`](playbooks/roles/openvpn/tasks/harden_sshd.yml)
36 | - [*auditd*](http://linux.die.net/man/8/auditd) is installed and configured to monitor administrative actions and/or suspicious activity. See [`harden_auditd.yml`](playbooks/roles/openvpn/tasks/harden_auditd.yml)
37 | - [*AIDE*](http://aide.sourceforge.net/) is a file and directory integrity checker. It's installed, configured and an initial baseline is taken using `aide --init` just before the playbook finishes. See [`harden_aide.yml`](playbooks/roles/openvpn/tasks/harden_aide.yml)
38 |
39 | ### *systemd* sandboxing
40 | While there are *systemd* detractors out there, it is the default init system for Debian, Ubuntu and Red Hat. And it does provide some useful features for sandboxing services. See [`etc_systemd_system_openvpn@.service.d_override.conf.j2`](playbooks/roles/openvpn/templates/etc_systemd_system_openvpn@.service.d_override.conf.j2) for how some of these features are enabled.
41 | - The *systemd* unit option `CapabilityBoundingSet` is used to bound the Linux capabilities available to the OpenVPN server process, allowing only `CAP_NET_ADMIN` and `CAP_NET_BIND_SERVICE`
42 | - The *systemd* unit options `ReadOnlyDirectories`, `InaccessibleDirectories`, `ProtectSystem` and `ProtectHome` are used to restrict the OpenVPN server process' access to the filesystem.
43 | - These aren't perfect as noted [in the *systemd* docs](https://www.freedesktop.org/software/systemd/man/systemd.exec.html), but better to have them than not:
44 |
45 | > Note that restricting access with these options does not extend to submounts of a directory that are created later on.
46 |
47 | ### OpenVPN server configuration
48 | For the full server configuration, see [`etc_openvpn_server.conf.j2`](playbooks/roles/openvpn/templates/etc_openvpn_server.conf.j2)
49 | - `tls-auth` aids in mitigating risk of denial-of-service attacks. Additionally, when combined with usage of UDP at the transport layer (the default configuration used by *ansible-openvpn-hardened*), it complicates attempts to port scan the OpenVPN server because any unsigned packets can be immediately dropped without sending anything back to the scanner.
50 | - From the [OpenVPN hardening guide](https://community.openvpn.net/openvpn/wiki/Hardening):
51 |
52 | > The tls-auth option uses a static pre-shared key (PSK) that must be generated in advance and shared among all peers. This features adds "extra protection" to the TLS channel by requiring that incoming packets have a valid signature generated using the PSK key... The primary benefit is that an unauthenticated client cannot cause the same CPU/crypto load against a server as the junk traffic can be dropped much sooner. This can aid in mitigating denial-of-service attempts.
53 |
54 | - `push block-outside-dns` used by OpenVPN server to fix a potential dns leak on Windows 10
55 | - See https://community.openvpn.net/openvpn/ticket/605
56 | - `tls-cipher` limits allowable TLS ciphers to a subset that supports [**perfect forward secrecy**](https://en.wikipedia.org/wiki/Forward_secrecy)
57 | - From wikipedia:
58 |
59 | > Forward secrecy protects past sessions against future compromises of secret keys or passwords. If forward secrecy is used, encrypted communications and sessions recorded in the past cannot be retrieved and decrypted should long-term secret keys or passwords be compromised in the future, even if the adversary actively interfered.
60 |
61 | - `cipher` set to `AES-256-CBC` by default
62 | - `2048` bit RSA key size by default.
63 | - This can be increased to `4096` by changing `openvpn_key_size` in [`defaults/main.yml`](playbooks/roles/openvpn/defaults/main.yml) if you don't mind extra processing time. Consensus seems to be that 2048 is sufficient for all but the most sensitive data.
64 |
65 | ### OpenVPN client configuration
66 | For the full client configuration, see [`client_common.ovpn.j2`](playbooks/roles/add_clients/templates/client_common.ovpn.j2)
67 | - `verify-x509-name` prevents MitM attacks by verifying the server name in the supplied certificate matches the clients configuration.
68 | - `persist-tun` prevents the traffic from leaking out over the default interface during interruptions and reconnection attempts by keeping the tun device up until connectivity is restored.
69 |
70 | ### PKI
71 | - [easy-rsa](https://github.com/OpenVPN/easy-rsa) is used to manage the public key infrastructure.
72 | - OpenVPN is configured to read the CRL generated by *easy-rsa* so that a single client's access can be revoked without having to reissue credentials to all of the clients.
73 | - The private keys generated for the clients and CA are all protected with a randomly generated passphrase to facilitate secure distribution to client devices.
74 |
75 | The bullets above are just an overview. See the task definitions with filenames in the form `harden_.yml` to review the complete set of steps.
76 |
77 | The [`audit.yml`](playbooks/audit.yml) playbook can be run on the target server to independently verify the steps taken and their efficacy so you don't have to put all your trust in the *ansible-openvpn-hardened* contributors.
78 |
79 | ### Hardening - Audit Notes
80 |
81 | None of the audit tools used by the `audit.yml` playbook give the server a perfect score, here are some brief notes on audit findings
82 |
83 | - Separate partitions for /tmp, /home, etc.
84 | - Partitioning can be tricky on cloud providers and the creation of partitions can be difficult to script without risking data loss. This is probably best left to the OS image creator or installer of the OS.
85 | - mount options such as `noexec`, `nosuid`, and `nodev` for /tmp, /dev/shm, etc.
86 | - This will likely be addressed in future versions. Pull requests welcome.
87 | - Password requirements
88 | - The created server should only have one account able to login over SSH and it will be protected with a randomly generated password and pub/priv key pair. Unless you're using this server for other purposes with users who login regularly, setting requirements for password minimum length, complexity, expirations, etc. seems like box-checking, not adding additional security.
89 | - The *pam* module *pwquality* is installed if password requirements are necessary for your setup
90 |
91 | # Quick start
92 |
93 | > Warning: **Potential to lock yourself out of the target box.** One of the hardening steps configures SSH to only listen on the VPN interfaces. Make sure you have a backup method to access the server in case the VPN doesn't come up. For example, Digital Ocean provides console access through their admin panel.
94 |
95 | > Requirement: **Currently a static IP is required** This may change in future releases with support for dynamic IP addresses. Static IPs are available on both Digital Ocean and Azure.
96 |
97 | > Suggestion: **Use a fresh install or image as a target** This playbook should work well, but issues will be less likely and more easily resolved if you can start over easily. Also, given the potential for locking yourself out of the box, you don't want to lose access to import things that may be on an existing server.
98 |
99 | Install the required packages if you don't have them already. On Ubuntu or Debian use the commands below. On other OSes, sub-in the appropriate package manager.
100 |
101 | sudo apt-get install python-pip git
102 | sudo pip install ansible
103 |
104 | Get *ansible-openvpn-hardened*
105 |
106 | git clone https://github.com/bau-sec/ansible-openvpn-hardened.git
107 |
108 | Create a target machine using your cloud provider of choice. The CentOS 7.2, Ubuntu 16.04 and Debian 8.7 images on Digital Ocean and Microsoft's Azure have been tested and should work well. Cloud providers are ideal because you can easily spin up a test box to try things out on and delete the instance when you're done or when you no longer need the VM. Other cloud providers, a local VM or box should work fine as well but haven't been tested.
109 |
110 | Make sure you can ssh into the target machine that will become your OpenVPN box. If using a cloud provider they should provide you with login credentials and instructions. For example, to log into the `root` account on a box with the ip `192.168.1.10` use
111 |
112 | ssh root@192.168.1.10
113 |
114 | Copy the example Ansible inventory to edit for your setup. `inventory.example` has example values for different ssh configurations. If *vim* isn't your editor of choice, substitute a different editor.
115 |
116 | cd ansible-openvpn-hardened/
117 | cp inventory.example inventory
118 | vim inventory
119 |
120 | Run the install playbook
121 |
122 | ansible-playbook playbooks/install.yml
123 |
124 | The playbook should run for **5-30 minutes** depending on how good your target box is at hashing and crypto operations. Assuming the above steps were successful, you should now have directory called `fetched_creds`. This contains the openvpn configuration files and private keys that can be distributed to your clients.
125 |
126 | Try connecting to the newly created OpenVPN server
127 |
128 | cd fetched_creds/[server ip]/[client name]/
129 | openvpn [client name]@[random domain]-pki-embedded.ovpn
130 |
131 | You'll be prompted for the private key passphrase, this is stored in a file ending in `.txt` in the client directory you just entered in the step above.
132 |
133 | ## Distributing key files
134 |
135 | *ansible-openvpn-hardened* provides three different OpenVPN configuration files because OpenVPN clients on different platforms have different requirements for how the PKI information is referenced by the .ovpn file. This is just for convenience. All the configuration information and PKI info is the same, it's just formatted differently to support different OpenVPN clients.
136 |
137 | - **PKI embedded** - the easiest if your client supports it. Only one file required and all the PKI information is embedded.
138 | - `X-pki-embedded.ovpn`
139 | - **PKCS#12** - all the PKI information is stored in the PKCS#12 file and referenced by the config. This can be more secure on Android where the OS can store the information in the PKCS#12 file in hardware backed encrypted storage.
140 | - `X-pkcs.ovpn`
141 | - `X.p12`
142 | - **PKI files** - if the above two fail, all clients should support this. All of the PKI information is stored in separate files and referenced by the config.
143 | - `X-pki-files.ovpn` - OpenVPN configuration
144 | - `ca.pem` - CA certificate
145 | - `X.key` - client private key
146 | - `X.pem` - client certificate
147 |
148 | All private keys (embedded in config, pkcs, and .key) are encrypted with a passphrase to facilitate secure distribution to client devices.
149 |
150 | For maximum security when copying the PKI files and configs to client devices don't copy the .txt file containing the randomly generated passphrase. Enter the passphrase manually onto the device after the key has been transferred.
151 |
152 | ## Private key passphrases
153 |
154 | Entering a pass phrase every time the client is started can be annoying. There are a few options to make this less burdensome after the keys have been securely distributed to the client devices.
155 |
156 | 1. When starting the client, use `openvpn --config [config] --askpass [pass.txt]` if you don't want to enter the password for the private key
157 |
158 | From the OpenVPN man page:
159 |
160 | > If file is specified, read the password from the first line of file. Keep in mind that storing your password in a file to a certain extent invalidates the extra security provided by using an encrypted key.
161 |
162 | 1. Remove or change the passphrase on the private key
163 |
164 | openssl rsa -in enc.key -out not_enc.key
165 |
166 | # Managing the OpenVPN server
167 |
168 | ## Credentials
169 |
170 | Credentials are generated during the install process and are saved as yml formatted files in the Ansible file hierarchy so they can be used without requiring the playbook caller to take any action. The locations are below.
171 |
172 | - CA Private key passphrase - saved in `group_vars/all.yml`
173 | - User account name and password - saved in `group_vars/openvpn-vpn.yml`
174 |
175 | After the install.yml playbook has successfully been run, **you'll only be able to SSH into the box when connected to the VPN** using the account defined in `group_vars/openvpn-vpn.yml`
176 |
177 | ssh [created_user]@10.9.0.1
178 |
179 | ## Add clients
180 |
181 | By default only two clients are created: `laptop` and `phone`. (These defaults can be changed by editing `openvpn_clients` in [`defaults/main.yml`](playbooks/roles/openvpn/defaults/main.yml))
182 |
183 | Connect to the VPN before running the playbook. For example, to create a client named `cool_client` use
184 |
185 | ansible-playbook playbooks/add_clients.yml -e clients_to_add=cool_client
186 |
187 | ### Advanced - Adding clients using a CSR
188 |
189 | Clients can also be added using a certificate signing request, CSR. This is useful if you intend to use keys generated and stored in a TPM. Generating the CSR will depend on your hardware, OS, TPM software, etc. If you're interested in this feature, you can probably figure this out (though [`.travis.yml`](.travis.yml) has an example of generating a CSR with *openssl*). This [blog post](https://qistoph.blogspot.nl/2015/12/tpm-authentication-in-openvpn-and-putty.html) shows how to create private key stored in a TPM and generate a CSR on Windows.
190 |
191 | The variable `csr_path` specifies the local path to the CSR. `cn` specifies the common name specified when the CSR was created.
192 |
193 | ansible-playbook -e "csr_path=~/test.csr cn=test@domain.com" playbooks/add_clients.yml
194 |
195 | This will generate the client's signed certificate and put it in `fetched_creds/[server ip]/[cn]/` as well as a nearly complete `.ovpn` client configuration file. You'll need to add references to or embed your private key and signed certificate. This will vary based on how your private key is stored. If your following the guide in the blog post mentioned above you'd do this using the OpenVPN option `cryptoapicert`.
196 |
197 | ## Revoke client access
198 |
199 | First connect to the VPN. To revoke `cool_client`'s access
200 |
201 | ansible-playbook playbooks/revoke_client -e client=cool_client
202 |
203 | ## Audit server
204 |
205 | First connect to the VPN. Run
206 |
207 | ansible-playbook playbooks/audit.yml
208 |
209 | The reports will be placed in `fetched_creds/[client_ip]/`
210 |
211 | # Contributing
212 |
213 | Contributions via pull request, feedback, bug reports are all welcome.
214 |
--------------------------------------------------------------------------------
/playbooks/roles/openvpn/templates/etc_dnsmasq.conf.j2:
--------------------------------------------------------------------------------
1 | # Configuration file for dnsmasq.
2 | #
3 | # Format is one option per line, legal options are the same
4 | # as the long options legal on the command line. See
5 | # "/usr/sbin/dnsmasq --help" or "man 8 dnsmasq" for details.
6 |
7 | # Listen on this specific port instead of the standard DNS port
8 | # (53). Setting this to zero completely disables DNS function,
9 | # leaving only DHCP and/or TFTP.
10 | #port=5353
11 |
12 | # The following two options make you a better netizen, since they
13 | # tell dnsmasq to filter out queries which the public DNS cannot
14 | # answer, and which load the servers (especially the root servers)
15 | # unnecessarily. If you have a dial-on-demand link they also stop
16 | # these requests from bringing up the link unnecessarily.
17 |
18 | # Never forward plain names (without a dot or domain part)
19 | domain-needed
20 |
21 | # Never forward addresses in the non-routed address spaces.
22 | bogus-priv
23 |
24 |
25 | # Uncomment this to filter useless windows-originated DNS requests
26 | # which can trigger dial-on-demand links needlessly.
27 | # Note that (amongst other things) this blocks all SRV requests,
28 | # so don't use it if you use eg Kerberos, SIP, XMMP or Google-talk.
29 | # This option only affects forwarding, SRV records originating for
30 | # dnsmasq (via srv-host= lines) are not suppressed by it.
31 | #filterwin2k
32 |
33 | # Change this line if you want dns to get its upstream servers from
34 | # somewhere other that /etc/resolv.conf
35 | #resolv-file=
36 |
37 | # By default, dnsmasq will send queries to any of the upstream
38 | # servers it knows about and tries to favour servers to are known
39 | # to be up. Uncommenting this forces dnsmasq to try each query
40 | # with each server strictly in the order they appear in
41 | # /etc/resolv.conf
42 | #strict-order
43 |
44 | # If you don't want dnsmasq to read /etc/resolv.conf or any other
45 | # file, getting its servers from this file instead (see below), then
46 | # uncomment this.
47 | no-resolv
48 |
49 | # If you don't want dnsmasq to poll /etc/resolv.conf or other resolv
50 | # files for changes and re-read them then uncomment this.
51 | #no-poll
52 |
53 | # Add other name servers here, with domain specs if they are for
54 | # non-public domains.
55 | {% for item in upstream_dns_servers %}
56 | server={{ item }}
57 | {% endfor %}
58 |
59 | # Example of routing PTR queries to nameservers: this will send all
60 | # address->name queries for 192.168.3/24 to nameserver 10.1.2.3
61 | #server=/3.168.192.in-addr.arpa/10.1.2.3
62 |
63 | # Add local-only domains here, queries in these domains are answered
64 | # from /etc/hosts or DHCP only.
65 | #local=/localnet/
66 |
67 | # Add domains which you want to force to an IP address here.
68 | # The example below send any host in double-click.net to a local
69 | # web-server.
70 | #address=/double-click.net/127.0.0.1
71 |
72 | # --address (and --server) work with IPv6 addresses too.
73 | #address=/www.thekelleys.org.uk/fe80::20d:60ff:fe36:f83
74 |
75 | # You can control how dnsmasq talks to a server: this forces
76 | # queries to 10.1.2.3 to be routed via eth1
77 | # server=10.1.2.3@eth1
78 |
79 | # and this sets the source (ie local) address used to talk to
80 | # 10.1.2.3 to 192.168.1.1 port 55 (there must be a interface with that
81 | # IP on the machine, obviously).
82 | # server=10.1.2.3@192.168.1.1#55
83 |
84 | # If you want dnsmasq to change uid and gid to something other
85 | # than the default, edit the following lines.
86 | user={{ dns_user }}
87 | group={{ dns_group }}
88 |
89 | # If you want dnsmasq to listen for DHCP and DNS requests only on
90 | # specified interfaces (and the loopback) give the name of the
91 | # interface (eg eth0) here.
92 | # Repeat the line for more than one interface.
93 | #interface=
94 | # Or you can specify which interface _not_ to listen on
95 | #except-interface=
96 | # Or which to listen on by address (remember to include 127.0.0.1 if
97 | # you use this.)
98 | #listen-address=
99 | listen-address=127.0.0.1{% for instance in openvpn_instances %},{{ instance.gateway }}{% endfor %}
100 |
101 | # If you want dnsmasq to provide only DNS service on an interface,
102 | # configure it as shown above, and then use the following line to
103 | # disable DHCP and TFTP on it.
104 | #no-dhcp-interface=
105 |
106 | # On systems which support it, dnsmasq binds the wildcard address,
107 | # even when it is listening on only some interfaces. It then discards
108 | # requests that it shouldn't reply to. This has the advantage of
109 | # working even when interfaces come and go and change address. If you
110 | # want dnsmasq to really bind only the interfaces it is listening on,
111 | # uncomment this option. About the only time you may need this is when
112 | # running another nameserver on the same machine.
113 | #bind-interfaces
114 |
115 | # If you don't want dnsmasq to read /etc/hosts, uncomment the
116 | # following line.
117 | #no-hosts
118 | # or if you want it to read another file, as well as /etc/hosts, use
119 | # this.
120 | #addn-hosts=/etc/banner_add_hosts
121 |
122 | # Set this (and domain: see below) if you want to have a domain
123 | # automatically added to simple names in a hosts-file.
124 | #expand-hosts
125 |
126 | # Set the domain for dnsmasq. this is optional, but if it is set, it
127 | # does the following things.
128 | # 1) Allows DHCP hosts to have fully qualified domain names, as long
129 | # as the domain part matches this setting.
130 | # 2) Sets the "domain" DHCP option thereby potentially setting the
131 | # domain of all systems configured by DHCP
132 | # 3) Provides the domain part for "expand-hosts"
133 | #domain=thekelleys.org.uk
134 |
135 | # Set a different domain for a particular subnet
136 | #domain=wireless.thekelleys.org.uk,192.168.2.0/24
137 |
138 | # Same idea, but range rather then subnet
139 | #domain=reserved.thekelleys.org.uk,192.68.3.100,192.168.3.200
140 |
141 | # Uncomment this to enable the integrated DHCP server, you need
142 | # to supply the range of addresses available for lease and optionally
143 | # a lease time. If you have more than one network, you will need to
144 | # repeat this for each network on which you want to supply DHCP
145 | # service.
146 | #dhcp-range=192.168.0.50,192.168.0.150,12h
147 |
148 | # This is an example of a DHCP range where the netmask is given. This
149 | # is needed for networks we reach the dnsmasq DHCP server via a relay
150 | # agent. If you don't know what a DHCP relay agent is, you probably
151 | # don't need to worry about this.
152 | #dhcp-range=192.168.0.50,192.168.0.150,255.255.255.0,12h
153 |
154 | # This is an example of a DHCP range which sets a tag, so that
155 | # some DHCP options may be set only for this network.
156 | #dhcp-range=set:red,192.168.0.50,192.168.0.150
157 |
158 | # Use this DHCP range only when the tag "green" is set.
159 | #dhcp-range=tag:green,192.168.0.50,192.168.0.150,12h
160 |
161 | # Specify a subnet which can't be used for dynamic address allocation,
162 | # is available for hosts with matching --dhcp-host lines. Note that
163 | # dhcp-host declarations will be ignored unless there is a dhcp-range
164 | # of some type for the subnet in question.
165 | # In this case the netmask is implied (it comes from the network
166 | # configuration on the machine running dnsmasq) it is possible to give
167 | # an explicit netmask instead.
168 | #dhcp-range=192.168.0.0,static
169 |
170 | # Enable DHCPv6. Note that the prefix-length does not need to be specified
171 | # and defaults to 64 if missing/
172 | #dhcp-range=1234::2, 1234::500, 64, 12h
173 |
174 | # Do Router Advertisements, BUT NOT DHCP for this subnet.
175 | #dhcp-range=1234::, ra-only
176 |
177 | # Do Router Advertisements, BUT NOT DHCP for this subnet, also try and
178 | # add names to the DNS for the IPv6 address of SLAAC-configured dual-stack
179 | # hosts. Use the DHCPv4 lease to derive the name, network segment and
180 | # MAC address and assume that the host will also have an
181 | # IPv6 address calculated using the SLAAC alogrithm.
182 | #dhcp-range=1234::, ra-names
183 |
184 | # Do Router Advertisements, BUT NOT DHCP for this subnet.
185 | # Set the lifetime to 46 hours. (Note: minimum lifetime is 2 hours.)
186 | #dhcp-range=1234::, ra-only, 48h
187 |
188 | # Do DHCP and Router Advertisements for this subnet. Set the A bit in the RA
189 | # so that clients can use SLAAC addresses as well as DHCP ones.
190 | #dhcp-range=1234::2, 1234::500, slaac
191 |
192 | # Do Router Advertisements and stateless DHCP for this subnet. Clients will
193 | # not get addresses from DHCP, but they will get other configuration information.
194 | # They will use SLAAC for addresses.
195 | #dhcp-range=1234::, ra-stateless
196 |
197 | # Do stateless DHCP, SLAAC, and generate DNS names for SLAAC addresses
198 | # from DHCPv4 leases.
199 | #dhcp-range=1234::, ra-stateless, ra-names
200 |
201 | # Do router advertisements for all subnets where we're doing DHCPv6
202 | # Unless overriden by ra-stateless, ra-names, et al, the router
203 | # advertisements will have the M and O bits set, so that the clients
204 | # get addresses and configuration from DHCPv6, and the A bit reset, so the
205 | # clients don't use SLAAC addresses.
206 | #enable-ra
207 |
208 | # Supply parameters for specified hosts using DHCP. There are lots
209 | # of valid alternatives, so we will give examples of each. Note that
210 | # IP addresses DO NOT have to be in the range given above, they just
211 | # need to be on the same network. The order of the parameters in these
212 | # do not matter, it's permissible to give name, address and MAC in any
213 | # order.
214 |
215 | # Always allocate the host with Ethernet address 11:22:33:44:55:66
216 | # The IP address 192.168.0.60
217 | #dhcp-host=11:22:33:44:55:66,192.168.0.60
218 |
219 | # Always set the name of the host with hardware address
220 | # 11:22:33:44:55:66 to be "fred"
221 | #dhcp-host=11:22:33:44:55:66,fred
222 |
223 | # Always give the host with Ethernet address 11:22:33:44:55:66
224 | # the name fred and IP address 192.168.0.60 and lease time 45 minutes
225 | #dhcp-host=11:22:33:44:55:66,fred,192.168.0.60,45m
226 |
227 | # Give a host with Ethernet address 11:22:33:44:55:66 or
228 | # 12:34:56:78:90:12 the IP address 192.168.0.60. Dnsmasq will assume
229 | # that these two Ethernet interfaces will never be in use at the same
230 | # time, and give the IP address to the second, even if it is already
231 | # in use by the first. Useful for laptops with wired and wireless
232 | # addresses.
233 | #dhcp-host=11:22:33:44:55:66,12:34:56:78:90:12,192.168.0.60
234 |
235 | # Give the machine which says its name is "bert" IP address
236 | # 192.168.0.70 and an infinite lease
237 | #dhcp-host=bert,192.168.0.70,infinite
238 |
239 | # Always give the host with client identifier 01:02:02:04
240 | # the IP address 192.168.0.60
241 | #dhcp-host=id:01:02:02:04,192.168.0.60
242 |
243 | # Always give the host with client identifier "marjorie"
244 | # the IP address 192.168.0.60
245 | #dhcp-host=id:marjorie,192.168.0.60
246 |
247 | # Enable the address given for "judge" in /etc/hosts
248 | # to be given to a machine presenting the name "judge" when
249 | # it asks for a DHCP lease.
250 | #dhcp-host=judge
251 |
252 | # Never offer DHCP service to a machine whose Ethernet
253 | # address is 11:22:33:44:55:66
254 | #dhcp-host=11:22:33:44:55:66,ignore
255 |
256 | # Ignore any client-id presented by the machine with Ethernet
257 | # address 11:22:33:44:55:66. This is useful to prevent a machine
258 | # being treated differently when running under different OS's or
259 | # between PXE boot and OS boot.
260 | #dhcp-host=11:22:33:44:55:66,id:*
261 |
262 | # Send extra options which are tagged as "red" to
263 | # the machine with Ethernet address 11:22:33:44:55:66
264 | #dhcp-host=11:22:33:44:55:66,set:red
265 |
266 | # Send extra options which are tagged as "red" to
267 | # any machine with Ethernet address starting 11:22:33:
268 | #dhcp-host=11:22:33:*:*:*,set:red
269 |
270 | # Give a fixed IPv6 address and name to client with
271 | # DUID 00:01:00:01:16:d2:83:fc:92:d4:19:e2:d8:b2
272 | # Note the MAC addresses CANNOT be used to identify DHCPv6 clients.
273 | # Note also the they [] around the IPv6 address are obilgatory.
274 | #dhcp-host=id:00:01:00:01:16:d2:83:fc:92:d4:19:e2:d8:b2, fred, [1234::5]
275 |
276 | # Ignore any clients which are not specified in dhcp-host lines
277 | # or /etc/ethers. Equivalent to ISC "deny unknown-clients".
278 | # This relies on the special "known" tag which is set when
279 | # a host is matched.
280 | #dhcp-ignore=tag:!known
281 |
282 | # Send extra options which are tagged as "red" to any machine whose
283 | # DHCP vendorclass string includes the substring "Linux"
284 | #dhcp-vendorclass=set:red,Linux
285 |
286 | # Send extra options which are tagged as "red" to any machine one
287 | # of whose DHCP userclass strings includes the substring "accounts"
288 | #dhcp-userclass=set:red,accounts
289 |
290 | # Send extra options which are tagged as "red" to any machine whose
291 | # MAC address matches the pattern.
292 | #dhcp-mac=set:red,00:60:8C:*:*:*
293 |
294 | # If this line is uncommented, dnsmasq will read /etc/ethers and act
295 | # on the ethernet-address/IP pairs found there just as if they had
296 | # been given as --dhcp-host options. Useful if you keep
297 | # MAC-address/host mappings there for other purposes.
298 | #read-ethers
299 |
300 | # Send options to hosts which ask for a DHCP lease.
301 | # See RFC 2132 for details of available options.
302 | # Common options can be given to dnsmasq by name:
303 | # run "dnsmasq --help dhcp" to get a list.
304 | # Note that all the common settings, such as netmask and
305 | # broadcast address, DNS server and default route, are given
306 | # sane defaults by dnsmasq. You very likely will not need
307 | # any dhcp-options. If you use Windows clients and Samba, there
308 | # are some options which are recommended, they are detailed at the
309 | # end of this section.
310 |
311 | # Override the default route supplied by dnsmasq, which assumes the
312 | # router is the same machine as the one running dnsmasq.
313 | #dhcp-option=3,1.2.3.4
314 |
315 | # Do the same thing, but using the option name
316 | #dhcp-option=option:router,1.2.3.4
317 |
318 | # Override the default route supplied by dnsmasq and send no default
319 | # route at all. Note that this only works for the options sent by
320 | # default (1, 3, 6, 12, 28) the same line will send a zero-length option
321 | # for all other option numbers.
322 | #dhcp-option=3
323 |
324 | # Set the NTP time server addresses to 192.168.0.4 and 10.10.0.5
325 | #dhcp-option=option:ntp-server,192.168.0.4,10.10.0.5
326 |
327 | # Send DHCPv6 option. Note [] around IPv6 addresses.
328 | #dhcp-option=option6:dns-server,[1234::77],[1234::88]
329 |
330 | # Send DHCPv6 option for namservers as the machine running
331 | # dnsmasq and another.
332 | #dhcp-option=option6:dns-server,[::],[1234::88]
333 |
334 | # Set the NTP time server address to be the same machine as
335 | # is running dnsmasq
336 | #dhcp-option=42,0.0.0.0
337 |
338 | # Set the NIS domain name to "welly"
339 | #dhcp-option=40,welly
340 |
341 | # Set the default time-to-live to 50
342 | #dhcp-option=23,50
343 |
344 | # Set the "all subnets are local" flag
345 | #dhcp-option=27,1
346 |
347 | # Send the etherboot magic flag and then etherboot options (a string).
348 | #dhcp-option=128,e4:45:74:68:00:00
349 | #dhcp-option=129,NIC=eepro100
350 |
351 | # Specify an option which will only be sent to the "red" network
352 | # (see dhcp-range for the declaration of the "red" network)
353 | # Note that the tag: part must precede the option: part.
354 | #dhcp-option = tag:red, option:ntp-server, 192.168.1.1
355 |
356 | # The following DHCP options set up dnsmasq in the same way as is specified
357 | # for the ISC dhcpcd in
358 | # http://www.samba.org/samba/ftp/docs/textdocs/DHCP-Server-Configuration.txt
359 | # adapted for a typical dnsmasq installation where the host running
360 | # dnsmasq is also the host running samba.
361 | # you may want to uncomment some or all of them if you use
362 | # Windows clients and Samba.
363 | #dhcp-option=19,0 # option ip-forwarding off
364 | #dhcp-option=44,0.0.0.0 # set netbios-over-TCP/IP nameserver(s) aka WINS server(s)
365 | #dhcp-option=45,0.0.0.0 # netbios datagram distribution server
366 | #dhcp-option=46,8 # netbios node type
367 |
368 | # Send an empty WPAD option. This may be REQUIRED to get windows 7 to behave.
369 | #dhcp-option=252,"\n"
370 |
371 | # Send RFC-3397 DNS domain search DHCP option. WARNING: Your DHCP client
372 | # probably doesn't support this......
373 | #dhcp-option=option:domain-search,eng.apple.com,marketing.apple.com
374 |
375 | # Send RFC-3442 classless static routes (note the netmask encoding)
376 | #dhcp-option=121,192.168.1.0/24,1.2.3.4,10.0.0.0/8,5.6.7.8
377 |
378 | # Send vendor-class specific options encapsulated in DHCP option 43.
379 | # The meaning of the options is defined by the vendor-class so
380 | # options are sent only when the client supplied vendor class
381 | # matches the class given here. (A substring match is OK, so "MSFT"
382 | # matches "MSFT" and "MSFT 5.0"). This example sets the
383 | # mtftp address to 0.0.0.0 for PXEClients.
384 | #dhcp-option=vendor:PXEClient,1,0.0.0.0
385 |
386 | # Send microsoft-specific option to tell windows to release the DHCP lease
387 | # when it shuts down. Note the "i" flag, to tell dnsmasq to send the
388 | # value as a four-byte integer - that's what microsoft wants. See
389 | # http://technet2.microsoft.com/WindowsServer/en/library/a70f1bb7-d2d4-49f0-96d6-4b7414ecfaae1033.mspx?mfr=true
390 | #dhcp-option=vendor:MSFT,2,1i
391 |
392 | # Send the Encapsulated-vendor-class ID needed by some configurations of
393 | # Etherboot to allow is to recognise the DHCP server.
394 | #dhcp-option=vendor:Etherboot,60,"Etherboot"
395 |
396 | # Send options to PXELinux. Note that we need to send the options even
397 | # though they don't appear in the parameter request list, so we need
398 | # to use dhcp-option-force here.
399 | # See http://syslinux.zytor.com/pxe.php#special for details.
400 | # Magic number - needed before anything else is recognised
401 | #dhcp-option-force=208,f1:00:74:7e
402 | # Configuration file name
403 | #dhcp-option-force=209,configs/common
404 | # Path prefix
405 | #dhcp-option-force=210,/tftpboot/pxelinux/files/
406 | # Reboot time. (Note 'i' to send 32-bit value)
407 | #dhcp-option-force=211,30i
408 |
409 | # Set the boot filename for netboot/PXE. You will only need
410 | # this is you want to boot machines over the network and you will need
411 | # a TFTP server; either dnsmasq's built in TFTP server or an
412 | # external one. (See below for how to enable the TFTP server.)
413 | #dhcp-boot=pxelinux.0
414 |
415 | # The same as above, but use custom tftp-server instead machine running dnsmasq
416 | #dhcp-boot=pxelinux,server.name,192.168.1.100
417 |
418 | # Boot for Etherboot gPXE. The idea is to send two different
419 | # filenames, the first loads gPXE, and the second tells gPXE what to
420 | # load. The dhcp-match sets the gpxe tag for requests from gPXE.
421 | #dhcp-match=set:gpxe,175 # gPXE sends a 175 option.
422 | #dhcp-boot=tag:!gpxe,undionly.kpxe
423 | #dhcp-boot=mybootimage
424 |
425 | # Encapsulated options for Etherboot gPXE. All the options are
426 | # encapsulated within option 175
427 | #dhcp-option=encap:175, 1, 5b # priority code
428 | #dhcp-option=encap:175, 176, 1b # no-proxydhcp
429 | #dhcp-option=encap:175, 177, string # bus-id
430 | #dhcp-option=encap:175, 189, 1b # BIOS drive code
431 | #dhcp-option=encap:175, 190, user # iSCSI username
432 | #dhcp-option=encap:175, 191, pass # iSCSI password
433 |
434 | # Test for the architecture of a netboot client. PXE clients are
435 | # supposed to send their architecture as option 93. (See RFC 4578)
436 | #dhcp-match=peecees, option:client-arch, 0 #x86-32
437 | #dhcp-match=itanics, option:client-arch, 2 #IA64
438 | #dhcp-match=hammers, option:client-arch, 6 #x86-64
439 | #dhcp-match=mactels, option:client-arch, 7 #EFI x86-64
440 |
441 | # Do real PXE, rather than just booting a single file, this is an
442 | # alternative to dhcp-boot.
443 | #pxe-prompt="What system shall I netboot?"
444 | # or with timeout before first available action is taken:
445 | #pxe-prompt="Press F8 for menu.", 60
446 |
447 | # Available boot services. for PXE.
448 | #pxe-service=x86PC, "Boot from local disk"
449 |
450 | # Loads /pxelinux.0 from dnsmasq TFTP server.
451 | #pxe-service=x86PC, "Install Linux", pxelinux
452 |
453 | # Loads /pxelinux.0 from TFTP server at 1.2.3.4.
454 | # Beware this fails on old PXE ROMS.
455 | #pxe-service=x86PC, "Install Linux", pxelinux, 1.2.3.4
456 |
457 | # Use bootserver on network, found my multicast or broadcast.
458 | #pxe-service=x86PC, "Install windows from RIS server", 1
459 |
460 | # Use bootserver at a known IP address.
461 | #pxe-service=x86PC, "Install windows from RIS server", 1, 1.2.3.4
462 |
463 | # If you have multicast-FTP available,
464 | # information for that can be passed in a similar way using options 1
465 | # to 5. See page 19 of
466 | # http://download.intel.com/design/archives/wfm/downloads/pxespec.pdf
467 |
468 |
469 | # Enable dnsmasq's built-in TFTP server
470 | #enable-tftp
471 |
472 | # Set the root directory for files available via FTP.
473 | #tftp-root=/var/ftpd
474 |
475 | # Make the TFTP server more secure: with this set, only files owned by
476 | # the user dnsmasq is running as will be send over the net.
477 | #tftp-secure
478 |
479 | # This option stops dnsmasq from negotiating a larger blocksize for TFTP
480 | # transfers. It will slow things down, but may rescue some broken TFTP
481 | # clients.
482 | #tftp-no-blocksize
483 |
484 | # Set the boot file name only when the "red" tag is set.
485 | #dhcp-boot=net:red,pxelinux.red-net
486 |
487 | # An example of dhcp-boot with an external TFTP server: the name and IP
488 | # address of the server are given after the filename.
489 | # Can fail with old PXE ROMS. Overridden by --pxe-service.
490 | #dhcp-boot=/var/ftpd/pxelinux.0,boothost,192.168.0.3
491 |
492 | # If there are multiple external tftp servers having a same name
493 | # (using /etc/hosts) then that name can be specified as the
494 | # tftp_servername (the third option to dhcp-boot) and in that
495 | # case dnsmasq resolves this name and returns the resultant IP
496 | # addresses in round robin fasion. This facility can be used to
497 | # load balance the tftp load among a set of servers.
498 | #dhcp-boot=/var/ftpd/pxelinux.0,boothost,tftp_server_name
499 |
500 | # Set the limit on DHCP leases, the default is 150
501 | #dhcp-lease-max=150
502 |
503 | # The DHCP server needs somewhere on disk to keep its lease database.
504 | # This defaults to a sane location, but if you want to change it, use
505 | # the line below.
506 | #dhcp-leasefile=/var/lib/misc/dnsmasq.leases
507 |
508 | # Set the DHCP server to authoritative mode. In this mode it will barge in
509 | # and take over the lease for any client which broadcasts on the network,
510 | # whether it has a record of the lease or not. This avoids long timeouts
511 | # when a machine wakes up on a new network. DO NOT enable this if there's
512 | # the slightest chance that you might end up accidentally configuring a DHCP
513 | # server for your campus/company accidentally. The ISC server uses
514 | # the same option, and this URL provides more information:
515 | # http://www.isc.org/files/auth.html
516 | #dhcp-authoritative
517 |
518 | # Run an executable when a DHCP lease is created or destroyed.
519 | # The arguments sent to the script are "add" or "del",
520 | # then the MAC address, the IP address and finally the hostname
521 | # if there is one.
522 | #dhcp-script=/bin/echo
523 |
524 | # Set the cachesize here.
525 | #cache-size=150
526 |
527 | # If you want to disable negative caching, uncomment this.
528 | #no-negcache
529 |
530 | # Normally responses which come form /etc/hosts and the DHCP lease
531 | # file have Time-To-Live set as zero, which conventionally means
532 | # do not cache further. If you are happy to trade lower load on the
533 | # server for potentially stale date, you can set a time-to-live (in
534 | # seconds) here.
535 | #local-ttl=
536 |
537 | # If you want dnsmasq to detect attempts by Verisign to send queries
538 | # to unregistered .com and .net hosts to its sitefinder service and
539 | # have dnsmasq instead return the correct NXDOMAIN response, uncomment
540 | # this line. You can add similar lines to do the same for other
541 | # registries which have implemented wildcard A records.
542 | #bogus-nxdomain=64.94.110.11
543 |
544 | # If you want to fix up DNS results from upstream servers, use the
545 | # alias option. This only works for IPv4.
546 | # This alias makes a result of 1.2.3.4 appear as 5.6.7.8
547 | #alias=1.2.3.4,5.6.7.8
548 | # and this maps 1.2.3.x to 5.6.7.x
549 | #alias=1.2.3.0,5.6.7.0,255.255.255.0
550 | # and this maps 192.168.0.10->192.168.0.40 to 10.0.0.10->10.0.0.40
551 | #alias=192.168.0.10-192.168.0.40,10.0.0.0,255.255.255.0
552 |
553 | # Change these lines if you want dnsmasq to serve MX records.
554 |
555 | # Return an MX record named "maildomain.com" with target
556 | # servermachine.com and preference 50
557 | #mx-host=maildomain.com,servermachine.com,50
558 |
559 | # Set the default target for MX records created using the localmx option.
560 | #mx-target=servermachine.com
561 |
562 | # Return an MX record pointing to the mx-target for all local
563 | # machines.
564 | #localmx
565 |
566 | # Return an MX record pointing to itself for all local machines.
567 | #selfmx
568 |
569 | # Change the following lines if you want dnsmasq to serve SRV
570 | # records. These are useful if you want to serve ldap requests for
571 | # Active Directory and other windows-originated DNS requests.
572 | # See RFC 2782.
573 | # You may add multiple srv-host lines.
574 | # The fields are ,,,,
575 | # If the domain part if missing from the name (so that is just has the
576 | # service and protocol sections) then the domain given by the domain=
577 | # config option is used. (Note that expand-hosts does not need to be
578 | # set for this to work.)
579 |
580 | # A SRV record sending LDAP for the example.com domain to
581 | # ldapserver.example.com port 389
582 | #srv-host=_ldap._tcp.example.com,ldapserver.example.com,389
583 |
584 | # A SRV record sending LDAP for the example.com domain to
585 | # ldapserver.example.com port 389 (using domain=)
586 | #domain=example.com
587 | #srv-host=_ldap._tcp,ldapserver.example.com,389
588 |
589 | # Two SRV records for LDAP, each with different priorities
590 | #srv-host=_ldap._tcp.example.com,ldapserver.example.com,389,1
591 | #srv-host=_ldap._tcp.example.com,ldapserver.example.com,389,2
592 |
593 | # A SRV record indicating that there is no LDAP server for the domain
594 | # example.com
595 | #srv-host=_ldap._tcp.example.com
596 |
597 | # The following line shows how to make dnsmasq serve an arbitrary PTR
598 | # record. This is useful for DNS-SD. (Note that the
599 | # domain-name expansion done for SRV records _does_not
600 | # occur for PTR records.)
601 | #ptr-record=_http._tcp.dns-sd-services,"New Employee Page._http._tcp.dns-sd-services"
602 |
603 | # Change the following lines to enable dnsmasq to serve TXT records.
604 | # These are used for things like SPF and zeroconf. (Note that the
605 | # domain-name expansion done for SRV records _does_not
606 | # occur for TXT records.)
607 |
608 | #Example SPF.
609 | #txt-record=example.com,"v=spf1 a -all"
610 |
611 | #Example zeroconf
612 | #txt-record=_http._tcp.example.com,name=value,paper=A4
613 |
614 | # Provide an alias for a "local" DNS name. Note that this _only_ works
615 | # for targets which are names from DHCP or /etc/hosts. Give host
616 | # "bert" another name, bertrand
617 | #cname=bertand,bert
618 |
619 | # For debugging purposes, log each DNS query as it passes through
620 | # dnsmasq.
621 | #log-queries
622 |
623 | # Log lots of extra information about DHCP transactions.
624 | #log-dhcp
625 |
626 | # Include a another lot of configuration options.
627 | #conf-file=/etc/dnsmasq.more.conf
628 | #conf-dir=/etc/dnsmasq.d
629 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 | {one line to give the program's name and a brief idea of what it does.}
635 | Copyright (C) {year} {name of author}
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | {project} Copyright (C) {year} {fullname}
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------