Repository navigation
Automate stable REST API permission reference doc generation - #67606
Conversation
|
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
|
jscheffl
left a comment
There was a problem hiding this comment.
It is missing to add it to .pre-commit-config.yaml
|
Implemented the requested changes:
This ensures the generated permission reference stays automatically synchronized with route changes and prevents stale generated docs from passing CI. |
There was a problem hiding this comment.
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.rstartifact.
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. |
|
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:
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. |
|
@potiuk review |
This comment was marked as spam.
This comment was marked as spam.
|
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. |
|
Addressed the feedback regarding public /api/v2 endpoints being omitted from the generated reference. Updates included:
CI is now green on the updated implementation. @potiuk could you please take another look when you have time? |
f1e0974 to
5d0369c
Compare
|
@jscheffl's approval here is from May 29 ( Drafted-by: Claude Code (Opus 4.8); reviewed by @potiuk before posting |
jscheffl
left a comment
There was a problem hiding this comment.
Re-Review OK for me. CI should be green and like another reviewer prior merge.
potiuk
left a comment
There was a problem hiding this comment.
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
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
39afaa7 to
a2e9d82
Compare
potiuk
left a comment
There was a problem hiding this comment.
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(), soPOST /clearDagRunscorrectly resolves to
/api/v2/dags/{dag_id}/clearDagRuns. Nice regression coverage in
test_multiple_routers_in_same_fileandtest_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
bytest_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.
Backport successfully created: v3-3-testNote: As of Merging PRs targeted for Airflow 3.X In matter of doubt please ask in #release-management Slack channel.
|
…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>
…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>
…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>
…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>
…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>
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:
This PR is intentionally opened as a draft to gather maintainer feedback on:
Closes: #10937