AwsAuthManager SAML _prepare_request ignores base_url scheme and port behind TLS reverse proxies
Under which category would you file this issue?
Providers
Apache Airflow version
main (Airflow 3.0+)
Apache Airflow Provider(s)
amazon
What happened and how to reproduce it?
In airflow/providers/amazon/aws/auth_manager/routes/login.py:
def _prepare_request(request: Request) -> dict:
parsed = urlparse(conf.get("api", "base_url", fallback="http://localhost"))
host = parsed.hostname
data: dict[str, Any] = {
"https": "on" if request.url.scheme == "https" else "off",
"http_host": host,
"server_port": request.url.port,
"script_name": request.url.path,
"get_data": request.query_params,
"post_data": {},
}
In production deployments where Airflow runs behind a reverse proxy or load balancer (such as an AWS Application Load Balancer, CloudFront, or Nginx with TLS termination), incoming requests to the internal FastAPI/uvicorn server are received over HTTP (e.g., request.url.scheme == "http", request.url.port == 8000), while the canonical public base_url configured in airflow.cfg is https://airflow.example.com.
Because assertionConsumerService in _init_saml_auth() is constructed from base_url:
"assertionConsumerService": {
"url": f"{base_url.rstrip('/')}{AUTH_MANAGER_FASTAPI_APP_PREFIX}/login_callback",
"binding": "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST",
}
the SAML Identity Provider (such as AWS IAM Identity Center) sends a SAML assertion with Destination="https://airflow.example.com/api/v2/auth/login_callback".
When login_callback processes the SAML response, python3-saml uses data from _prepare_request() to compute the current request URL (get_self_url_no_query()). Because https is set to "off" and server_port reflects the internal port rather than the public base_url scheme and port:
python3-samlreconstructs the ACS URL ashttp://airflow.example.com:8000/api/v2/auth/login_callback.- It detects a destination mismatch against
Destination="https://airflow.example.com/api/v2/auth/login_callback". - It aborts authentication with
OneLogin_Saml2_Error: The response was received at http://... instead of https://....
Note that line 98 in login.py already implements:
def _is_secure_request(request: Request) -> bool:
return request.base_url.scheme == "https" or bool(conf.get("api", "ssl_cert", fallback=""))
However, _prepare_request() does not check whether base_url is HTTPS or use _is_secure_request(request).
What you think should happen instead?
_prepare_request() should respect parsed.scheme and parsed.port from base_url:
- Set
"https": "on"ifparsed.scheme == "https"or_is_secure_request(request). - Use
parsed.portforserver_portif explicitly specified inbase_url(defaulting to 443 for https, 80 for http, or falling back torequest.url.port).
Operating System
Linux
Deployment
Other
Are you willing to submit PR?
- [x] Yes I am willing to submit a PR!
Code of Conduct
- [x] I agree to follow this project's Code of Conduct