Skip to content

Avoid a full asset table scan per request in simple auth manager - #72934

Merged
vincbeck merged 2 commits into
apache:mainfrom
astronomer:asset-auth-filter-perf
Oct 7, 2026
Merged

vincbeck merged 2 commits into
apache:mainfrom
astronomer:asset-auth-filter-perf

Conversation

@Lee-W

@Lee-W Lee-W commented Sep 11, 2026 •

Copy link
Copy Markdown
Member

Scoping asset API responses to what a user may read (#72682) gave BaseAuthManager a default that loads the id, name and uri of every asset and then asks is_authorized_asset about each row. Simple auth manager grants asset access by role alone and never inspects the asset it is asked about, so that loop re-derives a single constant answer once per row, and listing one page of assets costs time proportional to the size of the asset table rather than to the page.

The auth managers whose is_authorized_asset makes a remote call were given batched overrides at the time; simple auth manager, which is the default, was left on the generic path.


Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)

Generated-by: [Claude] following the guidelines


  • Read the Pull Request Guidelines for more information. Note: commit author/co-author name and email in commits become permanently public when merged.
  • For fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
  • When adding dependency, check compliance with the ASF 3rd Party License Policy.
  • For significant user-facing changes create newsfragment: {pr_number}.significant.rst, in airflow-core/newsfragments. You can add this file in a follow-up commit after the PR is created so you know the PR number.

@boring-cyborg boring-cyborg Bot added the area:API Airflow's REST/HTTP API label Sep 11, 2026
@Lee-W
Lee-W force-pushed the asset-auth-filter-perf branch from 0fc3dce to 4fa1cf2 Compare October 5, 2026 12:00
Lee-W added 2 commits October 6, 2026 17:13
Scoping asset API responses to what a user may read (apache#72682) gave
BaseAuthManager a default that loads the id, name and uri of every asset
and then asks is_authorized_asset about each row. Simple auth manager
grants asset access by role alone and never inspects the asset it is
asked about, so that loop re-derives a single constant answer once per
row, along with the name and uri it only loads to build the details it
then ignores.

The auth managers whose is_authorized_asset makes a remote call were
given batched overrides at the time; simple auth manager, which is the
default, was left on the generic path.
Simple auth manager now overrides get_authorized_assets, and it is the
auth manager the API tests run against. The asset route tests that
scope responses to readable assets patched the method on
BaseAuthManager, so the override bypassed the patch and the tests
stopped exercising the filtering they assert on.
@Lee-W
Lee-W force-pushed the asset-auth-filter-perf branch from 4fa1cf2 to 7b1a2c2 Compare October 6, 2026 16:13
@Lee-W
Lee-W marked this pull request as ready for review October 6, 2026 20:59
@Lee-W
Lee-W requested a review from vincbeck as a code owner October 6, 2026 20:59

@fat-catTW fat-catTW left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! lgtm

@Lee-W Lee-W added this to the Airflow 3.4.0 milestone Oct 7, 2026
@vincbeck
vincbeck merged commit 73a4ffa into apache:main Oct 7, 2026
154 checks passed
shahar1 pushed a commit that referenced this pull request Oct 19, 2026
…test (#75126)

SimpleAuthManager overrides get_authorized_assets since #72934, so patching the BaseAuthManager method left the real one in place, every asset stayed readable, and the test added in #72924 failed on main.

Generated-by: Claude Opus 5
potiuk added a commit that referenced this pull request Oct 19, 2026
…test (#75126)

SimpleAuthManager overrides get_authorized_assets since #72934, so patching the BaseAuthManager method left the real one in place, every asset stayed readable, and the test added in #72924 failed on main.

Generated-by: Claude Opus 5
(cherry picked from commit 33e6b5f)
potiuk added a commit that referenced this pull request Oct 19, 2026
…e base-class patch (#75138)

* Mock the simple auth manager in the dependencies graph permission tests

SimpleAuthManager overrides get_authorized_assets since #72934, so patching the BaseAuthManager method left the real one in place, every asset stayed readable, and the tests added in #73008 failed on main.

Generated-by: Claude Opus 5

* Reject patching BaseAuthManager methods that SimpleAuthManager overrides

Twice in one day a permission test patched BaseAuthManager.get_authorized_assets, which SimpleAuthManager overrides, so the mock never applied and main broke after merge. The hook reads which methods SimpleAuthManager overrides, so it keeps up when more are added.

Generated-by: Claude Opus 5
potiuk added a commit that referenced this pull request Oct 19, 2026
…gs the caller may read (#72924) (#75108)

* [v3-4-test] Scope upstream asset events of a Dag run to assets and Dags the caller may read (#72924)

GET /dags/{dag_id}/dagRuns/{dag_run_id}/upstreamAssetEvents returned every
asset event a run consumed as long as the caller could read the consuming Dag.
Events of assets, or produced by source Dags, the caller is not allowed to read
were exposed, including their name, uri, extra and source Dag/task ids, even
though GET /assets/events hides the same events.

Query the consumed events through the dagrun_asset_event table and apply the
same per-asset and per-source-Dag readability filters as GET /assets/events,
so hidden events are excluded from both the response and total_entries.
(cherry picked from commit 6f408e1)

Co-authored-by: Henry Chen <henrychen@apache.org>

* Mock the simple auth manager in the upstream asset events permission test (#75126)

SimpleAuthManager overrides get_authorized_assets since #72934, so patching the BaseAuthManager method left the real one in place, every asset stayed readable, and the test added in #72924 failed on main.

Generated-by: Claude Opus 5
(cherry picked from commit 33e6b5f)

---------

Co-authored-by: Henry Chen <henrychen@apache.org>
Co-authored-by: Jarek Potiuk <jarek@potiuk.com>
vatsrahul1001 pushed a commit that referenced this pull request Oct 20, 2026
…gs the caller may read (#72924) (#75108)

* [v3-4-test] Scope upstream asset events of a Dag run to assets and Dags the caller may read (#72924)

GET /dags/{dag_id}/dagRuns/{dag_run_id}/upstreamAssetEvents returned every
asset event a run consumed as long as the caller could read the consuming Dag.
Events of assets, or produced by source Dags, the caller is not allowed to read
were exposed, including their name, uri, extra and source Dag/task ids, even
though GET /assets/events hides the same events.

Query the consumed events through the dagrun_asset_event table and apply the
same per-asset and per-source-Dag readability filters as GET /assets/events,
so hidden events are excluded from both the response and total_entries.
(cherry picked from commit 6f408e1)

Co-authored-by: Henry Chen <henrychen@apache.org>

* Mock the simple auth manager in the upstream asset events permission test (#75126)

SimpleAuthManager overrides get_authorized_assets since #72934, so patching the BaseAuthManager method left the real one in place, every asset stayed readable, and the test added in #72924 failed on main.

Generated-by: Claude Opus 5
(cherry picked from commit 33e6b5f)

---------

Co-authored-by: Henry Chen <henrychen@apache.org>
Co-authored-by: Jarek Potiuk <jarek@potiuk.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:API Airflow's REST/HTTP API

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants