Skip to content

Automate stable REST API permission reference doc generation - #67606

Merged
potiuk merged 9 commits into
apache:mainfrom
durgaprasadml:feat/automate-api-permission-doc
Jul 3, 2026
Merged

potiuk merged 9 commits into
apache:mainfrom
durgaprasadml:feat/automate-api-permission-doc

Conversation

@durgaprasadml

Copy link
Copy Markdown
Contributor

Automate stable REST API permission reference doc generation.

This PR introduces an automated extractor for stable REST API permissions and generates a reference RST document directly from the source routes and permission declarations.

Current implementation:

  • statically analyzes /api/v2 route definitions
  • extracts requires_access_* permission metadata
  • generates api_permissions_ref.rst
  • includes regression and invariant tests
  • integrates with existing prek-based generation workflows

This PR is intentionally opened as a draft to gather maintainer feedback on:

  • AST-based extraction vs runtime introspection
  • final file placement
  • generation workflow integration
  • committed generated artifacts

Closes: #10937

@boring-cyborg

boring-cyborg Bot commented May 27, 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: dev@airflow.apache.org
    Slack: https://s.apache.org/airflow-slack

@durgaprasadml
durgaprasadml marked this pull request as ready for review May 29, 2026 06:30
Comment thread airflow-core/docs/security/api_permissions_ref.rst

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

It is missing to add it to .pre-commit-config.yaml

@durgaprasadml

Copy link
Copy Markdown
Contributor Author

Implemented the requested changes:

  • Added deterministic sorting for generated REST API permission entries (grouped by endpoint path, then HTTP method).
  • Registered the generator in .pre-commit-config.yaml following existing Airflow prek hook conventions.
  • Regenerated api_permissions_ref.rst with the stabilized ordering.

This ensures the generated permission reference stays automatically synchronized with route changes and prevents stale generated docs from passing CI.

@durgaprasadml
durgaprasadml requested a review from jscheffl May 29, 2026 12:57

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

Good for me, any other reviewer opinion? (besides CI needs to turn green...)

Copilot AI 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.

Pull request overview

This PR automates generation of stable REST API permission reference documentation by statically extracting requires_access_* dependencies from /api/v2 route definitions and rendering a committed RST reference.

Changes:

  • Adds a stdlib-only AST extractor and CLI for generating/checking API permission docs.
  • Adds regression/invariant tests for route parsing, resource mapping, rendering, and check mode.
  • Registers a prek hook and commits the generated api_permissions_ref.rst artifact.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
scripts/ci/prek/extract_permissions.py New extractor and RST generator for stable REST API permissions.
scripts/tests/ci/prek/test_extract_permissions.py Tests for extractor helpers, real route integration, rendering, and check mode.
airflow-core/docs/security/api_permissions_ref.rst Generated permission reference documentation.
.pre-commit-config.yaml Adds prek hook to regenerate the permission reference.

Comment thread scripts/ci/prek/extract_permissions.py
Comment thread .pre-commit-config.yaml
@durgaprasadml

Copy link
Copy Markdown
Contributor Author

Thanks for the review and the detailed feedback.

Addressed the positional access_entity case for requires_access_dag by extending the AST extraction logic to support both:

  • keyword usage (access_entity=...)
  • second positional argument usage

Also added a regression test covering the positional form (DagAccessEntity.TASK_LOGS) and regenerated the permission reference docs.

Additionally, the generator hook is now registered in .pre-commit-config.yaml to ensure generated docs remain synchronized with route/security changes during CI and local prek runs.

@durgaprasadml
durgaprasadml requested a review from jscheffl May 29, 2026 18:02
@durgaprasadml

Copy link
Copy Markdown
Contributor Author

@potiuk review

@Vamsi-klu

This comment was marked as spam.

@durgaprasadml

Copy link
Copy Markdown
Contributor Author

Good catch @Vamsi-klu , thanks for pointing this out.

You're right — the current extractor only emits routes declaring requires_access_* dependencies, while the generated page wording currently implies full /api/v2 endpoint coverage.

