{"id":490,"date":"2021-10-19T15:22:32","date_gmt":"2021-10-19T15:22:32","guid":{"rendered":"https:\/\/fde.cat\/index.php\/2021\/10\/19\/github-actions-security-best-practices\/"},"modified":"2021-10-19T15:22:32","modified_gmt":"2021-10-19T15:22:32","slug":"github-actions-security-best-practices","status":"publish","type":"post","link":"https:\/\/fde.cat\/index.php\/2021\/10\/19\/github-actions-security-best-practices\/","title":{"rendered":"Github Actions Security Best Practices"},"content":{"rendered":"<h3>Introduction<\/h3>\n<p>In the world of Continuous Integration and Continuous Deployment, Github Actions provide a nifty edge to quickly build end-to-end automation right into the repository. This makes integration of Actions into an organization\u2019s Github repositories pretty straightforward and convenient.<\/p>\n<p>Github Actions bring velocity to the Software Development Lifecycle. However, if it is swiftly adopted without a well chartered security plan, you may quickly find yourself in muddy\u00a0waters.<\/p>\n<p>In this blog post, we will discuss some of the key security concerns you should be aware of when using Github Actions. We will also cover the best practices that Salesforce Heroku follows to securely use this exceedingly popular\u00a0product.<\/p>\n<h3>A little about Github\u00a0Actions<\/h3>\n<p><a href=\"https:\/\/github.com\/actions\">Github Actions<\/a> enables users to run workflows, which are custom automated processes that can be set up in a repository to build, test, package, release, or deploy any code project. These workflows can be executed on Github runners or self-hosted runners.<\/p>\n<p>A workflow file constitutes one or more jobs, and each job is broken down into steps. A step can either execute commands on the runners or utilize an Action to perform a certain task. When building workflows, engineers can write their own custom Actions or utilize the available Actions in the Github Actions marketplace.<\/p>\n<p>The following diagram shows the various components of a workflow\u00a0file:<\/p>\n<p>To understand how a workflow is broken down into jobs and steps, let\u2019s look at a specific scenario.<\/p>\n<p>For every push to a repository, code should be scanned for open source vulnerabilities using Snyk and files should be uploaded to an S3\u00a0bucket<\/p>\n<p>The workflow file for this task may look something like\u00a0this:<\/p>\n<p>A couple of things to\u00a0note:<\/p>\n<p>This workflow will be executed when a push event occurs on any branch of the repository <strong><em>(line\u00a02)<\/em><\/strong>.The workflow has been broken down into two jobs, as they are distinct tasks that do not depend on each other. They will run simultaneously on two isolated containers.Job<em> \u201csnyk_run\u201d (<\/em><strong><em>line 4<\/em><\/strong><em>)<\/em> is divided into two steps that run on the same container in the defined order. This permits the steps within a job to share information via the filesystem.The Snyk action used here <strong><em>(line 10)<\/em><\/strong> requires a sensitive token that is stored via Github\u00a0Secrets.The last step in <em>\u201cupload-files\u201d <\/em><strong><em>(line 32)<\/em><\/strong><em> <\/em>runs a command to execute a script defined in the repository.<\/p>\n<p>Additional information about Github Actions can be found at <a href=\"https:\/\/docs.github.com\/en\/actions\/learn-github-actions\/understanding-github-actions\">https:\/\/docs.github.com\/en\/actions\/learn-github-actions\/understanding-github-actions<\/a><\/p>\n<h3>What can go\u00a0wrong?<\/h3>\n<p>Github Actions is an attractive solution to automate tasks and run tests. Integrating Actions into Github repositories, however, can add to an organization\u2019s risk surface. A few areas of concern are noted in the table\u00a0below:<\/p>\n<p><strong>Third party actions: <\/strong>The third party Action used could potentially run malicious code.<strong>Secrets and other sensitive information: <\/strong>Actions may need access to secrets\u200a\u2014\u200athese need to be stored securely and referenced safely.<strong>By-products of workflow runs: <\/strong>Access to by-products of a workflow execution (artifacts, caches) should be\u00a0audited.<strong>Forked repositories: <\/strong>Access to logs and\/or secrets through forked repositories should be examined.<strong>Malicious docker images: <\/strong>Actions could be built on malicious docker\u00a0images.<strong>Service Containers:<\/strong> Use of default credentials and access to service containers (redis, postgres) should be\u00a0audited.<strong>Runner escape: <\/strong>Malicious code on runners could lead to a potential container breakout.<strong>Workflow commands: <\/strong>Commands used in workflows may not function as expected\/documented.<strong>Improper configuration of self-hosted runners: <\/strong>Attacks on runners ( remote code execution, privilege escalation) via Actions can lead to lateral movement in an organization\u2019s environment.<strong>Third party product vulnerabilities in Actions:<\/strong> Packages used by an Action could have multiple open source vulnerabilities.<\/p>\n<h3>Best Practices<\/h3>\n<p>As noted above, things can go wrong if Github Actions has been hastily adopted. The best practices we\u2019ll discuss in the following sections help address these concerns.<\/p>\n<h4>RECOMMENDED THIRD PARTY ACTIONS TO\u00a0USE<\/h4>\n<p>To minimize risk associated with third party Actions, a standard\/guidance should be developed to define \u201ctrusted\u201d actions. Based on your particular needs and risk appetite the criteria *may*\u00a0include:<\/p>\n<p>GitHub provided standard actions,<br \/>\u200a\u2014\u200aThese are developed and maintained by GitHub.<br \/>\u200a\u2014\u200aA list of these actions can be found at<a href=\"https:\/\/github.com\/actions\"> https:\/\/github.com\/actions<\/a>Actions whose creators have been verified by GitHub,<br \/>\u200a\u2014\u200aThe blue badge next to the action identifies verified creators.Actions that have been released by trusted vendors of your organization.<\/p>\n<p>For Actions falling outside this criteria, it is highly recommended that a security assessment or code review should be conducted before\u00a0use.<\/p>\n<h4>WRITING SECURE WORKFLOWS<\/h4>\n<p>Poor practices while writing workflows may quickly compound risk and introduce security gaps. Below are a list of best practices that can help minimize these\u00a0threats:<\/p>\n<p>Use a stable version tag when calling Actions in a workflow file,<br \/>\u200a\u2014\u200aExample:<em> actions\/checkout@v2<br \/>\u200a\u2014\u200a<\/em>Alternatively, the commit hash of the stable version can be used, <em>actions\/download-artifact@1de1dea89c32dcb1f37183c96fe85cfe067b682a<\/em>Do <strong>not<\/strong> use <em>@master<\/em> tag while calling an Action,<br \/>\u200a\u2014\u200aExample, <strong>*this is NOT recommended*<\/strong>: <em>actions\/upload-artifact@master<\/em>Use only official or docker certified images when running jobs on docker containers.<br \/>\u200a\u2014\u200aAn appropriate security review should be obtained if an image not falling in the aforementioned category is\u00a0needed.When pulling docker images, use the version tag (preferably with the major version),<br \/>\u200a\u2014\u200aExample: <em>node:10<br \/> \u2014<\/em>version tag is preferred over <em>node:latest.<\/em>Do <strong>not<\/strong> use the <em>add::mask<\/em> command to prevent sensitive values from appearing as plaintext in workflow logs.<br \/>\u200a\u2014\u200aIf used with environment variables, plaintext values are printed as part of the execution environment into the\u00a0logs.Do <strong>not <\/strong>overwrite Github default variables, these have the prefix\u00a0GITHUB_.Do <strong>not<\/strong> store sensitive values i.e. access tokens in a file in the cache path.<br \/>\u200a\u2014\u200aDo <strong>not<\/strong> include &lt;home&gt;\/.docker\/config.json file in the cache, this file may contain unencrypted docker credentials.To create the unique key that identifies a cache, using context data is a common practice<br \/>\u200a\u2014\u200aHowever, do <strong>not<\/strong> use sensitive values like github.token or github.actor for key generation.<br \/>\u200a\u2014\u200aInstead use a hash of a file like<em> requirements.txt<\/em> or <em>package-lock.json<\/em> in combination with system related information like<em> runner.os<\/em>.Do <strong>not<\/strong> dump github context data into logs as it might contain sensitive informationArtifacts can be created for sharing information between jobs in the same workflow.<br \/>\u200a\u2014\u200aDo <strong>not<\/strong> store sensitive information in artifacts as they are available to anyone with access to the repository.<br \/>\u200a\u2014\u200aArtifacts are automatically deleted after 90 days. Safely upload them into an s3 bucket if needed beyond that time\u00a0period.Be aware of job execution limits.<br \/>\u200a\u2014\u200a<a href=\"https:\/\/docs.github.com\/en\/actions\/reference\/usage-limits-billing-and-administration#usage-limits\">https:\/\/docs.github.com\/en\/actions\/reference\/usage-limits-billing-and-administration#usage-limits<\/a>Maintain caution when adding outside collaborators\u200a\u2014\u200ausers with read permissions can view logs for workflow failures, view workflow history, as well as search and download logs.<br \/> \u2014External collaborators with write access to a repository can modify permissions associated with a GITHUB_TOKEN. This can lead to elevated privileges and possibility for other attacks [3]<br \/>\u200a\u2014\u200aIf adding external collaborators is required, follow the principle of least privilege and assign only read permissions for minimal disclosure.<\/p>\n<h4>USING GITHUB SECRETS THE RIGHT\u00a0WAY<\/h4>\n<p>Sensitive data like access tokens or credentials may be needed during workflow runs. Github Secrets is an built-in secret storage mechanism that can and should be used for these purposes. However, to ensure secrets are safely referenced, here is a list of recommendations to\u00a0follow:<\/p>\n<p>Store all credentials and anything considered sensitive using Github\u00a0Secrets.Github redacts values defined via Secrets from logs; however, do <strong>not<\/strong> print secrets to logs <strong>deliberately<\/strong>.If a Secret value is greater than 64kb, then users can follow the process defined in<a href=\"https:\/\/help.github.com\/en\/actions\/configuring-and-managing-workflows\/creating-and-storing-encrypted-secrets#limits-for-secrets\"> https:\/\/help.github.com\/en\/actions\/configuring-and-managing-workflows\/creating-and-storing-encrypted-secrets#limits-for-secrets<\/a><br \/>\u200a\u2014\u200aSecrets stored this way are <strong>not<\/strong> automatically redacted by GitHub.<br \/>\u200a\u2014\u200aDo <strong>not<\/strong> print secrets to logs.<br \/>\u200a\u2014\u200aDo <strong>not<\/strong> use secrets directly in command line programs.In the workflow file, use secrets as environment or normal variables.<br \/>\u200a\u2014\u200aUse quoting when passing them on the command\u00a0line.When a secret is being shared between multiple repositories, they can be added at the Organization level if feasible.<br \/>\u200a\u2014\u200aThis avoids duplication and simplifies the rotation\u00a0process.<strong>Avoid<\/strong> passing secrets between processes from the command\u00a0line.Establish a credential rolling process and regular\u00a0cadence.<\/p>\n<h4>USEFUL SETTINGS<\/h4>\n<p>Github provides useful settings that can be utilized at organization or repository level to further minimize risk associated with Actions. These have been described below<\/p>\n<p>To restrict actions used at the repo level:<br \/>\u200a\u2014\u200aIf use of third party actions is not required, in <em>Settings -&gt; Actions<\/em> tab, enable <em>\u201cAllow local actions only\u201d<br \/>\u200a\u2014\u200a<\/em>To use actions created by Github and Github verified creators, in <em>Settings -&gt; Actions<\/em> tab, choose \u201c<em>Allow Select Actions<\/em>\u201d. Enable <em>\u201cAllow actions created by Github\u201d <\/em>and<em> \u201cAllow Marketplace actions by verified creators\u201d<\/em>Forks of a repository, however, do <strong>not<\/strong> inherit Secrets, but they can create pull requests on the base branch and access caches. To minimize any information disclosure, if forking is not needed, it can be disabled in the repository under <em>Settings -&gt;\u00a0Options<\/em>To prevent workflow runs from pull requests originating from repository forks, in Settings -&gt; Actions tab, ensure <em>\u201cFork pull request workflows\u201d <\/em>is <strong>disabled.<\/strong>To control access of a repository from workflows originating in other repositories, the <em>\u201cAccess\u201d <\/em>setting can be utilized. This is available under Settings -&gt; Actions\u00a0tab.<\/p>\n<h4>RECOMMENDATIONS FOR CUSTOM\u00a0ACTIONS<\/h4>\n<p>Engineers may want to build their own custom actions to automate tasks. Described below are a few recommendations to keep in mind while doing\u00a0so:<\/p>\n<p>When creating docker container actions, use official or docker certified images.<br \/>\u200a\u2014\u200aUse the version tag (preferably the major version if available).If the custom action is built to interact with internal applications or approved third party applications, store relevant credentials using\u00a0Secrets.Create a separate repository for every action that is to be open\u00a0sourced.<a href=\"https:\/\/help.github.com\/en\/actions\/creating-actions\/about-actions#good-practices-for-release-management\">https:\/\/help.github.com\/en\/actions\/creating-actions\/about-actions#good-practices-for-release-management<\/a> lists good practices for creating a public\u00a0action.<\/p>\n<h4>PUBLIC REPOSITORIES<\/h4>\n<p>An organization may have Actions enabled in their public Github repositories. Described below are few recommendations to keep in mind with respect to Github Actions in public repositories:<\/p>\n<p>Github Actions is enabled by default in <strong>all<\/strong> repositories. Disable Actions in public repositories when not\u00a0requiredIn Settings -&gt; Actions tab, for <em>\u201cWorkflow permissions\u201d<\/em>, select <em>\u201cRead repository contents permission\u201d<\/em>. This ensures least privileges are given to the associated GITHUB_TOKEN<br \/>\u200a\u2014\u200aIf <em>\u201cRead and Write permissions\u201d <\/em>are assigned, within a workflow file, an user can add additional permissions to the GITHUB_TOKEN <br \/>\u200a\u2014\u200aThis setting can be enabled at the organization levelTo control workflow runs by outside collaborators:<br \/>\u200a\u2014\u200aIn Settings -&gt; Actions tab, for <em>\u201cFork pull request workflows from outside collaborators\u201d<\/em> select <em>\u201cRequire approval for all outside collaborators\u201d<\/em><\/p>\n<p>Additional best practices can be found at <a href=\"https:\/\/docs.github.com\/en\/actions\/learn-github-actions\/security-hardening-for-github-actions\">https:\/\/docs.github.com\/en\/actions\/learn-github-actions\/security-hardening-for-github-actions<\/a><\/p>\n<h3>Conclusion<\/h3>\n<p>To sum up, although Github Actions comes with the promise of conveniently integrating CI\/CD into code repositories, if left unchecked, like most any tool, it brings its own risks. However, incorporating these simple security recommendations enables users to approach Github Actions in a secure\u00a0manner.<\/p>\n<h3>References<\/h3>\n<p><a href=\"https:\/\/docs.github.com\/en\/actions\/learn-github-actions\/understanding-github-actions\">https:\/\/docs.github.com\/en\/actions\/learn-github-actions\/understanding-github-actions<\/a><a href=\"https:\/\/docs.github.com\/en\/actions\/learn-github-actions\/security-hardening-for-github-actions\">https:\/\/docs.github.com\/en\/actions\/learn-github-actions\/security-hardening-for-github-actions<\/a><a href=\"https:\/\/medium.com\/cider-sec\/bypassing-required-reviews-using-github-actions-6e1b29135cc7\">https:\/\/medium.com\/cider-sec\/bypassing-required-reviews-using-github-actions-6e1b29135cc7<\/a><\/p>\n<p><a href=\"https:\/\/engineering.salesforce.com\/github-actions-security-best-practices-b8f9df5c75f5\">Github Actions Security Best Practices<\/a> was originally published in <a href=\"https:\/\/engineering.salesforce.com\/\">Salesforce Engineering<\/a> on Medium, where people are continuing the conversation by highlighting and responding to this story.<\/p>\n<p><a href=\"https:\/\/engineering.salesforce.com\/github-actions-security-best-practices-b8f9df5c75f5?source=rss----cfe1120185d3---4\">Read More<\/a><\/p>","protected":false},"excerpt":{"rendered":"<p>Introduction In the world of Continuous Integration and Continuous Deployment, Github Actions provide a nifty edge to quickly build end-to-end automation right into the repository. This makes integration of Actions into an organization\u2019s Github repositories pretty straightforward and convenient. Github Actions bring velocity to the Software Development Lifecycle. However, if it is swiftly adopted without&hellip; <a class=\"more-link\" href=\"https:\/\/fde.cat\/index.php\/2021\/10\/19\/github-actions-security-best-practices\/\">Continue reading <span class=\"screen-reader-text\">Github Actions Security Best Practices<\/span><\/a><\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","footnotes":""},"categories":[7],"tags":[],"class_list":["post-490","post","type-post","status-publish","format-standard","hentry","category-technology","entry"],"jetpack_featured_media_url":"","jetpack-related-posts":[{"id":227,"url":"https:\/\/fde.cat\/index.php\/2021\/02\/02\/heroku-ci-and-github-checks-integration\/","url_meta":{"origin":490,"position":0},"title":"Heroku CI and Github Checks Integration","date":"February 2, 2021","format":false,"excerpt":"Heroku CI and GitHub Checks IntegrationBefore we dive into the crux of this article, let\u2019s first get an understanding of what GitHub Checks is and how it will be useful for you when you use any external Continuous Integration (CI) tool like CircleCI, Heroku CI, or any local tool. The\u2026","rel":"","context":"In &quot;Technology&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":255,"url":"https:\/\/fde.cat\/index.php\/2021\/08\/31\/sre-weekly-issue-252\/","url_meta":{"origin":490,"position":1},"title":"SRE Weekly Issue #252","date":"August 31, 2021","format":false,"excerpt":"View on sreweekly.com A message from our sponsor, StackHawk: Interested in how you can automate application security testing with GitHub Actions? Check out this on demand webinar from StackHawk and Snyk and see how simple it is to get started. https:\/\/sthwk.com\/stackhawk-snyk Articles Building On-Call Culture at GitHub Their on-call started\u2026","rel":"","context":"In &quot;SRE&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":511,"url":"https:\/\/fde.cat\/index.php\/2021\/12\/06\/sre-weekly-issue-299\/","url_meta":{"origin":490,"position":2},"title":"SRE Weekly Issue #299","date":"December 6, 2021","format":false,"excerpt":"View on sreweekly.com A message from our sponsor, Rootly: Manage incidents directly from Slack with Rootly \ud83d\ude92. Automate manual admin tasks like creating incident channel, Jira and Zoom, paging the right team, postmortem timeline, setting up reminders, and more. Book a demo:https:\/\/rootly.com\/?utm_source=sreweekly Articles More More More! Why the Most Resilient\u2026","rel":"","context":"In &quot;SRE&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":820,"url":"https:\/\/fde.cat\/index.php\/2024\/02\/06\/dotslash-simplified-executable-deployment\/","url_meta":{"origin":490,"position":3},"title":"DotSlash: Simplified executable deployment","date":"February 6, 2024","format":false,"excerpt":"We\u2019ve open sourced DotSlash, a tool that makes large executables available in source control with a negligible impact on repository size, thus avoiding I\/O-heavy clone operations. With DotSlash, a set of platform-specific executables is replaced with a single script containing descriptors for the supported platforms. DotSlash handles transparently fetching, decompressing,\u2026","rel":"","context":"In &quot;Technology&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":347,"url":"https:\/\/fde.cat\/index.php\/2021\/08\/31\/sre-weekly-issue-283\/","url_meta":{"origin":490,"position":4},"title":"SRE Weekly Issue #283","date":"August 31, 2021","format":false,"excerpt":"View on sreweekly.com I\u2019m on vacation enjoying the sunny beaches in Maine with my family, so I prepared this week\u2019s issue in advance.\u00a0 No outages section, save for\u00a0one big one I noticed due to direct personal experience.\u00a0 See you all next week! A message from our sponsor, StackHawk: StackHawk is\u2026","rel":"","context":"In &quot;SRE&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":781,"url":"https:\/\/fde.cat\/index.php\/2023\/11\/06\/sre-weekly-issue-397\/","url_meta":{"origin":490,"position":5},"title":"SRE Weekly Issue #397","date":"November 6, 2023","format":false,"excerpt":"View on sreweekly.com A message from our sponsor, FireHydrant: Incident management platform FireHydrant is combining alerting and incident response in one ring-to-retro tool. Sign up for the early access waitlist and be the first to experience the power of alerting + incident response in one platform at last. https:\/\/firehydrant.com\/signals\/ Modern\u2026","rel":"","context":"In &quot;SRE&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/fde.cat\/index.php\/wp-json\/wp\/v2\/posts\/490","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fde.cat\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fde.cat\/index.php\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/fde.cat\/index.php\/wp-json\/wp\/v2\/comments?post=490"}],"version-history":[{"count":0,"href":"https:\/\/fde.cat\/index.php\/wp-json\/wp\/v2\/posts\/490\/revisions"}],"wp:attachment":[{"href":"https:\/\/fde.cat\/index.php\/wp-json\/wp\/v2\/media?parent=490"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fde.cat\/index.php\/wp-json\/wp\/v2\/categories?post=490"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fde.cat\/index.php\/wp-json\/wp\/v2\/tags?post=490"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}