Skip to content

Commit d7f2b02

Browse files
committed
refactored file structure and readme
1 parent bfabfef commit d7f2b02

File tree

7 files changed

+143
-48
lines changed

7 files changed

+143
-48
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.idea

Dockerfile

+10-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
From alpine:latest
1+
FROM alpine:latest
22

33
MAINTAINER Pezhvak
44

@@ -25,23 +25,22 @@ RUN buildDeps="xz openssl gcc autoconf make linux-headers"; \
2525
&& rm -rf ./$OC_FILE \
2626
&& apk del --purge $buildDeps
2727

28-
COPY ocserv.conf /etc/ocserv/ocserv.conf
29-
RUN chmod 777 /etc/ocserv/ocserv.conf
30-
COPY cn-no-route.txt /tmp/
28+
COPY config/ocserv.conf /etc/ocserv/ocserv.conf
29+
RUN chmod 655 /etc/ocserv/ocserv.conf
30+
COPY config/no-route.txt /tmp/
3131
RUN set -x \
3232
&& sed -i 's/^no-route/#no-route/' /etc/ocserv/ocserv.conf \
33-
&& cat /tmp/cn-no-route.txt >> /etc/ocserv/ocserv.conf \
34-
&& rm -rf /tmp/cn-no-route.txt \
33+
&& cat /tmp/no-route.txt >> /etc/ocserv/ocserv.conf \
34+
&& rm -rf /tmp/no-route.txt \
3535
&& touch /etc/ocserv/data/ocpaswd
3636

3737
WORKDIR /etc/ocserv
3838

39-
COPY docker-entrypoint.sh /root/entrypoint.sh
40-
COPY ocuser /usr/local/bin/ocuser
41-
RUN chmod 777 ~/entrypoint.sh
42-
RUN chmod 777 /usr/local/bin/ocuser
39+
COPY scripts/docker-entrypoint.sh /root/entrypoint.sh
40+
COPY scripts/ocuser /usr/local/bin/ocuser
41+
RUN chmod +x ~/entrypoint.sh
42+
RUN chmod +x /usr/local/bin/ocuser
4343

44-
RUN ls /etc/ocserv > /root/list
4544
ENTRYPOINT ["/root/entrypoint.sh"]
4645

4746
EXPOSE 443

README.md

+132-37
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,111 @@
11
<div align="center">
22

33
# docker-ocserv
4-
Alpine based ocserv Docker image
54

