airflow: Infinite redirection loop when attempting to access a dockerized Airflow webserver using hostname
Apache Airflow version
3.0.0
If “Other Airflow 2 version” selected, which one?
No response
What happened?
Spinoff from: https://github.com/apache/airflow/issues/48825#issuecomment-2801229698
When accessing an instance of Airflow running via docker compose by accessing http://HOSTNAME:8080 (as opposed to http://localhost:8080), it results in a big “Unauthorized” message as well as an infinite redirection loop:
What you think should happen instead?
The UI should allow interaction.
How to reproduce
- Include the following configurations in the default 3.0.0rc4 docker-compose.yaml file:
# AIRFLOW__API__BASE_URL: UNSET!
AIRFLOW__CORE__AUTH_MANAGER: airflow.api_fastapi.auth.managers.simple.simple_auth_manager.SimpleAuthManager
AIRFLOW__WEBSERVER__BASE_URL: http://${VM_HOSTNAME}:8080
- Set the environment variable
VM_HOSTNAMEto the hostname of the machine on which the container will be running. - Run the container and wait for the api server to boot.
- Attempt to access the Airflow instance via
http://${VM_HOSTNAME}:8080- either from the machine on which the container is running, or from another one.
Operating System
Rocky Linux 9.3
Versions of Apache Airflow Providers
apache-airflow-providers-amazon | 9.6.0
apache-airflow-providers-celery | 3.10.6
apache-airflow-providers-cncf-kubernetes | 10.4.2
apache-airflow-providers-common-compat | 1.6.0
apache-airflow-providers-common-io | 1.5.3
apache-airflow-providers-common-messaging | 1.0.0rc3
apache-airflow-providers-common-sql | 1.25.0
apache-airflow-providers-docker | 4.3.1
apache-airflow-providers-elasticsearch | 6.2.1
apache-airflow-providers-fab | 2.0.1rc0
apache-airflow-providers-ftp | 3.12.3
apache-airflow-providers-git | 0.0.2rc0
apache-airflow-providers-google | 15.0.1
apache-airflow-providers-grpc | 3.7.3
apache-airflow-providers-hashicorp | 4.1.0
apache-airflow-providers-http | 5.2.1
apache-airflow-providers-microsoft-azure | 12.3.0
apache-airflow-providers-mysql | 6.2.1
apache-airflow-providers-odbc | 4.9.1
apache-airflow-providers-openlineage | 2.2.0rc0
apache-airflow-providers-postgres | 6.1.2
apache-airflow-providers-redis | 4.0.2
apache-airflow-providers-sendgrid | 4.0.1
apache-airflow-providers-sftp | 5.2.0
apache-airflow-providers-slack | 9.0.4
apache-airflow-providers-smtp | 2.0.2
apache-airflow-providers-snowflake | 6.2.1
apache-airflow-providers-ssh | 4.0.1
apache-airflow-providers-standard | 1.0.0rc0
Deployment
Docker-Compose
Deployment details
No response
Anything else?
CC: @ashb @pierrejeambrun @dheerajturaga
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
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 4
- Comments: 65 (50 by maintainers)
For anyone trying to patch this in their docker compose environment before the new version is available to fix this issue.
You can create a folder
airflow-patchin our compose project directory. For each of the patches, create the file and folder in your airflow-patch folder. You can find the files in the Files Changed section of each of the PR../airflow-patch/airflow/providers/fab/auth_manager/security_manager/override.py./airflow-patch/airflow/api_fastapi/auth/managers/simple/routes/login.py./airflow-patch/airflow/providers/fab/www/views.pyThis is how your compose project directory should look:
You can then use Dockerfile to copy the patched file to the containers
Here’s another approach https://github.com/apache/airflow/pull/49721#issuecomment-2829977945 that lives just in the Dockerfile
@YounHS That’s good, but that wasn’t anything I changed, I haven’t commited it yet 😄
We are also facing the same issue of infinite redirection with the latest Airflow Docker image 3.0.0. It is only occurring when accessing the airflow UI remotely, while it works fine when accessed from localhost. I tried installing it on a fresh server without any configuration. Just with the default docker-compose file (I only changed the version to
3.0.0as it was|version|in the default docker-compose file).Here are the screenshots:
Remote:
Localhost:
docker images release 3.0.1 any news?
3.0.1 is target in about 1.5/2 weeks.
I would say that early feedback is welcomed to help us debug by manually applying the patches and verifying if it helps.
You’ll need to run
airflow sync-permto apply these changesI think @Dev-iL is on the right track. I’m deploying the docker image (latest -> 07fc276fd638) and putting the service behind nginx. When hitting the service at
/it redirects tohttp://airflow.my_local_domain/auth/login/?next=http://airflow.my_local_domain/homeand directly into a 403 forbidden. If I remove the trailing slash from the URL it redirected tohttp://airflow.my_local_domain/auth/loginI can reach the login page but it then goes back to the wrong page after submitting and back to the originalauth/login/with trailing slash.I’ve tried this with a fresh deployment and also removing the airflow.cfg file from the container.
Let me know if there’s any information you need to debug!
IMO passing things in the URL is bad but in a different way – as that means it will show up in request logs on the server, and in any proxies in the path.
Thanks to the excellent work of @alkismavridis I landed here after a whole day of trying to upgrade from airflow 2 to 3.
I believe that this is very problematic in an enterprise environment. For instance, I have authelia setup with traefik managing authentication for all internal services. It turns out, authelia also sets HttpOnly and this behavior cannot be disabled. Nor would it be advisable or possible by policy, even if there was a flag in that specific software.
Moreover, this was not the case in airflow 2, leaving a huge incompatibility in authentication setups.
The only options I can try now is removing airflow from the global authentication, but this is not going to be feasible for everyone.
@pierrejeambrun sure, understand. So, here it is: https://github.com/apache/airflow/pull/52631
Correct, if you use
FabAuthManager, the fix has already been released so you can use it now. If you useSimpleAuthManager, you have to wait 3.0.1 😃@troeger related patches are either marked for 3.0.1 (for core PR) or already released as part of new provider release (or will be in the next wave but I think there was one recently).
So indeed this will be fixed in 3.0.1
@pierrejeambrun I can confirm #49721 works and solves infinite loops. There is been an issue from my end - with SSL which causing failing docker build. Thanks
@ebajalinov I suggest you try again with 3.0.1 once it’s released.
@YounHS Which auth manager are you using? You might need https://github.com/apache/airflow/pull/49724 too
I found out the root cause, not the explanation though.
When the user logs in, multiple redirections happen. The last one redirect towards home (
/) and pass the token through cookie. You can see theset-cookieheader below.When the browser redirects the user to the homepage, the cookie is not there, see below.
When using localhost, the token is in the cookie when redirecting to home.