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 2023/10/05 19:47:47 UTC
[PR] Add back decorator `has_access` [airflow]
vincbeck opened a new pull request, #34786:
URL: https://github.com/apache/airflow/pull/34786
See [comment thread](https://github.com/apache/airflow/pull/33213#discussion_r1343788762).
`has_access` decorator seems to be used by many plugins. Hence, in order to avoid breaking them. Adding back this function.
@utkarsharma2, @ashb, @jens-scheffler-bosch
<!--
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.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] Add back decorator `has_access` [airflow]
Posted by "vincbeck (via GitHub)" <gi...@apache.org>.
vincbeck commented on code in PR #34786:
URL: https://github.com/apache/airflow/pull/34786#discussion_r1347954018
##########
airflow/www/auth.py:
##########
@@ -44,6 +46,25 @@ def get_access_denied_message():
return conf.get("webserver", "access_denied_message")
+def has_access(permissions: Sequence[tuple[str, str]] | None = None) -> Callable[[T], T]:
+ """
+ Factory for decorator that checks current user's permissions against required permissions.
+
+ Deprecated. Do not use this decorator, use one of the decorator `has_access_cluster_*` defined in
+ airflow/www/auth.py instead.
+
+ This decorator is widely used in user plugins, do not remove it. See
+ https://github.com/apache/airflow/pull/33213#discussion_r1346287224
+ """
+ warnings.warn(
+ "The 'has_access' decorator is deprecated. Please use one of the decorator `has_access_cluster_*`"
+ "defined in airflow/www/auth.py instead.",
+ DeprecationWarning,
Review Comment:
Good point
--
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] Add back decorator `has_access` [airflow]
Posted by "jens-scheffler-bosch (via GitHub)" <gi...@apache.org>.
jens-scheffler-bosch commented on code in PR #34786:
URL: https://github.com/apache/airflow/pull/34786#discussion_r1349771522
##########
airflow/www/auth.py:
##########
@@ -44,6 +46,27 @@ def get_access_denied_message():
return conf.get("webserver", "access_denied_message")
+def has_access(permissions: Sequence[tuple[str, str]] | None = None) -> Callable[[T], T]:
+ """
+ Factory for decorator that checks current user's permissions against required permissions.
+
+ Deprecated. Do not use this decorator, use one of the decorator `has_access_cluster_*` defined in
+ airflow/www/auth.py instead.
Review Comment:
Maybe be a bit more explicit here?
```suggestion
Deprecated. Do not use this decorator, use one of the decorator `has_access_cluster_*` defined in
airflow/www/auth.py instead.
This decorator will only work with FAB authentication and not with other auth providers.
```
--
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] Add back decorator `has_access` [airflow]
Posted by "hussein-awala (via GitHub)" <gi...@apache.org>.
hussein-awala commented on code in PR #34786:
URL: https://github.com/apache/airflow/pull/34786#discussion_r1347951190
##########
airflow/auth/managers/fab/decorators/auth.py:
##########
@@ -0,0 +1,89 @@
+#
+# 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.
+from __future__ import annotations
+
+import logging
+from functools import wraps
+from typing import Callable, Sequence, TypeVar, cast
+
+from flask import current_app, render_template, request
+
+from airflow.configuration import conf
+from airflow.utils.net import get_hostname
+from airflow.www.auth import _has_access
+from airflow.www.extensions.init_auth_manager import get_auth_manager
+
+T = TypeVar("T", bound=Callable)
+
+log = logging.getLogger(__name__)
+
+
+def has_access_fab(permissions: Sequence[tuple[str, str]] | None = None) -> Callable[[T], T]:
Review Comment:
Could you make it private to tell users not to use it?
--
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] Add back decorator `has_access` [airflow]
Posted by "vincbeck (via GitHub)" <gi...@apache.org>.
vincbeck commented on code in PR #34786:
URL: https://github.com/apache/airflow/pull/34786#discussion_r1352939249
##########
airflow/www/auth.py:
##########
@@ -44,6 +46,27 @@ def get_access_denied_message():
return conf.get("webserver", "access_denied_message")
+def has_access(permissions: Sequence[tuple[str, str]] | None = None) -> Callable[[T], T]:
+ """
+ Factory for decorator that checks current user's permissions against required permissions.
+
+ Deprecated. Do not use this decorator, use one of the decorator `has_access_cluster_*` defined in
+ airflow/www/auth.py instead.
+
+ This decorator is widely used in user plugins, do not remove it. See
+ https://github.com/apache/airflow/pull/33213#discussion_r1346287224
+ """
+ warnings.warn(
+ "The 'has_access' decorator is deprecated. Please use one of the decorator `has_access_cluster_*`"
Review Comment:
Oh yeah, you're right. Nice catch!
--
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] Add back decorator `has_access` [airflow]
Posted by "ashb (via GitHub)" <gi...@apache.org>.
ashb commented on code in PR #34786:
URL: https://github.com/apache/airflow/pull/34786#discussion_r1347908652
##########
airflow/www/auth.py:
##########
@@ -44,6 +46,25 @@ def get_access_denied_message():
return conf.get("webserver", "access_denied_message")
+def has_access(permissions: Sequence[tuple[str, str]] | None = None) -> Callable[[T], T]:
+ """
+ Factory for decorator that checks current user's permissions against required permissions.
+
+ Deprecated. Do not use this decorator, use one of the decorator `has_access_cluster_*` defined in
+ airflow/www/auth.py instead.
+
+ This decorator is widely used in user plugins, do not remove it. See
+ https://github.com/apache/airflow/pull/33213#discussion_r1346287224
+ """
+ warnings.warn(
+ "The 'has_access' decorator is deprecated. Please use one of the decorator `has_access_cluster_*`"
+ "defined in airflow/www/auth.py instead.",
+ DeprecationWarning,
Review Comment:
There's a RemovedInAirflow3 warning class somewhere we should use instead
--
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] Add back decorator `has_access` [airflow]
Posted by "hussein-awala (via GitHub)" <gi...@apache.org>.
hussein-awala commented on PR #34786:
URL: https://github.com/apache/airflow/pull/34786#issuecomment-1749636013
> > @vincbeck @ashb Should we also update the [public interface document](https://airflow.apache.org/docs/apache-airflow/stable/public-airflow-interface.html) to include `has_access`? Maybe as a separate PR.
>
> I would definitely say yes. I would do it in a separate PR though, mainly because I dont really know how to explain besides saying: "Many plugins are using this decorator historically" :D One of you want to take a chance at it?
I don't have a strong opinion on this, but as I understood in the original discussion, this decorator should not be in the public interface, but just maintain it because it was used since Airflow 1 for plugins, and we kept it in Airflow 2.
Adding a deprecated method to the public interface doesn't make much sense for me.
--
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] Add back decorator `has_access` [airflow]
Posted by "vincbeck (via GitHub)" <gi...@apache.org>.
vincbeck commented on code in PR #34786:
URL: https://github.com/apache/airflow/pull/34786#discussion_r1352934435
##########
airflow/www/auth.py:
##########
@@ -44,6 +46,27 @@ def get_access_denied_message():
return conf.get("webserver", "access_denied_message")
+def has_access(permissions: Sequence[tuple[str, str]] | None = None) -> Callable[[T], T]:
+ """
+ Factory for decorator that checks current user's permissions against required permissions.
+
+ Deprecated. Do not use this decorator, use one of the decorator `has_access_cluster_*` defined in
+ airflow/www/auth.py instead.
Review Comment:
I like it
--
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] Add back decorator `has_access` [airflow]
Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk merged PR #34786:
URL: https://github.com/apache/airflow/pull/34786
--
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] Add back decorator `has_access` [airflow]
Posted by "vincbeck (via GitHub)" <gi...@apache.org>.
vincbeck commented on PR #34786:
URL: https://github.com/apache/airflow/pull/34786#issuecomment-1756037969
@utkarsharma2, @ashb, @hussein-awala Any comments?
--
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] Add back decorator `has_access` [airflow]
Posted by "jens-scheffler-bosch (via GitHub)" <gi...@apache.org>.
jens-scheffler-bosch commented on PR #34786:
URL: https://github.com/apache/airflow/pull/34786#issuecomment-1755949965
> > So besides public API would be good to add some hints into the plugin authoring docs - If you don't want to raise a PR I could if you help me in understanding.
>
> Yes, happy to work together on this one. Please feel free to create a PR and tag me on it and I'll be able to review it. Or you can ping me on Slack if you want
Promise to contribute this after merging this PR...
--
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] Add back decorator `has_access` [airflow]
Posted by "utkarsharma2 (via GitHub)" <gi...@apache.org>.
utkarsharma2 commented on PR #34786:
URL: https://github.com/apache/airflow/pull/34786#issuecomment-1749572624
@vincbeck @ashb Should we also update the [public interface document](https://airflow.apache.org/docs/apache-airflow/stable/public-airflow-interface.html)? Maybe as a separate PR?
--
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] Add back decorator `has_access` [airflow]
Posted by "jens-scheffler-bosch (via GitHub)" <gi...@apache.org>.
jens-scheffler-bosch commented on code in PR #34786:
URL: https://github.com/apache/airflow/pull/34786#discussion_r1349770592
##########
airflow/www/auth.py:
##########
@@ -44,6 +46,27 @@ def get_access_denied_message():
return conf.get("webserver", "access_denied_message")
+def has_access(permissions: Sequence[tuple[str, str]] | None = None) -> Callable[[T], T]:
+ """
+ Factory for decorator that checks current user's permissions against required permissions.
+
+ Deprecated. Do not use this decorator, use one of the decorator `has_access_cluster_*` defined in
+ airflow/www/auth.py instead.
+
+ This decorator is widely used in user plugins, do not remove it. See
+ https://github.com/apache/airflow/pull/33213#discussion_r1346287224
+ """
+ warnings.warn(
+ "The 'has_access' decorator is deprecated. Please use one of the decorator `has_access_cluster_*`"
Review Comment:
Thanks for pointing to the new API points, I assume there is a small type of the prefix used?
```suggestion
Deprecated. Do not use this decorator, use one of the decorator `has_access_*` defined in
airflow/www/auth.py instead.
This decorator is widely used in user plugins, do not remove it. See
https://github.com/apache/airflow/pull/33213#discussion_r1346287224
"""
warnings.warn(
"The 'has_access' decorator is deprecated. Please use one of the decorator `has_access_*`"
```
--
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] Add back decorator `has_access` [airflow]
Posted by "vincbeck (via GitHub)" <gi...@apache.org>.
vincbeck commented on code in PR #34786:
URL: https://github.com/apache/airflow/pull/34786#discussion_r1347955338
##########
airflow/auth/managers/fab/decorators/auth.py:
##########
@@ -0,0 +1,89 @@
+#
+# 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.
+from __future__ import annotations
+
+import logging
+from functools import wraps
+from typing import Callable, Sequence, TypeVar, cast
+
+from flask import current_app, render_template, request
+
+from airflow.configuration import conf
+from airflow.utils.net import get_hostname
+from airflow.www.auth import _has_access
+from airflow.www.extensions.init_auth_manager import get_auth_manager
+
+T = TypeVar("T", bound=Callable)
+
+log = logging.getLogger(__name__)
+
+
+def has_access_fab(permissions: Sequence[tuple[str, str]] | None = None) -> Callable[[T], T]:
Review Comment:
Yep
--
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] Add back decorator `has_access` [airflow]
Posted by "vincbeck (via GitHub)" <gi...@apache.org>.
vincbeck commented on PR #34786:
URL: https://github.com/apache/airflow/pull/34786#issuecomment-1750735846
> > > @vincbeck @ashb Should we also update the [public interface document](https://airflow.apache.org/docs/apache-airflow/stable/public-airflow-interface.html) to include `has_access`? Maybe as a separate PR.
> >
> >
> > I would definitely say yes. I would do it in a separate PR though, mainly because I dont really know how to explain besides saying: "Many plugins are using this decorator historically" :D One of you want to take a chance at it?
>
> I don't have a strong opinion on this, but as I understood in the original discussion, this decorator should not be in the public interface, but just maintain it because it was used since Airflow 1 for plugins, and we kept it in Airflow 2. Adding a deprecated method to the public interface doesn't make much sense for me.
That's true too ... I guess we are in some kind of grey area here. But what you said makes sense to me
--
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] Add back decorator `has_access` [airflow]
Posted by "vincbeck (via GitHub)" <gi...@apache.org>.
vincbeck commented on PR #34786:
URL: https://github.com/apache/airflow/pull/34786#issuecomment-1749629977
> @vincbeck @ashb Should we also update the [public interface document](https://airflow.apache.org/docs/apache-airflow/stable/public-airflow-interface.html) to include `has_access`? Maybe as a separate PR.
I would definitely say yes. I would do it in a separate PR though, mainly because I dont really know how to explain besides saying: "Many plugins are using this decorator historically" :D One of you want to take a chance at it?
--
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] Add back decorator `has_access` [airflow]
Posted by "vincbeck (via GitHub)" <gi...@apache.org>.
vincbeck commented on PR #34786:
URL: https://github.com/apache/airflow/pull/34786#issuecomment-1755910306
> What I did not fully get with the new API methods are, these are specific to the UI areas. If I add a `MyPlugin` then I would need to add a `has_access_my_plugin()` decorator, the ones existing are specific to the existing UI.
Yes it can be an option. If you implement `MyPlugin`, then you can implement `has_access_my_plugin()` which checks whether the user has permissions to access the view provided by your plugin. In a following PR of #34317 (meaning: whenever #34317 is merged I'll be able to create another PR), I implement a mechanism to check custom permissions. By custom permissions I mean permissions defined outside of Airflow codebase (which is the case of plugins). As part of this PR I'll be able to implement also a `has_access_custom()` decorator which then can be used in such use case. Stay tuned :)
> So besides public API would be good to add some hints into the plugin authoring docs - If you don't want to raise a PR I could if you help me in understanding.
Yes, happy to work together on this one. Please feel free to create a PR and tag me on it and I'll be able to review it. Or you can ping me on Slack if you want
--
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] Add back decorator `has_access` [airflow]
Posted by "utkarsharma2 (via GitHub)" <gi...@apache.org>.
utkarsharma2 commented on PR #34786:
URL: https://github.com/apache/airflow/pull/34786#issuecomment-1756075151
@vincbeck Thanks for adding it back :) changes look good to me.
--
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