Skip to content

Default-deny auth at the API and UI router level#66505

Open
potiuk wants to merge 1 commit intoapache:mainfrom
potiuk:f-007-default-deny-auth
Open

Default-deny auth at the API and UI router level#66505
potiuk wants to merge 1 commit intoapache:mainfrom
potiuk:f-007-default-deny-auth

Conversation

@potiuk
Copy link
Copy Markdown
Member

@potiuk potiuk commented May 7, 2026

Add dependencies=[Depends(get_user)] at the authenticated_router (parent of every authenticated /api/v2 route) and ui_router (every /ui route) constructors.

Today every authenticated route already declares its own GetUserDep or a requires_access_* dependency that itself depends on get_user, so this is purely additive — FastAPI deduplicates dependencies via its per-request cache, so each request still resolves get_user exactly once. The value is preventing a future route from being added under either router without an auth check: the router-level dependency catches the regression at registration time rather than at audit time.

Also adds a structural regression test that asserts both routers carry the router-level Depends(get_user), so a future refactor that drops the dependency without understanding its purpose fails the test rather than silently widening the unauthenticated surface.

The three explicit no-auth carve-outs (monitor_router for /api/v2/monitor/health, version_router for /api/v2/version, the public auth_router for /api/v2/auth/{login,logout}) are added to public_router directly rather than to authenticated_router, so they remain unaffected.


Was generative AI tooling used to co-author this PR?
  • Yes — Claude Opus 4.7 (1M context)

Generated-by: Claude Opus 4.7 (1M context) following the guidelines

Add `dependencies=[Depends(get_user)]` to `authenticated_router`
(parent of every route under `/api/v2` except the explicit no-auth
carve-outs `monitor_router`, `version_router`, and the public
`auth_router`) and to `ui_router` (every route under `/ui`).

Today every authenticated route already declares `GetUserDep` or a
`requires_access_*` dependency that itself depends on `get_user`, so
this is purely additive — FastAPI deduplicates the dependency via
its per-request cache, so each request still resolves `get_user`
once. The value is preventing a future route from being added under
either router without an auth check: the router-level dependency
catches the regression at registration time rather than at audit
time.

Add a structural test that asserts both routers carry the
router-level `Depends(get_user)`, so a future refactor that drops
the dependency without considering its purpose fails the test
rather than silently widening the unauthenticated surface.
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.

1 participant