6-
[![Open Source](https://badges.frapsoft.com/os/v1/open-source.svg?v=103)](https://opensource.org/) [![Active](http://img.shields.io/badge/Status-Active-green.svg)](https://github.com/Pezhvak/docker-ocserv)
5+
![GitHub](https://img.shields.io/github/license/pezhvak/docker-ocserv)
6+
![Docker Image Size (tag)](https://img.shields.io/docker/image-size/pezhvak/ocserv/latest)
7+
![Docker Image Version (latest semver)](https://img.shields.io/docker/v/pezhvak/ocserv)
8+
![Docker Cloud Automated build](https://img.shields.io/docker/cloud/automated/pezhvak/ocserv)
9+
![Docker Cloud Build Status](https://img.shields.io/docker/cloud/build/pezhvak/ocserv)
10+
711
</div>
812

13+
## About
14+
15+
Lightweight Alpine based ocserv Docker image.
16+
17+
You can either start by using the [pre-built image](#using-built-image)
18+
or [build your own](#build-your-own-image) for more customization.
19+
20+
### Table of Contents
21+
22+
- [Installation](#installation)
23+
- [Using Built Image](#using-built-image)
24+
- [Versioning](#versioning)
25+
- [Generate SSL Certificate](#step-1-generate-ssl-certificate)
26+
- [Running Container](#step-2-running-your-container)
27+
- [Using Docker Compose](#option-1-docker-compose-recommended)
28+
- [Using Docker Run](#option-2-docker-run-command)
29+
- [Build your own image](#build-your-own-image)
30+
- [Updating](#updating)
31+
- [Usage](#usage)
32+
- [User Management](#user-management)
33+
- [Creating a new user](#create-a-new-user)
34+
- [Deleting a user](#delete-a-user)
35+
- [Locking a user](#lock-a-user)
36+
- [Unlocking a user](#unlock-a-user)
37+
- [Connecting To Server](#connecting-to-server)
38+
- [References](#references)
39+
940
# Installation
10-
You can either start by using the 46.1MB (16.65 MB Compressed) [pre-built image](#using-built-image) or [build your own](#build-your-own-image).
1141

1242
## Using Built Image
13-
A [pre-built image](https://hub.docker.com/layers/pezhvak/ocserv) is available with the best configurations out of the box. Follow the instructions below to get up and running.
1443

15-
This setup includes:
44+
A [pre-built image](https://hub.docker.com/r/pezhvak/ocserv) is available with the best configurations out of the box.
45+
Follow the instructions bellow to get up and running.
46+
47+
#### This setup includes:
48+
1649
- 2 Device connections for each user (`max-same-clients=2`)
1750
- Up to 16 clients (`max-clients=16`)
1851
- 10.10.10.0/24 as the internal IP pool
1952
- Listens on port 1342 (can be changed by altering port mappings when you run the container)
2053
- Tunnels DNS to the server (`tunnel-all-dns=true`)
2154
- No-Route list configured by [CNMan/ocserv-cn-no-route](https://github.com/CNMan/ocserv-cn-no-route)
2255

23-
***Note:*** All limits can be increased or set to be unlimited in `ocserv.conf` by [building your own image](#build-your-own-image).
56+
***Note:*** All limits can be increased or set to be unlimited in `ocserv.conf`
57+
by [building your own image](#build-your-own-image).
58+
59+
### Versioning
60+
By default `docker-compose.yml` and the instructions written in this document uses the `latest`
61+
tag of the image which represents the latest commit in the `master` branch. beside that tagged commits
62+
are also available if you want to make sure no breaking changes enters your setup. checkout
63+
[tags](https://hub.docker.com/repository/docker/pezhvak/ocserv/tags) in our docker hub repo.
64+
65+
However, if you like to get the cutting edge features you can always use the `next` tag
66+
which represents the latest commit in the `develop` branch.
2467

2568
### STEP 1: Generate SSL Certificate
26-
No matter what, if you want to build the image yourself, run the pre-built one with `docker run` or with `docker-compose`, in all cases you will need
27-
an SSL certificate, It's up to you how you would like to generate it, perhaps you already have some kind of setup for that on your server,
28-
in case you don't, use the following [image](https://hub.docker.com/r/certbot/certbot/) to generate one:
2969

30-
***Note:*** You need to have a domain pointing to your server IP address and ports 80 and 443 available to be listened by the container for
31-
letsencrypt ACME challenge verification.
70+
No matter what, if you want to build the image yourself, run the pre-built one with `docker run` or
71+
with `docker-compose`, in all cases you will need an SSL certificate, It's up to you how you would like to generate it,
72+
perhaps you already have some kind of setup for that on your server, in case you don't, use the
73+
following [image](https://hub.docker.com/r/certbot/certbot/) to generate one:
74+
75+
***Note:*** You need to have a domain pointing to your server IP address and ports 80 and 443 available to be listened
76+
by the container for letsencrypt ACME challenge verification.
3277

3378
```BASH
3479
sudo docker run -it --rm --name certbot -p 80:80 -p 443:443 \
3580
-v $(pwd)/certs:/etc/letsencrypt certbot/certbot \
3681
certonly --standalone -m <email> -d <domain> -n --agree-tos
3782
```
3883

39-
Don't worry if you can't create one (most often because ports 80 and 443 are not available on your server or you don't have a domain), a fallback script will generate a self-signed certificate for you inside the container. The only difference is
40-
a warning message about the certificate not being trusted (due to being self-signed) when logging in.
84+
can't create one (most often because ports 80 and 443 are not available on your server, or you don't have a domain), a
85+
fallback script will generate a self-signed certificate for you inside the container. The only difference is a warning
86+
message about the certificate not being trusted (due to being self-signed) when logging in.
4187

4288
### STEP 2: Running Your Container
89+
4390
Now that we are done with the certificate, you have to run the container somehow.
4491

45-
***NOTE:*** If you haven't generated a certificate in the previous step, remove volume mountings to cert paths in your chosen method. as stated previously
46-
a self-signed certificate will be generated automatically with the downside of untrusted certificate warning at the logging phase.
92+
***NOTE:*** If you haven't generated a certificate in the previous step, remove volume mountings to cert paths in your
93+
chosen method. as stated previously a self-signed certificate will be generated automatically with the downside of
94+
untrusted certificate warning at the logging phase.
4795

48-
### OPTION 1: Docker Compose (Recommended)
96+
#### OPTION 1: Docker Compose (Recommended)
4997

50-
I highly recommend using docker-compose for running your container, feel free to change the port by editing `docker-compose.yml`.
98+
I highly recommend you to use docker-compose for running your container, feel free to change the port by
99+
editing `docer-compose.yml`. I highly recommend using docker-compose for running your container, feel free to change the
100+
port by editing `docker-compose.yml`.
51101

52102
```BASH
53103
wget https://raw.githubusercontent.com/Pezhvak/docker-ocserv/develop/docker-compose.yml
54104
# IMPORTANT: Make sure you have updated the cert paths in volumes section of the docker-compose.yml before running it.
55105
docker-compose up -d
56106
```
57107

58-
### OPTION 2: Docker Run Command
108+
#### OPTION 2: Docker Run Command
59109

60110
If you prefer to use `docker run` all you have to do is to execute the following command:
61111

@@ -72,77 +122,122 @@ docker run \
72122

73123
Your ocserv should be up and running now, you will have to create a user to be able to connect.
74124

125+
### Updating
126+
127+
To update to the latest version, simply just pull the image from docker hub.
128+
129+
#### For Docker Compose Installations
130+
131+
```BASH
132+
# this will pull the image from docker hub
133+
docker-compose pull
134+
# running up again will detect the newer image and recreates the container
135+
docker-compose up -d
136+
```
137+
138+
#### For Docker Run Installations
139+
```BASH
140+
# pull image from docker hub
141+
docker pull pezhvak/ocserv
142+
# restart the container
143+
docker restart ocserv
144+
```
145+
146+
## Build Your Own Image
147+
Although it's easier to use [pre-built image](https://hub.docker.com/r/pezhvak/ocserv),
148+
but it has its own downsides. namely, the limitations described [here](#this-setup-includes).
149+
150+
If you want to change the default configurations, you will have to build the image yourself, just clone the repo and
151+
change the files you need.
152+
153+
Configuration files are stored in `config` directory. you can also modify
154+
`scripts/docker-entrypoint.sh` if needed.
155+
156+
157+
1- Clone the repository to your server:
158+
159+
```BASH
160+
git clone https://github.com/Pezhvak/docker-ocserv.git
161+
cd docker-ocserv
162+
```
163+
164+
2- Build the image with your own settings, feel free to change `config/ocserv.conf` to your liking:
165+
166+
```BASH
167+
docker build -t <image_name> .
168+
```
169+
170+
3- Follow the steps of [Using Built Image](#using-built-image) (Change `pezhvak/ocserv` to your own image name)
171+
172+
# Usage
173+
75174
## User Management
175+
76176
I have created a simple proxy shell (`ocuser`) in the image for easier interaction with `ocpasswd`.
77177

78178
### Create a new user
79179

80180
Remove the specified user to the password file (Password of the user will be asked)
181+
81182
```BASH
82183
docker exec -it ocserv ash -c "ocuser create <username>"
83184
```
84185

85186
### Delete a User
86187

87188
Remove the specified user from the password file:
189+
88190
```BASH
89191
docker exec ocserv ash -c "ocuser delete <username>"
90192
```
91193

92194
### Lock a User
93195

94196
Prevent the specified user from logging in:
197+
95198
```BASH
96199
docker exec ocserv ash -c "ocuser lock <username>"
97200
```
98201

99202
### Unlock a User
100203

101204
Re-enable login for the specified user
205+
102206
```BASH
103207
docker exec ocserv ash -c "ocuser unlock <username>"
104208
```
105209

106-
## Connecting To Server
210+
## Connecting to Server
107211

108-
Now that everything is set up and user is created, you can connect to server using terminal or one of the available applications:
212+
Now that everything is set up and user is created, you can connect to server using terminal or one of the available
213+
applications:
109214

110215
### The Terminal Way
216+
111217
Make sure you have installed `openconnect` on your machine, you can do that in MacOS using `brew install openconnect`.
112218

113219
```BASH
114220
echo "<PASSWORD>" | sudo openconnect <DOMAIN>:<PORT> -u <USERNAME> --passwd-on-stdin
115221
```
222+
116223
You can also create an alias in your `~/.bash_profile` (or `~/.zshrc` if you're using zsh) for easier access:
117224

118225
```BASH
119226
alias vpn:oc="echo <PASSWORD> | sudo openconnect <DOMAIN>:<PORT> -u <USERNAME> --passwd-on-stdin"
120227
```
121228

122-
### VPN Clients
229+
### Using Clients
230+
123231
- [Android (Cisco Anyconnect)](https://play.google.com/store/apps/details?id=com.cisco.anyconnect.vpn.android.avf)
124-
- [Android (Openconnect)](https://play.google.com/store/apps/details?id=com.github.digitalsoftwaresolutions.openconnect)
232+
- [Android (OpenConnect)](https://play.google.com/store/apps/details?id=com.github.digitalsoftwaresolutions.openconnect)
125233
- [iOS](https://apps.apple.com/us/app/cisco-anyconnect/id1135064690)
126234
- [MacOS](https://www.cisco.com/c/en/us/support/docs/smb/routers/cisco-rv-series-small-business-routers/smb5642-install-cisco-anyconnect-secure-mobility-client-on-a-mac-com-rev1.html)
127235
- [Windows](https://www.cisco.com/c/en/us/support/docs/smb/routers/cisco-rv-series-small-business-routers/smb5686-install-cisco-anyconnect-secure-mobility-client-on-a-windows.html)
128236
- [Ubuntu](https://www.cisco.com/c/en/us/support/docs/smb/routers/cisco-rv-series-small-business-routers/Kmgmt-785-AnyConnect-Linux-Ubuntu.html)
129237

130-
## Build Your Own Image
131-
If you want to change the default configurations, you will have to build the image yourself, just clone the repo and change the files you need.
132-
133-
1- Clone the repository to your server:
134-
```BASH
135-
git clone https://github.com/Pezhvak/docker-ocserv.git
136-
cd docker-ocserv
137-
```
138-
139-
2- Build the image with your own settings, feel free to change `ocserv.conf` to your liking:
140-
```BASH
141-
docker build -t <image_name> .
142-
```
238+
# References
143239

144-
3- Follow the steps of [Using Built Image](#using-built-image) (Change `pezhvak/ocserv` to your own image name)
240+
I appreciate these repositories which inspired me and helped me to put the pieces together:
145241

146-
### References
147242
- [soreana/cisco-anyconnect-server-docker](https://github.com/soreana/cisco-anyconnect-server-docker)
148243
- [TommyLau/docker-ocserv](https://github.com/TommyLau/docker-ocserv)
File renamed without changes.

ocserv.conf config/ocserv.conf

File renamed without changes.
File renamed without changes.

ocuser scripts/ocuser

File renamed without changes.

0 commit comments

Comments
 (0)