Skip to content

Commit 6e8b6bf

Browse files
Allow passwordless Redis connections (#300)
1 parent 3c5e4e2 commit 6e8b6bf

6 files changed

Lines changed: 48 additions & 7 deletions

File tree

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,11 @@ Set the Redis password:
301301
REDIS_PASSWORD=
302302
```
303303

304+
Enable passwordless Redis connection (defaults to false for security):
305+
```bash
306+
ENABLE_REDIS_EMPTY_PASSWORD=false
307+
```
308+
304309
Set the base URL:
305310
```bash
306311
BASE_URL=https://<IP>:10443

core/files/entrypoint.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,15 @@ export MYSQL_DATABASE=${MYSQL_DATABASE:-misp}
1515
export MYSQL_CMD="mysql -u $MYSQL_USER -p$MYSQL_PASSWORD -P $MYSQL_PORT -h $MYSQL_HOST -r -N $MYSQL_DATABASE"
1616
export REDIS_HOST=${REDIS_HOST:-redis}
1717
export REDIS_PORT=${REDIS_PORT:-6379}
18-
export REDIS_PASSWORD=${REDIS_PASSWORD:-redispassword}
18+
export ENABLE_REDIS_EMPTY_PASSWORD=${ENABLE_REDIS_EMPTY_PASSWORD:-false}
19+
20+
# Set Redis password based on ENABLE_REDIS_EMPTY_PASSWORD setting
21+
if [ "$ENABLE_REDIS_EMPTY_PASSWORD" = "true" ]; then
22+
# This still need to be set to empty string to ensure all places where it's used got the correct value
23+
export REDIS_PASSWORD=""
24+
else
25+
export REDIS_PASSWORD=${REDIS_PASSWORD:-redispassword}
26+
fi
1927
export BASE_URL=${BASE_URL:-https://localhost}
2028
export DISABLE_IPV6=${DISABLE_IPV6:-false}
2129
export DISABLE_SSL_REDIRECT=${DISABLE_SSL_REDIRECT:-false}

core/files/entrypoint_fpm.sh

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,16 @@ change_php_vars() {
2626
echo "Configure PHP | Setting 'max_input_time = ${PHP_MAX_INPUT_TIME}'"
2727
sed -i "s/max_input_time = .*/max_input_time = ${PHP_MAX_INPUT_TIME}/" "$FILE"
2828
sed -i "s/session.save_handler = .*/session.save_handler = redis/" "$FILE"
29-
echo "Configure PHP | Setting 'session.save_path = '$(echo $REDIS_HOST | grep -E '^\w+://' || echo tcp://$REDIS_HOST):$REDIS_PORT?auth=${ESCAPED}'"
30-
sed -i "s|.*session.save_path = .*|session.save_path = '$(echo $REDIS_HOST | grep -E '^\w+://' || echo tcp://$REDIS_HOST):$REDIS_PORT?auth=${ESCAPED}'|" "$FILE"
29+
if [[ "$ENABLE_REDIS_EMPTY_PASSWORD" = "true" ]]; then
30+
echo "Configure PHP | Setting 'session.save_path = '$(echo $REDIS_HOST | grep -E '^\w+://' || echo tcp://$REDIS_HOST):$REDIS_PORT' (passwordless)"
31+
sed -i "s|.*session.save_path = .*|session.save_path = '$(echo $REDIS_HOST | grep -E '^\w+://' || echo tcp://$REDIS_HOST):$REDIS_PORT'|" "$FILE"
32+
elif [[ -n "$REDIS_PASSWORD" ]]; then
33+
echo "Configure PHP | Setting 'session.save_path = '$(echo $REDIS_HOST | grep -E '^\w+://' || echo tcp://$REDIS_HOST):$REDIS_PORT?auth=${ESCAPED}'"
34+
sed -i "s|.*session.save_path = .*|session.save_path = '$(echo $REDIS_HOST | grep -E '^\w+://' || echo tcp://$REDIS_HOST):$REDIS_PORT?auth=${ESCAPED}'|" "$FILE"
35+
else
36+
echo "ERROR: REDIS_PASSWORD is not set but ENABLE_REDIS_EMPTY_PASSWORD is false. Please set REDIS_PASSWORD or enable ENABLE_REDIS_EMPTY_PASSWORD=true for passwordless Redis."
37+
exit 1
38+
fi
3139
sed -i "s/session.sid_length = .*/session.sid_length = 64/" "$FILE"
3240
sed -i "s/session.use_strict_mode = .*/session.use_strict_mode = 1/" "$FILE"
3341
echo "Configure PHP | Setting 'date.timezone = ${PHP_TIMEZONE}'"

docker-compose.yml

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,26 @@ services:
1212

1313
redis:
1414
image: valkey/valkey:7.2
15-
command: "--requirepass '${REDIS_PASSWORD:-redispassword}'"
15+
command: |
16+
sh -c '
17+
if [ "$${ENABLE_REDIS_EMPTY_PASSWORD:-false}" = "true" ]; then
18+
exec valkey-server
19+
else
20+
exec valkey-server --requirepass "$${REDIS_PASSWORD:-redispassword}"
21+
fi
22+
'
23+
environment:
24+
- "ENABLE_REDIS_EMPTY_PASSWORD=${ENABLE_REDIS_EMPTY_PASSWORD:-false}"
25+
- "REDIS_PASSWORD=${REDIS_PASSWORD:-redispassword}"
1626
healthcheck:
17-
test: "valkey-cli -a '${REDIS_PASSWORD:-redispassword}' -p ${REDIS_PORT:-6379} ping | grep -q PONG || exit 1"
27+
test: |
28+
sh -c '
29+
if [ "$${ENABLE_REDIS_EMPTY_PASSWORD:-false}" = "true" ]; then
30+
valkey-cli -p $${REDIS_PORT:-6379} ping | grep -q PONG || exit 1
31+
else
32+
valkey-cli -a "$${REDIS_PASSWORD:-redispassword}" -p $${REDIS_PORT:-6379} ping | grep -q PONG || exit 1
33+
fi
34+
'
1835
interval: 2s
1936
timeout: 1s
2037
retries: 3
@@ -220,6 +237,7 @@ services:
220237
- "REDIS_HOST=${REDIS_HOST:-redis}"
221238
- "REDIS_PORT=${REDIS_PORT:-6379}"
222239
- "REDIS_PASSWORD=${REDIS_PASSWORD:-redispassword}"
240+
- "ENABLE_REDIS_EMPTY_PASSWORD=${ENABLE_REDIS_EMPTY_PASSWORD:-false}"
223241
# debug setting
224242
- "DEBUG=${DEBUG}"
225243
# SMTP setting

experimental/podman-systemd/redis.container

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ Image=docker.io/valkey/valkey:7.2
1111
Network=misp-net
1212
Volume=redis_data:/data
1313
PodmanArgs=--network-alias redis
14-
Exec=--requirepass ${REDIS_PASSWORD}
15-
HealthCmd=valkey-cli -a ${REDIS_PASSWORD} ping
14+
Exec=sh -c 'if [ "${ENABLE_REDIS_EMPTY_PASSWORD:-false}" = "true" ]; then exec valkey-server; else exec valkey-server --requirepass "${REDIS_PASSWORD}"; fi'
15+
HealthCmd=sh -c 'if [ "${ENABLE_REDIS_EMPTY_PASSWORD:-false}" = "true" ]; then valkey-cli ping; else valkey-cli -a "${REDIS_PASSWORD}" ping; fi'
1616
HealthInterval=2s
1717
HealthTimeout=1s
1818
HealthRetries=3

template.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ SYNCSERVERS_1_PULL_RULES=
110110
# REDIS_PORT=
111111
# remember to escape special character '$', e.g., 'test1%<$1323>' becomes 'test1%<$$1323>'
112112
# REDIS_PASSWORD=
113+
# Enable passwordless Redis connection (defaults to false for security)
114+
# ENABLE_REDIS_EMPTY_PASSWORD=false
113115

114116
# These variables allows overriding some MISP email values.
115117
# They all default to ADMIN_EMAIL.

0 commit comments

Comments
 (0)