Skip to content

Commit

Permalink
[httpd] Use absolute url with schema in redirect rule
Browse files Browse the repository at this point in the history
Use the endpoint in the redirect rule to ensure it references the correct
base url and schema which can be different to the current schema
when TLS is terminated at the route

Added horizonEndpoint template param with the full url, renamed the
incorrectly named horizonEndpointUrl to horizonEndpointHost.

Jira: OSPRH-12005
  • Loading branch information
olliewalsh committed Dec 17, 2024
1 parent 93454ef commit c0f6c6d
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 c0f6c6d

Please sign in to comment.