Skip to content

Commit 981dc6c

Browse files
committed
updating guidance on actions usage
1 parent a165c4c commit 981dc6c

1 file changed

Lines changed: 27 additions & 14 deletions

File tree

practices/actions-best-practices.md

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
GitHub Actions is a powerful automation tool that enables CI/CD workflows directly within your GitHub repository. Securing your GitHub Actions workflows is crucial to protect your code, secrets, and infrastructure from potential security threats.
66

7-
This guide outlines best practices for securing your GitHub Actions workflows and minimizing security risks.
7+
This guide outlines best practices for securing your GitHub Actions workflows and minimizing security risks. All actions used in committed workflow definitions must be pinned to a full-length commit SHA.
88

99
## Table of Contents
1010

@@ -40,7 +40,7 @@ jobs:
4040
environment: production
4141
runs-on: ubuntu-latest
4242
steps:
43-
- uses: actions/checkout@v3
43+
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
4444
- name: Deploy
4545
env:
4646
API_TOKEN: ${{ secrets.API_TOKEN }}
@@ -57,7 +57,7 @@ jobs:
5757
5858
### Use Least Privilege Principle
5959
60-
Limit the GitHub token permissions to only what's necessary please [see here](https://docs.github.com/en/actions/security-for-github-actions/security-guides/automatic-token-authentication#permissions-for-the-github_token) for details on the default permissions that the github token is given when the permissions block is not used:
60+
Limit the GitHub token permissions to only what's necessary [see here](https://docs.github.com/en/actions/security-for-github-actions/security-guides/automatic-token-authentication#permissions-for-the-github_token) for details on the default permissions that the github token is given when the permissions block is not used:
6161
6262
```yaml
6363
permissions:
@@ -83,19 +83,32 @@ While third-party actions can significantly enhance the functionality and effici
8383
- *Lack of Maintenance*: Some third-party actions may not be actively maintained, leaving them vulnerable to security issues or compatibility problems with newer GitHub Actions features.
8484
- *Excessive Permissions*: Third-party actions may request more permissions than necessary, potentially exposing sensitive data or allowing unauthorized access to your repository.
8585
86-
To mitigate these risks, always follow best practices, such as pinning actions to specific commit SHAs, reviewing the source code of actions, and using only trusted actions from reputable sources.
86+
To mitigate these risks, all actions must be pinned to specific commit SHAs, reviewed before adoption, and sourced only from trusted publishers.
8787
88-
### Pin Actions to Specific Versions
88+
### Pin All Actions to a Commit SHA
8989
90-
When including a GitHub Action within your workflow you should perform due diligence checks to ensure that the action achieves the aims you are intending it to, and that it doesn't do anything unintended, this would include performing a code review of the GitHub action code. To prevent the underlying code being changed without your awareness always use specific commit SHAs instead of tags or branches as tags can be modified if the upstream repository is compromised:
90+
When including a GitHub Action within your workflow you should perform due diligence checks to ensure that the action achieves the aims you are intending it to, and that it does not do anything unintended, including reviewing the action code where appropriate. Every action reference must use a full-length commit SHA, including GitHub-authored actions, marketplace actions, and internally maintained actions. Do not use tags or branch references in committed workflow definitions because they can move without review or be modified if the upstream repository is compromised:
9191
9292
```yaml
9393
# Not secure - can change unexpectedly
94-
- uses: actions/checkout@v3
95-
# Better - using a specific version tag
96-
- uses: actions/checkout@v3.1.0
97-
# Best - using a specific commit SHA
98-
- uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # v3.1.0
94+
- uses: actions/checkout@v4
95+
# Also not acceptable - tags can be moved
96+
- uses: actions/checkout@v4.1.7
97+
# Required - pin to the full commit SHA and optionally annotate the tag for readability
98+
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
99+
```
100+
101+
If you use automation such as Dependabot to keep actions up to date, enable the `github-actions` ecosystem in `dependabot.yml` and keep the release tag comment on the same line as the pinned SHA so updates continue to track tagged releases.
102+
103+
A minimal Dependabot configuration for GitHub Actions is:
104+
105+
```yaml
106+
version: 2
107+
updates:
108+
- package-ecosystem: "github-actions"
109+
directory: "/"
110+
schedule:
111+
interval: "weekly"
99112
```
100113

101114
### Verify Third-Party Actions
@@ -164,7 +177,7 @@ jobs:
164177
permissions:
165178
contents: read
166179
steps:
167-
- uses: actions/checkout@v3
180+
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
168181
- name: Run tests
169182
run: npm test
170183
```
@@ -189,9 +202,9 @@ jobs:
189202
id-token: write
190203
contents: read
191204
steps:
192-
- uses: actions/checkout@v3
205+
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
193206
- name: Configure AWS credentials
194-
uses: aws-actions/configure-aws-credentials@v1
207+
uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502 # v4.0.2
195208
with:
196209
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/github-actions
197210
aws-region: eu-west-2

0 commit comments

Comments
 (0)