Code Monkey home page Code Monkey logo

cisco-anyconnect-server-docker's Introduction

cisco anyconnect server docker

Sectoin I: Introduction

As an Iranian citizen, I always have trouble with censorship forced by our beloved government on one hand and foreign sanctions burden on another hand. They banned our IP, filtered our domain, drop MTProto and OpenVPN protocols and even removed our servers from their data centers, but we are always one step ahead :-)

To address these issues I start to use docker to ease the pain of installing and installing and installing the same applications again and again and again. In this way, I can change my host and deploy my applications on a new host in less than a minute. One of my favorite applications to bypass filter is Cisco AnyConnect. I like it because it relays traffic between clients and servers like OpenSSH and HTTPS. In this way, the government can't distinguish between Anyconnect traffic and HTTPS, as a result, they can't block AnyConnect traffic unless they block all HTTPS traffic.

There exist two ways of client authentication, with password or certificate. Password authentication is straightforward and it doesn't need complex configuration but configuration complexity of certificate authentication is rather high; You should understand how certificate works and generate certificate for every user. However, it saves you from having to type the password every time you want to connect. I tried to solve issue of configuration by introducing gcc (generate client certificate) command. You can easily generate new certificate by typing gcc <username> (more on that on section III).

In the section II I will show password authentication configuration and how you can add new clients. In section III I will use the same procedure to introduce certificate authentication. Some tricks to boost your network speed and minimize delay are provided in the final section.

Section II: password authentication configuration

Easiest ocserv configuration is its password authentication. By passing some arguments at build time you can build your own docker image customized for your domain. Run the below command in root directory of this repo to build fresh ocserv docker image with password authentication, customized for your domain. Description of build arguments are provided in Table. 1 .

$ docker build --build-arg ORGANIZATION="Example Corp" --build-arg DOMAIN=example.com -t anyconnect:password ./password/

After successful build run AnyConnect image by:

$ docker run --name any-pass -it --privileged -p 4321:4321 anyconnect:password
Parsing plain auth method subconfig using legacy format
note: setting 'plain' as primary authentication method
note: setting 'file' as supplemental config option
root@a86f00e3e939:/etc/ocserv#

You will be directed to any-pass container bash. Create clients with:

root@a86f00e3e939:/etc/ocserv# ocpasswd -c /etc/ocserv/ocpasswd <username>

After setting up users and their password hit Ctrl-p Ctrl-q to detach from bash. To add more users in future, first execute a new bash on any-pass with:

$ docker exec -it any-pass /bin/bash
root@a86f00e3e939:/etc/ocserv#

and then create users as stated before and quit with exit.


ARG Meaning Default
ORGANIZATION Organization field in generated cetificates. "Example Corp"
DOMAIN Certificate will generate for this domain "example.com"

Table. 1: description of password configuration build args

Section III: certificate authentication configuration

I don't know how you feel about typing your password every time you want to use VPN but I hate it. Certificate authentication comes to rescue. Although it is hard to setup and maintain certificates ocserv, you can easily setup and run your own ocserv with this container and enjoy joining your network with one click. To do so run the below command in root directory of this repo to build a fresh ocserv docker image with certificate authentication customized for your domain. Description of build arguments provided in Table. 1 .

$ docker build --build-arg ORGANIZATION="Example Corp" --build-arg DOMAIN=example.com -t anyconnect:certificate ./certificate/

Easyest way to copy generated certificate outside of container is to use docker volumes. Create cert folder to store certs and pass it as a volume to docker container just like below:

$ cd /to/appropriate/location/
$ mkdir certs
$ docker run --name any-cert -it --privileged -v $(pwd)/certs:/certs -p 4321:4321 anyconnect:certificate
Parsing plain auth method subconfig using legacy format
note: setting 'plain' as primary authentication method
note: setting 'file' as supplemental config option
root@a86f00e3e939:/certs/#

You will directed to any-cert container bash. Create client certificates with gcc <username> and provide certificate password and user password. For example:

