Repository navigation
Fix FAB public access in the API server without a Flask app context - #77538
Merged
vincbeck merged 7 commits intoNov 25, 2026
Merged
Conversation
vincbeck
reviewed
Nov 24, 2026
ChickenBenny
force-pushed
the
fab-public-user-without-app-context
branch
from
November 25, 2026 09:33
1668769 to
dd98154
Compare
Contributor
Author
|
Thanks for the review. All comments are addressed and CI is green now. The compat failures on Airflow 3.0.6, 3.1.8 and 3.2.2 came from the new API server tests in I also rebased on the latest |
vincbeck
enabled auto-merge (squash)
November 25, 2026 14:59
vincbeck
approved these changes
Nov 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Public access in the FAB auth manager breaks in the API server in two cases. Both happen because the FastAPI side reads Flask's
current_app, and FastAPI requests and startup run with no Flask app context.1. The legacy
AUTH_ROLE_PUBLICinwebserver_config.pyis ignoredThe FAB docs describe only this setting, with no mention of
[fab] auth_role_public, so it is what users following them set. WhenAUTH_ROLE_PUBLICis set only inwebserver_config.py, and[fab] auth_role_publicis not set, anonymous requests get a 401, and nothing is logged._get_auth_role_publicfalls back toself.appbuilder.app.config. Since the FAB 5 upgrade (#50960),appbuilder.appreturnscurrent_appinstead of the app it was initialised with. With no app context, it raisesRuntimeError, and theexceptreturnsNone. Soget_fastapi_middlewares()does not registerFabAuthRolePublicMiddleware, andbuild_public_user()builds no user.The value is already in the config of the Flask app that
get_fastapi_app()builds and keeps onself.flask_app. The fallback still readscurrent_appinside a Flask app context, like the other places that readAUTH_ROLE_PUBLIC, and readsself.flask_appoutside one.The docs now recommend
[fab] auth_role_public, and describe thewebserver_config.pyentry as legacy. This PR does not deprecate the legacy setting.2. Anonymous requests fail with a 500 once the public role is missing
The API server creates the public role at startup. If the role is deleted while the server runs, for example through
DELETE /auth/fab/v1/roles/{name}, every anonymous request that checks permissions fails with a 500 until the server restarts.build_public_user()left_rolesand_permsat their class defaultset().AnonymousUsertreats an empty set as "not loaded yet", so readingpermsfalls back tocurrent_appand raisesRuntimeError. Now:Nonemeans "not loaded yet".build_public_user()sets both to empty sets when the role does not exist, and logs it at debug level.Anonymous requests then get a 403, the same as when the public role exists but lacks the permission. With public access configured, an anonymous user is identified, so this is a missing permission, not a missing login.
The same lazy path in Flask views no longer builds
{None}for a missing role, which failed withAttributeError.build_public_user()still queries the role on every anonymous request, as before this PR.Before / after
GET /api/v2/poolsAUTH_ROLE_PUBLIC = 'Viewer'only inwebserver_config.pyDELETEgives 403)[fab] auth_role_publicset, role deleted while the server runsValidation
New tests in
test_public_access.pystart the API server withairflow.api_fastapi.app.create_appand send anonymous requests, with nothing mocked:They are skipped before Airflow 3.3, because the API server only registers auth manager middlewares through
get_fastapi_middlewaressince 3.3.0 (Honor AUTH_ROLE_PUBLIC in FastAPI API server #65685). Before that, anonymous requests always get a 401 from the API server.A unit test covers the Flask view path for a missing role.
Each of these tests fails without its fix.
providers/fab/tests/unit/fab, before rebasing on the latestmain: 802 passed, 1 failed. The failure istest_cleanup_dag_permissions_removes_specific_dag_resources, which fails the same way locally onmainwithout these changes.breeze build-docs common.compat fabpassed.prek run --stage pre-commitpassed.prek run --stage manualpassed exceptmypy-providers, which reports only errors inproviders/cncf/kubernetes, which this PR does not change.Was generative AI tooling used to co-author this PR?
Generated-by: Claude Code (Opus 5.5) following the guidelines