This is an automated email from the ASF dual-hosted git repository.
ash pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new 551066006b6 Use scheme-relative URLs for the UI so https works out of
the box more often (#49106)
551066006b6 is described below
commit 551066006b6a006701ee78a87eece1b7c2ed327d
Author: Ash Berlin-Taylor <[email protected]>
AuthorDate: Fri Apr 11 10:00:29 2025 +0100
Use scheme-relative URLs for the UI so https works out of the box more
often (#49106)
If you don't carefully read all the docs, you might not notice that you have
to specify `--proxy-headers` _and_ make sure your Reverse Proxy sets these
headers correctly.
We can work around this quite easily and make it Just Work, so lets do that.
(This PR driven by the fact that, for some reason in 2025, Istio, a common
Ingress ROuter and Service Mesh in larger Kube deploys seems hard to
configure
to send the X-Forwarded-* headers correctly without low level envoy filters.
Ick.)
---
.../api_fastapi/auth/managers/simple/simple_auth_manager.py | 3 ++-
.../airflow/api_fastapi/auth/managers/simple/ui/src/router.tsx | 10 ++++------
airflow-core/src/airflow/api_fastapi/core_api/app.py | 3 ++-
airflow-core/src/airflow/ui/src/main.tsx | 9 ++++-----
4 files changed, 12 insertions(+), 13 deletions(-)
diff --git
a/airflow-core/src/airflow/api_fastapi/auth/managers/simple/simple_auth_manager.py
b/airflow-core/src/airflow/api_fastapi/auth/managers/simple/simple_auth_manager.py
index af3a42db333..2746fbadecd 100644
---
a/airflow-core/src/airflow/api_fastapi/auth/managers/simple/simple_auth_manager.py
+++
b/airflow-core/src/airflow/api_fastapi/auth/managers/simple/simple_auth_manager.py
@@ -306,9 +306,10 @@ class
SimpleAuthManager(BaseAuthManager[SimpleAuthManagerUser]):
@app.get("/{rest_of_path:path}", response_class=HTMLResponse,
include_in_schema=False)
def webapp(request: Request, rest_of_path: str):
+ schema_relative_base =
str(request.base_url).removeprefix(request.base_url.scheme + ":")
return templates.TemplateResponse(
"/index.html",
- {"request": request, "backend_server_base_url":
str(request.base_url)},
+ {"request": request, "backend_server_base_url":
schema_relative_base},
media_type="text/html",
)
diff --git
a/airflow-core/src/airflow/api_fastapi/auth/managers/simple/ui/src/router.tsx
b/airflow-core/src/airflow/api_fastapi/auth/managers/simple/ui/src/router.tsx
index 69a951f7262..c5c90d53f42 100644
---
a/airflow-core/src/airflow/api_fastapi/auth/managers/simple/ui/src/router.tsx
+++
b/airflow-core/src/airflow/api_fastapi/auth/managers/simple/ui/src/router.tsx
@@ -32,12 +32,10 @@ export const routerConfig = [
},
];
-const baseHref = document.querySelector("head>base")?.getAttribute("href");
-const baseUrl =
- baseHref !== null && baseHref !== undefined && baseHref !== ""
- ? baseHref
- : `${globalThis.location.origin}/`;
+const baseHref = document.querySelector("head>base")?.getAttribute("href") ??
"";
-const basename = new URL(`${baseUrl}auth`).pathname;
+// Resolve the scheme-relative URL from the base relative to the current URL
+const baseUrl = new URL(baseHref, globalThis.location.origin);
+const basename = new URL("auth", baseUrl).pathname;
export const router = createBrowserRouter(routerConfig, { basename });
diff --git a/airflow-core/src/airflow/api_fastapi/core_api/app.py
b/airflow-core/src/airflow/api_fastapi/core_api/app.py
index f5f3485640d..f0984fa8567 100644
--- a/airflow-core/src/airflow/api_fastapi/core_api/app.py
+++ b/airflow-core/src/airflow/api_fastapi/core_api/app.py
@@ -66,9 +66,10 @@ def init_views(app: FastAPI) -> None:
@app.get("/{rest_of_path:path}", response_class=HTMLResponse,
include_in_schema=False)
def webapp(request: Request, rest_of_path: str):
+ schema_relative_base =
str(request.base_url).removeprefix(request.base_url.scheme + ":")
return templates.TemplateResponse(
"/index.html",
- {"request": request, "backend_server_base_url":
str(request.base_url)},
+ {"request": request, "backend_server_base_url":
schema_relative_base},
media_type="text/html",
)
diff --git a/airflow-core/src/airflow/ui/src/main.tsx
b/airflow-core/src/airflow/ui/src/main.tsx
index 92bb4a23f4e..9d26f27d986 100644
--- a/airflow-core/src/airflow/ui/src/main.tsx
+++ b/airflow-core/src/airflow/ui/src/main.tsx
@@ -45,11 +45,10 @@ axios.interceptors.response.use(
params.set("next", globalThis.location.href);
- const baseHref =
document.querySelector("head>base")?.getAttribute("href");
- const baseUrl =
- baseHref !== null && baseHref !== undefined && baseHref !== ""
- ? baseHref
- : `${globalThis.location.origin}/`;
+ const baseHref =
document.querySelector("head>base")?.getAttribute("href") ?? "";
+
+ // Resolve the scheme-relative URL from the base relative to the current
URL
+ const baseUrl = new URL(baseHref, globalThis.location.origin);
const loginPath = new URL("api/v2/auth/login", baseUrl).pathname;