SachinyadavAug20 opened a new issue, #77365:
URL: https://github.com/apache/airflow/issues/77365
### 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`:
```python
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`:
```python
"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:
1. `python3-saml` reconstructs the ACS URL as
`http://airflow.example.com:8000/api/v2/auth/login_callback`.
2. It detects a destination mismatch against
`Destination="https://airflow.example.com/api/v2/auth/login_callback"`.
3. 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:
```python
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"` if `parsed.scheme == "https"` or
`_is_secure_request(request)`.
- Use `parsed.port` for `server_port` if explicitly specified in `base_url`
(defaulting to 443 for https, 80 for http, or falling back to
`request.url.port`).
### Operating System
Linux
### Deployment
Other
### Are you willing to submit PR?
[✓] Yes I am willing to submit a PR!
### Code of Conduct
[✓] I agree to follow this project's Code of Conduct
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]