This is an automated email from the ASF dual-hosted git repository.
o-nikolas 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 b2f7a1daaf8 Respect base_url scheme and port in AwsAuthManager SAML
request (#77368)
b2f7a1daaf8 is described below
commit b2f7a1daaf8839edd049103a8c6eb597d08783d4
Author: Sachin Chandra Yadav <[email protected]>
AuthorDate: Sat Nov 28 01:16:47 2026 +0530
Respect base_url scheme and port in AwsAuthManager SAML request (#77368)
Behind a TLS-terminating reverse proxy, the SAML request data was built
from the incoming request's scheme and port, so python3-saml rebuilt a
URL that did not match the ACS URL derived from base_url and rejected
the login. Take the scheme and host:port from base_url only, and drop
server_port, which python3-saml 1.16 deprecates.
---
.../amazon/aws/auth_manager/routes/login.py | 5 +-
.../amazon/aws/auth_manager/routes/test_login.py | 57 ++++++++++++++++++++++
2 files changed, 59 insertions(+), 3 deletions(-)
diff --git
a/providers/amazon/src/airflow/providers/amazon/aws/auth_manager/routes/login.py
b/providers/amazon/src/airflow/providers/amazon/aws/auth_manager/routes/login.py
index 1067c604e73..fc2b869de5e 100644
---
a/providers/amazon/src/airflow/providers/amazon/aws/auth_manager/routes/login.py
+++
b/providers/amazon/src/airflow/providers/amazon/aws/auth_manager/routes/login.py
@@ -336,12 +336,11 @@ def _init_saml_auth(request: Request) ->
OneLogin_Saml2_Auth:
def _prepare_request(request: Request) -> dict:
parsed = urlparse(conf.get("api", "base_url", fallback="http://localhost"))
- host = parsed.hostname
+ host = parsed.netloc or parsed.hostname or "localhost"
data: dict[str, Any] = {
- "https": "on" if request.url.scheme == "https" else "off",
+ "https": "on" if parsed.scheme == "https" else "off",
"http_host": host,
- "server_port": request.url.port,
"script_name": request.url.path,
"get_data": request.query_params,
"post_data": {},
diff --git
a/providers/amazon/tests/unit/amazon/aws/auth_manager/routes/test_login.py
b/providers/amazon/tests/unit/amazon/aws/auth_manager/routes/test_login.py
index c07a4b650fa..80770be0a77 100644
--- a/providers/amazon/tests/unit/amazon/aws/auth_manager/routes/test_login.py
+++ b/providers/amazon/tests/unit/amazon/aws/auth_manager/routes/test_login.py
@@ -29,6 +29,7 @@ from tests_common.test_utils.version_compat import
AIRFLOW_V_3_0_PLUS
if not AIRFLOW_V_3_0_PLUS:
pytest.skip("AWS auth manager is only compatible with Airflow >= 3.0.0",
allow_module_level=True)
+from fastapi import Request
from fastapi.testclient import TestClient
from airflow.api_fastapi.app import AUTH_MANAGER_FASTAPI_APP_PREFIX, create_app
@@ -50,6 +51,7 @@ from airflow.providers.amazon.aws.auth_manager.routes.login
import ( # noqa: E4
LOGIN_MODE_REDIRECT,
LOGIN_MODE_TOKEN,
MAX_NEXT_URL_JSON_LENGTH,
+ _prepare_request,
_sign_login_state,
)
@@ -533,3 +535,58 @@ class TestLoginRouter:
def test_login_callback_unsuccessful(self):
response = get_login_callback_response(RELAY_REDIRECT,
is_authenticated=False)
assert response.status_code == 500
+
+ @pytest.mark.parametrize(
+ ("base_url", "req_scheme", "req_port", "expected_https",
"expected_host"),
+ [
+ pytest.param("http://localhost:8080", "http", 8080, "off",
"localhost:8080", id="http-local"),
+ pytest.param(
+ "https://airflow.example.com",
+ "http",
+ 8000,
+ "on",
+ "airflow.example.com",
+ id="tls-reverse-proxy",
+ ),
+ pytest.param(
+ "https://airflow.example.com:8443",
+ "http",
+ 8000,
+ "on",
+ "airflow.example.com:8443",
+ id="https-custom-port",
+ ),
+ pytest.param(
+ "http://airflow.example.com",
+ "http",
+ 80,
+ "off",
+ "airflow.example.com",
+ id="http-default-port",
+ ),
+ pytest.param(
+ "http://airflow.example.com",
+ "http",
+ 8080,
+ "off",
+ "airflow.example.com",
+ id="http-reverse-proxy",
+ ),
+ ],
+ )
+ def test_prepare_request_scheme_and_port(
+ self, base_url, req_scheme, req_port, expected_https, expected_host
+ ):
+ mock_request = Mock(spec=Request)
+ mock_request.url.scheme = req_scheme
+ mock_request.url.port = req_port
+ mock_request.url.path = "/api/v2/auth/login_callback"
+ mock_request.base_url.scheme = req_scheme
+ mock_request.query_params = {}
+ with conf_vars({("api", "base_url"): base_url}):
+ with
patch("airflow.providers.amazon.aws.auth_manager.routes.login._read_form",
return_value={}):
+ data = _prepare_request(mock_request)
+
+ assert data["https"] == expected_https
+ assert data["http_host"] == expected_host
+ assert "server_port" not in data