Skip to content

Commit

Permalink
Merge pull request #235 from coreruleset/error-low-port
Browse files Browse the repository at this point in the history
chore: error if port or ssl_port are lower than 1024
  • Loading branch information
fzipi authored Apr 24, 2024
2 parents f9ed657 + 3a11ef0 commit f5cd07b
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions apache/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/sh -e

/usr/local/bin/generate-certificate /usr/local/apache2
/usr/local/bin/check-low-port

. /opt/modsecurity/activate-plugins.sh
. /opt/modsecurity/activate-rules.sh
Expand Down
12 changes: 12 additions & 0 deletions nginx/docker-entrypoint.d/01-check-low-port.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh
# vim:sw=2:ts=2:sts=2:et

set -eu

LC_ALL=C
ME=$( basename "$0" )
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

/usr/local/bin/check-low-port

exit 0
26 changes: 26 additions & 0 deletions src/bin/check-low-port
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/sh

if [ "${PORT}" -lt 1024 ] || [ "${SSL_PORT}" -lt 1024 ]; then
echo<<EOF
ERROR: you are using PORT=${PORT} and SSL_PORT=${SSL_PORT}
Both nginx and httpd containers now run with an unprivileged user.
This means that we cannot bind to ports below 1024, so you might need to correct your PORT and SSL_PORT settings.
Now the defaults for both nginx and httpd are 8080 and 8443.
FIX:
if you have a port mapping like
ports:
- "80:80"
then update it to use a port higher than 1024. Example:
- "80:8080"
The same should be done for the SSL ports.
EOF
exit 1
fi

0 comments on commit f5cd07b

Please sign in to comment.