Keycloak auth manager: enforce team‑scoped authorization (AIP‑67)#61351
Conversation
|
Hello, Latest commit fixes many comments from the review done on branch #61256 before the split.
The 403 actually comes from the API auth flow. e.g. for dags, when the UI calls GET /api/v2/dags/~/dagRuns, flow goes like this: API goes through requires_access_dag function It normalizes Since there’s no With my first multi‑team implementation, only team‑scoped resources existed (e.g. Dag:team), so a global Dag#LIST check was denied -> 403. First implementation did not solve this cleanly, so I refactored: for teamless LIST, I now check a global LIST permission on the global resource (e.g. Dag#LIST, no :team). There is a theoretical caveat as it assumes every list endpoint applies permission filters later. I verified the code locally and it seems true for dags/dagRuns/pools/connections/variables/tags/dashboard stats, but I'd like your validation on this point to know if my assumption is correct. I’ll keep the PR as draft for now because I still have unresolved 403 errors around assets. |
6ec065b to
fb20c09
Compare
dabla
left a comment
There was a problem hiding this comment.
Nice work @stegololz , multi-team support in Keycloak is coming soon :-)
providers/keycloak/src/airflow/providers/keycloak/auth_manager/keycloak_auth_manager.py
Outdated
Show resolved
Hide resolved
providers/keycloak/src/airflow/providers/keycloak/auth_manager/keycloak_auth_manager.py
Outdated
Show resolved
Hide resolved
providers/keycloak/src/airflow/providers/keycloak/auth_manager/keycloak_auth_manager.py
Outdated
Show resolved
Hide resolved
dddc3a8 to
26bb6f7
Compare
Solved. Non team scoped resources ( Asset, AssetAlias, Configuration) also have LIST calls. I created relevant permissions in Keycloak. CLI updated to make it work: c6eb21e |
There was a problem hiding this comment.
Thanks for the PR @stegololz! Looks good!
I cannot see c6eb21e in the PR that you mentioned includes CLI changes. Are you planning to create another PR for CLI? I would suggest to please include into this PR so there would be a clear connectionwith the current implementation, as I see +7 -2 only, which is not high.
Could you please also check the tests? It fails for permission in Python 3.10 and in some others
https://github.com/apache/airflow/actions/runs/21682494606/job/62540136484?pr=61351
I would still like to get @o-nikolas's and @vincbeck's take on the multi-team approach, when you have time
Hey Bugra, thanks for the review. We agreed with @stegololz to split the PR in 2 PRs, one for CLI and one for the auth manager implementation. It makes it easier to review it :) You can find the PR related to CLI here: #61256 but overall you can track the overall effort in this issue: #60885 |
ce0114a to
abaf971
Compare
Thanks for the review! Vincent already pointed you to the other other and the issue. |
providers/keycloak/src/airflow/providers/keycloak/auth_manager/keycloak_auth_manager.py
Outdated
Show resolved
Hide resolved
providers/keycloak/src/airflow/providers/keycloak/auth_manager/keycloak_auth_manager.py
Outdated
Show resolved
Hide resolved
providers/keycloak/tests/unit/keycloak/auth_manager/test_keycloak_auth_manager.py
Outdated
Show resolved
Hide resolved
providers/keycloak/tests/unit/keycloak/auth_manager/test_keycloak_auth_manager.py
Outdated
Show resolved
Hide resolved
Thanks for the details Vincent!t Thats why I assumed I may missing some context and specifically tagged both :) |
6cb3476 to
ed16b0e
Compare
providers/keycloak/src/airflow/providers/keycloak/auth_manager/keycloak_auth_manager.py
Outdated
Show resolved
Hide resolved
ed16b0e to
a24e0a3
Compare
providers/keycloak/src/airflow/providers/keycloak/auth_manager/keycloak_auth_manager.py
Outdated
Show resolved
Hide resolved
providers/keycloak/src/airflow/providers/keycloak/auth_manager/keycloak_auth_manager.py
Outdated
Show resolved
Hide resolved
999ebea to
629d1ec
Compare
providers/keycloak/tests/unit/keycloak/auth_manager/test_keycloak_auth_manager.py
Outdated
Show resolved
Hide resolved
providers/keycloak/tests/unit/keycloak/auth_manager/test_keycloak_auth_manager.py
Outdated
Show resolved
Hide resolved
providers/keycloak/tests/unit/keycloak/auth_manager/test_keycloak_auth_manager.py
Outdated
Show resolved
Hide resolved
|
Thanks for your review @vincbeck ! The tests evolved alongside the iterations on keycloak_auth_manager.py throughout this PR. After the last round of changes, the test file clearly needed a refactor to keep the intent of each test case explicit. That refactor is now done. The following tests were added for multi-team support:
The refactor should cover your last review! |
providers/keycloak/tests/unit/keycloak/auth_manager/test_keycloak_auth_manager.py
Outdated
Show resolved
Hide resolved
providers/keycloak/tests/unit/keycloak/auth_manager/test_keycloak_auth_manager.py
Outdated
Show resolved
Hide resolved
providers/keycloak/tests/unit/keycloak/auth_manager/test_keycloak_auth_manager.py
Outdated
Show resolved
Hide resolved
providers/keycloak/tests/unit/keycloak/auth_manager/test_keycloak_auth_manager.py
Outdated
Show resolved
Hide resolved
providers/keycloak/tests/unit/keycloak/auth_manager/test_keycloak_auth_manager.py
Outdated
Show resolved
Hide resolved
providers/keycloak/tests/unit/keycloak/auth_manager/test_keycloak_auth_manager.py
Outdated
Show resolved
Hide resolved
providers/keycloak/tests/unit/keycloak/auth_manager/test_keycloak_auth_manager.py
Outdated
Show resolved
Hide resolved
providers/keycloak/tests/unit/keycloak/auth_manager/test_keycloak_auth_manager.py
Outdated
Show resolved
Hide resolved
providers/keycloak/tests/unit/keycloak/auth_manager/test_keycloak_auth_manager.py
Outdated
Show resolved
Hide resolved
providers/keycloak/tests/unit/keycloak/auth_manager/test_keycloak_auth_manager.py
Outdated
Show resolved
Hide resolved
Overall I like the tests, thank you! I added some comments, more style related which would help having a code easier to read |
… dynamically Regenerate Keycloak OpenAPI spec
Co-authored-by: Vincent <97131062+vincbeck@users.noreply.github.com>
…/keycloak_auth_manager.py Co-authored-by: Vincent <97131062+vincbeck@users.noreply.github.com>
03a2e3a to
abc0d56
Compare
|
Thanks @stegololz for the hard work!! Looks really nice :) Will merge once the CI is green |
|
Awesome work, congrats on your first merged pull request! You are invited to check our Issue Tracker for additional contributions. |
…ache#61351) * feat: update keycloak manager for multiteam setup * feat: refactor authorization checks for multi-team setup in KeycloakAuthManager * feat: refactor team name retrieval for multi-team support in KeycloakAuthManager * feat: update KeycloakAuthManager to retrieve multi-team configuration dynamically Regenerate Keycloak OpenAPI spec * Apply suggestion from @vincbeck Co-authored-by: Vincent <97131062+vincbeck@users.noreply.github.com> * feat: added error handling for missing team_name in multi-team mode * generalize team-scoped auth cases and add compat guards * test(keycloak): gate multiteam auth manager tests on Airflow 3.2+ * fix(keycloak): allow global team-scoped resources in multi-team mode * refactor(keycloak): inline resource name resolution in auth manager * test(keycloak): align multiteam skip reasons with 3.2.0 gate * Update providers/keycloak/src/airflow/providers/keycloak/auth_manager/keycloak_auth_manager.py Co-authored-by: Vincent <97131062+vincbeck@users.noreply.github.com> * Made type of _get_team_name explicit * refactored/renamed multiteam tests * Updated test style to enhance readability * moved auth manager patch from a with block to a decorator --------- Co-authored-by: Vincent <97131062+vincbeck@users.noreply.github.com>
…ache#61351) * feat: update keycloak manager for multiteam setup * feat: refactor authorization checks for multi-team setup in KeycloakAuthManager * feat: refactor team name retrieval for multi-team support in KeycloakAuthManager * feat: update KeycloakAuthManager to retrieve multi-team configuration dynamically Regenerate Keycloak OpenAPI spec * Apply suggestion from @vincbeck Co-authored-by: Vincent <97131062+vincbeck@users.noreply.github.com> * feat: added error handling for missing team_name in multi-team mode * generalize team-scoped auth cases and add compat guards * test(keycloak): gate multiteam auth manager tests on Airflow 3.2+ * fix(keycloak): allow global team-scoped resources in multi-team mode * refactor(keycloak): inline resource name resolution in auth manager * test(keycloak): align multiteam skip reasons with 3.2.0 gate * Update providers/keycloak/src/airflow/providers/keycloak/auth_manager/keycloak_auth_manager.py Co-authored-by: Vincent <97131062+vincbeck@users.noreply.github.com> * Made type of _get_team_name explicit * refactored/renamed multiteam tests * Updated test style to enhance readability * moved auth manager patch from a with block to a decorator --------- Co-authored-by: Vincent <97131062+vincbeck@users.noreply.github.com>
Description
This PR updates the Keycloak auth manager to enforce multi‑team authorization as outlined in AIP‑67. When core.multi_team is enabled, team context (e.g., team_name from DAGs, connections, assets) is now used to build team‑scoped permission checks so users can only list and access resources for their teams. The authorization flow also supports users in multiple teams by evaluating team‑scoped permissions consistently for list and non‑list requests, while preserving backward compatibility for non‑multi‑team deployments.
This is the auth‑manager part of the split. The CLI provisioning changes are in the companion PR: 61256
related issue: #60885
Open Questions:
Was generative AI tooling used to co-author this PR?