Skip to content

Commit

Permalink
Merge pull request #307 from bshephar/no-allowed-hosts-all
Browse files Browse the repository at this point in the history
Restrict ALLOWED_HOSTS
  • Loading branch information
openshift-merge-bot[bot] authored Mar 27, 2024
2 parents 19470c6 + 37cb430 commit 7b8ae01
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions templates/horizon/config/local_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,23 @@
# with the list of host/domain names that the application can serve.
# For more information see:
# https://docs.djangoproject.com/en/dev/ref/settings/#allowed-hosts
#ALLOWED_HOSTS = ["{{ .horizonEndpointUrl }}", ]
# liveness checks will fail if we restrict this to just the route. We are setting
# this to enable liveness checks.
ALLOWED_HOSTS = ["*", ]

# get_pod_ip retrieves the pod's primary interface IP address. This is necessary
# due to the dynamic IP addressing of pods. The HealthCheck needs to be able to
# check the specific pod. We can't simply check via the route, since such a check
# could land on any of the replicas. Instead, we need to explicity check the pod
# we're currently running on. Therefore, we need to execute this function to
# retrieve the IP address, which we will then in turn add to the ALLOWED_HOSTS list.
def get_pod_ip():
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
try:
s.connect(("{{ .horizonEndpointUrl }}", 80))
return s.getsockname()[0]
finally:
s.close()

ALLOWED_HOSTS = [get_pod_ip(), "{{ .horizonEndpointUrl }}"]

# Set SSL proxy settings:
# Pass this header from the proxy after terminating the SSL,
Expand Down

0 comments on commit 7b8ae01

Please sign in to comment.