You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "vincbeck (via GitHub)" <gi...@apache.org> on 2025/01/06 20:01:17 UTC
[PR] Do not use core Airflow Flask related resources in FAB provider [airflow]
vincbeck opened a new pull request, #45441:
URL: https://github.com/apache/airflow/pull/45441
As part of AIP-79.
The Flask application in FAB provider should not use any Flask related resources from core Airflow. Otherwise, deleting the main Flask application in core Airflow when the legacy Airflow 2 is gone will be impossible.
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<!--
Thank you for contributing! Please make sure that your code changes
are covered with tests. And in case of new features or big changes
remember to adjust the documentation.
Feel free to ping committers for the review!
In case of an existing issue, reference it using one of the following:
closes: #ISSUE
related: #ISSUE
How to write a good git commit message:
http://chris.beams.io/posts/git-commit/
-->
<!-- Please keep an empty line above the dashes. -->
---
**^ Add meaningful description above**
Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#pull-request-guidelines)** for more information.
In case of fundamental code changes, an Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals)) is needed.
In case of a new dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
In case of backwards incompatible changes please leave a note in a newsfragment file, named `{pr_number}.significant.rst` or `{issue_number}.significant.rst`, in [newsfragments](https://github.com/apache/airflow/tree/main/newsfragments).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Do not use core Airflow Flask related resources in FAB provider [airflow]
Posted by "vincbeck (via GitHub)" <gi...@apache.org>.
vincbeck merged PR #45441:
URL: https://github.com/apache/airflow/pull/45441
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Do not use core Airflow Flask related resources in FAB provider [airflow]
Posted by "vincbeck (via GitHub)" <gi...@apache.org>.
vincbeck commented on code in PR #45441:
URL: https://github.com/apache/airflow/pull/45441#discussion_r1904586547
##########
providers/src/airflow/providers/fab/www/security_manager.py:
##########
@@ -0,0 +1,310 @@
+# Licensed to the Apache Software Foundation (ASF) under one
Review Comment:
File copied from `airflow/www/security_manager.py`
##########
providers/src/airflow/providers/fab/www/session.py:
##########
@@ -0,0 +1,41 @@
+# Licensed to the Apache Software Foundation (ASF) under one
Review Comment:
Copy of `airflow/www/session.py`
##########
providers/src/airflow/providers/fab/auth_manager/fab_auth_manager.py:
##########
@@ -398,6 +400,32 @@ def get_permitted_dag_ids(
resources.add(resource)
return set(session.scalars(select(DagModel.dag_id).where(DagModel.dag_id.in_(resources))))
+ def filter_permitted_menu_items(self, menu_items: list[MenuItem]) -> list[MenuItem]:
Review Comment:
Implementation copied from the interface
##########
providers/src/airflow/providers/fab/www/extensions/init_session.py:
##########
@@ -0,0 +1,64 @@
+# Licensed to the Apache Software Foundation (ASF) under one
Review Comment:
File copied from `airflow/www/extensions/init_session.py`
##########
providers/src/airflow/providers/fab/www/views.py:
##########
@@ -0,0 +1,66 @@
+#
Review Comment:
Copied from `airflow/www/views.py`
##########
providers/src/airflow/providers/fab/www/utils.py:
##########
@@ -0,0 +1,933 @@
+#
Review Comment:
Copied from `airflow/www/utils.py`
##########
airflow/auth/managers/base_auth_manager.py:
##########
@@ -395,47 +400,6 @@ def _is_permitted_dag_id(method: ResourceMethod, methods: Container[ResourceMeth
if _is_permitted_dag_id("GET", methods, dag_id) or _is_permitted_dag_id("PUT", methods, dag_id)
}
- def filter_permitted_menu_items(self, menu_items: list[MenuItem]) -> list[MenuItem]:
- """
- Filter menu items based on user permissions.
-
- :param menu_items: list of all menu items
- """
- items = filter(
- lambda item: self.security_manager.has_access(ACTION_CAN_ACCESS_MENU, item.name), menu_items
- )
- accessible_items = []
- for menu_item in items:
- menu_item_copy = MenuItem(
- **{
- **menu_item.__dict__,
- "childs": [],
- }
- )
- if menu_item.childs:
- accessible_children = []
- for child in menu_item.childs:
- if self.security_manager.has_access(ACTION_CAN_ACCESS_MENU, child.name):
- accessible_children.append(child)
- menu_item_copy.childs = accessible_children
- accessible_items.append(menu_item_copy)
- return accessible_items
-
- @cached_property
- def security_manager(self) -> AirflowSecurityManagerV2:
Review Comment:
Remove the concept of security manager from the interface because it is very specific to Flask
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Do not use core Airflow Flask related resources in FAB provider [airflow]
Posted by "utkarsharma2 (via GitHub)" <gi...@apache.org>.
utkarsharma2 commented on code in PR #45441:
URL: https://github.com/apache/airflow/pull/45441#discussion_r1910360144
##########
providers/src/airflow/providers/fab/auth_manager/cli_commands/utils.py:
##########
@@ -25,17 +25,17 @@
from typing import TYPE_CHECKING
from flask import Flask
+from sqlalchemy.engine import make_url
import airflow
from airflow.configuration import conf
from airflow.exceptions import AirflowConfigException
-from airflow.www.app import make_url
-from airflow.www.extensions.init_appbuilder import init_appbuilder
-from airflow.www.extensions.init_session import init_airflow_session_interface
-from airflow.www.extensions.init_views import init_plugins
+from airflow.providers.fab.www.extensions.init_appbuilder import init_appbuilder
+from airflow.providers.fab.www.extensions.init_session import init_airflow_session_interface
+from airflow.providers.fab.www.extensions.init_views import init_plugins
if TYPE_CHECKING:
- from airflow.www.extensions.init_appbuilder import AirflowAppBuilder
+ from airflow.providers.fab.www.extensions.init_appbuilder import AirflowAppBuilder
Review Comment:
@vincbeck We don't have `add_permissions()` method in `from airflow.providers.fab.www.extensions.init_appbuilder import AirflowAppBuilder` class. Causing `airflow sync-perm` command to fail on the main branch.
```
Updating actions and resources for all existing roles
webserver | Traceback (most recent call last):
webserver | File "/usr/local/bin/airflow", line 8, in <module>
webserver | sys.exit(main())
webserver | ^^^^^^
webserver | File "/usr/local/lib/python3.12/site-packages/airflow/__main__.py", line 58, in main
webserver | args.func(args)
webserver | File "/usr/local/lib/python3.12/site-packages/airflow/cli/cli_config.py", line 49, in command
webserver | return func(*args, **kwargs)
webserver | ^^^^^^^^^^^^^^^^^^^^^
webserver | File "/usr/local/lib/python3.12/site-packages/airflow/utils/cli.py", line 111, in wrapper
webserver | return f(*args, **kwargs)
webserver | ^^^^^^^^^^^^^^^^^^
webserver | File "/usr/local/lib/python3.12/site-packages/airflow/utils/providers_configuration_loader.py", line 55, in wrapped_function
webserver | return func(*args, **kwargs)
webserver | ^^^^^^^^^^^^^^^^^^^^^
webserver | File "/usr/local/lib/python3.12/site-packages/airflow/providers/fab/auth_manager/cli_commands/sync_perm_command.py", line 35, in sync_perm
webserver | appbuilder.add_permissions(update_perms=True)
webserver | ^^^^^^^^^^^^^^^^^^^^^^^^^^
webserver | AttributeError: 'AirflowAppBuilder' object has no attribute 'add_permissions'. Did you mean: '_add_permission'?
```
Is there an alternative method we should use?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Do not use core Airflow Flask related resources in FAB provider [airflow]
Posted by "utkarsharma2 (via GitHub)" <gi...@apache.org>.
utkarsharma2 commented on code in PR #45441:
URL: https://github.com/apache/airflow/pull/45441#discussion_r1913028358
##########
providers/src/airflow/providers/fab/auth_manager/cli_commands/utils.py:
##########
@@ -25,17 +25,17 @@
from typing import TYPE_CHECKING
from flask import Flask
+from sqlalchemy.engine import make_url
import airflow
from airflow.configuration import conf
from airflow.exceptions import AirflowConfigException
-from airflow.www.app import make_url
-from airflow.www.extensions.init_appbuilder import init_appbuilder
-from airflow.www.extensions.init_session import init_airflow_session_interface
-from airflow.www.extensions.init_views import init_plugins
+from airflow.providers.fab.www.extensions.init_appbuilder import init_appbuilder
+from airflow.providers.fab.www.extensions.init_session import init_airflow_session_interface
+from airflow.providers.fab.www.extensions.init_views import init_plugins
if TYPE_CHECKING:
- from airflow.www.extensions.init_appbuilder import AirflowAppBuilder
+ from airflow.providers.fab.www.extensions.init_appbuilder import AirflowAppBuilder
Review Comment:
@vincbeck, I have created a PR for the same. PTAL - https://github.com/apache/airflow/pull/45611
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Do not use core Airflow Flask related resources in FAB provider [airflow]
Posted by "vincbeck (via GitHub)" <gi...@apache.org>.
vincbeck commented on code in PR #45441:
URL: https://github.com/apache/airflow/pull/45441#discussion_r1910685238
##########
providers/src/airflow/providers/fab/auth_manager/cli_commands/utils.py:
##########
@@ -25,17 +25,17 @@
from typing import TYPE_CHECKING
from flask import Flask
+from sqlalchemy.engine import make_url
import airflow
from airflow.configuration import conf
from airflow.exceptions import AirflowConfigException
-from airflow.www.app import make_url
-from airflow.www.extensions.init_appbuilder import init_appbuilder
-from airflow.www.extensions.init_session import init_airflow_session_interface
-from airflow.www.extensions.init_views import init_plugins
+from airflow.providers.fab.www.extensions.init_appbuilder import init_appbuilder
+from airflow.providers.fab.www.extensions.init_session import init_airflow_session_interface
+from airflow.providers.fab.www.extensions.init_views import init_plugins
if TYPE_CHECKING:
- from airflow.www.extensions.init_appbuilder import AirflowAppBuilder
+ from airflow.providers.fab.www.extensions.init_appbuilder import AirflowAppBuilder
Review Comment:
Is it still happening? The solution would be to copy over `add_permissions` from core Airflow to FAB provider
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Do not use core Airflow Flask related resources in FAB provider [airflow]
Posted by "github-advanced-security[bot] (via GitHub)" <gi...@apache.org>.
github-advanced-security[bot] commented on code in PR #45441:
URL: https://github.com/apache/airflow/pull/45441#discussion_r1904588141
##########
providers/src/airflow/providers/fab/www/extensions/init_security.py:
##########
@@ -40,3 +42,18 @@
return response
app.after_request(apply_caching)
+
+
+def init_api_auth(app):
+ """Load authentication backends."""
+ auth_backends = conf.get("api", "auth_backends")
+
+ app.api_auth = []
+ try:
+ for backend in auth_backends.split(","):
+ auth = import_module(backend.strip())
+ auth.init_app(app)
+ app.api_auth.append(auth)
+ except ImportError as err:
+ log.critical("Cannot import %s for API authentication due to: %s", backend, err)
Review Comment:
## Clear-text logging of sensitive information
This expression logs [sensitive data (secret)](1) as clear text.
This expression logs [sensitive data (secret)](2) as clear text.
[Show more details](https://github.com/apache/airflow/security/code-scanning/301)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org