Skip to content

Commit

Permalink
Fix sync-perm to work correctly when update_fab_perms = False (#14847)
Browse files Browse the repository at this point in the history
If Airflow is configured with update_fab_perms config setting to False,
then the Op, User and Viewer roles are created _before_ the permissions
objects are written to the database, meaning that these roles did not
correctly get assigned all the permissions we asked for (the missing
permissions are just silently not created.)

Because of the "migrate to resource permission" migration this problem
is not "disasterous" as all most of the Permissions et al. we use are
created by a migration.

This changes it so that the permissions are always created/synced before
we look at the roles.

(Re-running sync-perm wouldn't fix this, as although the second time
around the Permissions will exist in the DB, we see that Op role already
has permissions and don't make any changes, assuming that the site
operators made such changes.)

(cherry picked from commit 1cd62b9)
  • Loading branch information
ashb authored and potiuk committed May 9, 2021
1 parent 7fda8d1 commit c3962e0
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions airflow/cli/commands/sync_perm_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ def sync_perm(args):
"""Updates permissions for existing roles and DAGs"""
appbuilder = cached_app().appbuilder # pylint: disable=no-member
print('Updating permission, view-menu for all existing roles')
appbuilder.sm.sync_roles()
# Add missing permissions for all the Base Views
# Add missing permissions for all the Base Views _before_ syncing/creating roles
appbuilder.add_permissions(update_perms=True)
appbuilder.sm.sync_roles()
print('Updating permission on all DAG views')
dagbag = DagBag(read_dags_from_db=True)
dagbag.collect_dags_from_db()
Expand Down

0 comments on commit c3962e0

Please sign in to comment.