Skip to content

Exclude stale Dags from active Dag source authorization - #74576

Open
TinyGeek wants to merge 3 commits into
apache:mainfrom
TinyGeek:fix/73284-dag-source-stale-auth
Open

TinyGeek wants to merge 3 commits into
apache:mainfrom
TinyGeek:fix/73284-dag-source-stale-auth

Conversation

@TinyGeek

Copy link
Copy Markdown

When a stale Dag shares a source file and bundle with an active Dag, the source endpoint can redact code even when the caller can read every active Dag in that file.

Update the per-file authorization check to:

  • Exclude stale co-located Dags when the requested Dag is active.
  • Retain stale co-located Dags when the requested Dag is stale, since its stored source may still contain them.
  • Always include the requested Dag ID so the authorization check cannot be skipped.

Make the existing co-located test fixture explicitly active and add a parametrized regression test for both requested-Dag states. This follows the security boundary raised during review of #73292.

Tests

  • RED: The original implementation redacts an active Dag's source when an unreadable stale sibling exists.
  • RED: An intermediate fix exposes a stale requested Dag's source when an unreadable stale sibling exists.
  • GREEN: Both regression cases and all 15 tests in test_dag_sources.py pass.
  • Ruff 0.16.8 format and lint checks, git diff --check, and applicable manual prek hooks pass.
  • Tests run locally with Python 3.14.4, SQLite, and uv, without Docker.
  • Real FAB role-based authorization integration is not tested. The generate-openapi-spec and mypy-airflow-core prek hooks cannot complete locally because Docker and the C compiler/Kerberos headers are unavailable. GitHub CI is pending.

Fixes #73284


Was generative AI tooling used to co-author this PR?
  • Yes (OpenAI Codex, GPT-6)

Generated-by: Codex (GPT-6) following the guidelines

@boring-cyborg boring-cyborg Bot added the area:API Airflow's REST/HTTP API label Oct 12, 2026
@boring-cyborg

boring-cyborg Bot commented Oct 12, 2026

Copy link
Copy Markdown

Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contributors' Guide
Here are some useful points:

  • Pay attention to the quality of your code (ruff, mypy and type annotations). Our prek-hooks will help you with that.
  • In case of a new feature add useful documentation (in docstrings or in docs/ directory). Adding a new operator? Check this short guide Consider adding an example Dag that shows how users should use it.
  • Consider using Breeze environment for testing locally, it's a heavy docker but it ships with a working Airflow and a lot of integrations.
  • Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
  • Please follow ASF Code of Conduct for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
  • Be sure to read the Airflow Coding style.
  • Always keep your Pull Requests rebased, otherwise your build might fail due to changes not related to your commits.
    Apache Airflow is a community-driven project and together we are making it better 🚀.
    In case of doubts contact the developers at:
    Mailing List: [email protected]
    Slack: https://s.apache.org/airflow-slack

@Eason09053360 Eason09053360 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.

Thanks for the fix! One inline question

select(DagModel.dag_id).where(
DagModel.relative_fileloc == dag_model.relative_fileloc,
DagModel.bundle_name == dag_model.bundle_name,
DagModel.is_stale.in_([False, dag_model.is_stale]),

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.

Should stale siblings still count for older versions (?version_number=)? An older version's source can still define the now-stale sibling, which main redacts but this now returns in full.

@TinyGeek TinyGeek Oct 18, 2026 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks for catching this. The follow-up compares the selected DagVersion with the latest one. When the selected version is older, stale co-located Dags stay in the file authorization check because the stored source may still define them. An omitted version or an explicitly selected latest version keeps the active Dag behavior: stale siblings are excluded when the requested Dag is active. The requested Dag ID remains in the authorization set in every case.

DagCode has no immutable per-version list of co-located Dag IDs, so this change restores the conservative check for the historical case without claiming to reconstruct every historical file membership.


Drafted-by: Codex (GPT-6) (no human review before posting)

Stored Dag source can still contain a sibling that is stale now. Filtering it solely by current Dag state exposes code to callers who cannot read that sibling.

This branch has not been deployed

No deployments
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.

Dag source is redacted when a stale Dag shares the same source file

2 participants