Skip to content

Commit 2c7c3a0

Browse files
authored
Add MISP-Guard container (#301)
1 parent 79ba736 commit 2c7c3a0

File tree

9 files changed

+251
-4
lines changed

9 files changed

+251
-4
lines changed

.github/workflows/release-latest.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111

1212
strategy:
1313
matrix:
14-
target: [misp-core, misp-modules, misp-core-slim, misp-modules-slim]
14+
target: [misp-core, misp-modules, misp-core-slim, misp-modules-slim, misp-guard]
1515

1616
permissions:
1717
contents: read

.github/workflows/test-build-latest.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010

1111
strategy:
1212
matrix:
13-
target: [misp-core, misp-modules, misp-core-slim, misp-modules-slim]
13+
target: [misp-core, misp-modules, misp-core-slim, misp-modules-slim, misp-guard]
1414

1515
steps:
1616
- name: Checkout repository

README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,58 @@ To override these behaviours edit the docker-compose.yml file's misp-core volume
9696
If it is just a default setting that is meant to be set if not already set by the user, add it in one of the `*.default.json` files.
9797
If it is a setting controlled by an environment variable which is meant to override whatever is set, add it in one of the `*.envars.json` files (note that you can still specify a default value).
9898

99+
### MISP-Guard (optional)
100+
101+
[MISP-Guard](https://github.com/MISP/misp-guard) is a mitmproxy add-on designed to apply configurable filters that prevent the unintentional leakage of sensitive threat intelligence data while facilitating controlled information sharing.
102+
103+
It is disabled by default, but can be enabled using compose profiles.
104+
105+
#### Enabling
106+
107+
1. Enable the profile in your `.env` file:
108+
```bash
109+
COMPOSE_PROFILES=misp-guard
110+
```
111+
2. Ensure `misp-core` is configured to use a proxy:
112+
```bash
113+
PROXY_ENABLE=true
114+
PROXY_HOST=misp-guard
115+
# this must match GUARD_PORT (DEFAULT=8888)
116+
PROXY_PORT=8888
117+
```
118+
119+
#### Configuration
120+
121+
- Rules are defined in `guard/config.json`.
122+
- The container automatically replaces the `misp-core` IP at runtime using `entrypoint.sh`.
123+
124+
The following format is required to target the misp-core, the IP is replaced with the misp-core container's IP at runtime.
125+
```json
126+
{
127+
"instances": {
128+
"misp_container": {
129+
"ip": "placeholder"
130+
}
131+
}
132+
}
133+
```
134+
135+
- After making changes to `guard/config.json` restart the container to apply the changes:
136+
```bash
137+
docker compose restart misp-guard
138+
```
139+
140+
#### Environment Variables
141+
142+
```bash
143+
# Port for misp-guard to listen on (must match PROXY_PORT)
144+
# Default: 8888
145+
GUARD_PORT=8888
146+
147+
# optional: mitmdump misp-guard runtime arguments (space separated, no quotes)
148+
GUARD_ARGS=--ssl-insecure -v
149+
```
150+
99151
### Authentication
100152

101153
#### LDAP Authentication

docker-bake.hcl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,14 @@ variable "CORE_COMMIT" {
7474
default = ""
7575
}
7676

77+
variable "GUARD_TAG" {
78+
default = ""
79+
}
80+
81+
variable "GUARD_COMMIT" {
82+
default = ""
83+
}
84+
7785
variable "PHP_VER" {
7886
default = null
7987
}
@@ -84,6 +92,7 @@ group "default" {
8492
"misp-modules-slim",
8593
"misp-core",
8694
"misp-core-slim",
95+
"misp-guard",
8796
]
8897
}
8998

@@ -160,3 +169,14 @@ target "misp-core-slim" {
160169
}
161170
platforms = "${PLATFORMS}"
162171
}
172+
173+
target "misp-guard" {
174+
context = "guard/."
175+
dockerfile = "Dockerfile"
176+
tags = flatten(["${NAMESPACE}/misp-guard:latest", "${NAMESPACE}/misp-guard:${COMMIT_HASH}", GUARD_TAG != "" ? ["${NAMESPACE}/misp-guard:${GUARD_TAG}"] : []])
177+
args = {
178+
"GUARD_TAG": "${GUARD_TAG}",
179+
"GUARD_COMMIT": "${GUARD_COMMIT}"
180+
}
181+
platforms = "${PLATFORMS}"
182+
}

