fix: Explicit host header in HTTP redirects

Configuration for nginx is now generated in a way such that redirects
have a suitable Host header, which is important e.g. to run skyline
on k8s.

Change-Id: I89503dcbcf988f3e13781d137fc1fde377c3076d
This commit is contained in:
Florian Haftmann 2023-12-01 09:11:31 +01:00
parent 9c58aef47c
commit 0af15c5687
2 changed files with 6 additions and 5 deletions

View File

@ -42,6 +42,7 @@ class ProxyEndpoint(BaseModel):
part: str
location: str
url: str
host: str
def get_system_session() -> Session:
@ -69,7 +70,7 @@ def get_proxy_endpoints() -> Dict[str, ProxyEndpoint]:
endpoints = {}
for endpoint in endpoints_list:
proxy = ProxyEndpoint(part="", location="", url="")
proxy = ProxyEndpoint(part="", location="", url="", host="")
region = endpoint.region
service_type = services.get(endpoint.service_id)
service = CONF.openstack.service_mapping.get(service_type)
@ -105,8 +106,9 @@ def get_proxy_endpoints() -> Dict[str, ProxyEndpoint]:
path = "" if str(raw_path.parents[0]) == "/" else str(raw_path.parents[0])
else:
path = str(raw_path)
proxy.url = raw_url._replace(path=f"{str(path)}/").geturl()
url = raw_url._replace(path=f"{str(path)}/")
proxy.url = url.geturl()
proxy.host = url.netloc
endpoints[f"{region}-{service_type}"] = proxy
return dict(sorted(endpoints.items(), key=lambda d: d[0]))

View File

@ -117,10 +117,9 @@ http {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header Host $http_host;
proxy_set_header Host {{ endpoint["host"] }};
}
{% endfor %}
}
}