Skip to content

Commit 6599e57

Browse files
capileostefano
authored andcommittedDec 6, 2024·
FIX: Slow startup and performance on NFS or slow volume mounts #188
1 parent c7a5fff commit 6599e57

7 files changed

+53
-15
lines changed
 

‎README.md

+11
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,17 @@ If it is a setting controlled by an environment variable which is meant to overr
109109
- `./gnupg`: `/var/www/MISP/.gnupg/`
110110
- If you need to automatically run additional steps each time the container starts, create a new file `files/customize_misp.sh`, and replace the variable `${CUSTOM_PATH}` inside `docker-compose.yml` with its parent path.
111111

112+
#### Using slow disks as volume mounts
113+
114+
Using a slow disk as the mounted volume or a volume with high latency like NFS, EFS or S3 might significantly increase the startup time and downgrade the performance of the service. To address this we will mount the bare minimum that needs to be persisted.
115+
116+
- Remove the `/var/www/MISP/app/files/` volume mount.
117+
- Add the following volume mounts instead:
118+
- `./img/`: `/var/www/MISP/app/files/img`
119+
- `./terms`: `/var/www/MISP/app/files/terms`
120+
- `./attachments`: `/var/www/MISP/app/attachments`
121+
- Set the environment variable `ATTACHMENTS_DIR` to the above folder location (it is important that it doesn't replace the `/var/www/MISP/app/files/` folder).
122+
112123
## Installing custom root CA certificates
113124

114125
Custom root CA certificates can be mounted under `/usr/local/share/ca-certificates` and will be installed during the `misp-core` container start.

‎core/Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ EOF
253253

254254
RUN <<-EOF
255255
cp -R /var/www/MISP/app/files /var/www/MISP/app/files.dist
256+
echo "${CORE_COMMIT:-${CORE_TAG}}" > /var/www/MISP/app/files/VERSION
256257
cp -R /var/www/MISP/app/Config /var/www/MISP/app/Config.dist
257258
find /var/www/MISP \( ! -user www-data -or ! -group www-data \) -exec chown www-data:www-data '{}' +;
258259
find /var/www/MISP -not -perm 550 -type f -exec chmod 0550 '{}' +;

‎core/files/entrypoint.sh

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export SMTP_FQDN=${SMTP_FQDN:-mail}
2525
export ADMIN_EMAIL=${ADMIN_EMAIL:-admin@admin.test}
2626
export GPG_PASSPHRASE=${GPG_PASSPHRASE:-passphrase}
2727
export MISP_MODULES_FQDN=${MISP_MODULES_FQDN:-http://misp-modules}
28+
export ATTACHMENTS_DIR=${ATTACHMENTS_DIR:-/var/www/MISP/app/files}
2829

2930
export AUTOCONF_GPG=${AUTOCONF_GPG:-true}
3031
export AUTOCONF_ADMIN_KEY=${AUTOCONF_ADMIN_KEY:-true}

‎core/files/entrypoint_nginx.sh

+34-15
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,18 @@ EOT
138138
}
139139

140140
update_misp_data_files(){
141+
# If $MISP_APP_FILES_PATH was not changed since the build, skip file updates there
142+
FILES_VERSION=
143+
MISP_APP_FILES_PATH=/var/www/MISP/app/files
144+
CORE_COMMIT=${CORE_COMMIT:-${CORE_TAG}}
145+
if [ -f ${MISP_APP_FILES_PATH}/VERSION ]; then
146+
FILES_VERSION=$(cat ${MISP_APP_FILES_PATH}/VERSION)
147+
echo "... found local files/VERSION:" $FILES_VERSION
148+
if [ "$FILES_VERSION" = "${CORE_COMMIT:-$(jq -r '"v\(.major).\(.minor).\(.hotfix)"' /var/www/MISP/VERSION.json)}" ]; then
149+
echo "... local files/ match distribution version, skipping file sync"
150+
return 0;
151+
fi
152+
fi
141153
for DIR in $(ls /var/www/MISP/app/files.dist); do
142154
if [ "$DIR" = "certs" ] || [ "$DIR" = "img" ] || [ "$DIR" == "taxonomies" ] ; then
143155
echo "... rsync -azh \"/var/www/MISP/app/files.dist/$DIR\" \"/var/www/MISP/app/files/\""
@@ -150,21 +162,28 @@ update_misp_data_files(){
150162
}
151163

152164
enforce_misp_data_permissions(){
153-
echo "... chown -R www-data:www-data /var/www/MISP/app/tmp" && find /var/www/MISP/app/tmp \( ! -user www-data -or ! -group www-data \) -exec chown www-data:www-data {} +
154-
# Files are also executable and read only, because we have some rogue scripts like 'cake' and we can not do a full inventory
155-
echo "... chmod -R 0550 files /var/www/MISP/app/tmp" && find /var/www/MISP/app/tmp -not -perm 550 -type f -exec chmod 0550 {} +
156-
# Directories are also writable, because there seems to be a requirement to add new files every once in a while
157-
echo "... chmod -R 0770 directories /var/www/MISP/app/tmp" && find /var/www/MISP/app/tmp -not -perm 770 -type d -exec chmod 0770 {} +
158-
# We make 'files' and 'tmp' (logs) directories and files user and group writable (we removed the SGID bit)
159-
echo "... chmod -R u+w,g+w /var/www/MISP/app/tmp" && chmod -R u+w,g+w /var/www/MISP/app/tmp
160-
161-
echo "... chown -R www-data:www-data /var/www/MISP/app/files" && find /var/www/MISP/app/files \( ! -user www-data -or ! -group www-data \) -exec chown www-data:www-data {} +
162-
# Files are also executable and read only, because we have some rogue scripts like 'cake' and we can not do a full inventory
163-
echo "... chmod -R 0550 files /var/www/MISP/app/files" && find /var/www/MISP/app/files -not -perm 550 -type f -exec chmod 0550 {} +
164-
# Directories are also writable, because there seems to be a requirement to add new files every once in a while
165-
echo "... chmod -R 0770 directories /var/www/MISP/app/files" && find /var/www/MISP/app/files -not -perm 770 -type d -exec chmod 0770 {} +
166-
# We make 'files' and 'tmp' (logs) directories and files user and group writable (we removed the SGID bit)
167-
echo "... chmod -R u+w,g+w /var/www/MISP/app/files" && chmod -R u+w,g+w /var/www/MISP/app/files
165+
# If $MISP_APP_FILES_PATH was not changed since the build, skip file updates there
166+
MISP_APP_FILES_PATH=/var/www/MISP/app/files
167+
CORE_COMMIT=${CORE_COMMIT:-${CORE_TAG}}
168+
if [ -f "${MISP_APP_FILES_PATH}/VERSION" ] && [ "$(cat ${MISP_APP_FILES_PATH}/VERSION)" = "${CORE_COMMIT:-$(jq -r '"v\(.major).\(.minor).\(.hotfix)"' /var/www/MISP/VERSION.json)}" ]; then
169+
echo "... local files/ match distribution version, skipping data permissions in files/"
170+
else
171+
echo "... chown -R www-data:www-data /var/www/MISP/app/tmp" && find /var/www/MISP/app/tmp \( ! -user www-data -or ! -group www-data \) -exec chown www-data:www-data {} +
172+
# Files are also executable and read only, because we have some rogue scripts like 'cake' and we can not do a full inventory
173+
echo "... chmod -R 0550 files /var/www/MISP/app/tmp" && find /var/www/MISP/app/tmp -not -perm 550 -type f -exec chmod 0550 {} +
174+
# Directories are also writable, because there seems to be a requirement to add new files every once in a while
175+
echo "... chmod -R 0770 directories /var/www/MISP/app/tmp" && find /var/www/MISP/app/tmp -not -perm 770 -type d -exec chmod 0770 {} +
176+
# We make 'files' and 'tmp' (logs) directories and files user and group writable (we removed the SGID bit)
177+
echo "... chmod -R u+w,g+w /var/www/MISP/app/tmp" && chmod -R u+w,g+w /var/www/MISP/app/tmp
178+
179+
echo "... chown -R www-data:www-data /var/www/MISP/app/files" && find /var/www/MISP/app/files \( ! -user www-data -or ! -group www-data \) -exec chown www-data:www-data {} +
180+
# Files are also executable and read only, because we have some rogue scripts like 'cake' and we can not do a full inventory
181+
echo "... chmod -R 0550 files /var/www/MISP/app/files" && find /var/www/MISP/app/files -not -perm 550 -type f -exec chmod 0550 {} +
182+
# Directories are also writable, because there seems to be a requirement to add new files every once in a while
183+
echo "... chmod -R 0770 directories /var/www/MISP/app/files" && find /var/www/MISP/app/files -not -perm 770 -type d -exec chmod 0770 {} +
184+
# We make 'files' and 'tmp' (logs) directories and files user and group writable (we removed the SGID bit)
185+
echo "... chmod -R u+w,g+w /var/www/MISP/app/files" && chmod -R u+w,g+w /var/www/MISP/app/files
186+
fi
168187

169188
echo "... chown -R www-data:www-data /var/www/MISP/app/Config" && find /var/www/MISP/app/Config \( ! -user www-data -or ! -group www-data \) -exec chown www-data:www-data {} +
170189
# Files are also executable and read only, because we have some rogue scripts like 'cake' and we can not do a full inventory

‎core/files/etc/misp-docker/initialisation.envars.json

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
"MISP.contact": {
1313
"default_value": "${SETTING_CONTACT}"
1414
},
15+
"MISP.attachments_dir": {
16+
"default_value": "${ATTACHMENTS_DIR}"
17+
},
1518
"Security.encryption_key": {
1619
"default_value": "${ENCRYPTION_KEY}",
1720
"command_args": "-f"

‎docker-compose.yml

+1
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ services:
114114
- "ADMIN_ORG=${ADMIN_ORG}"
115115
- "ADMIN_ORG_UUID=${ADMIN_ORG_UUID}"
116116
- "GPG_PASSPHRASE=${GPG_PASSPHRASE}"
117+
- "ATTACHMENTS_DIR=${ATTACHMENTS_DIR}"
117118
# OIDC authentication settings
118119
- "OIDC_ENABLE=${OIDC_ENABLE}"
119120
- "OIDC_PROVIDER_URL=${OIDC_PROVIDER_URL}"

‎template.env

+2
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ ENABLE_DB_SETTINGS=
5353
ENCRYPTION_KEY=
5454
# enable background updates. defaults to false
5555
ENABLE_BACKGROUND_UPDATES=
56+
# use a different attachments_dir. defaults to /var/www/MISP/app/files
57+
ATTACHMENTS_DIR=
5658

5759
# defines the FQDN of the mail sub-system (defaults to 'mail')
5860
# SMTP_FQDN=

0 commit comments

Comments
 (0)
Please sign in to comment.