docker-compose.yml

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,31 @@ services:
276276
- "./custom/export_mod/:/custom/export_mod/:Z"
277277
- "./custom/import_mod/:/custom/import_mod/:Z"
278278

279+
misp-guard:
280+
profiles:
281+
- misp-guard
282+
image: ghcr.io/misp/misp-docker/misp-guard:${GUARD_RUNNING_TAG:-latest}
283+
build:
284+
context: guard/.
285+
args:
286+
- GUARD_TAG=${GUARD_TAG:?Missing .env file, see README.md for instructions}
287+
- GUARD_COMMIT=${GUARD_COMMIT}
288+
depends_on:
289+
- misp-core
290+
ports:
291+
- "${GUARD_PORT:-8888}:${GUARD_PORT:-8888}"
292+
environment:
293+
- "GUARD_PORT=${GUARD_PORT:-8888}"
294+
- "GUARD_ARGS=${GUARD_ARGS}"
295+
volumes:
296+
- ./guard/config.json:/config.json:ro
297+
healthcheck:
298+
test: "/bin/bash -c '</dev/tcp/localhost/${GUARD_PORT:-8888}'"
299+
interval: 2m
300+
timeout: 5s
301+
retries: 3
302+
start_period: 10s
303+
304+
279305
volumes:
280306
mysql_data:
281-

guard/Dockerfile

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
ARG DOCKER_HUB_PROXY=""
2+
3+
FROM "${DOCKER_HUB_PROXY}python:3.12-slim-bookworm" AS python-build
4+
ENV DEBIAN_FRONTEND=noninteractive
5+
ARG GUARD_TAG
6+
ARG GUARD_COMMIT
7+
8+
RUN <<-EOF
9+
apt-get update
10+
apt-get install -y --no-install-recommends \
11+
ca-certificates \
12+
git
13+
apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/*
14+
EOF
15+
16+
RUN mkdir /wheels
17+
18+
RUN <<-EOF
19+
if [ ! -z ${GUARD_COMMIT} ]; then
20+
git clone https://github.com/MISP/misp-guard.git /srv/misp-guard && cd /srv/misp-guard && git checkout ${GUARD_COMMIT}
21+
else
22+
git clone --branch ${GUARD_TAG} --depth 1 https://github.com/MISP/misp-guard.git /srv/misp-guard
23+
fi
24+
EOF
25+
26+
WORKDIR /srv/misp-guard/src
27+
RUN pip wheel -r requirements.txt --no-cache-dir -w /wheels/
28+
29+
30+
31+
FROM "${DOCKER_HUB_PROXY}python:3.12-slim-bookworm"
32+
ENV DEBIAN_FRONTEND=noninteractive
33+
34+
RUN <<-EOF
35+
apt-get update
36+
apt-get install -y --no-install-recommends \
37+
jq
38+
apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/*
39+
EOF
40+
41+
COPY --from=python-build /wheels /wheels
42+
RUN pip install --no-cache-dir /wheels/*.whl && rm -rf /wheels
43+
44+
COPY --from=python-build /srv /srv
45+
COPY files/ /
46+
47+
WORKDIR /srv/misp-guard/src
48+
ENTRYPOINT [ "/entrypoint.sh" ]

guard/config.json

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
{
2+
"allowlist": {
3+
"urls": [],
4+
"domains": []
5+
},
6+
"compartments_rules": {
7+
"can_reach": {
8+
"compartment_1": [
9+
"compartment_1"
10+
]
11+
}
12+
},
13+
"instances": {
14+
"misp_container": {
15+
"ip": "AUTO_REPLACED_AT_RUNTIME",
16+
"host": "local-misp",
17+
"port": 443,
18+
"compartment_id": "compartment_1",
19+
"affiliation": "internal",
20+
"taxonomies_rules": {
21+
"required_taxonomies": [],
22+
"allowed_tags": {},
23+
"blocked_tags": [
24+
"tlp:red"
25+
]
26+
},
27+
"blocked_distribution_levels": [],
28+
"blocked_sharing_groups_uuids": [],
29+
"blocked_attribute_types": [],
30+
"blocked_attribute_categories": [],
31+
"blocked_object_types": []
32+
},
33+
"partner_example": {
34+
"ip": "10.0.0.1",
35+
"host": "partner.misp.org",
36+
"port": 443,
37+
"compartment_id": "compartment_1",
38+
"affiliation": "partner",
39+
"taxonomies_rules": {
40+
"required_taxonomies": [],
41+
"allowed_tags": {
42+
"tlp": [
43+
"tlp:clear",
44+
"tlp:white",
45+
"tlp:green"
46+
]
47+
},
48+
"blocked_tags": [
49+
"tlp:red"
50+
]
51+
},
52+
"blocked_distribution_levels": [],
53+
"blocked_sharing_groups_uuids": [],
54+
"blocked_attribute_types": [],
55+
"blocked_attribute_categories": [],
56+
"blocked_object_types": []
57+
}
58+
}
59+
}

guard/files/entrypoint.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/sh
2+
3+
# Entry point for misp-guard.
4+
# This ensures MISP-core's IP is set at runtime when misp-guard starts.
5+
# config.json must reflect this structure to ensure the source container is targeted
6+
# {
7+
# "instances": {
8+
# "misp_container": {
9+
# "ip": "placeholder"
10+
# }
11+
# }
12+
# }
13+
14+
15+
set -e
16+
17+
# resolve misp-core from docker dns
18+
MISP_IP=$(getent hosts misp-core | awk '{print $1}')
19+
20+
# replace runtime ip into config.json
21+
jq --arg ip "$MISP_IP" \
22+
'.instances.misp_container.ip = $ip' \
23+
/config.json > /srv/misp-guard/src/config.json
24+
25+
exec mitmdump -s mispguard.py -p ${GUARD_PORT:-8888} ${GUARD_ARGS:+$GUARD_ARGS} --set config=config.json

template.env

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ CORE_TAG=v2.5.21
66
# CORE_FLAVOR=full
77
MODULES_TAG=v3.0.2
88
# MODULES_FLAVOR=full
9+
GUARD_TAG=v1.2
910
PHP_VER=20220829
1011

1112
# PYPY_* vars take precedence over MISP's
@@ -26,13 +27,16 @@ PYPI_SUPERVISOR_VERSION="==4.2.5"
2627
# CORE_COMMIT=0bba3f5
2728
# MODULES_COMMIT takes precedence over MODULES_TAG
2829
# MODULES_COMMIT=de69ae3
30+
# GUARD_COMMIT takes precedence over GUARD_TAG
31+
# GUARD_COMMIT=370b043
2932

3033
##
3134
# Run-time variables
3235
##
3336

3437
# CORE_RUNNING_TAG=latest
3538
# MODULES_RUNNING_TAG=latest
39+
# GUARD_RUNNING_TAG=latest
3640

3741
# Email/username for user #1, defaults to MISP's default (admin@admin.test)
3842
ADMIN_EMAIL=
@@ -204,14 +208,28 @@ SYNCSERVERS_1_PULL_RULES=
204208
# AAD_MISP_SITEADMIN="Misp Site Admins"
205209
# AAD_CHECK_GROUPS=false
206210

207-
# Enable the use of a Proxy server
211+
# Enable the use of a Proxy server (MISP-Guard or external)
208212
# PROXY_ENABLE=true
209213
# PROXY_HOST=
210214
# PROXY_PORT=
211215
# PROXY_METHOD=
212216
# PROXY_USER=
213217
# PROXY_PASSWORD=
214218

219+
## MISP-Guard
220+
# Configure rules in ./guard/config.json.
221+
# Requires restart of misp-guard container after changes.
222+
223+
# Toggle to enable MISP-Guard container (optional)
224+
# COMPOSE_PROFILES=misp-guard
225+
# If you enable MISP-Guard, you must also configure MISP to use it as a proxy:
226+
# PROXY_PORT must match GUARD_PORT
227+
228+
# MISP-Guard runtime flags (optional)
229+
# GUARD_PORT=8888
230+
# mitmdump misp-guard runtime arguments (space separated, no quotes)
231+
# GUARD_ARGS=--ssl-insecure -v
232+
215233
# Enable debugging
216234
# ALWAYS SET THIS TO 0 IN PRODUCTION
217235
# 0 - Debug off (default)

0 commit comments

Comments
 (0)