Skip to content
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

Don't show grid actions if server would reject with permission denied #23332

Merged
merged 3 commits into from
Apr 28, 2022

Conversation

bbovenzi
Copy link
Contributor

@bbovenzi bbovenzi commented Apr 28, 2022

The Grid view wasn't checking DAG edit permissions. Also, the permission error body response is HTML, not json.

  • Check if body in ConfirmDialog is an array to prevent the grid view from crashing
  • Add canEdit check to disabled all grid view action buttons, and don't show mapped instance selection at all

Before:
2022-04-28 20 16 50

After:
Screen Shot 2022-04-28 at 11 19 20 AM


^ Add meaningful description above

Read the Pull Request Guidelines for more information.
In case of fundamental code change, Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in a newsfragement file, named {pr_number}.significant.rst, in newsfragments.

@boring-cyborg boring-cyborg bot added area:UI Related to UI/UX. For Frontend Developers. area:webserver Webserver related Issues labels Apr 28, 2022
@ashb
Copy link
Member

ashb commented Apr 28, 2022

What's the current behaviour? Permissions are still respected on the API/server-side right?

@bbovenzi
Copy link
Contributor Author

What's the current behaviour? Permissions are still respected on the API/server-side right?

Yes, the server still doesn't perform any actions. But the UI was also not handling the non-JSON error correctly and the grid view went blank. (I added a gif to the PR description)

@@ -82,6 +82,9 @@
{% endif %}
{% if external_log_name is defined %}
<meta name="external_log_name" content="{{ external_log_name }}">
{% if appbuilder.sm.can_edit_dag(dag.dag_id) %}
<meta name="can_edit" content="{{ appbuilder.sm.can_edit_dag(dag.dag_id) }}">
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only checking edit permissions on the DAG. Is there an easy way to check Task Instance and DAG Run edit perrmissions via FAB?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dag.can_edit should exist I think.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

def add_user_permissions_to_dag(sender, template, context, **extra):
"""
Adds `.can_edit`, `.can_trigger`, and `.can_delete` properties
to DAG based on current user's permissions.
Located in `views.py` rather than the DAG model to keep
permissions logic out of the Airflow core.
"""
if 'dag' in context:
dag = context['dag']
can_create_dag_run = current_app.appbuilder.sm.has_access(
permissions.ACTION_CAN_CREATE, permissions.RESOURCE_DAG_RUN
)
dag.can_edit = current_app.appbuilder.sm.can_edit_dag(dag.dag_id)
dag.can_trigger = dag.can_edit and can_create_dag_run
dag.can_delete = current_app.appbuilder.sm.can_delete_dag(dag.dag_id)
context['dag'] = dag
before_render_template.connect(add_user_permissions_to_dag)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, that's not the right thing (but still, use dag.can_edit instead.)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I can't see anything currently that makes that decision.

Will this PR now gracefully handle getting a (non-JSON?) permission denied error.

Copy link
Contributor Author

@bbovenzi bbovenzi Apr 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I use that instead of the current meta content?

Also, what I meant is that a lot of these endpoints are checking multiple permissions, not just dag.can_edit. (ie: /clear)

@expose('/clear', methods=['POST'])
@auth.has_access(
    [
        (permissions.ACTION_CAN_EDIT, permissions.RESOURCE_DAG),
        (permissions.ACTION_CAN_DELETE, permissions.RESOURCE_TASK_INSTANCE),
    ]
)

Copy link
Contributor Author

@bbovenzi bbovenzi Apr 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More gracefully, yes. The error response is still an html redirect. But the UI won't crash.
I feel like fixing the error response from the webserver should be in another PR?

@ashb ashb changed the title Add edit permission check for grid actions Don't show grid actions if server would reject with permission denied Apr 28, 2022
@github-actions github-actions bot added the okay to merge It's ok to merge this PR as it does not require more tests label Apr 28, 2022
@github-actions
Copy link

The PR is likely OK to be merged with just subset of tests for default Python and Database versions without running the full matrix of tests, because it does not modify the core of Airflow. If the committers decide that the full tests matrix is needed, they will add the label 'full tests needed'. Then you should rebase to the latest main or amend the last commit of the PR, and push it with --force-with-lease.

@bbovenzi bbovenzi added this to the Airflow 2.3.1 milestone Apr 28, 2022
@bbovenzi bbovenzi merged commit 67e8bdd into apache:main Apr 28, 2022
@bbovenzi bbovenzi deleted the grid-view-edit-permissions branch April 28, 2022 17:20
jedcunningham pushed a commit to astronomer/airflow that referenced this pull request Apr 28, 2022
…apache#23332)

* Add edit permission check for grid actions

* Remove if wrapper for meta tag

* Use dag.can_edit

(cherry picked from commit 67e8bdd)
@ephraimbuddy ephraimbuddy added the type:bug-fix Changelog: Bug Fixes label May 8, 2022
ephraimbuddy pushed a commit that referenced this pull request May 8, 2022
…#23332)

* Add edit permission check for grid actions

* Remove if wrapper for meta tag

* Use dag.can_edit

(cherry picked from commit 67e8bdd)
ephraimbuddy pushed a commit that referenced this pull request May 21, 2022
…#23332)

* Add edit permission check for grid actions

* Remove if wrapper for meta tag

* Use dag.can_edit

(cherry picked from commit 67e8bdd)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:UI Related to UI/UX. For Frontend Developers. area:webserver Webserver related Issues okay to merge It's ok to merge this PR as it does not require more tests type:bug-fix Changelog: Bug Fixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants