Skip to content

Commit a179d35

Browse files
wmuldergovfatbird
authored andcommitted
DBC22-5324: Logic to block IP's using Env variable
1 parent 6c915f7 commit a179d35

4 files changed

Lines changed: 20 additions & 0 deletions

File tree

compose/frontend/StaticBuild

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ COPY ./compose/frontend/default.conf /etc/nginx/conf.d
3434
COPY ./compose/frontend/default_maintenance.txt /etc/nginx
3535
COPY ./compose/frontend/legacy_redirects.conf /etc/nginx
3636
COPY ./compose/frontend/security_headers.conf /etc/nginx/conf.d
37+
COPY ./compose/frontend/blocked_ips.conf /etc/nginx/conf.d
3738
COPY --from=buildnode /app/build /usr/share/nginx/html
3839
RUN chmod -R 777 /run /var/log/nginx /var/cache/nginx /usr/share/nginx/html/static/js /usr/share/nginx/html/static/css /usr/share/nginx/html/static/media /etc/nginx/conf.d
3940

compose/frontend/blocked_ips.conf

Whitespace-only changes.

compose/frontend/default.conf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ error_log /var/log/nginx/error.log;
5656

5757
open_log_file_cache max=1000 inactive=20s valid=1m min_uses=2;
5858

59+
# Trust OpenShift Router IP range
60+
set_real_ip_from 10.0.0.0/8;
61+
real_ip_header X-Forwarded-For;
62+
5963
# --- CONSOLIDATED REDIRECTS BLOCK ---
6064
server {
6165
listen 3000;
@@ -82,6 +86,7 @@ server {
8286
root /usr/share/nginx/html;
8387
access_log /logs/$hostname-$formatted_date-access.log drivebc;
8488
server_tokens off;
89+
include /etc/nginx/conf.d/blocked_ips.conf;
8590
include /etc/nginx/conf.d/security_headers.conf;
8691

8792
location ~* \.(?:css|js|woff|woff2|ttf|eot|svg|png|jpe?g|gif|ico)$ {

compose/frontend/entrypoint

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,20 @@ else
4848
echo "Environment is not 'prod', keeping X-Robots-Tag noindex header."
4949
fi
5050

51+
# Create blocked IPs configuration file
52+
BLOCKED_CONF="/etc/nginx/conf.d/blocked_ips.conf"
53+
> "$BLOCKED_CONF"
54+
if [ -n "$BLOCKED_IPS" ]; then
55+
echo "Processing blocked IPs..."
56+
for ip in $(echo "$BLOCKED_IPS" | tr ';' ' '); do
57+
CLEAN_IP=$(echo "$ip" | tr -d ' ')
58+
if [ -n "$CLEAN_IP" ]; then
59+
echo "deny $CLEAN_IP;" >> "$BLOCKED_CONF"
60+
fi
61+
done
62+
echo "Blocked IPs configuration updated."
63+
fi
64+
5165
#precompress the main js and css files to improve performance
5266
gzip -k $MAIN
5367
gzip -k $MAINCSS

0 commit comments

Comments
 (0)