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:

Image

What you think should happen instead?

The UI should allow interaction.

How to reproduce

  1. 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
  1. Set the environment variable VM_HOSTNAME to the hostname of the machine on which the container will be running.
  2. Run the container and wait for the api server to boot.
  3. 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

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 4
  • Comments: 65 (50 by maintainers)

Most upvoted comments

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-patch in 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.

  • #49581: Copy the override.py file to ./airflow-patch/airflow/providers/fab/auth_manager/security_manager/override.py
  • #49721: Copy the login.py file to ./airflow-patch/airflow/api_fastapi/auth/managers/simple/routes/login.py
  • #49724: Copy the views.py file to ./airflow-patch/airflow/providers/fab/www/views.py

This is how your compose project directory should look:

.
├── docker-compose.yml
├── Dockerfile
├── airflow-patch/
│   └── airflow/
│       ├── providers/
│       │   └── fab
│       │   │    └── auth_manager
│       │   │    │    └── security_manager
│       │   │    │    │    └── override.py     # patched file from PR
│       │   │    └── ... (other patched files)
└── ... (other files like .env, dags, logs, etc.)

You can then use Dockerfile to copy the patched file to the containers

USER root

ENV SITE_PACKAGES_DIR /home/airflow/.local/lib/python3.12/site-packages

# Copy the entire patch structure into the site-packages directory
COPY --chown=airflow:airflow ./airflow-patch/ ${SITE_PACKAGES_DIR}/

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.0 as it was |version| in the default docker-compose file).

Here are the screenshots:

Remote: Image

Localhost: Image

docker images release 3.0.1 any news?

3.0.1 is target in about 1.5/2 weeks.

@ebajalinov I suggest you try again with 3.0.1 once it’s released.

I would say that early feedback is welcomed to help us debug by manually applying the patches and verifying if it helps.

I definitely think #49581 might solve it

cool! but you need to rebuild database?

You’ll need to run airflow sync-perm to apply these changes

I 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 to http://airflow.my_local_domain/auth/login/?next=http://airflow.my_local_domain/home and directly into a 403 forbidden. If I remove the trailing slash from the URL it redirected to http://airflow.my_local_domain/auth/login I can reach the login page but it then goes back to the wrong page after submitting and back to the original auth/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.

After tons of debugging, and comparing the working with the non working version, I found that the guilty part was the HttpOnly cookies. You see, my reverse proxy was setup in such way to rewrite all Set-Cookie hedears and make all cookies http-only. This was a good practice for the rest of the apps that the reverse proxy serves. But airflow frontend seems to need access the cookie (I checked the localStorage in my browser and I found the token lands there, so I assume JS needs it). In any case, as soon as I removed the HttpOnly Cookie enhancement, it all worked fine.

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.

@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

Correct, if you use FabAuthManager, the fix has already been released so you can use it now. If you use SimpleAuthManager, 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 the set-cookie header below.

Image

When the browser redirects the user to the homepage, the cookie is not there, see below.

Image

When using localhost, the token is in the cookie when redirecting to home.