Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
About
The OpenConnect VPN server (ocserv) is an open source Linux SSL VPN server designed for organizations that require a remote access VPN with enterprise user management and control. It follows the openconnect protocol and is the counterpart of the openconnect VPN client. It is also compatible with CISCO's AnyConnect SSL VPN.
The program consists of:
- ocserv, the main server application
- occtl, the server's control tool. A tool which allows one to query the server for information.
- ocpasswd, a tool to administer simple password files.
Supported platforms
The OpenConnect VPN server is designed and tested to work, with both IPv6 and IPv4, on Linux systems. It is, however, known to work on FreeBSD, OpenBSD and other BSD derived systems.
Known limitation is that on platforms, which do not support procfs(5), changes to the configuration must only be made while ocserv(8) is stopped. Not doing so will cause new worker processes picking up the new configuration while ocserv-main will use the previous configuration.
Build dependencies
Debian/Ubuntu:
# Basic build tools
apt-get install -y build-essential meson ninja-build pkg-config
# Required
apt-get install -y libgnutls28-dev nettle-dev libev-dev libreadline-dev
# Required when building from git (see "Building from git" below)
apt-get install -y protobuf-c-compiler gperf
# Optional: enable optional features (when found at configure time) and
# provide the tools needed to run the test suite
apt-get install -y libtasn1-bin libpam0g-dev liblz4-dev libseccomp-dev \
libnl-route-3-dev libkrb5-dev libradcli-dev \
libcurl4-gnutls-dev libcjose-dev libjansson-dev liboath-dev \
libprotobuf-c-dev libtalloc-dev libllhttp-dev \
iperf3 lcov libuid-wrapper libpam-wrapper libnss-wrapper \
libsocket-wrapper gss-ntlmssp haproxy iputils-ping freeradius \
gawk gnutls-bin iproute2 procps jq tcpdump ipcalc-ng faketime
# For manpages
apt-get install -y ronn
Fedora/RHEL:
# Basic build tools
yum install -y meson ninja-build gcc pkgconf-pkg-config
# Required
yum install -y gnutls-devel nettle-devel libev-devel readline-devel
# Required when building from git (see "Building from git" below)
yum install -y protobuf-c-compiler gperf
# Optional: enable optional features (when found at configure time) and
# provide the tools needed to run the test suite
yum install -y libtasn1-tools pam-devel lz4-devel libseccomp-devel \
libnl3-devel krb5-devel radcli-devel libcurl-devel cjose-devel \
jansson-devel liboath-devel protobuf-c-devel libtalloc-devel \
llhttp-devel iperf3 lcov uid_wrapper \
pam_wrapper nss_wrapper socket_wrapper gssntlmssp haproxy iputils \
freeradius gawk gnutls-utils iproute procps-ng jq tcpdump ipcalc faketime
# For manpages
yum install -y rubygem-ronn-ng
See README-radius for more information on Radius dependencies and its configuration.
Runtime dependencies
When the restrict-user-to-routes or restrict-user-to-ports options are
configured, ocserv invokes /usr/libexec/ocserv-fw at runtime to enforce
firewall rules. That script requires either nft (nftables) or iptables
depending on the backend selected with the -Dfirewall-script= meson option
at build time. The default is nftables when nft is present at configure
time, otherwise iptables.
Build instructions
$ meson setup build
$ ninja -C build
$ meson test -C build
meson setup build configures the build into a build/ subdirectory.
ninja -C build compiles. meson test -C build runs the test suite.
Running the test suite in a virtual machine
Most tests need root, network namespaces and /dev/net/tun; without them they
are skipped or fail. contrib/run-test-suite-vng.sh builds ocserv and runs the
whole test suite as root inside a virtme-ng
(vng) virtual machine under QEMU, without changing the host. It needs Fedora,
virtme-ng, QEMU and access to /dev/kvm, and installs the other build and
test dependencies with sudo dnf.
The quick way, from your own shell, shares the host's root filesystem (read-only) with the VM and boots the host kernel:
$ contrib/run-test-suite-vng.sh --host-root
Missing build and test dependencies are installed on the host.
To isolate the run from the host, give the VM its own Fedora root filesystem. Create it once, and refresh it from time to time with the same command:
$ contrib/run-test-suite-vng.sh --build-root
This installs the dependencies and a kernel into ~/tmp/vng-roots/default/
with sudo dnf --installroot, then makes you the owner of every file in it.
Run it as your normal user; the script calls sudo itself. Then:
$ contrib/run-test-suite-vng.sh
The VM boots that rootfs and its own kernel, and sees no host files except
the rootfs, the source tree (read-only) and the log directory, so the test
suite can also be run by a user or tool without access to the rest of the
host. Without --build-root, a run creates the rootfs or adds missing
packages first; --no-install makes it fail instead of running sudo. Set
VNG_ROOT=<name> to use ~/tmp/vng-roots/<name>/ instead of default.
Run specific tests with --tests, and see all options with --help:
$ contrib/run-test-suite-vng.sh --tests test-pass,kerberos
$ VERBOSE=1 contrib/run-test-suite-vng.sh --tests kerberos
The results are written to vng-logs/meson-logs/testlog.txt.
Listing and changing build options
To see all available build options and their current values:
$ meson configure build
Before the build directory exists, you can also view the available options with:
$ meson setup --help
Options are set at configure time with -D:
$ meson setup build -Doidc-auth=enabled -Dlatency-stats=enabled
Or changed after the fact:
$ meson configure build -Doidc-auth=enabled
$ ninja -C build
Common options:
| Option | Default | Description |
|---|---|---|
-Doidc-auth=enabled |
disabled | OpenID Connect authentication |
-Dlatency-stats=enabled |
disabled | Latency statistics gathering |
-Dpam=disabled |
auto | PAM authentication |
-Dradius=disabled |
auto | RADIUS authentication/accounting |
-Dgssapi=disabled |
auto | GSSAPI/Kerberos authentication |
-Dseccomp=disabled |
auto | seccomp worker isolation |
-Dseccomp-trap=true |
false | Filtered syscalls fail with a signal |
-Dkerberos-tests=true |
false | Enable Kerberos tests (requires KDC) |
-Dwith-werror=true |
false | Treat compiler warnings as errors |
-Db_coverage=true |
false | Enable gcov code coverage instrumentation |
Code coverage
$ CFLAGS="-g -O0" meson setup build -Db_coverage=true
$ ninja -C build
$ meson test -C build
$ ninja -C build coverage
The HTML report is written to build/meson-logs/coveragereport/index.html.
Building from git
Building from git requires, in addition to the dependencies of a release
build, protoc-c (package protobuf-c-compiler) and gperf, to generate
source files that are not stored in the repository. Prepared release tarballs
ship these generated files, so the tools are optional there. The
automatically generated GitLab source archives are not release tarballs and
also require the tools.
After cloning:
$ git submodule update --init
$ meson setup build
$ ninja -C build
Basic installation instructions
Distribution packages, where available, already perform these steps and are the recommended way to install ocserv.
Installing the binaries
After building, install as root:
# meson install -C build
The prefix defaults to /usr/local; set another one at configure time with
meson setup build --prefix=/usr. With the default prefix this installs
ocserv and ocserv-worker in /usr/local/sbin, occtl and ocpasswd in
/usr/local/bin, the ocserv-fw script in /usr/local/libexec and the
manual pages. ocserv executes ocserv-worker from its own directory, so the
two must be kept together; on systems without /proc (e.g., BSD) start
ocserv by its absolute path. Use ninja -C build uninstall to remove the
installed files.
Configuring the server
Generate a certificate and key, e.g.:
$ certtool --generate-privkey > ./server-key.pem
$ certtool --generate-self-signed --load-privkey server-key.pem --outfile server-cert.pem
(make sure you enable encryption or signing)
The server reads /etc/ocserv/ocserv.conf unless --config is given. Start
from the annotated sample.config, which documents every
option but references test files by relative paths:
# install -d -m 0755 /etc/ocserv
# install -m 0600 doc/sample.config /etc/ocserv/ocserv.conf
Create a dedicated user and group for the unprivileged worker processes
(e.g., ocserv) and set them in the run-as-user and run-as-group options.
Then at least select the authentication method (auth), set server-cert and
server-key to the absolute paths of your certificate and key, configure the
address pool, DNS and routes, and remove the example virtual hosts you do not
use. Check the result with:
# /usr/local/sbin/ocserv --test-config --config /etc/ocserv/ocserv.conf
IP forwarding, firewall rules and NAT or return routes for the VPN address pool are not set up by the installation; see the networking considerations section of the ocserv(8) manual page.
Running as a systemd service
Example units are provided in doc/systemd/: standalone, where
ocserv opens its own sockets, and socket-activated, where systemd opens them
(requires building with libsystemd). Copy the chosen unit(s) to
/etc/systemd/system/ and, if ocserv was not installed under /usr, adjust
the /usr/sbin/ocserv path in ExecStart. Then:
# systemctl daemon-reload
# systemctl enable --now ocserv.service
Configuration
Several configuration instruction are available in the recipes repository.
Profiling
To identify the bottlenecks in software under certain loads you can profile ocserv using the following command.
# perf record -g ocserv
After the server is terminated, the output is placed in perf.data. You may examine the output using:
# perf report
Continuous Integration (CI)
We use the gitlab-ci continuous integration system. It is used to test most of the Linux systems (see .gitlab-ci.yml),and is split in two phases, build image creation and compilation/test. The build image creation is done at the openconnect/build-images subproject and uploads the image at the gitlab.com container registry. The compilation/test phase is on every commit to project.
How the VPN works
Please see the technical description page.
License
The license of ocserv is GPLv2+. See COPYING for the license terms.
Some individual code may be covered under other (compatible with GPLv2) licenses. For the CCAN components see src/ccan/licenses/ The inih library is under the simplified BSD license (src/inih/LICENSE.txt).