2020-06-08 02:44:19 +08:00
---
title: "Docker"
date: 2020-05-26T20:57:28+03:00
draft: false
pre: '< i class = "fab fa-docker" > < / i > '
weight: 4
2021-01-28 02:23:40 +08:00
tags: ["setup", "docker", "linux", "windows"]
2020-06-08 02:44:19 +08:00
---
2021-06-07 21:54:09 +08:00
## Supported operating systems
The Infection Monkey Docker container works on Linux only. It is not compatible with Docker for Windows or Docker for Mac.
2020-06-08 02:44:19 +08:00
## Deployment
2021-06-07 21:56:02 +08:00
### 1. Load the docker images
1. Pull the MongoDB v4.2 Docker image:
2021-05-11 23:27:59 +08:00
2021-06-07 21:56:02 +08:00
```bash
sudo docker pull mongo:4.2
```
2020-06-08 02:44:19 +08:00
2021-06-07 21:56:02 +08:00
1. Extract the Monkey Island Docker tarball:
2020-06-08 02:44:19 +08:00
2021-06-07 21:56:02 +08:00
```bash
2021-10-22 15:03:18 +08:00
tar -xvzf InfectionMonkey-docker-v1.12.0.tgz
2021-06-07 21:56:02 +08:00
```
2020-06-14 20:44:07 +08:00
2021-06-07 21:56:02 +08:00
1. Load the Monkey Island Docker image:
```bash
2021-10-22 15:03:18 +08:00
sudo docker load -i InfectionMonkey-docker-v1.12.0.tar
2021-06-07 21:56:02 +08:00
```
### 2. Start MongoDB
1. Start a MongoDB Docker container:
```bash
sudo docker run \
--name monkey-mongo \
--network=host \
--volume db:/data/db \
2021-06-18 08:08:28 +08:00
--detach \
mongo:4.2
2021-06-07 21:56:02 +08:00
```
### 3a. Start Monkey Island with default certificate
By default, Infection Monkey comes with a [self-signed SSL certificate ](https://aboutssl.org/what-is-self-sign-certificate/ ). In
enterprise or other security-sensitive environments, it is recommended that the
user [provide Infection Monkey with a
certificate](#3b-start-monkey-island-with-user-provided-certificate) that has
been signed by a private certificate authority.
1. Run the Monkey Island server
```bash
sudo docker run \
--name monkey-island \
--network=host \
2021-08-06 02:48:06 +08:00
guardicore/monkey-island:VERSION
2021-06-07 21:56:02 +08:00
```
2021-06-07 22:37:06 +08:00
### 3b. Start Monkey Island with user-provided certificate
2021-06-07 21:56:02 +08:00
1. Create a directory named `monkey_island_data` . This will serve as the
location where Infection Monkey stores its configuration and runtime
artifacts.
```bash
mkdir ./monkey_island_data
2021-06-10 23:33:05 +08:00
chmod 700 ./monkey_island_data
2021-06-07 21:56:02 +08:00
```
1. Run Monkey Island with the `--setup-only` flag to populate the `./monkey_island_data` directory with a default `server_config.json` file.
```bash
sudo docker run \
--rm \
--name monkey-island \
--network=host \
2021-06-10 23:34:08 +08:00
--user "$(id -u ${USER}):$(id -g ${USER})" \
2021-06-07 21:56:02 +08:00
--volume "$(realpath ./monkey_island_data)":/monkey_island_data \
2021-08-06 02:48:06 +08:00
guardicore/monkey-island:VERSION --setup-only
2021-06-07 21:56:02 +08:00
```
2021-06-10 22:50:59 +08:00
1. Move your `.crt` and `.key` files to `./monkey_island_data` .
2021-06-07 21:56:02 +08:00
2021-06-11 01:08:02 +08:00
1. Make sure that your `.crt` and `.key` files are readable and writeable only by you.
2021-06-07 21:56:02 +08:00
```bash
2021-06-10 22:50:59 +08:00
chmod 600 ./monkey_island_data/< KEY_FILE >
chmod 600 ./monkey_island_data/< CRT_FILE >
2021-06-07 21:56:02 +08:00
```
1. Edit `./monkey_island_data/server_config.json` to configure Monkey Island
to use your certificate. Your config should look something like this:
```json {linenos=inline,hl_lines=["11-14"]}
{
"data_dir": "/monkey_island_data",
"log_level": "DEBUG",
"environment": {
"server_config": "password",
"deployment": "docker"
},
"mongodb": {
"start_mongodb": false
},
"ssl_certificate": {
2021-06-10 22:50:59 +08:00
"ssl_certificate_file": "/monkey_island_data/< CRT_FILE > ",
"ssl_certificate_key_file": "/monkey_island_data/< KEY_FILE > "
2021-06-07 21:56:02 +08:00
}
}
```
1. Start the Monkey Island server:
```bash
sudo docker run \
--name monkey-island \
--network=host \
2021-06-10 23:34:08 +08:00
--user "$(id -u ${USER}):$(id -g ${USER})" \
2021-06-07 21:56:02 +08:00
--volume "$(realpath ./monkey_island_data)":/monkey_island_data \
2021-08-06 02:48:06 +08:00
guardicore/monkey-island:VERSION
2021-06-07 21:56:02 +08:00
```
### 4. Accessing Monkey Island
After the Monkey Island docker container starts, you can access Monkey Island by pointing your browser at `https://localhost:5000` .
2021-05-11 23:27:59 +08:00
2020-06-14 20:44:07 +08:00
## Upgrading
2021-01-28 01:54:35 +08:00
Currently, there's no "upgrade-in-place" option when a new version is released.
To get an updated version, download it, stop the current container and run the
installation commands again with the new file.
2020-06-14 20:44:07 +08:00
2021-01-28 01:54:35 +08:00
If you'd like to keep your existing configuration, you can export it to a file
using the *Export config* button and then import it to the new Monkey Island.
2020-06-14 20:44:07 +08:00
![Export configuration ](../../images/setup/export-configuration.png "Export configuration" )
2021-03-31 19:10:36 +08:00
## Troubleshooting
### The Monkey Island container crashes due to a 'UnicodeDecodeError'
2021-06-07 21:56:52 +08:00
You will encounter a `UnicodeDecodeError` if the `monkey-island` container is
using a different secret key to encrypt sensitive data than was initially used
to store data in the `monkey-mongo` container.
2021-03-31 19:10:36 +08:00
2021-06-07 21:56:52 +08:00
```
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xee in position 0: invalid continuation byte
```
2021-03-31 19:10:36 +08:00
2021-08-06 02:48:06 +08:00
Starting a new container from the `guardicore/monkey-island:VERSION` image
2021-06-07 21:56:52 +08:00
generates a new secret key for storing sensitive information in MongoDB. If you
have an old database instance running (from a previous instance of Infection
Monkey), the data stored in the `monkey-mongo` container has been encrypted
with a key that is different from the one that Monkey Island is currently
using. When MongoDB attempts to decrypt its data with the new key, decryption
fails and you get this error.
You can fix this in one of three ways:
2021-03-31 19:10:36 +08:00
1. Instead of starting a new container for the Monkey Island, you can run `docker container start -a monkey-island` to restart the existing container, which will contain the correct key material.
2021-06-07 21:56:52 +08:00
1. Kill and remove the existing MongoDB container, and start a new one. This will remove the old database entirely. Then, start the new Monkey Island container.
1. When you start the Monkey Island container, use `--volume
monkey_island_data:/monkey_island_data`. This will store all of Monkey
Island's runtime artifacts (including the encryption key file) in a docker
volume that can be reused by subsequent Monkey Island containers.