Skip to content

Commit aee58c4

Browse files
Fix Timezone Handling for Containers (#375)
* Add timezone setting to template.env Add timezone setting option to template.env * Add timezone environment variable to services - Add timezone environment variable to all services - Setting Default to "UTC" * Add PHP timezone config to docker-compose - Add timezone configuration for PHP in docker-compose file. - Replace PHP timezone in misp-core with the new config-file tzone.ini Perhaps there are better solutions for changing the time zone from PHP during runtime. * Change PHP timezone variable and set localtime Updated PHP timezone configuration and added symlink for timezone for supervisord. * Fix timezone setting in PHP configuration sed dosen´t use "?" so PHP_TIMEZONE was setting in php.ini * Change PHP_TIMEZONE variable to use TZ PHP_TIMEZONE wasn`t in template.env and so most not in use. TZ Variable the global Timezone variable in this Project * Remove tzone.ini configuration from docker-compose Removed timezone configuration from docker-compose. With the "sed fix" in the entrypoint_fpm.sh, No need to mount a separate file now * Change timezone setting to use update-alternatives Updated timezone setting method for supervisord compatibility with debian standard methode * sed TZ:UTC to TZ:-UTC add `-` so default (UTC) is in use, if TZ is not in use * Change php-timezone variable to use TZ directly * Remove PHP_TIMEZONE environment variable PHP_timezone isn`t in use TZ exist * Update PHP timezone configuration to TZ in entrypoint_fpm.sh * Update timezone comment in template.env CET or CEST not useable timezone in /usr/share/zoneinfo/ * Update timezone setting in entrypoint.sh Remove default value for TZ when setting timezone.
1 parent fe79c58 commit aee58c4

File tree

4 files changed

+19
-4
lines changed

4 files changed

+19
-4
lines changed

core/files/entrypoint.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ export PHP_SESSION_CHECK_AGENT=${PHP_SESSION_CHECK_AGENT:-false}
8989
export PHP_SESSION_COOKIE_SECURE=${PHP_SESSION_COOKIE_SECURE:-true}
9090
export PHP_SESSION_COOKIE_DOMAIN=${PHP_SESSION_COOKIE_DOMAIN}
9191
export PHP_SESSION_COOKIE_SAMESITE=${PHP_SESSION_COOKIE_SAMESITE:-Lax}
92-
export PHP_TIMEZONE=${PHP_TIMEZONE:-UTC}
92+
93+
export TZ=${TZ:-UTC}
9394

9495
export NGINX_X_FORWARDED_FOR=${NGINX_X_FORWARDED_FOR:-false}
9596
export NGINX_SET_REAL_IP_FROM=${NGINX_SET_REAL_IP_FROM}
@@ -102,6 +103,11 @@ export SUPERVISOR_HOST=${SUPERVISOR_HOST:-127.0.0.1}
102103
export SUPERVISOR_USERNAME=${SUPERVISOR_USERNAME:-supervisor}
103104
export SUPERVISOR_PASSWORD=${SUPERVISOR_PASSWORD:-supervisor}
104105

106+
# Setting Timezone for supervisord
107+
update-alternatives --install /etc/localtime localtime /usr/share/zoneinfo/${TZ} 0
108+
# Also set /etc/timezone for broader compatibility
109+
echo "${TZ}" > /etc/timezone
110+
105111
# Hinders further execution when sourced from other scripts
106112
if [[ "${BASH_SOURCE[0]}" != "$0" ]]; then
107113
return

core/files/entrypoint_fpm.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ change_php_vars() {
4646
fi
4747
sed -i "s/session.sid_length = .*/session.sid_length = 64/" "$FILE"
4848
sed -i "s/session.use_strict_mode = .*/session.use_strict_mode = 1/" "$FILE"
49-
echo "Configure PHP | Setting 'date.timezone = ${PHP_TIMEZONE}'"
50-
sed -i "s/;?date.timezone = .*/date.timezone = ${PHP_TIMEZONE}/" "$FILE"
49+
echo "Configure PHP | Setting 'date.timezone = ${TZ}'"
50+
sed -i "s/;date.timezone = .*/date.timezone = ${TZ}/" "$FILE"
5151
done
5252

5353
for FILE in /etc/php/*/fpm/pool.d/www.conf

docker-compose.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ services:
1616
- "SMARTHOST_USER=${SMARTHOST_USER}"
1717
- "SMARTHOST_PASSWORD=${SMARTHOST_PASSWORD}"
1818
- "SMARTHOST_ALIASES=${SMARTHOST_ALIASES}"
19+
- "TZ=${TZ:-UTC}"
1920

2021
redis:
2122
image: ${REGISTRY_MIRROR_URL:-}valkey/valkey:7.2
@@ -31,6 +32,7 @@ services:
3132
environment:
3233
- "ENABLE_REDIS_EMPTY_PASSWORD=${ENABLE_REDIS_EMPTY_PASSWORD:-false}"
3334
- "REDIS_PASSWORD=${REDIS_PASSWORD:-redispassword}"
35+
- "TZ=${TZ:-UTC}"
3436
healthcheck:
3537
test: |
3638
sh -c '
@@ -57,6 +59,7 @@ services:
5759
- "MYSQL_PASSWORD=${MYSQL_PASSWORD:-example}"
5860
- "MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD:-password}"
5961
- "MYSQL_DATABASE=${MYSQL_DATABASE:-misp}"
62+
- "TZ=${TZ:-UTC}"
6063
command: "\
6164
--innodb-buffer-pool-size=${INNODB_BUFFER_POOL_SIZE:-2048M} \
6265
--innodb-change-buffering=${INNODB_CHANGE_BUFFERING:-none} \
@@ -155,6 +158,7 @@ services:
155158
- "ADMIN_ORG_UUID=${ADMIN_ORG_UUID}"
156159
- "GPG_PASSPHRASE=${GPG_PASSPHRASE}"
157160
- "ATTACHMENTS_DIR=${ATTACHMENTS_DIR}"
161+
- "TZ=${TZ:-UTC}"
158162
- "ENABLE_THEMES=${ENABLE_THEMES}"
159163
# OIDC authentication settings
160164
- "OIDC_ENABLE=${OIDC_ENABLE}"
@@ -318,7 +322,6 @@ services:
318322
- "PHP_SESSION_COOKIE_SECURE=${PHP_SESSION_COOKIE_SECURE:-true}"
319323
- "PHP_SESSION_COOKIE_DOMAIN=${PHP_SESSION_COOKIE_DOMAIN}"
320324
- "PHP_SESSION_COOKIE_SAMESITE=${PHP_SESSION_COOKIE_SAMESITE:-Lax}"
321-
- "PHP_TIMEZONE=${PHP_TIMEZONE:-UTC}"
322325
# security settings
323326
- "HSTS_MAX_AGE=${HSTS_MAX_AGE}"
324327
- "X_FRAME_OPTIONS=${X_FRAME_OPTIONS}"
@@ -348,6 +351,8 @@ services:
348351
- "./custom/expansion/:/custom/expansion/:Z"
349352
- "./custom/export_mod/:/custom/export_mod/:Z"
350353
- "./custom/import_mod/:/custom/import_mod/:Z"
354+
environment:
355+
- "TZ=${TZ:-UTC}"
351356

352357
misp-guard:
353358
profiles:
@@ -366,6 +371,7 @@ services:
366371
environment:
367372
- "GUARD_PORT=${GUARD_PORT:-8888}"
368373
- "GUARD_ARGS=${GUARD_ARGS}"
374+
- "TZ=${TZ:-UTC}"
369375
volumes:
370376
- ./guard/config.json:/config.json:ro
371377
- misp_guard_ca:/misp_guard_ca

template.env

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ ATTACHMENTS_DIR=
8080
# enable UI themes
8181
# ENABLE_THEMES=false
8282

83+
# Setting the timezone (UTC, Europe/Berlin etc.). Default is UTC.
84+
# TZ="UTC"
85+
8386
# By default, a daily synchronization is performed, but you can modify this by changing the push and pull frequency (in seconds).
8487
# CRON_PULLALL="86400"
8588
# CRON_PUSHALL="86400"

0 commit comments

Comments
 (0)