Skip to content

ci: pin action hashes and escape variables with minimum permission #441

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

Merged
merged 2 commits into from
May 17, 2025

Conversation

zimeg
Copy link
Member

@zimeg zimeg commented May 15, 2025

Summary

This PR uses the wonderful zizmor tool to audit our own workflows and pinact for pinned versioning 👾

While not so simple to bump ourselves, the kind @dependabot can help keep these hashes updated with the changes of dependabot/dependabot-core#5951 having landed 🤖 ✨

Reviewers

A similar audit can be performed with the zizmor tool:

$ zizmor .
...
No findings to report. Good job! (1 ignored, 4 suppressed)

The suppressed findings are expected permission blocks at the top-level of a workflow, but we set this for each job.

Notes

Most changes I hope are repetitive, but I will comment on the more significant ones! FWIW the develop and test workflow continue to work with these changes:

Requirements

@zimeg zimeg added the github_actions Pull requests that update GitHub Actions code label May 15, 2025
Copy link

codecov bot commented May 15, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.85%. Comparing base (abe8518) to head (7b4083b).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #441   +/-   ##
=======================================
  Coverage   99.85%   99.85%           
=======================================
  Files           7        7           
  Lines         709      709           
=======================================
  Hits          708      708           
  Misses          1        1           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Member Author

@zimeg zimeg left a comment

Choose a reason for hiding this comment

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

💌 Notes for the kind reviewers!

These might be patterns common across other repos that I hope to follow up with, and I might reference this pull request elsewhere or perhaps write those comments separate. In either case, I'm looking forward to improving workflow securities around 🔏

Comment on lines +15 to +16
permissions:
contents: read
Copy link
Member Author

Choose a reason for hiding this comment

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

📝 These permissions limit the default $GITHUB_TOKEN but the generated app token used for opening a PR later has the scopes of the app.

If this does cause strangeness, I will be quick to follow up 🫡

Comment on lines +28 to +30
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
persist-credentials: false
Copy link
Member Author

Choose a reason for hiding this comment

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

📝 A similar note about this token not being required for more than a checkout here!

Comment on lines +42 to +44
rsync -av --delete ./docs/ "./docs_repo/content/$REPO/"
env:
REPO: ${{ github.event.repository.name }}
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 is a common pattern used to avoid script injections! We make user inputs an environment variable and also quote the variable when used for inline scripts.

📚 https://docs.github.com/en/actions/security-for-github-actions/security-guides/security-hardening-for-github-actions#good-practices-for-mitigating-script-injection-attacks

pull_request_target:
pull_request_target: # zizmor: ignore[dangerous-triggers]
Copy link
Member Author

Choose a reason for hiding this comment

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

📝 To test the requested changes of a PR, pull_request_target is required.

🔗 https://docs.zizmor.sh/audits/#dangerous-triggers

I am hoping we can add the zizmor tool as a check of slackapi/slack-health-score soon, but also want to make it obvious that this pattern is known to exist here 🙏 ✨

@@ -70,12 +74,14 @@ jobs:
payload: |
author: ${{ github.event.sender.login }}
channel_id: ${{ secrets.SLACK_CHANNEL_ID }}
event_url: ${{ env.EVENT_URL}}
event_url: ${{ steps.push.outputs.url || steps.pull_request.outputs.url }}
Copy link
Member Author

Choose a reason for hiding this comment

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

📣 TIL writing to $GITHUB_ENV is not a good practice!

🔗 https://docs.zizmor.sh/audits/#github-env

Some workaround was required to keep the noted step as a single step with various possible inputs, but this continues to match expectations:

Both links above use changes on a fork's main branch!

@zimeg
Copy link
Member Author

zimeg commented May 15, 2025

📣 I meant to note that the test changes of this PR are not reflected in the actual status with pull_request_target! Please trust and inspect these downstream results for now I hope.

Copy link
Contributor

@hello-ashleyintech hello-ashleyintech left a comment

Choose a reason for hiding this comment

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

🙌

Copy link
Contributor

@WilliamBergamin WilliamBergamin left a comment

Choose a reason for hiding this comment

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

This might be a hot take but I don't think we need to pin the hashes, I think the readability of the raw version outweighs the benefits of pinning hashes and leaving comments for the actual version, I'm concerned about how dependabot handles updating these dependencies :dependabot:

Could you explain what are the security improvements gained by using the hash rather then referencing the version and share any documented cases of critical vulnerability in this area 🙏

It may also be worth considering what is at risk here, as far as I know these Github Actions don't have access to our package release keys, I don't think we should be building a "complex security vault" if we are leaving it empty

@zimeg
Copy link
Member Author

zimeg commented May 16, 2025

@hello-ashleyintech @WilliamBergamin Thank y'all both for reviewing this! 🔐

@WilliamBergamin I agree a tag is more simple, but tags can be changed which can result in supply chain problems if unexpected write access is found in an upstream project.

In this project, the publish.yml workflow has the following permissions to create tags that are used within workflows downstream:

permissions:
  contents: write

We're using trusted and reviewed actions at this time. But for the sake of this example if the current v1.2.1 tag of the step teunmooij/github-versioned-release was moved to a different commit that injects code to send action inputs to an untrusted domain before packaging the rest of the code, this action would be compromised without us realizing 😓

In a less theoretical scenario, CVE-2025-30066 shows this happening a few months ago elsewhere - writeup here 📚

Using a commit hash removes these possibilities altogether and is recommended as a best practice as well. IMHO we should consider recommending this within the example code samples of this project, but this might be a discussion for later.

FWIW @dependabot is kind too and automates the hash update and also the version comment at the time of update!

Copy link
Contributor

@WilliamBergamin WilliamBergamin left a comment

Choose a reason for hiding this comment

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

Thanks for the detailed update, lets try it out

@zimeg
Copy link
Member Author

zimeg commented May 17, 2025

@WilliamBergamin This was a surprising case to explore for me, and I hope the caution keeps these actions more secure 👾

@hello-ashleyintech @WilliamBergamin Once more, thank you for the reviews! I believe a @codecov update is fanning out now and I'll report back on these updates soon!

Similar updates to other repositories are also in the works. I plan to share these in following hours ⏳ ✨

@zimeg zimeg merged commit ab28db9 into slackapi:main May 17, 2025
5 checks passed
@zimeg zimeg added the security label May 17, 2025
@zimeg
Copy link
Member Author

zimeg commented May 17, 2025

Woah! This was so quick but is also showing a hopeful update: #443 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
github_actions Pull requests that update GitHub Actions code security
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy