diff --git a/ansible.cfg b/ansible.cfg new file mode 100644 index 0000000..26730d6 --- /dev/null +++ b/ansible.cfg @@ -0,0 +1,17 @@ +[defaults] +inventory = inventories/prod/hosts.ini + +remote_user = root + +host_key_checking = False +retry_files_enabled = False + +forks = 10 +timeout = 30 + +interpreter_python = auto_silent + +roles_path = roles + +[ssh_connection] +pipelining = True \ No newline at end of file diff --git a/inventories/prod/group_vars/all.yml b/inventories/prod/group_vars/all.yml new file mode 100644 index 0000000..8bd753c --- /dev/null +++ b/inventories/prod/group_vars/all.yml @@ -0,0 +1,11 @@ +timezone: Europe/Berlin + +common_packages: + - vim + - curl + - wget + - jq + - net-tools + - tcpdump + - htop + - unzip \ No newline at end of file diff --git a/inventories/prod/hosts.ini b/inventories/prod/hosts.ini new file mode 100644 index 0000000..38f1e28 --- /dev/null +++ b/inventories/prod/hosts.ini @@ -0,0 +1,4 @@ +[vpn_nodes] +# vpn01 ansible_host=65.108.87.246 private_ip=10.100.0.1 +vpn01-test ansible_host=65.108.95.144 private_ip=10.100.0.2 +# vpn01-bmw ansible_host=65.108.93.171 private_ip=10.100.0.3 \ No newline at end of file diff --git a/playbooks/bootstrap.yml b/playbooks/bootstrap.yml new file mode 100644 index 0000000..491e85b --- /dev/null +++ b/playbooks/bootstrap.yml @@ -0,0 +1,7 @@ +--- +- name: Bootstrap VPN nodes + hosts: vpn_nodes + become: true + + roles: + - common \ No newline at end of file diff --git a/playbooks/monitoring.yml b/playbooks/monitoring.yml new file mode 100644 index 0000000..e69de29 diff --git a/playbooks/networking.yml b/playbooks/networking.yml new file mode 100644 index 0000000..97caa68 --- /dev/null +++ b/playbooks/networking.yml @@ -0,0 +1,7 @@ +--- +- name: Configure networking + hosts: vpn_nodes + become: true + + roles: + - networking \ No newline at end of file diff --git a/playbooks/openvpn.yml b/playbooks/openvpn.yml new file mode 100644 index 0000000..85e9754 --- /dev/null +++ b/playbooks/openvpn.yml @@ -0,0 +1,10 @@ +--- +- name: Configure OpenVPN nodes + hosts: vpn_nodes + become: true + + roles: + - common + - networking + - radius-nat + - openvpn \ No newline at end of file diff --git a/playbooks/radius-nat.yml b/playbooks/radius-nat.yml new file mode 100644 index 0000000..4e5deef --- /dev/null +++ b/playbooks/radius-nat.yml @@ -0,0 +1,7 @@ +--- +- name: Configure OpenVPN nodes + hosts: vpn_nodes + become: true + + roles: + - radius-nat \ No newline at end of file diff --git a/roles/common/handlers/main.yml b/roles/common/handlers/main.yml new file mode 100644 index 0000000..73b314f --- /dev/null +++ b/roles/common/handlers/main.yml @@ -0,0 +1 @@ +--- \ No newline at end of file diff --git a/roles/common/tasks/main.yml b/roles/common/tasks/main.yml new file mode 100644 index 0000000..17fd83a --- /dev/null +++ b/roles/common/tasks/main.yml @@ -0,0 +1,18 @@ +--- +- name: Update apt cache + apt: + update_cache: true + cache_valid_time: 3600 + +- name: Upgrade packages + apt: + upgrade: dist + +- name: Install common packages + apt: + name: "{{ common_packages }}" + state: present + +- name: Configure timezone + timezone: + name: "{{ timezone }}" \ No newline at end of file diff --git a/roles/networking/README.md b/roles/networking/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/roles/networking/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/roles/networking/defaults/main.yml b/roles/networking/defaults/main.yml new file mode 100644 index 0000000..4afc3c6 --- /dev/null +++ b/roles/networking/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for roles/networking diff --git a/roles/networking/handlers/main.yml b/roles/networking/handlers/main.yml new file mode 100644 index 0000000..19e0c71 --- /dev/null +++ b/roles/networking/handlers/main.yml @@ -0,0 +1,4 @@ +--- +# handlers file for roles/networking +- name: reload sysctl + command: sysctl --system \ No newline at end of file diff --git a/roles/networking/tasks/bridge.yml b/roles/networking/tasks/bridge.yml new file mode 100644 index 0000000..da17cda --- /dev/null +++ b/roles/networking/tasks/bridge.yml @@ -0,0 +1,19 @@ +--- +- name: Ensure bridge-utils is installed + apt: + name: + - bridge-utils + - vlan + - iproute2 + state: present + +- name: Create bridge if missing + command: ip link add br-main-vpn type bridge + register: bridge_create + failed_when: false + changed_when: bridge_create.rc == 0 + +- name: Bring bridge up + command: ip link set br-main-vpn up + failed_when: false + changed_when: false \ No newline at end of file diff --git a/roles/networking/tasks/main.yml b/roles/networking/tasks/main.yml new file mode 100644 index 0000000..18e0c67 --- /dev/null +++ b/roles/networking/tasks/main.yml @@ -0,0 +1,16 @@ +--- +# tasks file for roles/networking +- name: Deploy networking sysctl configuration + template: + src: 99-openvpn.conf.j2 + dest: /etc/sysctl.d/99-openvpn.conf + owner: root + group: root + mode: "0644" + notify: reload sysctl + +- name: Apply sysctl immediately + command: sysctl --system + changed_when: false + +- import_tasks: bridge.yml \ No newline at end of file diff --git a/roles/networking/templates/99-openvpn.conf.j2 b/roles/networking/templates/99-openvpn.conf.j2 new file mode 100644 index 0000000..cfb3c87 --- /dev/null +++ b/roles/networking/templates/99-openvpn.conf.j2 @@ -0,0 +1,6 @@ +net.ipv4.ip_forward=1 + +net.ipv4.conf.all.rp_filter=0 +net.ipv4.conf.default.rp_filter=0 + +net.ipv4.conf.enp7s0.rp_filter=0 \ No newline at end of file diff --git a/roles/openvpn/README.md b/roles/openvpn/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/roles/openvpn/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/roles/openvpn/defaults/main.yml b/roles/openvpn/defaults/main.yml new file mode 100644 index 0000000..a829512 --- /dev/null +++ b/roles/openvpn/defaults/main.yml @@ -0,0 +1,17 @@ +openvpn_port: 1194 +openvpn_proto: tcp +openvpn_mode: tap0 + +openvpn_ccd_dir: /etc/openvpn/ccd +openvpn_cert_dir: /etc/openvpn/certs +openvpn_config_dir: /etc/openvpn/server + +openvpn_service: openvpn-server@server + +radius_server: 10.1.0.101 +radius_auth_port: 1812 +radius_acct_port: 1813 +radius_shared_secret: aloulou + +nas_identifier: "{{ inventory_hostname }}" +nas_ip_address: "{{ private_ip }}" \ No newline at end of file diff --git a/roles/openvpn/files/certs/ca.crt b/roles/openvpn/files/certs/ca.crt new file mode 100644 index 0000000..0a7cca4 --- /dev/null +++ b/roles/openvpn/files/certs/ca.crt @@ -0,0 +1,23 @@ +-----BEGIN CERTIFICATE----- +MIID3DCCAsSgAwIBAgIIIWlpje69/KowDQYJKoZIhvcNAQELBQAwdDELMAkGA1UE +BhMCREUxCzAJBgNVBAYTAkRFMRAwDgYDV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pIVlJcqTl +Z8ILE5+Wi5sPK2QCCiYZngv+Piauo2cno9mKGkrNYQjI6Da0Ve8n+UIkGirbYQLb +nwwSHLUIoXhLMh21Gmlw6cHPlzUws+G8eyfGUYolE8S+K8Dlpmhhse1dGZhW/iDV +f8rOFkvWgtXIie5ljdSA2Ez9Tg1vQQIdgxKAW62I4Jk= +-----END CERTIFICATE----- \ No newline at end of file diff --git a/roles/openvpn/files/certs/server.crt b/roles/openvpn/files/certs/server.crt new file mode 100644 index 0000000..01c145d --- /dev/null +++ b/roles/openvpn/files/certs/server.crt @@ -0,0 +1,25 @@ +-----BEGIN CERTIFICATE----- +MIIEIzCCAwugAwIBAgIIXQADw2Y0rCkwDQYJKoZIhvcNAQELBQAwdDELMAkGA1UE +BhMCREUxCzAJBgNVBAYTAkRFMRAwDgYDVQQIEwdCYXZhcmlhMQ8wDQYDVQQHEwZN +dW5pY2gxEjAQBgNVBAoTCU15Q29tcGFueTEMMAoGA1UECxMDVlBOMRMwEQYDVQQD +EwpPcGVuVlBOLUNBMB4XDTI1MTExMTA5MjYwMFoXDTI2MTExMTA5MjYwMFowazEL +MAkGA1UEBhMCREUxEDAOBgNVBAgTB0JhdmFyaWExDzANBgNVBAcTBk11bmljaDES +MBAGA1UEChMJTXlDb21wYW55MQwwCgYDVQQLEwNWUE4xFzAVBgNVBAMTDjEyOC4x +NDAuMzEuMTMwMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAqS+40lrT +JnMvpdATIwPkK+tlgRSMP6o7T3lPrEQs5hs3i7cz/7iQyKA+m6aGbBeq9UkjZEn1 +YBL0B7W+JN5EKQIRB5CSP+dQPX1v29KJpg2pBERoz//q5s0HDDm+cGm7g/eyDoeU +mQRq2coJlSCTMxDBIbh5kBzWckA0wI1ttFJgrWkNg8vlC/tMcScUs8dUcq2fD2AK +p8MPlj6y2/P91VOcfKHied96tJFZ4AQa9NXgfKVpK/6SvofskorU3rdH9sDXPG1C +7uoenZwB9IxAaA7aAbp5vn7e/sQz51OkIYpJ/bmo19Gsr479swzLwiZIN/RTeC56 +2bkJTfwuECOK3QIDAQABo4HBMIG+MAwGA1UdEwEB/wQCMAAwHQYDVR0OBBYEFBYa +XMnt5E8Nm5QcEXoXoioOMRRXMB8GA1UdIwQYMBaAFKKI+gy0SqgucXKV2WDSDAJb +pIjiMAsGA1UdDwQEAwID6DATBgNVHSUEDDAKBggrBgEFBQcDATAZBgNVHREEEjAQ +gg4xMjguMTQwLjMxLjEzMDARBglghkgBhvhCAQEEBAMCBkAwHgYJYIZIAYb4QgEN +BBEWD3hjYSBjZXJ0aWZpY2F0ZTANBgkqhkiG9w0BAQsFAAOCAQEALsvqnSEoO82r +YxcH+Zo0+H4CdCYmwondZ7m0SuGaHDF0Sk1SecLVIKLMAZykzSEZPnYY9LancjCv +HYy2qtWYUxZxj5EwO1WUvxMzqpg6rCuUvlfZVBdoawjQq7N2FRgsZqA1GvCRo4g1 +FkH+KDL7EH77tMXQceJroM1/RFLotbwoT+QegENTHYf2pWTFikdMissSlWBzG7P/ +Vv3qY//LGJBtejvJWdNKE179S/X0Emyj0HWcNJ63ZxTvxbs+xVf4X4qNKY1JyGS2 +WtWquMJAfgD9hfr9fDptt+fAq4zTiTZ0Xrxs3uYo5xFszNvYevl4900ZvrQwygve +ywb75tRo2g== +-----END CERTIFICATE----- \ No newline at end of file diff --git a/roles/openvpn/files/certs/server.key b/roles/openvpn/files/certs/server.key new file mode 100644 index 0000000..b740748 --- /dev/null +++ b/roles/openvpn/files/certs/server.key @@ -0,0 +1,27 @@ +-----BEGIN RSA PRIVATE KEY----- +MIIEowIBAAKCAQEAqS+40lrTJnMvpdATIwPkK+tlgRSMP6o7T3lPrEQs5hs3i7cz +/7iQyKA+m6aGbBeq9UkjZEn1YBL0B7W+JN5EKQIRB5CSP+dQPX1v29KJpg2pBERo +z//q5s0HDDm+cGm7g/eyDoeUmQRq2coJlSCTMxDBIbh5kBzWckA0wI1ttFJgrWkN +g8vlC/tMc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mtXjDquQwzSB5YxQjNzn1CSPJ +OnINjocQEFCG2z/AfTau3RWUHRK9RJzkpXLFNAS2tSj8rpekiJnvDmwxg7Wjcm4k +GR/j0jE0y+aV/Ai6j9iGNPiye7si6YMhBVYjZWaugQ9k8LeNO8NIgCHxvczIg8R9 +J8M+gQKBgCa8WFdvu4mwjfX+rkOyVpkY/rmktgMot1YRarC9xSDaOydS5C1D++UU +NxPRDwb7Ci1GNPAEHofOXXDLFVwlqJFg8meoYET4tP5L5dKb0MlQfb2dWyCITsNf +WVBGoDNIW3jbOD5/hPS8TfFvAVsRggMQTPSiMr5Z+pLrIoj45VkO +-----END RSA PRIVATE KEY----- \ No newline at end of file diff --git a/roles/openvpn/files/client-connect.sh b/roles/openvpn/files/client-connect.sh new file mode 100644 index 0000000..c39946e --- /dev/null +++ b/roles/openvpn/files/client-connect.sh @@ -0,0 +1,10 @@ +#!/bin/bash +TENANT="${common_name#*@}" + +VLAN_ID=$(( ( $(echo -n "$TENANT" | cksum | cut -d' ' -f1) % 3000 ) + 100 )) + +if [ -n "$VLAN_ID" ]; then + echo "vlan-pvid $VLAN_ID" >> "$client_connect_config_file" +fi + +exit 0 \ No newline at end of file diff --git a/roles/openvpn/handlers/main.yml b/roles/openvpn/handlers/main.yml new file mode 100644 index 0000000..801dfcc --- /dev/null +++ b/roles/openvpn/handlers/main.yml @@ -0,0 +1,5 @@ +--- +- name: restart openvpn + systemd: + name: "{{ openvpn_service }}" + state: restarted \ No newline at end of file diff --git a/roles/openvpn/tasks/bridge-tap.yml b/roles/openvpn/tasks/bridge-tap.yml new file mode 100644 index 0000000..567ee49 --- /dev/null +++ b/roles/openvpn/tasks/bridge-tap.yml @@ -0,0 +1,19 @@ +--- +- name: Start OpenVPN + systemd: + name: "{{ openvpn_service }}" + state: started + enabled: true + +- name: Wait for tap0 + command: ip link show tap0 + register: tap_check + retries: 10 + delay: 2 + until: tap_check.rc == 0 + +- name: Bring tap0 up + command: ip link set tap0 up + +- name: Attach tap0 to bridge + command: ip link set tap0 master br-main-vpn \ No newline at end of file diff --git a/roles/openvpn/tasks/certs.yml b/roles/openvpn/tasks/certs.yml new file mode 100644 index 0000000..ae57f1a --- /dev/null +++ b/roles/openvpn/tasks/certs.yml @@ -0,0 +1,32 @@ +--- +- name: Create certificate directory + file: + path: "{{ openvpn_cert_dir }}" + state: directory + owner: root + group: root + mode: "0755" + +- name: Deploy CA certificate + copy: + src: certs/ca.crt + dest: "{{ openvpn_cert_dir }}/ca.crt" + owner: root + group: root + mode: "0644" + +- name: Deploy server certificate + copy: + src: certs/server.crt + dest: "{{ openvpn_cert_dir }}/server.crt" + owner: root + group: root + mode: "0644" + +- name: Deploy server private key + copy: + src: certs/server.key + dest: "{{ openvpn_cert_dir }}/server.key" + owner: root + group: root + mode: "0600" \ No newline at end of file diff --git a/roles/openvpn/tasks/config.yml b/roles/openvpn/tasks/config.yml new file mode 100644 index 0000000..354a50f --- /dev/null +++ b/roles/openvpn/tasks/config.yml @@ -0,0 +1,31 @@ +--- +- name: Deploy OpenVPN configuration + template: + src: server.conf.j2 + dest: /etc/openvpn/server/server.conf + owner: root + group: root + mode: "0644" + notify: restart openvpn + +- name: Deploy Radius configuration + template: + src: radiusplugin.cnf.j2 + dest: /etc/openvpn/radiusplugin.cnf + owner: root + group: root + mode: "0600" + notify: restart openvpn + +- name: Deploy client-connect script + copy: + src: client-connect.sh + dest: /etc/openvpn/scripts/client-connect.sh + owner: root + group: root + mode: "0755" + +- name: Enable OpenVPN service + systemd: + name: openvpn@server + enabled: true \ No newline at end of file diff --git a/roles/openvpn/tasks/install.yml b/roles/openvpn/tasks/install.yml new file mode 100644 index 0000000..10ce7e2 --- /dev/null +++ b/roles/openvpn/tasks/install.yml @@ -0,0 +1,20 @@ +--- +- name: Install OpenVPN packages + apt: + name: + - openvpn + - openvpn-auth-radius + state: present + update_cache: true + +- name: Create OpenVPN directories + file: + path: "{{ item }}" + state: directory + owner: root + group: root + mode: "0755" + loop: + - "{{ openvpn_ccd_dir }}" + - "{{ openvpn_config_dir }}" + - /etc/openvpn/scripts \ No newline at end of file diff --git a/roles/openvpn/tasks/main.yml b/roles/openvpn/tasks/main.yml new file mode 100644 index 0000000..8396c97 --- /dev/null +++ b/roles/openvpn/tasks/main.yml @@ -0,0 +1,5 @@ +--- +- import_tasks: install.yml +- import_tasks: certs.yml +- import_tasks: config.yml +- import_tasks: bridge-tap.yml \ No newline at end of file diff --git a/roles/openvpn/templates/radiusplugin.cnf.j2 b/roles/openvpn/templates/radiusplugin.cnf.j2 new file mode 100644 index 0000000..55aafb8 --- /dev/null +++ b/roles/openvpn/templates/radiusplugin.cnf.j2 @@ -0,0 +1,31 @@ +NAS-Identifier={{ nas_identifier }} +NAS-IP-Address={{ nas_ip_address }} + +Service-Type=5 +Framed-Protocol=1 +NAS-Port-Type=5 + +OpenVPNConfig=/etc/openvpn/server/server.conf + +subnet=255.255.255.0 + +useauthcontrolfile=true +useclientconnectdeferfile=true +overwriteccfiles=true + +nonfatalaccounting=false + +AddMessageAuthenticator=yes + +log_level=5 + +server +{ + name={{ radius_server }} + authport={{ radius_auth_port }} + acctport={{ radius_acct_port }} + sharedsecret={{ radius_shared_secret }} + + retry=3 + wait=10 +} \ No newline at end of file diff --git a/roles/openvpn/templates/server.conf.j2 b/roles/openvpn/templates/server.conf.j2 new file mode 100644 index 0000000..bfc4e1d --- /dev/null +++ b/roles/openvpn/templates/server.conf.j2 @@ -0,0 +1,45 @@ +port {{ openvpn_port }} +proto {{ openvpn_proto }} + +dev {{ openvpn_mode }} + +client-to-client + +persist-key +persist-tun + +keepalive 10 120 + +server-bridge +mode server + +vlan-tagging + +plugin /usr/lib/openvpn/radiusplugin.so /etc/openvpn/radiusplugin.cnf + +verify-client-cert none +username-as-common-name + +client-config-dir {{ openvpn_ccd_dir }} + +script-security 2 +client-connect /etc/openvpn/scripts/client-connect.sh + +ca {{ openvpn_cert_dir }}/ca.crt +cert {{ openvpn_cert_dir }}/server.crt +key {{ openvpn_cert_dir }}/server.key + +dh none +ecdh-curve prime256v1 + +data-ciphers AES-256-GCM:AES-128-GCM +data-ciphers-fallback AES-256-CBC + +sndbuf 0 +rcvbuf 0 + +tun-mtu 1400 + +verb 3 + +status /var/log/openvpn-status.log \ No newline at end of file diff --git a/roles/radius-nat/defaults/main.yml b/roles/radius-nat/defaults/main.yml new file mode 100644 index 0000000..a08fea3 --- /dev/null +++ b/roles/radius-nat/defaults/main.yml @@ -0,0 +1,4 @@ +--- +# defaults file for roles/networking +radius_auth_nodeport: 30131 +radius_acct_nodeport: 31622 \ No newline at end of file diff --git a/roles/radius-nat/tasks/main.yml b/roles/radius-nat/tasks/main.yml new file mode 100644 index 0000000..a8ce52b --- /dev/null +++ b/roles/radius-nat/tasks/main.yml @@ -0,0 +1,27 @@ +--- +- name: Install iptables persistence + apt: + name: + - iptables-persistent + state: present + +- name: DNAT RADIUS auth traffic + iptables: + table: nat + chain: OUTPUT + protocol: udp + destination_port: "1812" + jump: DNAT + to_destination: ":{{ radius_auth_nodeport }}" + +- name: DNAT RADIUS accounting traffic + iptables: + table: nat + chain: OUTPUT + protocol: udp + destination_port: "1813" + jump: DNAT + to_destination: ":{{ radius_acct_nodeport }}" + +- name: Save iptables rules + command: netfilter-persistent save \ No newline at end of file