Skip to content

chore(tests): Restrict repository permissions for the test workflow - #48

Open
jonaseberle wants to merge 1 commit into
mainfrom
2025-09-30_permissions_for_tests
Open

jonaseberle wants to merge 1 commit into
mainfrom
2025-09-30_permissions_for_tests

Conversation

@jonaseberle

Copy link
Copy Markdown
Member

Potential fix for https://github.com/ddev/github-action-setup-ddev/security/code-scanning/2

To fix the problem, explicitly set the minimal required permissions for the workflow. Since the workflow does not perform any actions that require write permissions (e.g., it does not comment on PRs, update statuses, or push commits), setting permissions: contents: read at the workflow level (the root) is the preferred solution. This restricts the GITHUB_TOKEN to read-only access to repository contents, greatly reducing the attack surface.

Specifically, add the following at the top level of .github/workflows/main.yml, after the name: and before the on: block:

permissions:
  contents: read

No changes are required to the existing jobs or steps, as none are observed to require greater permissions.

Suggested fixes powered by Copilot Autofix. Review carefully before merging.

@jonaseberle
jonaseberle marked this pull request as ready for review September 30, 2025 13:53
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@jonaseberle
jonaseberle force-pushed the 2025-09-30_permissions_for_tests branch from 2913048 to a20e749 Compare October 1, 2025 14:59
@jonaseberle jonaseberle changed the title Potential fix for code scanning alert no. 2: Workflow does not contain permissions chore(tests): Restrict repository permissions for the test workflow Oct 1, 2025

@davereid davereid left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

praise: Thanks, Jonas. This repo's default workflow token can write, so this is worth merging. It closes code scanning alert 3, the same rule as alert 2, which GitHub marked fixed when the file changed.

question: #65 passes the workflow token to ddev utility download-ddev --head, which downloads the build from ddev/ddev's artifacts. Does that still work with only contents: read, or does the job need actions: read? Once #65 merges, we'll update this branch, and the head jobs' logs should show whether it fell back to nightly.link.

Drafted with Claude Code using project-triage. I had the change checked with zizmor and against the repo's token settings and code scanning alerts, chose which points to raise, and reviewed the final text.

Comment on lines +2 to +3
permissions:
contents: read

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

suggestion (non-blocking): I'd prefer permissions: {} here, with the test job's permissions on the job and a comment saying why, e.g. contents: read # actions/checkout. Then any job added later starts with no permissions.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants