GitHub/Repository Security/GitHub Workflows & Actions: Difference between revisions

From MozillaWiki
Jump to navigation Jump to search
(Add OpenSSF article)
(truncating content as we transition ownership from IT to CloudEng)
Tag: Replaced
 
(27 intermediate revisions by 4 users not shown)
Line 1: Line 1:
= GitHub Workflows and Actions =
'''2026-10-07: GitHub Enterprise ownership has been transitioned from IT to CloudEng.''' Customer documentation has been moved to [https://mozilla-hub.atlassian.net/wiki/spaces/GHE/pages/3087892663/Getting+help+with+GitHub Getting help with GitHub] in Confluence. Please update any links to this page accordingly. If you are an external contributor, please reach out to your sponsor in the appropriate [https://chat.mozilla.org/ Matrix channel] for support.


GitHub Workflows and Actions provide tremendous value, but also are subject to non-obvious abuse. They:
This content has been moved to: https://mozilla-hub.atlassian.net/wiki/spaces/GHE/pages/3088580797/Repository+requirements+policy+and+security#GitHub-Actions-and-workflows
 
* are a “hybrid language”
* have non-obvious variable expansion semantics
* inherit (invisible) global state
 
As such, they take a bit of learning to utilize in a secure manner. The following steps are part of “best practices” for using GitHub Workflows, and are strongly recommended for all sensitive repos.
 
# Protect all workflows by requiring code reviews from folks who have familiarized themselves with the security issues of workflows.
# Use scanning to detect problems and lack of best practices.
# Treat GitHub actions as you would any 3rd party library shipped with your product.
#* Examine the supply chain!
#* Use mitigations where appropriate.
# As always, enforce “least privilege” wherever possible.
#* Explicitly set "<code>persist-credentials: false</code>" when using the "<code>actions/checkout</code>" action. (Prevent hidden state.)
#* Explicitly unset <tt>GITHUB_TOKEN</tt> when not needed at the workflow or job level with "<code>permissions: {}</code>".
# When configuring automatic merging or making exceptions in the workflow for Dependabot, make sure to validate the user and not the actor in the Github action.
#* Use the check "<code>github.event.pull_request.user.login == 'dependabot[bot]'</code>" instead of "<code>github.actor == 'dependabot[bot]'</code>"
 
 
== Resources and tools ==
 
There are a number of ways to implement the recommendations above. Here are some suggestions - other tools may be available and a better fit. (See [[GitHub#How_do_I_hook_up_a_new_GitHub_Actions_or_3rd_party_application_to_a_repository_in_the_mozilla_org.3F|requesting installations]] for more information.)
 
=== Learning about Workflow security issues ===
 
* Read GitHub’s [https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions security hardening for actions].
* Always reduce permissions to the minimum needed, using the [https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#defining-access-for-the-github_token-scopes <code>permissions</code> parameter]. ([https://github.blog/changelog/2021-04-20-github-actions-control-permissions-for-github_token/ more info])
* More details on how those vulnerabilities work, in a 3 part section from github:
** [https://securitylab.github.com/research/github-actions-preventing-pwn-requests/ Part 1] - Preventing Pwn requests
** [https://securitylab.github.com/research/github-actions-untrusted-input/ Part 2] - Sources of untrusted input
** [https://securitylab.github.com/research/github-actions-building-blocks/ Part 3] - Understanding the GitHub Action Supply Chain
* Understand implications of running workflows on the [https://docs.github.com/en/enterprise-cloud@latest/actions/using-workflows/events-that-trigger-workflows#pull_request_target <code>pull_request_target</code> event] (read the <code>Warning</code> section).
* [https://www.synacktiv.com/publications/github-actions-exploitation-untrusted-input Real Life Misconfiguration] examples (2024-07-02)
* [https://www.synacktiv.com/publications/github-actions-exploitation-dependabot Exploiting Dependabot] (2024-08-06)
* [https://openssf.org/blog/2024/08/12/mitigating-attack-vectors-in-github-workflows/ Mitigating Attack Vectors in GitHub Workflows] (2024-08-12)
 
=== Scanning Tools ===
 
* [https://github.com/ossf/scorecard-action OSSF Scorecard] action will detected unsafe workflows. Note that some findings are “stricter” than our recommendations. Please evaluate the benefit before adopting a “get to zero reported findings”. Recommendations:
** Set <code>publish_results</code> to <code>false</code>. This is a manual step if you follow the [https://github.com/ossf/scorecard-action?tab=readme-ov-file#workflow-setup-required installation instructions].
** “Must correct” findings as of 2024-06-12 include
*** [https://github.com/ossf/scorecard/blob/main/docs/checks.md#dangerous-workflow Dangerous Workflow]
** '''''Note:''''' While the action has been approved for use in all organizations, it may not yet have been added to an organization you are working in. If you receive a message that the action is not available, please follow [[GitHub#github_actions|these instructions]] to have it added.
* [https://github.com/synacktiv/octoscan Synacktiv's octoscan], which can check workflows on all branches locally.
 
=== Supply Chain Hygiene ===
 
How much effort to put into supply chain checks for 3rd party actions is directly related to how much you can trust the providers. And that includes trusting the process of the providers to ensure that level of trust continues to be warranted over time.
 
Some indications that an action deserves some trust include:
 
* Does the author follow the [https://github.blog/2023-11-16-security-best-practices-for-authors-of-github-actions/ Security Best Practices for authors of GitHub Actions]?
* If the action is implemented via a container image, are there [https://github.blog/2024-04-30-where-does-your-software-really-come-from/ attestations about the image]?
 
Unless you have some sort of contractual protection, you probably want to do the following for any action:
 
* Enforce least privilege – only provide a token that can do what the action ''should'' require to perform the advertised function.
* Harden the execution environment.
** use tooling to block internet access, unless specifically needed
** refactor jobs to minimize access to unneeded tokens, resources, and services
* Audit the code for reasonableness before first time use
** Audit the changes before taking a version update
** Don’t forget to audit dependencies
** Consider permitting only a specific revision (instead of relying on a version tag)

Latest revision as of 21:29, 7 October 2026

2026-10-07: GitHub Enterprise ownership has been transitioned from IT to CloudEng. Customer documentation has been moved to Getting help with GitHub in Confluence. Please update any links to this page accordingly. If you are an external contributor, please reach out to your sponsor in the appropriate Matrix channel for support.

This content has been moved to: https://mozilla-hub.atlassian.net/wiki/spaces/GHE/pages/3088580797/Repository+requirements+policy+and+security#GitHub-Actions-and-workflows