ovpn-ad-sync/README.md

69 lines
4.6 KiB
Markdown
Raw Normal View History

2014-12-03 14:11:57 -05:00
#ovpn-ad-sync
2014-12-03 13:31:16 -05:00
============
2014-12-03 14:12:43 -05:00
###Description:
2014-12-03 14:19:59 -05:00
Script to synchronize AD/LDAP users with OpenVPN config files and email user certificates and a setup guide to end users. This script is a very rudimentary hack to fill my purpose. It may or may not work for you. It could also be put to use with LDAP with minimal modification even though I wrote it for an Active Directory environment.
2014-12-03 13:46:31 -05:00
2014-12-03 14:12:43 -05:00
###Author:
2014-12-03 14:19:59 -05:00
Josh North 2014-12-01
josh.north@point808.com
Free for use and modification. Credit is appreciated if you do anything with it but nothing is required.
2014-12-03 14:07:34 -05:00
2014-12-03 14:47:28 -05:00
###Status:
This script is (as of today, 2014-12-03) in *fully-working beta status*. It currently does not delete or revoke certificates but will in the near (but unknown) future.
2014-12-03 14:12:43 -05:00
###Theory:
2014-12-03 14:19:59 -05:00
Basically, the script should be run on a cron schedule. At run, it searches all users in a specified AD group. It then checks to see if subdirectories exist for the user, if not, it decides to create them. It then loops through to look for directories that do not have a corresponding user in the AD list and deletes them. It technically (at this point) does not revoke access and restart the vpn, this is IMPORTANT, because in my setup we are authenticating against AD anyway as a second layer.
This is not fully secure but like I said, it is a major work in progress.
2014-12-03 13:46:31 -05:00
2014-12-03 14:12:43 -05:00
###Requirements:
2014-12-03 14:19:59 -05:00
* Ubuntu 14+ (will likely work with plenty of other systems, but I wrote it on and for Ubuntu server)
* sendmail (must be configured correctly - I used ssmtp and wrote this script as such)
* sharutils
* easy-rsa
* ldap-utils
* openvpn-auth-ldap
2014-12-03 13:46:31 -05:00
2014-12-03 14:12:43 -05:00
###Setup Assumptions:
2014-12-03 14:18:26 -05:00
The below instructions make the following assumptions. If you use a different setup you will need to modify accordingly.
2014-12-03 14:18:12 -05:00
1. We assume your vpn name will be vpn.example.com
2. We asssume your LDAP bind root is example.com
3. We assume your LDAP user/pass for bind is oas_user/oas_user
2014-12-03 14:19:03 -05:00
4. We assume 192.168.5.0/24 is your VPN network range.
2014-12-03 14:18:12 -05:00
5. We assume you want your rsa key infrastructure to live under the OpenVPN config directory in /etc
6. We assume your public IP is 66.66.66.66 - obviously this needs to be changed in the template file in the clients directory.
7. We assume your local network is 192.168.1.0/24 and your Active Directory or LDAP servers reside at .21 and .22 in this network.
8. We assume that you will set up a group in Active Directory called "OpenVPNUsers" - any users in this group will have files generated and emailed automatically.
2014-12-03 14:19:03 -05:00
9. You will see other variables that reference example.com - change these accordingly.
2014-12-03 14:11:04 -05:00
2014-12-03 14:12:43 -05:00
###Setup Instructions:
2014-12-03 14:23:35 -05:00
1. Install and configure all pre-requisites listed above
2. Clone the repository `sudo git clone https://github.com/joshnorth/ovpn-ad-sync.git /tmp/ovpn-ad-sync`
3. Copy RSA directory `sudo cp -R /usr/share/easy-rsa /etc/openvpn/rsa`
2014-12-03 14:36:37 -05:00
4. Edit RSA variable file - IMPORTANT! Make sure you use 2048 instead of 1024!!! `sudo nano /etc/openvpn/rsa/vars`
2014-12-03 14:25:51 -05:00
5. Build RSA CA
2014-12-03 14:27:16 -05:00
```
sudo -s
cd /etc/openvpn/rsa
source ./vars
./build-ca
./build-dh
./build-key-server vpn.example.com
2014-12-03 14:36:37 -05:00
exit
2014-12-03 14:27:16 -05:00
```
2014-12-03 14:36:37 -05:00
6. Copy client directory to openvpn directory `sudo cp -R /tmp/ovpn-ad-sync/oas_clients /etc/openvpn`
2014-12-08 11:32:02 -05:00
7. Copy user guide directory to openvpn directory `sudo cp -R /tmp/ovpn-ad-sync/oas_attachments /etc/openvpn`
8. Copy templates directory to openvpn directory `sudo cp -R /tmp/ovpn-ad-sync/oas_templates /etc/openvpn`
8. Edit the client template to match your IP, etc `sudo nano /etc/openvpn/oas_templates/template.ovpn`
2014-12-08 11:32:02 -05:00
9. Copy server files into place `sudo cp -R /tmp/ovpn-ad-sync/oas_configs/* /etc/openvpn`
10. Edit server file `sudo nano /etc/openvpn/vpn.example.com.conf`
11. Edit LDAP auth file `sudo nano /etc/openvpn/vpn.example.com.ldap`
12. Copy main program into place `sudo cp /tmp/ovpn-ad-sync/ovpn-ad-sync.sh /usr/local/bin`
13. Edit main program variables - IMPORTANT! `sudo nano /usr/local/bin/ovpn-ad-sync.sh`
14. Allow program to execute `sudo chmod +x /usr/local/bin/ovpn-ad-sync.sh`
15. On your Active Directory, make sure you have created a group (by default, OpenVPNUsers).
16. On your Active Directory, make sure the oas_user exists and has a proper password set.
17. Check the rest of the items in the assumptions list above and double-check they are all checked before running.
18. All checked? Let's add it to cron. `sudo crontab -e` and add a line like this `0,10,20,30,40,50 * * * * /usr/local/bin/ovpn-ad-sync.sh >/dev/null 2>&1`
19. Now go to Active Directory and add a new user, set a valid email address for them, and add them to the group. Within 10 minutes that email should receive a message with the config and user guide attached!