Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Harden GitHub Actions workflows and actions #945

Merged
merged 25 commits into from
Jan 14, 2025
Merged

Conversation

jdbaldry
Copy link
Member

@jdbaldry jdbaldry commented Jan 13, 2025

Limits vulnerabilities in workflows and especially importantly for actions that are used in multiple other repositories.

I can add a Dependabot or Renovate workflow to keep the pinned hashes up to date.

Linted using zizmor.

Tested with:

zizmor --persona auditor --quiet "--gh-token=${GITHUB_TOKEN}" *.yml

Notable changes:

  • Prevent template injection from inputs by using environment variables instead of actions templating expressions in scripts.
  • Ensure no checkout actions persist credentials.
  • Pin all actions to commit SHAs to prevent mutable references changing action behavior.
  • Move elevated permissions to just the jobs that need them so that those permissions aren't accidentally leaked to other jobs that don't.

Deploy PR Preview workflow tested in: https://github.com/grafana/writers-toolkit/actions/runs/12745697349/job/35520196992?pr=945. I believe the failure is expected given this branch isn't approved for Cloud Run usage.

Other docs related workflows were also tested in 95995a7 (#945).

Signed-off-by: Jack Baldry [email protected]

  • I've used a relevant pull request (PR) title.
  • I've added a link to any relevant issues in the PR description.
  • I've checked my changes on the deploy preview and they look good.
  • I've added an entry to the What's new page (only required for notable changes).

Copy link
Member Author

Choose a reason for hiding this comment

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

This workflow isn't used in this repository.

.github/workflows/prettier.yml Outdated Show resolved Hide resolved
Signed-off-by: Jack Baldry <[email protected]>
Signed-off-by: Jack Baldry <[email protected]>
Signed-off-by: Jack Baldry <[email protected]>
Signed-off-by: Jack Baldry <[email protected]>
Signed-off-by: Jack Baldry <[email protected]>
Signed-off-by: Jack Baldry <[email protected]>
Signed-off-by: Jack Baldry <[email protected]>
Signed-off-by: Jack Baldry <[email protected]>
Signed-off-by: Jack Baldry <[email protected]>
They can only exist at the job, not step, level.

Signed-off-by: Jack Baldry <[email protected]>
Signed-off-by: Jack Baldry <[email protected]>
Signed-off-by: Jack Baldry <[email protected]>
@jdbaldry jdbaldry force-pushed the jdb/2025-01-harden-actions branch from 7858358 to db6c03b Compare January 13, 2025 10:37
Signed-off-by: Jack Baldry <[email protected]>
Signed-off-by: Jack Baldry <[email protected]>
Signed-off-by: Jack Baldry <[email protected]>
Signed-off-by: Jack Baldry <[email protected]>
Signed-off-by: Jack Baldry <[email protected]>
Signed-off-by: Jack Baldry <[email protected]>
@jdbaldry jdbaldry force-pushed the jdb/2025-01-harden-actions branch from da306b5 to 961ef10 Compare January 13, 2025 11:03
@jdbaldry jdbaldry marked this pull request as ready for review January 13, 2025 11:05
@jdbaldry jdbaldry requested a review from a team as a code owner January 13, 2025 11:05
@grafana grafana deleted a comment from github-actions bot Jan 13, 2025
Copy link
Contributor

@robbymilo robbymilo left a comment

Choose a reason for hiding this comment

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

Nice work! TIL about passing the inputs to envs, will keep that in mind for the future.

@jdbaldry jdbaldry merged commit cf72765 into main Jan 14, 2025
5 checks passed
@jdbaldry jdbaldry deleted the jdb/2025-01-harden-actions branch January 14, 2025 12:12
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