Skip to content

Add read-only permissions and self-repo actions in python_tests.yml - #41526

Merged
derrickaw merged 1 commit into
masterfrom
codescan/gha-python-tests-permissions
Nov 24, 2026
Merged

derrickaw merged 1 commit into
masterfrom
codescan/gha-python-tests-permissions

Conversation

@derrickaw

@derrickaw derrickaw commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Note: this PR was auto-generated by tooling. Before moving it out of draft, the author has done a full review of the PR, specifically evaluating it on the following criteria:

  • The PR remediates confirmed, live Code Scanning finding(s) (CodeQL / zizmor) on master without altering intended public API or workflow semantics
  • The fix is minimal, idiomatic, and avoids suppressing alerts or masking underlying defects
  • Relevant unit tests, linters, and CI checks have been verified

If you have concerns with the PR or with the underlying methodology used to generate this, please comment below - they will be addressed by the author not the tooling :)

Summary

  • Resolves 12 open Code Scanning findings (CodeQL + zizmor) in .github/workflows/python_tests.yml:
    • CodeQL actions/missing-workflow-permissions (#30, #31, #32, #35) & zizmor/excessive-permissions (#1612, #1613, #1614, #1615, #1616): adds explicit top-level permissions: contents: read across all four read-only test jobs.
    • zizmor/self-repository (#3139, #3140, #3141): updates local composite action references from ./.github/actions/setup-environment-action to $/.github/actions/setup-environment-action.

Verification

@derrickaw

Copy link
Copy Markdown
Collaborator Author

/gemini review

@github-actions github-actions Bot 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.

📋 Review Summary

This PR appears to be a test PR that introduces several breaking changes to .github/workflows/python_tests.yml without a description or linked issue. As currently written, the changes will cause the Python Tests workflow to fail immediately and disable pull_request triggers across nearly all branches.

🔍 General Feedback

  • The pull_request trigger is restricted to a non-standard master2 branch, which disables pre-commit testing on master.
  • The checkout action is downgraded from actions/checkout@v6 to actions/checkout@v1 (which uses the deprecated and removed Node 12 runtime on GitHub-hosted runners).
  • Both the runs-on runner label (ubuntu-latest-invalid) and the local composite action path ($/.github/actions/setup-environment-action) are invalid and will prevent the job from executing.

💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.

💬 Inline Findings

  • .github/workflows/python_tests.yml (line 36): 🔴 Critical: Restricting pull_request triggers to master2 prevents this workflow from running on pull requests targeting master or release branches. Unless this is strictly for temporary testing, the branches filter should be removed.

  • .github/workflows/python_tests.yml (line 44): 🔴 Critical: ubuntu-latest-invalid is not a valid GitHub-hosted or self-hosted runner label in this repository, which will cause jobs to remain queued indefinitely and fail to acquire a runner.

    runs-on: [ubuntu-latest]
  • .github/workflows/python_tests.yml (line 53): 🟠 High: Downgrading actions/checkout from v6 to v1 will break workflow execution on modern GitHub-hosted runners because v1 relies on the deprecated Node 12 runtime and lacks critical security and git fetch updates.
        uses: actions/checkout@v6
  • .github/workflows/python_tests.yml (line 55): 🔴 Critical: Local composite action paths in GitHub Actions uses: must start with ./. Using $/ is invalid syntax and causes workflow validation to fail (PreCommit GHA).
        uses: ./.github/actions/setup-environment-action

@github-actions github-actions Bot added build size/xs XS: <10 lines changed labels Nov 20, 2026
@derrickaw derrickaw added the ready-for-human Draft PR with all checks passing and all review comments resolved, ready for human review label Nov 20, 2026
@derrickaw

Copy link
Copy Markdown
Collaborator Author

Note: The initial automated review above ran immediately at PR creation before the PR diff endpoint populated (referencing nonexistent master2 / ubuntu-latest-invalid / actions/checkout@v1 lines). The actual diff (f6273562571) only adds top-level permissions: contents: read and updates the three setup-environment-action steps to $/, and PreCommit GHA, zizmor, and CodeQL have all passed.

/gemini review

@github-actions github-actions Bot 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.

📋 Review Summary

This PR hardens .github/workflows/python_tests.yml by setting explicit top-level contents: read permissions and updating local composite action references to use the self-repository syntax ($/...). The changes are clean, minimal, and properly address the CodeQL and zizmor findings without altering workflow behavior.

🔍 General Feedback

  • All four jobs (check_gcp_variables, build_python_sdk_source, python_unit_tests, and python_wordcount_direct_runner) only perform checkouts, local builds/tests, and artifact uploads, so restricting GITHUB_TOKEN to contents: read at the workflow level is safe and appropriate.
  • Switching setup-environment-action references from ./.github/actions/... to $/... aligns with GitHub Actions self-repository syntax and zizmor security best practices.

💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.

@derrickaw derrickaw added ready-for-human Draft PR with all checks passing and all review comments resolved, ready for human review and removed ready-for-human Draft PR with all checks passing and all review comments resolved, ready for human review labels Nov 20, 2026
@derrickaw
derrickaw marked this pull request as ready for review November 21, 2026 02:41
@github-actions

Copy link
Copy Markdown
Contributor

Assigning reviewers:

R: @Abacn for label build.
Backup reviewer: damccorm (if the main reviewer is unresponsive, you can escalate to them by tagging their username)

Note: If you would like to opt out of this review, comment assign to next reviewer.

Available commands:

  • stop reviewer notifications - opt out of the automated review tooling
  • remind me after tests pass - tag the comment author after tests pass
  • waiting on author - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)

The PR bot will only process comments in the main thread (not review comments).

@derrickaw

Copy link
Copy Markdown
Collaborator Author

Verified via sample workflow_dispatch run against codescan/gha-python-tests-permissions: https://github.com/apache/beam/actions/runs/45211013785 (succeeded across Linux, macOS, and Windows for Python 3.11–3.14)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants