Skip to content

Commit 663c154

Browse files
committed
Add support for 'X-Forwarded-For'; merge podman PR by @urfin00djuce
1 parent b033dae commit 663c154

18 files changed

+231
-0
lines changed

README.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,65 @@ A GitHub Action builds both `misp-core` and `misp-modules` images automatically
141141
- `misp-core:${commit-sha1}[0:7]` and `misp-modules:${commit-sha1}[0:7]` where `${commit-sha1}` is the commit hash triggering the build
142142
- `misp-core:latest` and `misp-modules:latest` in order to track the latest builds available
143143
- `misp-core:${CORE_TAG}` and `misp-modules:${MODULES_TAG}` reflecting the underlying version of MISP and MISP modules (as specified inside the `template.env` file at build time)
144+
145+
## Podman (experimental)
146+
147+
It is possible to run the image using `podman-systemd` rather than `docker` to:
148+
- Run containers in **rootless** mode
149+
- Manage containers with **systemd**
150+
- Write container descriptions in an **ignition** file and deploy them (not covered in this documentation)
151+
152+
Note that this is **experimental** and it is **NOT SUPPORTED** (issues will be automatically closed).
153+
154+
### Configuration
155+
156+
Copy the following directories and files:
157+
- Content of `experimental/podman-systemd` to `$USER/.config/containers/systemd/`
158+
- `template.vars` to `$USER/.config/containers/systemd/vars.env`
159+
160+
Edit `vars.env`, and initialize the following MySQL settings:
161+
```bash
162+
MYSQL_HOST=
163+
MYSQL_USER=
164+
MYSQL_PASSWORD=
165+
MYSQL_ROOT_PASSWORD=
166+
MYSQL_DATABASE=
167+
```
168+
169+
Set the Redis password:
170+
```bash
171+
REDIS_PASSWORD=
172+
```
173+
174+
Set the base URL:
175+
```bash
176+
BASE_URL=https://<IP>:10443
177+
```
178+
179+
### Run
180+
181+
Reload systemd user daemon:
182+
```bash
183+
systemctl --user daemon-reload
184+
```
185+
186+
Start services:
187+
```bash
188+
systemctl --user start misp-mail.service
189+
systemctl --user start misp-db.service
190+
systemctl --user start misp-redis.service
191+
systemctl --user start misp-core.service
192+
systemctl --user start misp-modules.service
193+
```
194+
195+
Wait a bit and check your service at `https://<IP>:10443`.
196+
If everything checks out, you can make services persistent across reboots and logouts:
197+
```bash
198+
sudo loginctl enable-linger $USER
199+
```
200+
201+
You can even set podman to check for new container versions by activating the specific timer `podman-auto-update.timer`:
202+
```bash
203+
systemctl --user enable podman-auto-update.timer --now
204+
```
205+

core/files/entrypoint.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,8 @@ export PHP_UPLOAD_MAX_FILESIZE=${PHP_UPLOAD_MAX_FILESIZE:-50M}
4545
export PHP_POST_MAX_SIZE=${PHP_POST_MAX_SIZE:-50M}
4646
export PHP_MAX_INPUT_TIME=${PHP_MAX_INPUT_TIME:-300}
4747

48+
export NGINX_X_FORWARDED_FOR=${NGINX_X_FORWARDED_FOR:-false}
49+
export NGINX_SET_REAL_IP_FROM=${NGINX_SET_REAL_IP_FROM}
50+
4851
# start supervisord using the main configuration file so we have a socket interface
4952
/usr/bin/supervisord -c /etc/supervisor/supervisord.conf

core/files/entrypoint_nginx.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,26 @@ init_nginx() {
206206
echo "... adjusting 'fastcgi_connect_timeout' to ${FASTCGI_CONNECT_TIMEOUT}"
207207
sed -i "s/fastcgi_connect_timeout .*;/fastcgi_connect_timeout ${FASTCGI_CONNECT_TIMEOUT};/" /etc/nginx/includes/misp
208208

209+
# Adjust forwarding header settings (clean up first)
210+
sed -i '/real_ip_header/d' /etc/nginx/includes/misp
211+
sed -i '/real_ip_recursive/d' /etc/nginx/includes/misp
212+
sed -i '/set_real_ip_from/d' /etc/nginx/includes/misp
213+
if [[ "$NGINX_X_FORWARDED_FOR" = "true" ]]; then
214+
echo "... enabling X-Forwarded-For header"
215+
echo "... setting 'real_ip_header X-Forwarded-For'"
216+
echo "... setting 'real_ip_recursive on'"
217+
sed -i "/index index.php/a real_ip_header X-Forwarded-For;\nreal_ip_recursive on;" /etc/nginx/includes/misp
218+
if [[ ! -z "$NGINX_SET_REAL_IP_FROM" ]]; then
219+
SET_REAL_IP_FROM_PRINT=$(echo $NGINX_SET_REAL_IP_FROM | tr ',' '\n')
220+
for real_ip in ${SET_REAL_IP_FROM_PRINT[@]}; do
221+
echo "... setting 'set_real_ip_from ${real_ip}'"
222+
done
223+
SET_REAL_IP_FROM=$(echo $NGINX_SET_REAL_IP_FROM | tr ',' '\n' | while read line; do echo -n "set_real_ip_from ${line};\n"; done)
224+
SET_REAL_IP_FROM_ESCAPED=$(echo $SET_REAL_IP_FROM | sed '$!s/$/\\/' | sed 's/\\n$//')
225+
sed -i "/real_ip_recursive on/a $SET_REAL_IP_FROM_ESCAPED" /etc/nginx/includes/misp
226+
fi
227+
fi
228+
209229
# Testing for files also test for links, and generalize better to mounted files
210230
if [[ ! -f "/etc/nginx/sites-enabled/misp80" ]]; then
211231
echo "... enabling port 80 redirect"

docker-compose.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@ services:
146146
- "AAD_MISP_ORGADMIN=${AAD_MISP_ORGADMIN}"
147147
- "AAD_MISP_SITEADMIN=${AAD_MISP_SITEADMIN}"
148148
- "AAD_CHECK_GROUPS=${AAD_CHECK_GROUPS}"
149+
# Nginx settings
150+
- "NGINX_X_FORWARDED_FOR=${NGINX_X_FORWARDED_FOR}"
151+
- "NGINX_SET_REAL_IP_FROM=${NGINX_SET_REAL_IP_FROM}"
149152
# Proxy settings
150153
- "PROXY_ENABLE=${PROXY_ENABLE}"
151154
- "PROXY_HOST=${PROXY_HOST}"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[Volume]
2+
VolumeName=certs
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[Volume]
2+
VolumeName=conf
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
[Unit]
2+
Description=MISP Database system
3+
Requires=misp-net-network.service
4+
After=misp-net-network.service
5+
6+
[Container]
7+
AutoUpdate=registry
8+
ContainerName=db
9+
Image=docker.io/library/mariadb:10.11
10+
Network=misp-net
11+
Volume=mysql_data:/var/lib/mysql
12+
PodmanArgs=--network-alias db
13+
EnvironmentFile=vars.env
14+
AddCapability=SYS_NICE
15+
HealthCmd=mysqladmin --user=${MYSQL_USER} --password=${MYSQL_PASSWORD} status
16+
HealthInterval=2s
17+
HealthTimeout=1s
18+
HealthRetries=3
19+
HealthStartPeriod=30s
20+
21+
[Service]
22+
EnvironmentFile=%h/.config/containers/systemd/vars.env
23+
Restart=always
24+
25+
[Install]
26+
WantedBy=default.target
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[Volume]
2+
VolumeName=files
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[Volume]
2+
VolumeName=gpg
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[Volume]
2+
VolumeName=logs

0 commit comments

Comments
 (0)