Repository navigation
Add declarative configuration for FAB custom roles - #72820
Merged
Merged
Conversation
vincbeck
reviewed
Sep 10, 2026
Allow deployments to provision custom roles from configuration while preserving permissions maintained through the UI and CLI. Role creation must not leave partial permissions or alter a role created concurrently.
Prevent misspelled names from creating unintended database entries while allowing new permission combinations for registered names.
ucaeon
force-pushed
the
fab-declarative-custom-roles
branch
from
September 11, 2026 02:28
9f66898 to
1e3179c
Compare
|
Awesome work, congrats on your first merged pull request! You are invited to check our Issue Tracker for additional contributions. |
1 task done
28 of 93 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The FAB provider currently has no configuration for provisioning custom roles during API server startup. Deployments must create them through the UI or CLI separately from their Airflow configuration.
This PR adds
[fab] custom_rolesto create missing roles with their declared permissions. Existing roles are skipped, preserving changes made through the UI or CLI. This follows the same-name skip behavior ofairflow roles import.Existing FAB creation helpers commit each operation individually. Reusing them could leave a role with incomplete permissions after a failure, and subsequent initialization would skip that role because it already exists.
Change
[fab] custom_roles, defaulting to{}, with support forAIRFLOW__FAB__CUSTOM_ROLES.sync_roles().Example:
Permission entries contain exactly
actionandresource, using actual FAB names such ascan_readandDAGs. Duplicate permission pairs are applied once.The configuration does not create actions or resources. It can create a missing permission combination using registered names and assign that permission to a new role.
The creation path reuses lookup helpers but avoids the existing helpers that commit individual writes. If creation fails, the current role's transaction is rolled back; roles successfully created earlier remain committed.
If another process creates the same role first, that role is skipped without adding permissions. A conflict caused by concurrent creation of a shared permission is checked after rollback and retried from the beginning of role creation, with at most three attempts. Other failures are propagated.
bulk_sync_roles()is not reused for configured roles because it can add permissions to existing roles.Behavior change
API server startup applies the configuration when
[fab] update_fab_permsis enabled. Explicitly runningairflow sync-permalso applies it, regardless of that flag.Changing or removing a configured role does not update or delete an existing database role. Deleting a configured role from the database allows it to be recreated during the next initialization.
An empty permission list declares no permissions, but normal FAB initialization still grants custom roles
can_readonWebsite. Existing default-role and permission maintenance remains unchanged.Action and resource names must already be registered when the configuration is applied. Default-role permissions are synchronized before validation. Names supplied by plugins or individual Dags must be registered beforehand; names registered later during startup are not available to this initialization step.
Registered names do not guarantee that every action-resource combination grants access to a feature. The documentation recommends
DAG(access_control=...)for access to individual Dags.This PR does not make roles read-only in the UI, create users, or assign roles to users.
Tests
update_fab_perms, while explicit role synchronization applies the configuration independently of the flag.Tested locally with Breeze using Python 3.10 after the name-validation update:
The SQLite skip covers shared-permission creation concurrency, which is exercised on PostgreSQL and MySQL.
Regular and manual static checks passed, including formatting, linting, provider type checks, and provider documentation validation.
closes: #38347
Was generative AI tooling used to co-author this PR?
Generated-by: Codex (GPT-6) following the guidelines