Skip to content

Commit 1cd62b9

Browse files
authored
Fix sync-perm to work correctly when update_fab_perms = False (#14847)
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.)
1 parent 03d3c7d commit 1cd62b9

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

airflow/cli/commands/sync_perm_command.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ def sync_perm(args):
2626
"""Updates permissions for existing roles and DAGs"""
2727
appbuilder = cached_app().appbuilder # pylint: disable=no-member
2828
print('Updating permission, view-menu for all existing roles')
29-
appbuilder.sm.sync_roles()
30-
# Add missing permissions for all the Base Views
29+
# Add missing permissions for all the Base Views _before_ syncing/creating roles
3130
appbuilder.add_permissions(update_perms=True)
31+
appbuilder.sm.sync_roles()
3232
print('Updating permission on all DAG views')
3333
dagbag = DagBag(read_dags_from_db=True)
3434
dagbag.collect_dags_from_db()

0 commit comments

Comments
 (0)