I’ll update the generation logic to include public endpoints without Airflow permission dependencies and render them explicitly as requiring no Airflow permission, so the generated reference remains complete and self-consistent.

@durgaprasadml

Copy link
Copy Markdown
Contributor Author

Addressed the feedback regarding public /api/v2 endpoints being omitted from the generated reference.

Updates included:

  • Public stable API endpoints are now extracted and rendered explicitly as requiring no Airflow permission.
  • Added regression and integration coverage for:
    • /api/v2/monitor/health
    • /api/v2/version
    • /api/v2/auth/login
    • /api/v2/auth/logout
  • Kept deterministic generation ordering and simplified the rendering pipeline so sorting happens only during normalization/extraction.
  • Regenerated api_permissions_ref.rst.

CI is now green on the updated implementation.

@potiuk could you please take another look when you have time?

@durgaprasadml
durgaprasadml force-pushed the feat/automate-api-permission-doc branch from f1e0974 to 5d0369c Compare June 4, 2026 13:46
@potiuk

potiuk commented Jun 5, 2026

Copy link
Copy Markdown
Member

@jscheffl's approval here is from May 29 (74ad787b0), and there have been 8 commits since — the mypy fix, the prek hook, positional access-entity extraction, more endpoints in the reference. Worth a re-review before merge so the approval reflects the current diff. @jscheffl, could you take another look?


Drafted-by: Claude Code (Opus 4.8); reviewed by @potiuk before posting

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

Re-Review OK for me. CI should be green and like another reviewer prior merge.

@potiuk potiuk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Really nice tooling — static AST extraction with a --check staleness gate is the right shape, and the resource mapping is thorough. One correctness bug to fix before this lands, since the output is a published security reference:

Wrong path for multi-router files. _extract_router_prefix() returns only the first AirflowRouter in a file, but dag_run.py defines two (dag_run_router → /dags/{dag_id}/dagRuns, dag_run_at_dag_router → /dags/{dag_id}). As a result POST /clearDagRuns is generated as /api/v2/dags/{dag_id}/dagRuns/clearDagRuns (line 270 of the generated api_permissions_ref.rst) — that path doesn't exist; the real one is /api/v2/dags/{dag_id}/clearDagRuns. Suggest keying the prefix off the router variable in each decorator (@dag_run_at_dag_router.post → look up that router's prefix) instead of a single file-wide prefix.

Secondary (non-blocking but security-relevant): the extractor only reads per-route decorator dependencies=[…]. It won't see permissions declared at the router level (AirflowRouter(dependencies=[…])) or via Security(…). None are used in the public routes today, so nothing is wrong now — but if a permission ever moves to the router level, those endpoints would silently render as "No Airflow permission required," which is the dangerous direction for this doc. A small regression test (or an explicit assertion/comment) guarding that assumption would make this robust.


Drafted-by: Claude Code (Opus 4.8); reviewed by @potiuk before posting

@durgaprasadml
durgaprasadml requested a review from jscheffl June 6, 2026 11:12
@durgaprasadml
durgaprasadml marked this pull request as draft June 6, 2026 11:26
@durgaprasadml
durgaprasadml force-pushed the feat/automate-api-permission-doc branch from 39afaa7 to a2e9d82 Compare June 6, 2026 14:49
@durgaprasadml
durgaprasadml marked this pull request as ready for review June 9, 2026 04:13
@potiuk potiuk added the ready for maintainer review Set after triaging when all criteria pass. label Jun 17, 2026

@potiuk potiuk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You fixed exactly what I flagged, and then some:

  • The multi-router prefix bug now keys off each decorator's router variable via
    _extract_routers(), so POST /clearDagRuns correctly resolves to
    /api/v2/dags/{dag_id}/clearDagRuns. Nice regression coverage in
    test_multiple_routers_in_same_file and test_clear_dag_runs_endpoint_prefix.
  • Router-level permission dependencies now raise loudly ("Unsupported extraction
    semantics…") instead of silently rendering "No Airflow permission required" —
    which was the dangerous direction for a published security reference. Guarded
    by test_router_level_permission_dependency_raises_value_error.

CI green. Thanks for the thorough follow-up — LGTM.


This review was drafted by an AI-assisted tool and confirmed by an Airflow
maintainer. The maintainer approving this PR has read the findings and signed
off. If something feels off, please reply on the PR and a maintainer will
follow up.

More on how Airflow handles maintainer review:
contributing-docs/05_pull_requests.rst.

@potiuk
potiuk merged commit 63b9826 into apache:main Jul 3, 2026
275 of 281 checks passed
@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Backport successfully created: v3-3-test

Note: As of Merging PRs targeted for Airflow 3.X
the committer who merges the PR is responsible for backporting the PRs that are bug fixes (generally speaking) to the maintenance branches.

In matter of doubt please ask in #release-management Slack channel.

Status Branch Result
✅ v3-3-test PR Link

potiuk pushed a commit that referenced this pull request Jul 3, 2026
…ion (#67606)

* Generate stable REST API permission reference docs automatically

* Fix mypy typing issue in permission extractor

* chore: rerun flaky CI

* Add prek hook and sort generated API permission docs

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* Handle positional DAG access entity extraction

* Include public API endpoints in permission reference docs

* Update generated REST API permission reference

* Fix multi-router path extraction in permission docs

---------
(cherry picked from commit 63b9826)

Co-authored-by: Durgaprasad M L <durgaprasadmadikeri@gmail.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
potiuk pushed a commit that referenced this pull request Jul 3, 2026
…ion (#67606) (#69334)

* Generate stable REST API permission reference docs automatically

* Fix mypy typing issue in permission extractor

* chore: rerun flaky CI

* Add prek hook and sort generated API permission docs

* Potential fix for pull request finding



* Handle positional DAG access entity extraction

* Include public API endpoints in permission reference docs

* Update generated REST API permission reference

* Fix multi-router path extraction in permission docs

---------
(cherry picked from commit 63b9826)

Co-authored-by: Durgaprasad M L <durgaprasadmadikeri@gmail.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@durgaprasadml
durgaprasadml deleted the feat/automate-api-permission-doc branch July 3, 2026 18:21
@potiuk potiuk added this to the Airflow 3.3.1 milestone Jul 3, 2026
vatsrahul1001 pushed a commit that referenced this pull request Jul 7, 2026
…ion (#67606) (#69334)

* Generate stable REST API permission reference docs automatically

* Fix mypy typing issue in permission extractor

* chore: rerun flaky CI

* Add prek hook and sort generated API permission docs

* Potential fix for pull request finding



* Handle positional DAG access entity extraction

* Include public API endpoints in permission reference docs

* Update generated REST API permission reference

* Fix multi-router path extraction in permission docs

---------
(cherry picked from commit 63b9826)

Co-authored-by: Durgaprasad M L <durgaprasadmadikeri@gmail.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
vatsrahul1001 pushed a commit that referenced this pull request Jul 9, 2026
…ion (#67606) (#69334)

* Generate stable REST API permission reference docs automatically

* Fix mypy typing issue in permission extractor

* chore: rerun flaky CI

* Add prek hook and sort generated API permission docs

* Potential fix for pull request finding



* Handle positional DAG access entity extraction

* Include public API endpoints in permission reference docs

* Update generated REST API permission reference

* Fix multi-router path extraction in permission docs

---------
(cherry picked from commit 63b9826)

Co-authored-by: Durgaprasad M L <durgaprasadmadikeri@gmail.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
vatsrahul1001 pushed a commit that referenced this pull request Aug 5, 2026
…ion (#67606) (#69334)

* Generate stable REST API permission reference docs automatically

* Fix mypy typing issue in permission extractor

* chore: rerun flaky CI

* Add prek hook and sort generated API permission docs

* Potential fix for pull request finding



* Handle positional DAG access entity extraction

* Include public API endpoints in permission reference docs

* Update generated REST API permission reference

* Fix multi-router path extraction in permission docs

---------
(cherry picked from commit 63b9826)

Co-authored-by: Durgaprasad M L <durgaprasadmadikeri@gmail.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Automate reference doc creation for stable API permissions

6 participants