Skip to content

Commit d6eb287

Browse files
committed
Partial rewrite
Changed config directory structure, changed command names, added backup/restore, reorganized code, switched to new baseimage
1 parent 92388f1 commit d6eb287

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+1087
-1391
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# Changelog
22

3+
### 2.0.0 - Partial rewrite
4+
5+
- Moved `/config/hooks` to `/config/openvpn/hooks`
6+
- Renamed `/config/openvpn/server` to `config`
7+
- Changed base image to [slocomptech/baseimage-alpine](https://github.com/SloCompTech/docker-baseimage-alpine)
8+
- Moved all helper scripts to `/root/usr/local/bin`
9+
- Got rid of bash lib files
10+
- Hiearhicaly moved all commands under the hood of `ovpn` command
11+
- Improved backup command
12+
- Added restore command
13+
314
### 1.0.6 - Bugfix
415

516
- Added missing `DNS` keyword to **dhcp-option** in example configs

CONTRIBUTING.md

Lines changed: 49 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -6,76 +6,70 @@ Feel free to contribute to this project.
66

77
Sections:
88

9-
- [Example configs & hooks](root/defaults/example/README.md)
9+
- [Example configs & hooks](root/defaults/example/README.md)
1010
- [Guides](docs/README.md)
1111
- [Helper Scripts](root/app/README.md)
1212
- [Modules](root/defaults/module/README.md)
1313

1414
## Syntax
1515

16-
- Identation: tab (4 spaces width)
16+
- Identation: space (2 spaces width)
1717
- Javadoc style documentation
1818

1919
## Directory structure of project
2020

2121
```
22-
/app # Utils (part of image)
23-
bin # Scripts for using this image
2422
/config # Configuration dir (all config is here, generated on container start)
25-
openvpn # Openvpn configuration
26-
ccd # Client config directory
27-
client # Client configuration directory
28-
<clientconffile>.conf # Base for building client config (all files merged)
29-
server # Server configuration directory
30-
<name>.conf # Server config files (all files merged)
31-
pki
32-
ca.crt # CA certificate
33-
certs by serial # Certs by Serial ID
34-
<serial-id-cert>.pem
35-
crl.pem # CRL
36-
dh.pem
37-
index.txt # Database index file
38-
issued
39-
<name>.crt # Certificates
40-
private # Directory with private keys
41-
ca.key # CA secret
42-
<name>.key # Certificate secrets
43-
reqs # Directroy with signing requests
44-
serial # The current serial number
45-
ta.key # Secret for tls-auth, tls-crypt
46-
ssl
47-
safessl-easyrsa.cnf
48-
vars
49-
example # Example configs (see root/defaults/example/README.md)
50-
config # Example client & server configs
51-
hook # Example hook configs
52-
module # Modules for openvpn
23+
backup # Folder where backups are generated
24+
example # Example configs (see root/defaults/example/README.md)
25+
module # Modules for openvpn
26+
openvpn # Openvpn configuration
27+
ccd # OpenVPN client-specific configuration directory (applied when client connects)
28+
client # Client configuration directory (for generation of .ovpn files)
29+
<clientconffile>.conf # Base for building client config (all files merged)
30+
config # Running config (server/client)
31+
<name>.conf # Config files (all files merged)
5332
hooks # Put your custom scripts in one of subfolders
54-
auth # On authentication (needs to be enabled in config)
55-
client-connect # Client connected
56-
client-disconnect # Client disconnected
57-
down # After interface is down
58-
finish # Deinit container
59-
init # Init container
60-
learn-address
61-
route-up # After routes are added
62-
route-pre-down # Before routes are removed
63-
up # After interface is up
64-
tls-verify # Check certificate
33+
auth # On authentication (needs to be enabled in config)
34+
client-connect # Client connected
35+
client-disconnect # Client disconnected
36+
down # After interface is down
37+
finish # Deinit container
38+
init # Init container
39+
learn-address
40+
route-up # After routes are added
41+
route-pre-down # Before routes are removed
42+
up # After interface is up
43+
tls-verify # Check certificate
6544
system.conf # System OpenVPN config file (do not edit, unless instructed)
66-
include-server.conf # File that includes all server configuration files (automatically generated)
67-
donotdelete # Leave this file alone, if deleted it triggers full setup
45+
include-conf.conf # File that includes all configuration files (automatically generated)
46+
pki
47+
ca.crt # CA certificate
48+
certs by serial # Certs by Serial ID
49+
<serial-id-cert>.pem
50+
crl.pem # CRL
51+
dh.pem
52+
index.txt # Database index file
53+
issued
54+
<name>.crt # Certificates
55+
private # Directory with private keys
56+
ca.key # CA secret
57+
<name>.key # Certificate secrets
58+
reqs # Directroy with signing requests
59+
secret.key # Static key (if not using real PKI)
60+
serial # The current serial number
61+
ta.key # Secret for tls-auth, tls-crypt
62+
ssl
63+
safessl-easyrsa.cnf
64+
vars
65+
tmp # Temporary folder
6866
/defaults # Default configuration, which is copied into config on full setup
69-
example # Examples
70-
config # Example configs
71-
hook # Example hooks
72-
module # Modules (for example password authentication ...)
73-
system.conf # Original server config
67+
...
7468
/etc # System config
75-
cont-init.d # Scripts run before services are started
76-
fix-attrs.d # Fix file permissions
77-
logrotate.d # Log settings
78-
services.d # Scripts that start services
69+
cont-init.d # Scripts run before services are started
70+
cont-finish.d # Scripts run after services are finished
71+
fix-attrs.d # Fix file permissions
72+
services.d # Scripts that start services
7973
```
8074

8175
## Useful links
@@ -92,4 +86,4 @@ Sections:
9286
- [OpenVPN docs](https://community.openvpn.net/openvpn/wiki/GettingStartedwithOVPN)
9387
- [Setup OpenVPN on alpine linux](https://wiki.alpinelinux.org/wiki/Setting_up_a_OpenVPN_server#Alternative_Certificate_Method)
9488
- [EasyRSA](https://community.openvpn.net/openvpn/wiki/GettingStartedwithOVPN)
95-
- [EasyRSA doc](https://github.com/OpenVPN/easy-rsa/tree/master/doc)
89+
- [EasyRSA doc](https://github.com/OpenVPN/easy-rsa/tree/master/doc)

Dockerfile

Lines changed: 49 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# @see https://github.com/linuxserver/docker-baseimage-alpine
44
# @see https://github.com/linuxserver/docker-baseimage-alpine-python3
55
#
6-
FROM lsiobase/alpine.python3:latest
6+
FROM slocomptech/baseimage-alpine
77

88
# Build arguments
99
ARG BUILD_DATE
@@ -17,61 +17,76 @@ ARG VERSION
1717
# @see http://label-schema.org/rc1/
1818
# @see https://semver.org/
1919
#
20-
LABEL org.opencontainers.image.title="OpenVPN Server" \
21-
org.label-schema.name="OpenVPN Server" \
22-
org.opencontainers.image.description="Docker image with OpenVPN server" \
23-
org.label-schema.description="Docker image with OpenVPN server" \
24-
org.opencontainers.image.url="https://github.com/SloCompTech/docker-openvpn" \
25-
org.label-schema.url="https://github.com/SloCompTech/docker-openvpn" \
26-
org.opencontainers.image.authors="Martin Dagarin <martin.dagarin@gmail.com>" \
27-
org.opencontainers.image.version=$VERSION \
28-
org.label-schema.version=$VERSION \
29-
org.opencontainers.image.revision=$VCS_REF \
30-
org.label-schema.vcs-ref=$VCS_REF \
31-
org.opencontainers.image.source=$VCS_SRC \
32-
org.label-schema.vcs-url=$VCS_SRC \
33-
org.opencontainers.image.created=$BUILD_DATE \
34-
org.label-schema.build-date=$BUILD_DATE \
35-
org.label-schema.schema-version="1.0"
20+
LABEL org.opencontainers.image.title="OpenVPN Server" \
21+
org.label-schema.name="OpenVPN Server" \
22+
org.opencontainers.image.description="Docker image with OpenVPN server" \
23+
org.label-schema.description="Docker image with OpenVPN server" \
24+
org.opencontainers.image.url="https://github.com/SloCompTech/docker-openvpn" \
25+
org.label-schema.url="https://github.com/SloCompTech/docker-openvpn" \
26+
org.opencontainers.image.authors="Martin Dagarin <martin.dagarin@gmail.com>" \
27+
org.opencontainers.image.version=$VERSION \
28+
org.label-schema.version=$VERSION \
29+
org.opencontainers.image.revision=$VCS_REF \
30+
org.label-schema.vcs-ref=$VCS_REF \
31+
org.opencontainers.image.source=$VCS_SRC \
32+
org.label-schema.vcs-url=$VCS_SRC \
33+
org.opencontainers.image.created=$BUILD_DATE \
34+
org.label-schema.build-date=$BUILD_DATE \
35+
org.label-schema.schema-version="1.0"
3636

3737

3838
#
3939
# Environment variables
4040
# @see https://github.com/OpenVPN/easy-rsa/blob/master/doc/EasyRSA-Advanced.md
4141
#
42-
ENV PATH="/app/bin:$PATH" \
43-
S6_BEHAVIOUR_IF_STAGE2_FAILS=0 \
44-
EASYRSA=/usr/share/easy-rsa \
42+
ENV EASYRSA=/usr/share/easy-rsa \
4543
EASYRSA_PKI=/config/pki \
4644
EASYRSA_VARS_FILE=/config/ssl/vars \
4745
#EASYRSA_SSL_CONF=/config/ssl/openssl-easyrsa.cnf \
4846
EASYRSA_SAFE_CONF=/config/ssl/safessl-easyrsa.cnf \
49-
EASYRSA_TEMP_FILE=/config/temp \
50-
OVPN_ROOT=/config \
51-
OVPN_HOOKS=/config/hooks \
52-
OVPN_RUN=system.conf
47+
EASYRSA_TEMP_FILE=/config/tmp/temp
5348

5449
# Install packages
55-
RUN echo "http://dl-cdn.alpinelinux.org/alpine/edge/main/" >> /etc/apk/repositories && \
56-
apk add --no-cache \
50+
RUN apk add --no-cache \
5751
# Core packages
58-
bash sudo iptables ip6tables git openvpn easy-rsa && \
52+
bash \
53+
easy-rsa \
54+
iptables \
55+
ip6tables \
56+
openvpn \
57+
python3 \
58+
sudo && \
5959
# Link easy-rsa in bin directory
6060
ln -s ${EASYRSA}/easyrsa /usr/local/bin && \
6161
# Link python3 also as python
62+
ln -s /usr/bin/pip3 /usr/bin/pip && \
6263
ln -s /usr/bin/python3 /usr/bin/python && \
6364
# Remove any temporary files created by apk
6465
rm -rf /tmp/* /var/tmp/* /var/cache/apk/* /var/cache/distfiles/* && \
6566
# Add permission for network management to user abc
66-
echo "abc ALL=(ALL) NOPASSWD: /sbin/ip, /sbin/ip6tables, /sbin/ip6tables-compat, /sbin/ip6tables-compat-restore, /sbin/ip6tables-compat-save, /sbin/ip6tables-restore, /sbin/ip6tables-restore-translate, \
67-
/sbin/ip6tables-save, /sbin/ip6tables-translate, /sbin/iptables, /sbin/iptables-compat, /sbin/iptables-compat-restore, /sbin/iptables-compat-save, \
68-
/sbin/iptables-restore, /sbin/iptables-restore-translate, /sbin/iptables-save, /sbin/iptables-translate, /sbin/route" \
69-
>> /etc/sudoers.d/abc
67+
echo "abc ALL=(ALL) NOPASSWD: \
68+
/sbin/ip, \
69+
/sbin/ip6tables, \
70+
/sbin/ip6tables-compat, \
71+
/sbin/ip6tables-compat-restore, \
72+
/sbin/ip6tables-compat-save, \
73+
/sbin/ip6tables-restore, \
74+
/sbin/ip6tables-restore-translate, \
75+
/sbin/ip6tables-save, \
76+
/sbin/ip6tables-translate, \
77+
/sbin/iptables, \
78+
/sbin/iptables-compat, \
79+
/sbin/iptables-compat-restore, \
80+
/sbin/iptables-compat-save, \
81+
/sbin/iptables-restore, \
82+
/sbin/iptables-restore-translate, \
83+
/sbin/iptables-save, \
84+
/sbin/iptables-translate, \
85+
/sbin/route" \
86+
>> /etc/sudoers.d/abc
7087

7188
# Add repo files to image
7289
COPY root/ /
7390

7491
# Configure
75-
RUN chmod +x /app/bin/* && \
76-
chmod +x /usr/local/sbin/* && \
77-
chmod -R 0644 /etc/logrotate.d
92+
RUN chmod -R 0644 /etc/logrotate.d

README.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,13 @@ services:
6868

6969
|**Parameter**|**Function**|
7070
|:-----------:|:----------:|
71+
|`-e FAIL_MODE=hard`|Restart whole container on error|
7172
|`-e PUID=1000`|for UserID - see below for explanation|
7273
|`-e PGID=1000`|for GroupID - see below for explanation|
73-
|`-e OVPN_NFW=true`|Disable any firewall related rules to be created, modified ... (must be implemented in example)|
74-
|`-e OVPN_PERINT=true`|Enable persistent TUN interface|
74+
|`-e PERSISTENT_INTERFACE=true`|Enable persistent TUN interface|
75+
|`-e USE_FIREWALL=false`|Disable any firewall related rules to be created, modified ... (must be implemented in example)|
7576
|`-v /config`|All the config files including OpenVPNs reside here|
77+
|`-v /log`|Log files reside here|
7678

7779
See also: [EasyRSA](https://github.com/OpenVPN/easy-rsa/blob/master/doc/EasyRSA-Advanced.md)
7880

@@ -104,13 +106,13 @@ If you are new to containers please see rather [Detailed first setup guide](docs
104106
2. At this point you will have bash shell which runs in container. Now run following commands to setup your PKI:
105107

106108
``` bash
107-
ovpn_init [nopass] # Inits PKI
109+
ovpn pki init [nopass] # Inits PKI
108110
```
109111

110112
3. Setup OpenVPN config based on example `basic_nat` with configuration wizard:
111113

112114
``` bash
113-
ovpn_enconf basic_nat
115+
ovpn enconf basic_nat
114116
#Out interface [eth0]: <interface connected to the Internet>
115117
#Protocol udp, tcp, udp6, tcp6 [udp]:
116118
#VPN network [10.0.0.0]:
@@ -125,13 +127,13 @@ If you are new to containers please see rather [Detailed first setup guide](docs
125127

126128
``` bash
127129
# Generates client certificates
128-
ovpn_client add <name> [nopass]
130+
ovpn client add <name> [nopass]
129131

130-
# Generates client config file and prints it to screen (redirect to file)
131-
ovpn_client ovpn <name> > <config file>.ovpn
132+
# Generates client config file and saves it to /config/tmp
133+
ovpn client ovpn <name>
132134

133135
# OR BETTER SOLLUTION: Run outside container
134-
docker exec -it <container name> ovpn_client ovpn <name> > <config file>.ovpn
136+
docker exec -it <container name> ovpn client ovpnp <name> > <config file>.ovpn
135137
```
136138

137139
5. Exit container with `exit`, then it will destroy itself.
@@ -170,4 +172,4 @@ Wanted features (please help implement):
170172

171173
## Versions
172174

173-
See [CHANGELOG](CHANGELOG.md)
175+
See [CHANGELOG](CHANGELOG.md)

0 commit comments

Comments
 (0)