Docker/Pods/Wifi: Difference between revisions
From charlesreid1
| Line 80: | Line 80: | ||
This is the configuration file that will be copied into the Docker container and used with its stunnel instance. It is recommended you check out https://charlesreid1.com:3000/docker/d-stunnel and put it into the d-stunnel/ directory. | This is the configuration file that will be copied into the Docker container and used with its stunnel instance. It is recommended you check out https://charlesreid1.com:3000/docker/d-stunnel and put it into the d-stunnel/ directory. | ||
===TLDR=== | ===TLDR=== | ||
Revision as of 03:49, 31 March 2017
Wifi Boat Overview
Services
UGR wifi boat ships the following services in Docker containers:
- stunnel server
- web server (hello world, report, file management)
- https web server 9hello world)
- mongodb database
Stretch goals:
- Data to inform the server about processes that are running? How to install a program that runs on the pi and tries to call home and send updates on information going on with the operating system, running processes, etc.?
Please make a note:
- The UGR wifi boat does not receive or process raw packet data. The Raspberry Pi device will extract network data, either by using a tool that extracts relevant information or by running a tool like scapy or aircrack on the Raspberry Pi to capture and process network data local to the Pi. Only small, digested, processed data is sent back to the server.
Getting Set Up For The Boat
Make sure your node is all set: Deployment/New Node Checklist
Make sure docker installed: Docker/Installing
Boat Containers
Stunnel
Stunnel is a server/client service that allows arbitrary traffic to be transported through an encrypted HTTP over SSL layer (HTTPS). Since port 443 is usually open even on locked-down networks, this is an extremely handy tool for punching through firewalls. Due to the nature of encrypted traffic, the contents of an HTTPS packet cannot be inspected, so services that would otherwise be blocked due to their protocols, like SSH, can pass in and out of the network just fine by being wrapped up in HTTPS.
Here's how the Stunnel Docker container will be set up:
- Create a Dockerfile (you can download a prepared one, but they are easy enough to make that it is worth doing yourself.)
- Make a Docker Stunnel container image
- Run a Docker Stunnel container image
- Ensure that Stunnel is working and configured properly (ignoring network)
- Ensure that networking with host is working and configured properly
Get Files
Get the Dockerfile from the git.charlesreid1.com repo: https://charlesreid1.com:3000/docker/d-stunnel
$ mkdir ~/docker $ cd ~/docker $ git clone https://charlesreid1.com:3000/docker/d-stunnel $ cd d-stunnel
This will also have some supporting scripts and example config files.
Create Certificate
Next step is to create a certificate.
Option 1 is to use Let's Encrypt (recommended). Use the LetsEncrypt page and the generate_letsencrypt_cert.sh script in the d-stunnel repository.
Option 2 is to use a self-signed certificate. See RaspberryPi/SSH Stunnel for details and use the generate_ss_cert.sh script in the d-stunnel repository.
Link to d-stunnel repository: https://charlesreid1.com:3000/docker/d-stunnel
Configure Client
Next, configure your client stunnel using stunnel.conf. On a Mac, this will go in /usr/local/etc/stunnel/stunnel.conf. On Ubuntu/Linux, it will go in /etc/stunnel/stunnel.conf. The client machine's configuration should map ports matching whatever you're trying to do. There are some examples in the docker/d-stunnel repository on git.charlesreid1.com: https://charlesreid1.com:3000/docker/d-stunnel
These pages have sample client configuration files:
- Stunnel/SSH - tunneling SSH over port 443
- Stunnel/Scp - tunneling secure copy over port 443
- Stunnel/HTTP - tunneling HTTP traffic over port 8000
Configure Server
Configure the server by setting the server's stunnel.conf file to match the client's and whatever service you're trying to access.
These pages have sample server configuration files:
This is the configuration file that will be copied into the Docker container and used with its stunnel instance. It is recommended you check out https://charlesreid1.com:3000/docker/d-stunnel and put it into the d-stunnel/ directory.
TLDR
You have to map ports from container to host, and your host and container have to share the same network interface. Here is what the final run command looks like:
docker run \ --network=host \ -p 443:443 -p 22:22 \ -ti cmr_stunnel \ /bin/bash
Build Docker stunnel container image from Dockerfile
From the git repo checked out above, which contains a Dockerfile, run docker build to build the image:
$ docker build -t cmr_stunnel .
This may take a minute. Once that's finished make sure Docker now lists the image:
$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE cmr_stunnel latest 2b197f506e02 59 seconds ago 219 MB
Run the Docker stunnel container image
You can fire up the docker container and get a Bash shell:
$ docker run -ti cmr_stunnel /bin/bash
Test that the stunnel command works.
Now that stunnel is running okay, and the certificates are working, let's get the networking and ports figured out.
Port Mapping
Docker networking guide provides some useful info: https://docs.docker.com/engine/userguide/networking/
We can specify three networks: the host network, a bridge network (shared between host and container only), or no network at all.
We want to attach the container to the outside world via the standard network interface onboard the host. Use --network=host when running the container .
ok,
but now prob is,
how to id self, container missing ifconfig
Load Image with Networking/Ports Configured
Links
Stunnel documentation (man page): https://www.stunnel.org/static/stunnel.html
Stunnel Dockerfile that is about as simple as it is going to get: https://github.com/taskworld/docker-stunnel/blob/master/Dockerfile
Note: ufw needs to accept, not drop, traffic: [1]
Note: container needs to bind to 0.0.0.0, not localhost, or it won't be accessible outside the container: [2]