This is an automated email from the ASF dual-hosted git repository.
vincbeck pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new 9c93fe8bbfe Apply FAB session settings to the Airflow 2 plugins app
(#77620)
9c93fe8bbfe is described below
commit 9c93fe8bbfedd349528a64d29d085f7b9e59a026
Author: Kevin Yang <[email protected]>
AuthorDate: Thu Nov 26 10:00:57 2026 -0500
Apply FAB session settings to the Airflow 2 plugins app (#77620)
With the FAB auth manager, the Flask app serving Airflow 2 plugins also
serves the FAB login views, but it kept Flask's default sessions instead
of the [fab] session settings. It now uses the same session settings as
the FAB auth manager app, so both apps share one session.
---
providers/fab/src/airflow/providers/fab/www/app.py | 6 ++--
providers/fab/tests/unit/fab/www/test_app.py | 34 ++++++++++++++++++++--
2 files changed, 35 insertions(+), 5 deletions(-)
diff --git a/providers/fab/src/airflow/providers/fab/www/app.py
b/providers/fab/src/airflow/providers/fab/www/app.py
index 47f4f89d00f..fdd898dd363 100644
--- a/providers/fab/src/airflow/providers/fab/www/app.py
+++ b/providers/fab/src/airflow/providers/fab/www/app.py
@@ -130,11 +130,11 @@ def create_app(enable_plugins: bool):
is_fab_auth_manager = isinstance(get_auth_manager(), FabAuthManager)
if enable_plugins:
init_plugins(flask_app)
- elif is_fab_auth_manager:
+ if is_fab_auth_manager:
+ # The plugins app serves the FAB login views too, so its sessions
follow the same
+ # ``[fab]`` session settings as the FAB auth manager app.
init_airflow_session_interface(flask_app, db)
init_session_max_lifetime(flask_app)
- if is_fab_auth_manager:
- # The plugins app reads the FAB login session too, with the
``securecookie`` backend.
init_session_token_generation(flask_app)
init_jinja_globals(flask_app, enable_plugins=enable_plugins)
init_wsgi_middleware(flask_app)
diff --git a/providers/fab/tests/unit/fab/www/test_app.py
b/providers/fab/tests/unit/fab/www/test_app.py
index d1ba700caac..97e772c7a6e 100644
--- a/providers/fab/tests/unit/fab/www/test_app.py
+++ b/providers/fab/tests/unit/fab/www/test_app.py
@@ -24,6 +24,10 @@ from airflow import settings
from airflow.api_fastapi.auth.managers.base_auth_manager import BaseAuthManager
from airflow.providers.fab.auth_manager.fab_auth_manager import FabAuthManager
from airflow.providers.fab.www.app import create_app
+from airflow.providers.fab.www.session import (
+ AirflowDatabaseSessionInterface,
+ AirflowSecureCookieSessionInterface,
+)
from tests_common.test_utils.config import conf_vars
@@ -53,20 +57,46 @@ class TestCreateApp:
)
@conf_vars({("core", "auth_manager"): FAB_AUTH_MANAGER})
@mock.patch("airflow.providers.fab.www.app.init_session_token_generation",
autospec=True)
+ @mock.patch("airflow.providers.fab.www.app.init_session_max_lifetime",
autospec=True)
+
@mock.patch("airflow.providers.fab.www.app.init_airflow_session_interface",
autospec=True)
@mock.patch("airflow.providers.fab.www.app.get_auth_manager",
autospec=True)
- def test_sessions_checked_wherever_fab_login_sessions_are_read(
+ def test_fab_session_settings_apply_wherever_fab_login_sessions_are_used(
self,
mock_get_auth_manager,
+ mock_init_airflow_session_interface,
+ mock_init_session_max_lifetime,
mock_init_session_token_generation,
auth_manager_cls,
enable_plugins,
called,
):
- """The plugins app reads the FAB login session too, with the
``securecookie`` backend."""
+ """The plugins app serves the FAB login views too."""
mock_get_auth_manager.return_value = mock.Mock(spec=auth_manager_cls)
flask_app = create_app(enable_plugins=enable_plugins)
if called:
+
mock_init_airflow_session_interface.assert_called_once_with(flask_app, mock.ANY)
+ mock_init_session_max_lifetime.assert_called_once_with(flask_app)
mock_init_session_token_generation.assert_called_once_with(flask_app)
else:
+ mock_init_airflow_session_interface.assert_not_called()
+ mock_init_session_max_lifetime.assert_not_called()
mock_init_session_token_generation.assert_not_called()
+
+ @pytest.mark.parametrize(
+ ("session_backend", "expected_interface"),
+ [
+ pytest.param("database", AirflowDatabaseSessionInterface,
id="database"),
+ pytest.param("securecookie", AirflowSecureCookieSessionInterface,
id="securecookie"),
+ ],
+ )
+ def test_plugins_app_uses_the_configured_session_backend(self,
session_backend, expected_interface):
+ """Both apps run in the API server, so the plugins app is created next
to the FAB app."""
+ with conf_vars(
+ {("core", "auth_manager"): FAB_AUTH_MANAGER, ("fab",
"session_backend"): session_backend}
+ ):
+ fab_app = create_app(enable_plugins=False)
+ plugins_app = create_app(enable_plugins=True)
+
+ assert isinstance(fab_app.session_interface, expected_interface)
+ assert isinstance(plugins_app.session_interface, expected_interface)