Skip to content

Commit

Permalink
Merge pull request #1262 from ministryofjustice/feature/LGA-2991-hide…
Browse files Browse the repository at this point in the history
…-non-prod

LGA-2991 - Disable indexing and whitelisting of Non-Production environments
  • Loading branch information
said-moj committed May 13, 2024
2 parents d07f294 + 1bb5881 commit 2be4145
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .circleci/define_build_environment_variables
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ if [ "$CIRCLE_BRANCH" == "master" ]; then
else
export TARGET_TAGS=$IMAGE_TAG,$safe_git_branch
fi

export PINGDOM_IPS=`python3 bin/pingdom_ips.py`
22 changes: 22 additions & 0 deletions bin/pingdom_ips.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env python3
import re
import requests
import sys


def get_pingdom_probe_ips():
ip_list = []
pingdom_link = "https://my.pingdom.com/probes/ipv4"
pingdom_ips = requests.get(pingdom_link).text.split()
parsed_pingdom_ip_list = ["".join([ip.strip(), "/32"]) for ip in pingdom_ips]
regex = r"^(?:[0-9]{1,3}\.){3}[0-9]{1,3}/32$"

for ip in parsed_pingdom_ip_list:
if re.match(regex, ip) is not None:
ip_list.append(ip)
return ip_list


if __name__ == "__main__":
ips = r"\,".join(get_pingdom_probe_ips())
sys.stdout.write(ips)
1 change: 1 addition & 0 deletions bin/production_deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ helm upgrade cla-public \
--set ingress.cluster.weight=${INGRESS_CLUSTER_WEIGHT} \
--set image.repository=$DOCKER_REPOSITORY \
--set image.tag=$IMAGE_TAG \
--set-string pingdomIPs=$PINGDOM_IPS \
--force \
--install
1 change: 1 addition & 0 deletions bin/staging_deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ helm upgrade cla-public \
--set ingress.cluster.weight=${INGRESS_CLUSTER_WEIGHT} \
--set image.repository=$DOCKER_REPOSITORY \
--set image.tag=$IMAGE_TAG \
--set-string pingdomIPs=$PINGDOM_IPS \
--force \
--install
1 change: 1 addition & 0 deletions bin/staging_multideploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ helm upgrade $CLEANED_BRANCH_NAME \
--set image.repository=$DOCKER_REPOSITORY \
--set image.tag=$IMAGE_TAG \
--set dashboard.enabled=false \
--set-string pingdomIPs=$PINGDOM_IPS \
--force \
--install
4 changes: 4 additions & 0 deletions helm_deploy/cla-public/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,7 @@ in an appropriate format
{{- end -}}
{{- end -}}
{{- end -}}

{{- define "cla-public.whitelist" -}}
{{ join "," .Values.ingress.whitelist }},{{- .Values.pingdomIPs }}
{{- end -}}
7 changes: 7 additions & 0 deletions helm_deploy/cla-public/templates/ingress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ metadata:
SecRuleRemoveById 942230
SecRuleRemoveById 930120
SecRuleRemoveById 933210
{{- if .Values.ingress.addNoIndexResponseHeader }}
nginx.ingress.kubernetes.io/server-snippet: |
add_header X-Robots-Tag "noindex, nofollow";
{{- end }}
{{- if .Values.ingress.whitelist }}
nginx.ingress.kubernetes.io/whitelist-source-range: "{{ include "cla-public.whitelist" . }}"
{{- end }}
spec:
ingressClassName: "modsec"
tls:
Expand Down
2 changes: 2 additions & 0 deletions helm_deploy/cla-public/values-production.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ replicaCount: 2
ingress:
enabled: true
secretName: tls-certificate
addNoIndexResponseHeader: false
whitelist: false

envVars:
GDS_GA_ID:
Expand Down
12 changes: 12 additions & 0 deletions helm_deploy/cla-public/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ ingress:
name: ~
weight: ~
tls: []
addNoIndexResponseHeader: true
whitelist:
# Cisco Anyconnect (Dom1) / ARK data centre
- 194.33.192.0/25
- 194.33.196.0/25
# HGS
- 84.43.86.100/32
# GlobalProtect VPN (Digital Mac)
- 18.169.147.172/32
- 35.176.93.186/32
- 18.130.148.126/32
- 35.176.148.126/32

envVars:
MAINTENANCE_MODE:
Expand Down

0 comments on commit 2be4145

Please sign in to comment.