-
Notifications
You must be signed in to change notification settings - Fork 183
Add stunnel functionality for plaintext service TLS encapsulation #336
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
UFOSmuggler
wants to merge
17
commits into
MISP:master
Choose a base branch
from
UFOSmuggler:stunnel
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 9 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
82cb681
add stunnel functionality and a cheeky rename of the mysql_tls defaul…
UFOSmuggler d2d59bf
Defaults only inside entrypoint.sh for consistency
UFOSmuggler 4867289
add documentation for stunnel service
UFOSmuggler 10dca58
add a bit on troubleshooting
UFOSmuggler 56faa68
add gitignored docker-compose.override.yml file
UFOSmuggler f948a3c
fix headline level
UFOSmuggler 42ed8b3
tune logging, turn off ocsprequire in example config
UFOSmuggler b83b672
fix log tuning mistake
UFOSmuggler c47d50e
increase verify level
UFOSmuggler 9fa95d1
Merge branch 'master' into stunnel
ostefano 80368e8
Merge branch 'MISP:master' into stunnel
UFOSmuggler d024b20
change stunnel installation to be conditional on STUNNEL envar
UFOSmuggler db78197
Revert "change stunnel installation to be conditional on STUNNEL envar"
UFOSmuggler 7a85ad8
remove stunnel4 from slim
UFOSmuggler b27076b
bring STUNNEL_CONFIG envar default value into alignment with document…
UFOSmuggler 68a6ac4
make gencerts.sh executable as suggested in documentation
UFOSmuggler 6c4679a
fix gencerts.sh permissions in correct location
UFOSmuggler File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| [program:stunnel] | ||
| directory=/tmp | ||
| command=/usr/bin/stunnel %(ENV_STUNNEL_CONFIG)s | ||
| process_name=%(program_name)s_%(process_num)02d | ||
| numprocs=1 | ||
| autostart=%(ENV_STUNNEL)s | ||
| autorestart=true | ||
| redirect_stderr=false | ||
| stderr_logfile=/var/www/MISP/app/tmp/logs/stunnel-errors.log | ||
| stdout_logfile=/var/www/MISP/app/tmp/logs/stunnel.log | ||
| stderr_logfile_backups=2 | ||
| stderr_logfile_maxbytes=5MB | ||
| stdout_logfile_backups=2 | ||
| stdout_logfile_maxbytes=5MB | ||
| user=root |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| services: | ||
| misp-core: | ||
| volumes: | ||
| - ./misp_custom:/custom | ||
| redis: | ||
| command: | | ||
| sh -c ' | ||
| if [ "$${ENABLE_REDIS_EMPTY_PASSWORD:-false}" = "true" ]; then | ||
| exec valkey-server \ | ||
| --port 0 \ | ||
| --tls-port 6379 \ | ||
| --tls-cert-file /custom/server-cert.pem \ | ||
| --tls-key-file /custom/server-key.pem \ | ||
| --tls-ca-cert-file /custom/ca.pem \ | ||
| --tls-auth-clients yes | ||
| else | ||
| exec valkey-server \ | ||
| --port 0 \ | ||
| --tls-port 6379 \ | ||
| --tls-cert-file /custom/client-cert.pem \ | ||
| --tls-key-file /custom/client-key.pem \ | ||
| --tls-ca-cert-file /custom/ca.pem \ | ||
| --tls-auth-clients yes \ | ||
| --requirepass "$${REDIS_PASSWORD:-redispassword}" | ||
| fi | ||
| ' | ||
| healthcheck: | ||
| test: | | ||
| sh -c ' | ||
| if [ "$${ENABLE_REDIS_EMPTY_PASSWORD:-false}" = "true" ]; then | ||
| valkey-cli \ | ||
| --tls \ | ||
| --cert /custom/client-cert.pem \ | ||
| --key /custom/client-key.pem \ | ||
| --cacert /custom/ca.pem \ | ||
| -p $${REDIS_PORT:-6379} \ | ||
| ping | grep -q PONG || exit 1 | ||
| else | ||
| valkey-cli \ | ||
| --tls \ | ||
| --cert /custom/client-cert.pem \ | ||
| --key /custom/client-key.pem \ | ||
| --cacert /custom/ca.pem \ | ||
| -a "$${REDIS_PASSWORD:-redispassword}" \ | ||
| -p $${REDIS_PORT:-6379} \ | ||
| ping | grep -q PONG || exit 1 | ||
| fi | ||
| ' | ||
| volumes: | ||
| - ./misp_custom/redis_tls:/custom:ro |
52 changes: 52 additions & 0 deletions
52
docs/examples/stunnel/redis/misp_custom/redis_tls/gencerts.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| #!/bin/bash | ||
|
|
||
| # --- CA --- | ||
| openssl genrsa -out ca-key.pem 4096 | ||
|
|
||
| openssl req -x509 -new -nodes \ | ||
| -key ca-key.pem \ | ||
| -sha256 -days 3650 \ | ||
| -subj "/C=AU/ST=VIC/L=Melbourne/O=Example/OU=CA/CN=Example-CA" \ | ||
| -out ca.pem | ||
|
|
||
|
|
||
| # --- SERVER CERT --- | ||
| openssl genrsa -out server-key.pem 2048 | ||
|
|
||
| openssl req -new \ | ||
| -key server-key.pem \ | ||
| -subj "/C=AU/ST=VIC/L=Melbourne/O=Example/OU=Server/CN=redis" \ | ||
| -addext "subjectAltName=DNS:redis,DNS:localhost,IP:127.0.0.1" \ | ||
| -out server.csr | ||
|
|
||
| openssl x509 -req \ | ||
| -in server.csr \ | ||
| -CA ca.pem \ | ||
| -CAkey ca-key.pem \ | ||
| -CAcreateserial \ | ||
| -sha256 -days 825 \ | ||
| -out server-cert.pem \ | ||
| -extfile <(printf "subjectAltName=DNS:redis,DNS:localhost,IP:127.0.0.1") | ||
|
|
||
|
|
||
| # --- CLIENT CERT --- | ||
| openssl genrsa -out client-key.pem 2048 | ||
|
|
||
| openssl req -new \ | ||
| -key client-key.pem \ | ||
| -subj "/C=AU/ST=VIC/L=Melbourne/O=Example/OU=Client/CN=client" \ | ||
| -out client.csr | ||
|
|
||
| openssl x509 -req \ | ||
| -in client.csr \ | ||
| -CA ca.pem \ | ||
| -CAkey ca-key.pem \ | ||
| -CAcreateserial \ | ||
| -sha256 -days 825 \ | ||
| -out client-cert.pem | ||
|
|
||
|
|
||
| # --- PERMS --- | ||
| chmod 600 ca-key.pem server-key.pem client-key.pem | ||
| chmod 644 ca.pem server-cert.pem client-cert.pem | ||
|
|
13 changes: 13 additions & 0 deletions
13
docs/examples/stunnel/redis/misp_custom/stunnel/stunnel.conf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| foreground = yes | ||
| pid = /var/run/stunnel.pid | ||
| debug = 3 | ||
| [elasticache] | ||
| client = yes | ||
| accept = localhost:6379 | ||
| connect = redis:6379 | ||
|
|
||
| cert = /custom/redis_tls/client-cert.pem | ||
| key = /custom/redis_tls/client-key.pem | ||
| CAfile = /custom/redis_tls/ca.pem | ||
| verify = 2 | ||
| OCSPrequire = no |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| # MISP stunnel Guide # | ||
|
|
||
| This guide provides some basic examples of how to use the [stunnel](https://www.stunnel.org/) functionality provided in the misp-docker image. | ||
|
|
||
| ## Enabling ## | ||
|
|
||
| `template.env` contains two stunnel related variables: | ||
| | Variable | Values | Default | Purpose | | ||
| | :------------- | :--------------- | :------ | :------------------------------------------------------------------------- | | ||
| | STUNNEL | `true`/`false` | `false` | If true will start the stunnel service on container start, via supervisord | | ||
| | STUNNEL_CONFIG | File path string | | Must contain a file path to a stunnel config file | | ||
|
|
||
| If `STUNNEL` is `true` but `STUNNEL_CONFIG` is unset, empty or otherwise does not point to a config file, supervisord will retry starting the service a few times before failing. | ||
|
|
||
| ## Configuration ## | ||
|
|
||
| You can find the stunnel configuration documentation [here](https://www.stunnel.org/static/stunnel.html), and general examples [here](https://www.stunnel.org/examples.html). | ||
|
|
||
| ## Example: Redis over TLS ## | ||
|
|
||
| This example demonstrates how misp-docker's Redis (Valkey) container might be configured to use TLS, and how to leverage the stunnel functionality to communicate with it over TLS. | ||
|
|
||
| The general idea here is that stunnel will expose a plaintext port for the MISP codebase to talk Redis over, which will then be proxied to the `redis` container's TLS speaking port. Traffic across the containers will be via TLS as a result. You could just as easily point to an AWS Elasticache or other external Redis instance with the benefit of TLS encryption. | ||
|
|
||
| This example largely builds on [this](https://redis.io/blog/stunnel-secure-redis-ssl/) redis.io blog post. | ||
|
|
||
| ### Steps: ### | ||
|
|
||
| #### Copy the example files into the root of your misp-docker project #### | ||
|
|
||
| If you have an existing directory named `misp_custom` or a `docker-compose.override.yml` file already, the below will mess with them. You may wish to manually add these things in that case. | ||
|
|
||
| Change into your misp-docker project dir first. | ||
|
|
||
| ``` | ||
| cp -r docs/examples/stunnel/redis/misp_custom . | ||
| cp docs/examples/stunnel/redis/docker-compose.override.yml . | ||
| ``` | ||
|
|
||
| The `docker-compose.override.yml` file will reference the files within the `misp_custom` directory, tell Redis to use TLS key files for TLS communications, and tell the health check to use it as well. | ||
|
|
||
| #### Roll some certificates #### | ||
|
|
||
| We will do this in the `misp_custom/redis_tls` directory using `gencerts.sh` which were copied from the last step: | ||
|
|
||
| ``` | ||
| cd misp_custom/redis_tls | ||
| ./gencerts.sh | ||
| cd ../.. | ||
| ``` | ||
|
|
||
| You should be left with a directory structure that looks like this: | ||
|
|
||
| ``` | ||
| tree misp_custom | ||
| misp_custom/ | ||
| ├── redis_tls | ||
| │ ├── ca-key.pem | ||
| │ ├── ca.pem | ||
| │ ├── ca.srl | ||
| │ ├── client-cert.pem | ||
| │ ├── client.csr | ||
| │ ├── client-key.pem | ||
| │ ├── gencerts.sh | ||
| │ ├── server-cert.pem | ||
| │ ├── server.csr | ||
| │ └── server-key.pem | ||
| └── stunnel | ||
| └── stunnel.conf | ||
|
|
||
| 3 directories, 11 files | ||
| ``` | ||
|
|
||
| #### Update .env file with necessary values #### | ||
|
|
||
| Edit your .env file so that the following envars are like this: | ||
|
|
||
| ``` | ||
| REDIS_HOST=localhost | ||
| STUNNEL=true | ||
| STUNNEL_CONFIG=/custom/stunnel/stunnel.conf | ||
| ``` | ||
|
|
||
| #### Bring up the compose project #### | ||
|
|
||
| ``` | ||
| docker compose up -d | ||
| ``` | ||
|
|
||
| You should now have TLS wrapped Redis, where the client and server are authenticating each other. | ||
|
|
||
| Check the Administration -> Server Settings & Maintenance -> Diagnostics tool for system status. | ||
|
|
||
| ### Troubleshooting ### | ||
|
|
||
| Places to look for clues if you run into trouble: | ||
|
|
||
| * stunnel log files will appear in in the `logs` dir as `stunnel.log` and `stunnel-errors.log` | ||
| * Redis/valkey log output can be found in the `redis` container | ||
| * Supervisord log output can be found in the `misp-core` container |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.