Skip to content

Add declarative configuration to define custom roles #38347

Closed

Description

@ketozhang

Description

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).

It seems like this feature is already possible with webserver_config.py, however not documented here. If so, I will change the request...
https://airflow.apache.org/docs/apache-airflow/stable/security/webserver.html

Related issues

No response

Are you willing to submit a PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Activity

  1. added
    kind:feature
    needs-triage
    on Mar 20, 2024
  2. potiuk commented on Mar 22, 2024

    @potiuk
    Member

    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.

  3. ketozhang commented on Mar 22, 2024

    @ketozhang
    ContributorAuthor

    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.

    So far all the efforts failed on that step

    How have they failed?

  4. potiuk commented on Mar 22, 2024

    @potiuk
    Member

    How have they failed?

    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.

  5. potiuk commented on Mar 22, 2024

    @potiuk
    Member

    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

  6. shahar1 commented on Jul 13, 2024

    @shahar1
    Contributor

    @ketozhang Would you still like to work on this issue?

  7. added
    area:webserver
    and removed
    needs-triage
    area:webserver
    on Jul 13, 2024
  8. ketozhang commented on Jul 15, 2024

    @ketozhang
    ContributorAuthor

    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:

    • 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={...}))
  9. vincbeck commented on Jan 22, 2026

    @vincbeck
    Contributor

    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
  10. ucaeon commented on Sep 8, 2026

    @ucaeon
    Contributor

    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?
  11. vincbeck commented on Sep 9, 2026

    @vincbeck
    Contributor

    Looks good

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions