Skip to content

chore: secure github actions using hash instead of versions #1232

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 4 commits into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/auto-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ jobs:
runs-on: ubuntu-latest
if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' && github.actor == 'dependabot[bot]'
steps:
- uses: actions/checkout@v3
- uses: ahmadnassri/action-workflow-run-wait@v1
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- uses: ahmadnassri/action-workflow-run-wait@2aa3d9e1a12ecaaa9908e368eaf2123bb084323e # v1.4.4
with:
timeout: 300000
- name: 'Download artifact'
uses: actions/[email protected]
uses: actions/github-script@47f7cf65b5ced0830a325f705cad64f2f58dddf7 # v3.1.0
with:
script: |
var artifacts = await github.actions.listWorkflowRunArtifacts({
Expand All @@ -43,7 +43,7 @@ jobs:
fs.writeFileSync('${{github.workspace}}/pr.zip', Buffer.from(download.data));
- run: unzip pr.zip
- name: Create review
uses: actions/github-script@v3
uses: actions/github-script@47f7cf65b5ced0830a325f705cad64f2f58dddf7 # v3.1.0
with:
script: |
var fs = require('fs');
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/build-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ jobs:
docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@bd6b4b6205c4dbad673328db7b31b7fab9e241c0 # v4.6.1
with:
python-version: "3.8"
- name: Capture branch and tag
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,17 @@ jobs:
JAVA: ${{ matrix.java }}
AWS_REGION: eu-west-1
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- name: Setup java
uses: actions/setup-java@v3
uses: actions/setup-java@5ffc13f4174014e2d4d4572b3d74c3fa61aeb2c2 # v3.11.0
with:
distribution: 'corretto'
java-version: ${{ matrix.java }}
cache: 'maven'
- name: Build with Maven
run: mvn -B install --file pom.xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@d9f34f8cd5cb3b3eb79b3e4b5dae3a16df499a70 # 3.1.1
uses: codecov/codecov-action@d9f34f8cd5cb3b3eb79b3e4b5dae3a16df499a70 # v3.1.1
if: ${{ matrix.java == '11' }} # publish results once
with:
files: ./powertools-cloudformation/target/site/jacoco/jacoco.xml,./powertools-core/target/site/jacoco/jacoco.xml,./powertools-idempotency/target/site/jacoco/jacoco.xml,./powertools-logging/target/site/jacoco/jacoco.xml,./powertools-metrics/target/site/jacoco/jacoco.xml,./powertools-parameters/target/site/jacoco/jacoco.xml,./powertools-serialization/target/site/jacoco/jacoco.xml,./powertools-sqs/target/site/jacoco/jacoco.xml,./powertools-tracing/target/site/jacoco/jacoco.xml,./powertools-validation/target/site/jacoco/jacoco.xml
Expand All @@ -77,7 +77,7 @@ jobs:
mkdir -p ./pr
echo ${{ github.event.number }}
echo ${{ github.event.number }} > ./pr/NR
- uses: actions/upload-artifact@v2
- uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2
name: Upload artifact
with:
name: pr
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/dispatch_analytics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
environment: analytics
steps:
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@e1e17a757e536f70e52b5a12b2e8d1d1c60e04ef
uses: aws-actions/configure-aws-credentials@5fd3084fc36e372ff1fff382a39b10d03659f355 # v2.2.0
with:
aws-region: eu-central-1
role-to-assume: ${{ secrets.AWS_ANALYTICS_ROLE_ARN }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ jobs:
runs-on: ubuntu-latest
environment: Docs
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@bd6b4b6205c4dbad673328db7b31b7fab9e241c0 # v4.6.1
with:
python-version: "3.8"
- name: Capture branch and tag
Expand Down
9 changes: 5 additions & 4 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@ jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- name: Set up Maven Central Repository
uses: actions/setup-java@v2
uses: actions/setup-java@5ffc13f4174014e2d4d4572b3d74c3fa61aeb2c2 # v3.11.0
with:
distribution: 'zulu'
distribution: 'corretto'
java-version: 8
server-id: ossrh
server-username: MAVEN_USERNAME
server-password: MAVEN_PASSWORD
# TODO: use environments https://docs.github.com/en/actions/deployment/targeting-different-environments/using-environments-for-deployment
gpg-private-key: ${{ secrets.GPG_SIGNING_KEY }} # Value of the GPG private key to import
gpg-passphrase: GPG_PASSPHRASE # env variable for GPG private key passphrase
- name: Set release notes tag
Expand All @@ -30,7 +31,7 @@ jobs:
MAVEN_PASSWORD: ${{ secrets.OSSRH_JIRA_PASSWORD }}
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
- name: Close issues related to this release
uses: actions/github-script@v5
uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # v6.4.1
with:
script: |
const post_release = require('.github/workflows/post_release.js')
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-drafter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ jobs:
update_release_draft:
runs-on: ubuntu-latest
steps:
- uses: release-drafter/release-drafter@v5
- uses: release-drafter/release-drafter@569eb7ee3a85817ab916c8f8ff03a5bd96c9c83e # v5.23.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
16 changes: 8 additions & 8 deletions .github/workflows/release-prep.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,50 +10,50 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- name: Get current date
id: date
run: echo "::set-output name=date::$(date +'%Y-%m-%d')"
- name: Set current release version env variable
run: |
echo "CURRENT_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)" >> $GITHUB_ENV
- name: Find and Replace ${{ env.CURRENT_VERSION }} with ${{ github.event.inputs.targetRelease }} in mkdocs.yml
uses: jacobtomlinson/gha-find-replace@v2
uses: jacobtomlinson/gha-find-replace@f485fdc3f67a6d87ae6e3d11e41f648c26d7aee3 # v2.0.0
with:
find: 'version: ${{ env.CURRENT_VERSION }}'
replace: 'version: ${{ github.event.inputs.targetRelease }}'
regex: false
include: "mkdocs.yml"
- name: Find and Replace ${{ env.CURRENT_VERSION }} with ${{ github.event.inputs.targetRelease }} in main pom.xml
uses: jacobtomlinson/gha-find-replace@v2
uses: jacobtomlinson/gha-find-replace@f485fdc3f67a6d87ae6e3d11e41f648c26d7aee3 # v2.0.0
with:
find: ${{ env.CURRENT_VERSION }}
replace: ${{ github.event.inputs.targetRelease }}
regex: false
include: "pom.xml"
- name: Find and Replace ${{ env.CURRENT_VERSION }} with ${{ github.event.inputs.targetRelease }} in modules pom.xml
uses: jacobtomlinson/gha-find-replace@v2
uses: jacobtomlinson/gha-find-replace@f485fdc3f67a6d87ae6e3d11e41f648c26d7aee3 # v2.0.0
with:
find: ${{ env.CURRENT_VERSION }}
replace: ${{ github.event.inputs.targetRelease }}
regex: false
include: "**/*pom.xml"
- name: Find and Replace ${{ env.CURRENT_VERSION }} with ${{ github.event.inputs.targetRelease }} in build.gradle
uses: jacobtomlinson/gha-find-replace@v2
uses: jacobtomlinson/gha-find-replace@f485fdc3f67a6d87ae6e3d11e41f648c26d7aee3 # v2.0.0
with:
find: ${{ env.CURRENT_VERSION }}
replace: ${{ github.event.inputs.targetRelease }}
regex: false
include: "**/*build.gradle"
- name: Find and Replace ${{ env.CURRENT_VERSION }} with ${{ github.event.inputs.targetRelease }} in README.md
uses: jacobtomlinson/gha-find-replace@v2
uses: jacobtomlinson/gha-find-replace@f485fdc3f67a6d87ae6e3d11e41f648c26d7aee3 # v2.0.0
with:
find: ${{ env.CURRENT_VERSION }}
replace: ${{ github.event.inputs.targetRelease }}
regex: false
include: "README.md"
- name: Create changelog placeholder for ${{ github.event.inputs.targetRelease }}
uses: jacobtomlinson/gha-find-replace@v2
uses: jacobtomlinson/gha-find-replace@f485fdc3f67a6d87ae6e3d11e41f648c26d7aee3 # v2.0.0
with:
find: '## [Unreleased]'
replace: |
Expand All @@ -66,7 +66,7 @@ jobs:
regex: false
include: CHANGELOG.md
- name: Create Release Pull Request
uses: peter-evans/create-pull-request@v3
uses: peter-evans/create-pull-request@18f7dc018cc2cd597073088f7c7591b9d1c02672 # v3.14.0
with:
commit-message: chore:prep release ${{ github.event.inputs.targetRelease }}
token: ${{ secrets.RELEASE }}
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/run-e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ jobs:
id-token: write # needed to interact with GitHub's OIDC Token endpoint.
contents: read
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- name: Setup java
uses: actions/setup-java@v3
uses: actions/setup-java@5ffc13f4174014e2d4d4572b3d74c3fa61aeb2c2 # v3.11.0
with:
distribution: 'corretto'
java-version: ${{ matrix.java }}
cache: maven
- name: Setup AWS credentials
uses: aws-actions/configure-aws-credentials@v1.6.1
uses: aws-actions/configure-aws-credentials@5fd3084fc36e372ff1fff382a39b10d03659f355 # v2.2.0
with:
role-to-assume: ${{ secrets.AWS_ROLE_ARN_TO_ASSUME }}
aws-region: ${{ env.AWS_DEFAULT_REGION }}
Expand Down
32 changes: 32 additions & 0 deletions .github/workflows/secure_workflows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Lockdown untrusted workflows

# PROCESS
#
# 1. Scans for any external GitHub Action being used without version pinning (@<commit-sha> vs @v3)
# 2. Scans for insecure practices for inline bash scripts (shellcheck)
# 3. Fail CI and prevent PRs to be merged if any malpractice is found

# USAGE
#
# Always triggered on new PR, PR changes and PR merge.


on:
push:
paths:
- ".github/workflows/**"
pull_request:
paths:
- ".github/workflows/**"

jobs:
enforce_pinned_workflows:
name: Harden Security
runs-on: ubuntu-latest
permissions:
contents: read # checkout code and subsequently GitHub action workflows
steps:
- name: Checkout code
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- name: Ensure 3rd party workflows have SHA pinned
uses: zgosalvez/github-actions-ensure-sha-pinned-actions@555a30da2656b4a7cf47b107800bef097723363e # v2.1.3
6 changes: 3 additions & 3 deletions .github/workflows/spotbugs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ jobs:
codecheck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- name: Setup java JDK 1.8
uses: actions/setup-java@v2
uses: actions/setup-java@5ffc13f4174014e2d4d4572b3d74c3fa61aeb2c2 # v3.11.0
with:
distribution: 'zulu'
distribution: 'corretto'
java-version: 8
# https://github.com/jwgmeligmeyling/spotbugs-github-action/issues/6
# https://github.blog/2020-08-03-github-actions-improvements-for-fork-and-pull-request-workflows/
Expand Down