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/07/07 16:03:41 UTC
[GitHub] [airflow] vincbeck opened a new pull request, #32428: Add AuthManager.is_logged_in and use to determine whether a user is logged in
vincbeck opened a new pull request, #32428:
URL: https://github.com/apache/airflow/pull/32428
Add `is_logged_in` method in `AuthManager` and implementation in `FabAuthManager`. Use this method across the code to determine whether a user is logged in.
<!--
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/
-->
---
**^ 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
[GitHub] [airflow] vandonr-amz commented on a diff in pull request #32428: Add AuthManager.is_logged_in and use it to determine whether a user is logged in
Posted by "vandonr-amz (via GitHub)" <gi...@apache.org>.
vandonr-amz commented on code in PR #32428:
URL: https://github.com/apache/airflow/pull/32428#discussion_r1256611114
##########
airflow/auth/managers/base_auth_manager.py:
##########
@@ -33,3 +33,8 @@ class BaseAuthManager(LoggingMixin):
def get_user_name(self) -> str:
"""Return the username associated to the user in session."""
...
+
+ @abstractmethod
+ def is_logged_in(self) -> bool:
+ """Return whether the user is logged in."""
+ ...
Review Comment:
should this be abstract ? Or maybe we could implement it using `get_user_name` ? If it returns None if user is not logged ?
##########
airflow/www/auth.py:
##########
@@ -46,7 +46,7 @@ def decorated(*args, **kwargs):
)
if appbuilder.sm.check_authorization(permissions, dag_id):
return func(*args, **kwargs)
- elif not g.user.is_anonymous and not g.user.perms:
+ elif auth_manager.is_logged_in() and not g.user.perms:
Review Comment:
I suppose `g.user.perms` is something we'll touch too, but later on in the project ?
##########
airflow/auth/managers/fab/fab_auth_manager.py:
##########
@@ -39,3 +39,7 @@ def get_user_name(self) -> str:
first_name = current_user.first_name or ""
last_name = current_user.last_name or ""
return f"{first_name} {last_name}".strip()
+
+ def is_logged_in(self) -> bool:
+ """Return whether the user is logged in."""
+ return not current_user.is_anonymous
Review Comment:
should we check if `current_user` is None before ? Given the fact that it was done in https://github.com/apache/airflow/pull/32428/files#diff-8075dbc4ae06e7b83cd163eeb206322a7977c227bb57398e7343c9e09c80ae59L71
--
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
[GitHub] [airflow] vincbeck merged pull request #32428: Add AuthManager.is_logged_in and use it to determine whether a user is logged in
Posted by "vincbeck (via GitHub)" <gi...@apache.org>.
vincbeck merged PR #32428:
URL: https://github.com/apache/airflow/pull/32428
--
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
[GitHub] [airflow] vincbeck commented on a diff in pull request #32428: Add AuthManager.is_logged_in and use to determine whether a user is logged in
Posted by "vincbeck (via GitHub)" <gi...@apache.org>.
vincbeck commented on code in PR #32428:
URL: https://github.com/apache/airflow/pull/32428#discussion_r1256058509
##########
tests/www/test_security.py:
##########
@@ -374,7 +374,6 @@ def test_verify_anon_user_with_admin_role_has_access_to_each_dag(
def test_get_user_roles(app_builder, security_manager):
user = mock.MagicMock()
- user.is_anonymous = False
Review Comment:
This was useless in this test
--
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
[GitHub] [airflow] vandonr-amz commented on a diff in pull request #32428: Add AuthManager.is_logged_in and use it to determine whether a user is logged in
Posted by "vandonr-amz (via GitHub)" <gi...@apache.org>.
vandonr-amz commented on code in PR #32428:
URL: https://github.com/apache/airflow/pull/32428#discussion_r1259975848
##########
airflow/auth/managers/base_auth_manager.py:
##########
@@ -33,3 +33,8 @@ class BaseAuthManager(LoggingMixin):
def get_user_name(self) -> str:
"""Return the username associated to the user in session."""
...
+
+ @abstractmethod
+ def is_logged_in(self) -> bool:
+ """Return whether the user is logged in."""
+ ...
Review Comment:
ok gotcha
--
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
[GitHub] [airflow] uranusjr commented on a diff in pull request #32428: Add AuthManager.is_logged_in and use it to determine whether a user is logged in
Posted by "uranusjr (via GitHub)" <gi...@apache.org>.
uranusjr commented on code in PR #32428:
URL: https://github.com/apache/airflow/pull/32428#discussion_r1260443490
##########
airflow/auth/managers/fab/fab_auth_manager.py:
##########
@@ -39,3 +39,7 @@ def get_user_name(self) -> str:
first_name = current_user.first_name or ""
last_name = current_user.last_name or ""
return f"{first_name} {last_name}".strip()
+
+ def is_logged_in(self) -> bool:
+ """Return whether the user is logged in."""
+ return current_user and not current_user.is_anonymous
Review Comment:
Is there a case `current_user` can be falsy?
--
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
[GitHub] [airflow] vincbeck commented on a diff in pull request #32428: Add AuthManager.is_logged_in and use it to determine whether a user is logged in
Posted by "vincbeck (via GitHub)" <gi...@apache.org>.
vincbeck commented on code in PR #32428:
URL: https://github.com/apache/airflow/pull/32428#discussion_r1258344522
##########
airflow/auth/managers/base_auth_manager.py:
##########
@@ -33,3 +33,8 @@ class BaseAuthManager(LoggingMixin):
def get_user_name(self) -> str:
"""Return the username associated to the user in session."""
...
+
+ @abstractmethod
+ def is_logged_in(self) -> bool:
+ """Return whether the user is logged in."""
+ ...
Review Comment:
I dont really like that. Each auth manager can be very different and retrieving the user name to check whether the user is logged in feels wrong to me. Some auth manager can have very complex/costly operation to retrieve the username and some cheap one to just check whether a user is logged in, so I rather have two operation. If one auth manager thinks one method can use the other, it can do it in their own implementation
--
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
[GitHub] [airflow] vincbeck commented on a diff in pull request #32428: Add AuthManager.is_logged_in and use it to determine whether a user is logged in
Posted by "vincbeck (via GitHub)" <gi...@apache.org>.
vincbeck commented on code in PR #32428:
URL: https://github.com/apache/airflow/pull/32428#discussion_r1258347657
##########
airflow/auth/managers/fab/fab_auth_manager.py:
##########
@@ -39,3 +39,7 @@ def get_user_name(self) -> str:
first_name = current_user.first_name or ""
last_name = current_user.last_name or ""
return f"{first_name} {last_name}".strip()
+
+ def is_logged_in(self) -> bool:
+ """Return whether the user is logged in."""
+ return not current_user.is_anonymous
Review Comment:
I am not sure it can happen but I dont mind adding 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
[GitHub] [airflow] vincbeck commented on a diff in pull request #32428: Add AuthManager.is_logged_in and use it to determine whether a user is logged in
Posted by "vincbeck (via GitHub)" <gi...@apache.org>.
vincbeck commented on code in PR #32428:
URL: https://github.com/apache/airflow/pull/32428#discussion_r1261166773
##########
airflow/auth/managers/fab/fab_auth_manager.py:
##########
@@ -39,3 +39,7 @@ def get_user_name(self) -> str:
first_name = current_user.first_name or ""
last_name = current_user.last_name or ""
return f"{first_name} {last_name}".strip()
+
+ def is_logged_in(self) -> bool:
+ """Return whether the user is logged in."""
+ return current_user and not current_user.is_anonymous
Review Comment:
I added it from [this comment](https://github.com/apache/airflow/pull/32428#discussion_r1256614403). To be honest I dont know, I just did it because to be safe
##########
airflow/auth/managers/fab/fab_auth_manager.py:
##########
@@ -39,3 +39,7 @@ def get_user_name(self) -> str:
first_name = current_user.first_name or ""
last_name = current_user.last_name or ""
return f"{first_name} {last_name}".strip()
+
+ def is_logged_in(self) -> bool:
+ """Return whether the user is logged in."""
+ return current_user and not current_user.is_anonymous
Review Comment:
I added it from [this comment](https://github.com/apache/airflow/pull/32428#discussion_r1256614403). To be honest I dont know, I just did it to be safe
--
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
[GitHub] [airflow] vincbeck commented on a diff in pull request #32428: Add AuthManager.is_logged_in and use it to determine whether a user is logged in
Posted by "vincbeck (via GitHub)" <gi...@apache.org>.
vincbeck commented on code in PR #32428:
URL: https://github.com/apache/airflow/pull/32428#discussion_r1258345478
##########
airflow/www/auth.py:
##########
@@ -46,7 +46,7 @@ def decorated(*args, **kwargs):
)
if appbuilder.sm.check_authorization(permissions, dag_id):
return func(*args, **kwargs)
- elif not g.user.is_anonymous and not g.user.perms:
+ elif auth_manager.is_logged_in() and not g.user.perms:
Review Comment:
Exactly. The plan is to remove `g.user` from the code, but as you said, step by step :)
--
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