-
Notifications
You must be signed in to change notification settings - Fork 14.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix dag warning endpoint permissions #34355
Conversation
query = query.where(DagWarningModel.dag_id == dag_id) | ||
if warning_type: | ||
query = query.where(DagWarningModel.warning_type == warning_type) | ||
total_entries = get_query_count(query, session=session) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
useless query, the count could be calculated from the list
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually not useless, because the is limit
in the query, I will fix it
I thought about using IN (list of accessible dags), but after some search, it looks like IN has limits in the different engines:
I will try to find a way to join the table with the dag table. |
Looks like there is no other solution, we do the same thing for dag endpoint: airflow/airflow/api_connexion/endpoints/dag_endpoint.py Lines 99 to 101 in fe05e1a
|
for dag_warning in dag_warnings | ||
if get_airflow_app().appbuilder.sm.can_read_dag(dag_warning.dag_id, g.user) | ||
] | ||
total_entries = len(dag_warnings) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is supposed to show the actual total, not the paginated value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah. This is the total not paginated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad, I changed it but I forgot to push my commit. Just pushed it
dag_warnings = [ | ||
dag_warning | ||
for dag_warning in dag_warnings | ||
if get_airflow_app().appbuilder.sm.can_read_dag(dag_warning.dag_id, g.user) | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Filtering should happen before limit, otherwise this would show a weird number of entries if some of the warnings are not viewable by the current user, even possibly an empty list.
@@ -57,7 +60,12 @@ def get_dag_warnings( | |||
allowed_filter_attrs = ["dag_id", "warning_type", "message", "timestamp"] | |||
query = select(DagWarningModel) | |||
if dag_id: | |||
if not get_airflow_app().appbuilder.sm.can_read_dag(dag_id, g.user): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel we should have the DAG permission in the decorator instead of handling this by ourselves. My vote would go to just adding (permissions.ACTION_CAN_READ, permissions.RESOURCE_DAG)
to the list of permissions.
That should solve this. Assuming it's dag_ids instead of dag_id, then we can do as you're doing now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I see that if dag_id is not provided, then it gets all dag warning, my bad.
57a0480
to
658a853
Compare
Co-authored-by: Tzu-ping Chung <uranusjr@gmail.com>
* Fix dag warning endpoint permissions * update the query to have an accurate result for total entries and pagination * add unit tests * Update test_dag_warning_endpoint.py Co-authored-by: Tzu-ping Chung <uranusjr@gmail.com> --------- Co-authored-by: Tzu-ping Chung <uranusjr@gmail.com> (cherry picked from commit 3570bbf)
No description provided.