AwsAuthManager: requested page (next_url) is dropped during SAML login
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?
Issue Description
When an unauthenticated user visits a deep link (such as a specific DAG, task run, or log page), Airflow routes them to /auth/login?next=<destination>.
In AwsAuthManager, this destination is completely lost:
AwsAuthManager.get_url_login(next_url=...)ignores thenext_urlkwarg and returns a bare/auth/loginwithout query parameters (providers/amazon/.../aws_auth_manager.py:540).- Even when
nextis passed as a query param to/auth/login,_start_login()inproviders/amazon/.../routes/login.pydoes not read or retain it. - Upon completing the SAML authentication round trip at
/auth/login_callback, the handler hardcodes a redirect toconf.get("api", "base_url", fallback="/"), always sending users to the home page instead of their requested page.
The same bug was previously resolved for:
SimpleAuthManagerin #67483 and #67965 (#67476)FabAuthManagerin #73134 (#73133)KeycloakAuthManagerin #76362
AwsAuthManager is currently the only auth manager where next_url is not preserved.
Steps to reproduce:
- Configure Airflow to use
AwsAuthManager. - As a logged-out user, navigate to a direct link such as
http://localhost:8080/dags/my_dag/runs/run_id/tasks/my_task. - Complete the login flow with the IdP.
- After callback, observe that the browser is redirected to
/instead of/dags/my_dag/runs/run_id/tasks/my_task.
What you think should happen instead?
AwsAuthManager.get_url_login(next_url=...)should append?next=<url>.- The login route should validate
nextusingis_safe_urland retain it in a short-lived HTTP-only cookie. login_callbackshould redirect to the storednextURL (falling back to[api] base_urlif unset or unsafe) and clear the cookie.
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
Thanks for opening your first issue here! Be sure to follow the issue template! If you are willing to raise PR to address this issue please do so, no need to wait for approval.
Proposed fix:
Follow the same pattern recently merged in KeycloakAuthManager (#76362) and FabAuthManager (#73134):
-
Preserve
next_urlquery param:AwsAuthManager.get_url_login(next_url=...)--> appends?next=<url>(viaurlencode) when present. -
Store safe destination in cookie: User hits
/auth/login?next=...--> validatenextwithis_safe_url(): => If safe: save in a short-lived HTTP-only cookie (_awsam_login_next_url, SameSite=None if HTTPS else Lax, max-age 10m matching login state). => If unsafe or missing: clear/delete any stale_awsam_login_next_urlcookie. -
Redirect on SAML callback: IdP completes SAML POST to
/auth/login_callback--> read_awsam_login_next_urlfrom cookie: => If present & safe: redirect user tonext_url(e.g./dags/...). => If absent or invalid: fallback to[api] base_url. => Clear_awsam_login_next_urlcookie (Max-Age=0).
I have the patch and unit tests ready locally (all 95 auth manager tests passing). Opening PR shortly!