root@a86f00e3e939:/certs# gcc john
Generating a 3072 bit RSA private key...
Generating a signed certificate...
X.509 Certificate Information:
  ....
Generating a PKCS #12 structure...
Loading private key list...
Loaded 1 private keys.
Enter a name for the key: john
Enter password:
Confirm password:
Enter plain ocpasswd password:
Enter password:
Re-enter password:
root@a86f00e3e939:/certs#

After generating clients certificates hit Ctrl-p Ctrl-q to detach from bash. To add more users in future, first execute a new bash on any-cert with:

$ docker exec -it any-cert /bin/bash
root@a86f00e3e939:/certs/#

and then create users as stated before and quit with exit.

Use certificate in cisco anyconnect client.

todo

Speed up your network

You can Boost Ubuntu Network Performance by Enabling TCP BBR. Before going forward, check your kernel version. It probably uses a 4.9 or higher kernel version. The following lines quoted from [4].

Once you have kernel 4.9 or above, edit sysctl.conf file.

$ sudo nano /etc/sysctl.conf

Add the following two line at the end of the file.

net.core.default_qdisc=fq
net.ipv4.tcp_congestion_control=bbr

Save and close the file. Then reload sysctl configurations.

sudo sysctl -p

Now check the congestion control algorithm in use.

$ sysctl net.ipv4.tcp_congestion_control
net.ipv4.tcp_congestion_control = bbr

Congrats! You have successfully enabled TCP BBR on Ubuntu.

Some useful commands

Get certificate's expiration date:

# openssl pkcs12 -in <certificate file name> -nodes     -passin pass:"<password>" | openssl x509 -noout -enddate

Enable ip forwarding

# apt install iptables-persistent
# iptables -P FORWARD ACCEPT
# iptables-save > /etc/iptables/iptables.rules
# vim /etc/crontab ( add "* * * * * root iptables -P FORWARD ACCEPT" there)

References

[1] : https://lowendbox.com/blog/install-openconnect-server-on-ubuntu-16-04/
[2] : https://www.linuxbabe.com/ubuntu/openconnect-vpn-server-ocserv-ubuntu-16-04-17-10-lets-encrypt
[3] : https://www.linuxbabe.com/ubuntu/certificate-authentication-openconnect-vpn-server-ocserv
[4] : https://www.linuxbabe.com/ubuntu/enable-google-tcp-bbr-ubuntu
[5] : https://github.com/sfc9982/AnyConnect-Server

cisco-anyconnect-server-docker's People

Contributors

saarangsoltani avatar soreana avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

cisco-anyconnect-server-docker's Issues

not working anycisco cert

سلام وقت بخیر چون فکر می کنم مخاطبان بیشتر ایرانی هستن این پست رو میذارم

من در حالت پسورد عادی می تونم کانکت بشم ولی روی ایرانسل جواب نمیده بنابراین اومدم و روی حالت cert راه اندازی کردم ولی دیگه اصلا نمی تونم حتی با isp های دیگه هم متصل بشم نمی دونم مشکل چی هست و چطوری حلش کنم اگر راهنمایی بفرمایید ممنون میشم

certtools issue

when I built a Docker file, got this error:

[10/15] RUN certtool --generate-self-signed --load-privkey ca-key.pem --template ca.tmpl --outfile ca-cert.pem:
#0 0.318 Trailing garbage: ` '
#0 0.318 error parsing number: 1

Do you have any idea, how I can fix that?

Cannot access SSH when client is connected

First of all, I really appreciate your effort. This image is what I really was looking for.
I just faced an issue with connecting to host machine's internal network when my client is connected to OCServ container. Perhaps the container cannot access the host machine's network.

I don't know if linking the container to host network using --net=host suitable. Do you have any idea around it?

couldn't set any limitation on connection and timing per user

I really appreciate your effort. I am looking for a limitation on the maximum size of connection per user and set a limitation on the time period of using this account.
for example, create a user for my client that only let him connect by only one device and set a time limit for 30 days of using this account

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.