Skip to content

Commit

Permalink
Merge pull request #398 from openshift-cherrypick-robot/cherry-pick-3…
Browse files Browse the repository at this point in the history
…96-to-18.0-fr1

[18.0-fr1] [httpd] Use absolute url with schema in redirect rule
  • Loading branch information
openshift-merge-bot[bot] authored Dec 23, 2024
2 parents 2e200c1 + 4fd122e commit 9353ce7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
17 changes: 9 additions & 8 deletions controllers/horizon_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -888,14 +888,15 @@ func (r *HorizonReconciler) generateServiceConfigMaps(
}

templateParameters := map[string]interface{}{
"keystoneURL": authURL,
"horizonEndpointUrl": url.Host,
"memcachedServers": mc.GetMemcachedServerListQuotedString(),
"memcachedTLS": mc.GetMemcachedTLSSupport(),
"ServerName": fmt.Sprintf("%s.%s.svc", horizon.ServiceName, instance.Namespace),
"Port": horizon.HorizonPort,
"TLS": false,
"isPublicHTTPS": url.Scheme == "https",
"keystoneURL": authURL,
"horizonEndpoint": instance.Status.Endpoint,
"horizonEndpointHost": url.Host,
"memcachedServers": mc.GetMemcachedServerListQuotedString(),
"memcachedTLS": mc.GetMemcachedTLSSupport(),
"ServerName": fmt.Sprintf("%s.%s.svc", horizon.ServiceName, instance.Namespace),
"Port": horizon.HorizonPort,
"TLS": false,
"isPublicHTTPS": url.Scheme == "https",
}

// create httpd tls template parameters
Expand Down
2 changes: 1 addition & 1 deletion templates/horizon/config/httpd.conf
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ LogLevel debug
CustomLog /dev/stdout "%a %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" env=forwarded

## RedirectMatch rules
RedirectMatch permanent ^/$ /dashboard
RedirectMatch permanent ^/$ "{{ .horizonEndpoint }}/dashboard"

## WSGI configuration
WSGIApplicationGroup %{GLOBAL}
Expand Down
14 changes: 11 additions & 3 deletions templates/horizon/config/local_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,26 @@
def get_pod_ip():
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
hostport = (
"{{ .horizonEndpointHost }}",
{{- if .isPublicHTTPS }}
443
{{- else }}
80
{{- end }}
)
try:
s.connect(("{{ .horizonEndpointUrl }}", 80))
s.connect(hostport)
return s.getsockname()[0]
except socket.gaierror:
s.close()
s = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
s.connect(("{{ .horizonEndpointUrl }}", 80))
s.connect(hostport)
return "[{}]".format(s.getsockname()[0])
finally:
s.close()

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

USE_X_FORWARDED_HOST = True

Expand Down

0 comments on commit 9353ce7

Please sign in to comment.