You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add declarative configuration to define custom roles #38347
Add declarative configuration to define custom roles in either airflow.cfg or webserver_config.py.
Use case/motivation
Currently the only way to define custom roles is through the CLI or UI. This isn't ideal for those deploying configuration through a repository (e.g., GitOps).
Sure. If you have a good idea how to do it in a robust way - proposing a solution, especially one that will not overwrite existing DB and will allow to both declaratively upload roles from a source and manually modify them, and keep those local modificiattions - PRs are most welcome.
Just make sure when you submit the PR to propose a solution for this conundrum where you have both manually modifiable data and uploadable from the externally depoyable sources in declarative way. So far all the efforts failed on that step, but maybe you will be able to propose something.
BTW. once you find a solution, also similar thing should be done from connections, users and variables - those suffer from the same issue and if you find and get approval to solve it for roles, applying similar approach for the others is a natural next step.
Thanks and yep, it's a classic problem most devops folks have to deal with. It's heavily dependent if you want to lock down configs post-deploy and if DB should be overwritten during a redeploy.
What's currently being done for connections and variables to solve that issue? They both already have declarative equivalents.
To solve all the edge cases and the fact that users can modify the DB after it has been created and how to consistently mantain source of the truth.t But maybe your proposal will fix it. Looking forward to it.
What's currently being done for connections and variables to solve that issue? They both already have declarative equivalents.
No - they don't - same problem. When you allow to edit data over the UI and want to also upload it at the deployment time, you need to solve the problem of data being modified both manually and through declarative sources at deplpyment time
I don't have a implementation proposal yet. Someone else can take it if they've got ideas.
Well I do have one idea... env vars. Airflow does allow many configs to be set/overridden with env vars (I guess it's a simple if env var exist, don't use DB values).
The value of the role env var would be JSON string. Here's an example without proper formatting...
You cannot modify the roles of the same name in the UI and env-vars. Precedence goes to env-vars. Different name is OK.
UI should show env-vars defined roles to be grayed-out (i.e., read-only)
You cannot use env-vars to define custom roles with DAG-level permissions. Instead, this is declaratively set by the DAG file (DAG(access_control={...}))
I think it is a great idea. Of course it aims only FAB auth manager but for that purpose I think it could be useful. I marked as good first issue because I do not think this is complicated. I think the idea is to:
Define a new config in fab provider to define these custom roles
Update fab auth manager (and more specifically override.py to create these roles if they do not exist when the api server is starting
Thanks @vincbeck for the implementation guidance!
Before I start working on this, I'd like to confirm the intended scope.
My understanding is that the new [fab] configuration would define custom roles and their permissions. Then, when the API server starts:
If the role does not exist, create it and attach the declared permissions.
If the role already exists, leave it unchanged, including its permissions, so that any edits made through the UI/CLI are preserved.
So this would be create-if-missing only, rather than continuously syncing existing roles with the configuration.
Is that the intended behavior for this issue?
Activity
potiuk commentedon Mar 22, 2024
Sure. If you have a good idea how to do it in a robust way - proposing a solution, especially one that will not overwrite existing DB and will allow to both declaratively upload roles from a source and manually modify them, and keep those local modificiattions - PRs are most welcome.
Just make sure when you submit the PR to propose a solution for this conundrum where you have both manually modifiable data and uploadable from the externally depoyable sources in declarative way. So far all the efforts failed on that step, but maybe you will be able to propose something.
BTW. once you find a solution, also similar thing should be done from connections, users and variables - those suffer from the same issue and if you find and get approval to solve it for roles, applying similar approach for the others is a natural next step.
ketozhang commentedon Mar 22, 2024
Thanks and yep, it's a classic problem most devops folks have to deal with. It's heavily dependent if you want to lock down configs post-deploy and if DB should be overwritten during a redeploy.
What's currently being done for connections and variables to solve that issue? They both already have declarative equivalents.
How have they failed?
potiuk commentedon Mar 22, 2024
To solve all the edge cases and the fact that users can modify the DB after it has been created and how to consistently mantain source of the truth.t But maybe your proposal will fix it. Looking forward to it.
potiuk commentedon Mar 22, 2024
No - they don't - same problem. When you allow to edit data over the UI and want to also upload it at the deployment time, you need to solve the problem of data being modified both manually and through declarative sources at deplpyment time
shahar1 commentedon Jul 13, 2024
@ketozhang Would you still like to work on this issue?
ketozhang commentedon Jul 15, 2024
I don't have a implementation proposal yet. Someone else can take it if they've got ideas.
Well I do have one idea... env vars. Airflow does allow many configs to be set/overridden with env vars (I guess it's a simple if env var exist, don't use DB values).
The value of the role env var would be JSON string. Here's an example without proper formatting...
{ "roles": { "PythonTester": [ { "permission": "ACTION_CAN_EDIT", "resource": "RESOURCE_DAG" } ] } }A few caveats:
DAG(access_control={...}))vincbeck commentedon Jan 22, 2026
I think it is a great idea. Of course it aims only FAB auth manager but for that purpose I think it could be useful. I marked as good first issue because I do not think this is complicated. I think the idea is to:
ucaeon commentedon Sep 8, 2026
Thanks @vincbeck for the implementation guidance!
Before I start working on this, I'd like to confirm the intended scope.
My understanding is that the new [fab] configuration would define custom roles and their permissions. Then, when the API server starts:
So this would be create-if-missing only, rather than continuously syncing existing roles with the configuration.
Is that the intended behavior for this issue?
vincbeck commentedon Sep 9, 2026
Looks good