项目作者: jriguera

项目描述 :
Strongswan for RPI
高级语言: Shell
项目地址: git://github.com/jriguera/docker-rpi-strongswan.git
创建时间: 2019-12-31T17:23:21Z
项目社区:https://github.com/jriguera/docker-rpi-strongswan

开源协议:Apache License 2.0

下载


Strongswan VPN Server Docker Image

Run Strongswan 5.8 in docker. This docker image uses the new swanctl configuration
instead of the old ipsec. This image is created for Raspberry Pi but it can be build
and run in X86 arch.

This project was initially based on https://github.com/netzfisch/rpi-vpn-server

Features

  • It generates certificates and configuration parameters to setup a VPN server with Strongswan.
    Configuration is splitted in a conf.d folder.

  • Default configuration is generated from templates, you can provide your own templates and
    use environment variables to fill the values.

  • Manage client certificates and secrets: add or revoke using CRL.

Usage

  1. docker run --privileged --name vpnserver --cap-add net_admin -v $(pwd)/strongswan:/data -p 500:500/udp -p 4500:4500/udp strongswan help
  2. Usage:
  3. run.sh [ run-server | add-client | revoke-client | public-ip | render-template | swanctl | help ] [options]
  4. Strongswan VPN manager. It generates certificates and configuration parameters to setup a
  5. VPN server with Stronswan and manage client certificates and secrets. Default configuration
  6. is generated from templates, you can provide your own templates in <datadir>/templates
  7. (/data/conf.d) and use environment variables to fill the values.
  8. If the configuration is already provided in /data/conf.d,
  9. it will not be overwritten, so you can define your own complex configuration there.
  10. Subcommands:
  11. help Shows usage help
  12. run-server [<maintemplate>]
  13. Renders connection <maintemplate> -if provided- in /data/conf.d, generates certs
  14. if they are not found and finally starts strongswan charon responder.
  15. Variables depend on the template, but the default/base template uses:
  16. - SERVER_NAME=<server-ip-or-dns>
  17. - BASE_DN=<C=ES, O=Lar>
  18. - CONNECTION_DEVICE=<server-net-device>
  19. - CONNECTION_POOL_ADDRS=<client-ip-pool>
  20. - CONNECTION_POOL_DNS=<client-dns>
  21. add-client <user> [<password>]
  22. Generates client certificates ready to be imported in
  23. "/data/pkcs12/.p12" and defines "/data/conf.d/secrets/<user>.conf"
  24. for server. Variables used:
  25. - BASE_DN=<C=ES, O=Lar>
  26. revoke-client <user>
  27. Revokes client in "/data/x509crl/server.crl", deletes "/data/pkcs12/<user>.p12"
  28. and renames "/data/conf.d/secrets/<user>.conf".
  29. public-ip Shows public IPv4 and IPv6
  30. render-template <template> <name> [<kind>]
  31. Renders the template (it can be a file or a name matching a file <template>.template)
  32. and outputs the generated file in /data/conf.d/<kind>/<name>.conf. By default kind is
  33. "connection", but it can be: connection, pool, secret.
  34. Variables depend on the template, so you are free to use as many as you
  35. want. You can define your own template files in <datadir>/templates.
  36. swanctl [args]
  37. Invoke swanctl with the arguments passed.

By default, if no parameters are provided, it will run strongswan server (responder).
The best way to run this project is with docker-compose with a configuration like:

  1. version: "3.3"
  2. services:
  3. vpnserver:
  4. image: strongswan:latest
  5. container_name: vpnserver
  6. sysctls:
  7. - net.core.somaxconn=1024
  8. - net.ipv4.ip_forward=1
  9. - net.ipv4.tcp_syncookies=0
  10. environment:
  11. - SERVER_NAME=192.168.1.105
  12. - BASE_DN=C=ES, O=Lar
  13. - CONNECTION_DEVICE=wlp61s0
  14. - CONNECTION_POOL_ADDRS=10.1.1.0/24
  15. - CONNECTION_POOL_DNS=1.1.1.1,8.8.4.4
  16. cap_add:
  17. - NET_ADMIN
  18. network_mode: "host"
  19. privileged: true
  20. ports:
  21. - "500:500/udp"
  22. - "4500:4500/udp"
  23. volumes:
  24. - ./strongswan:/data
  25. restart: unless-stopped

First time, certificates and configuration is automatically created based
on the environment variables defined in the docker-compose.yml file
or using the defaults in docker/vpn.sh, if not defined. when docker-compose
is up (docker-compose up) you can create clients by attaching a session
to the container and run add-client <user> [<password>]:

  1. docker exec -ti vpnserver /run.sh add-client pepe password

In the directory /data/clients you will find the encrypted PKCS#12 file
pepe.p12 and the pepe-P12-XAUTH-Password.txt file. Import <user>.p12
(unlocked by <user-P12-XAUTH-Password.txt>) into your
remote system, e.g. use:

  • Android - Install strongSwan
  • Linux - Install network-manager.
  • macOS X - Open Keychain App and import the PKCS#12 file into the system-keychain (not login) and mark as “always trusted”. Than go to [Network Settings] > [Add Interface] > [VPN (IKEv2)] and enter the credentials:
    • ServerAdress = HOSTNAME
    • RemoteID = HOSTNAME
    • LocalID = VPN_USER
    • AuthenticationSettings = Certificate of VPN_USER

The user-P12-XAUTH-Password.txt will be also used as key for XAUTH scenarios!

References

Develop

Run ./docker-build.sh to build the docker image based on the current architecture.

Create final release and publish to Docker Hub and Github

Run ./create-publish-release.sh after defining the GITHUB_TOKEN and docker login

Author and License

(c) 2020 Jose Riguera, jriguera@gmail.com

Licensed under the Apache License, Version 2.0 (the “License”);
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

  1. http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an “AS IS” BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.