Skip to content

Commit e0418e4

Browse files
committed
Harden GitHub Actions workflows
- Pin all actions to commit SHAs for supply chain security - Set persist-credentials: false on all checkout steps - Pass context expressions via env to prevent script injection - Use explicit remote URL with token for tag push in update-major-tag
1 parent fdaf88f commit e0418e4

File tree

4 files changed

+36
-21
lines changed

4 files changed

+36
-21
lines changed

.github/workflows/docker-publish.yml

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,34 +17,38 @@ jobs:
1717

1818
steps:
1919
- name: Checkout
20-
uses: actions/checkout@v4
20+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
2121
with:
2222
fetch-depth: 0
23+
persist-credentials: false
2324

2425
- name: Determine version
2526
id: version
27+
env:
28+
REF_NAME: ${{ github.ref_name }}
29+
EVENT_NAME: ${{ github.event_name }}
2630
run: |
27-
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
31+
if [ "$EVENT_NAME" = "workflow_dispatch" ]; then
2832
TAG=$(git tag --sort=-version:refname --list 'v*.*' | head -1)
2933
if [ -z "$TAG" ]; then
3034
echo "::error::No version tag found"
3135
exit 1
3236
fi
3337
git checkout "$TAG"
3438
else
35-
TAG="${{ github.ref_name }}"
39+
TAG="$REF_NAME"
3640
fi
3741
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
3842
3943
- name: Set up QEMU
40-
uses: docker/setup-qemu-action@v3
44+
uses: docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130 # v3.7.0
4145

4246
- name: Set up Docker Buildx
43-
uses: docker/setup-buildx-action@v3
47+
uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3.12.0
4448

4549
- name: Extract metadata
4650
id: meta
47-
uses: docker/metadata-action@v5
51+
uses: docker/metadata-action@c299e40c65443455700f0fdfc63efafe5b349051 # v5.10.0
4852
with:
4953
images: ghcr.io/${{ github.repository }}
5054
tags: |
@@ -54,14 +58,14 @@ jobs:
5458
type=raw,value=latest
5559
5660
- name: Login to GHCR
57-
uses: docker/login-action@v3
61+
uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3.7.0
5862
with:
5963
registry: ghcr.io
6064
username: ${{ github.actor }}
6165
password: ${{ secrets.GITHUB_TOKEN }}
6266

6367
- name: Build and push
64-
uses: docker/build-push-action@v6
68+
uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2
6569
env:
6670
DOCKER_BUILD_CHECKS_ANNOTATIONS: true
6771
DOCKER_BUILD_SUMMARY: true

.github/workflows/image-scan.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,17 @@ jobs:
1717
steps:
1818
- name: Checkout
1919
if: github.event_name == 'workflow_dispatch'
20-
uses: actions/checkout@v4
20+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
21+
with:
22+
persist-credentials: false
2123

2224
- name: Set up Docker Buildx
2325
if: github.event_name == 'workflow_dispatch'
24-
uses: docker/setup-buildx-action@v3
26+
uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3.12.0
2527

2628
- name: Build image
2729
if: github.event_name == 'workflow_dispatch'
28-
uses: docker/build-push-action@v6
30+
uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2
2931
env:
3032
DOCKER_BUILD_CHECKS_ANNOTATIONS: false
3133
DOCKER_BUILD_SUMMARY: false
@@ -37,7 +39,7 @@ jobs:
3739

3840
- name: Scan image with Trivy
3941
id: trivy-scan
40-
uses: aquasecurity/trivy-action@0.34.0
42+
uses: aquasecurity/trivy-action@c1824fd6edce30d7ab345a9989de00bbd46ef284 # 0.34.0
4143
with:
4244
image-ref: ${{ github.event_name == 'schedule' && format('ghcr.io/{0}:latest', github.repository) || 'buildcage:scan' }}
4345
ignore-unfixed: true
@@ -47,6 +49,6 @@ jobs:
4749
severity: CRITICAL,HIGH
4850

4951
- name: Upload Trivy scan results to GitHub Security
50-
uses: github/codeql-action/upload-sarif@v4
52+
uses: github/codeql-action/upload-sarif@9e907b5e64f6b83e7804b09294d44122997950d6 # v4.32.3
5153
with:
5254
sarif_file: trivy-results.sarif

.github/workflows/test.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ jobs:
4040

4141
steps:
4242
- name: Checkout
43-
uses: actions/checkout@v4
43+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
44+
with:
45+
persist-credentials: false
4446

4547
- name: Build containers
4648
run: docker compose build
@@ -52,13 +54,13 @@ jobs:
5254
run: docker compose up -d --wait
5355

5456
- name: Set up Docker Buildx
55-
uses: docker/setup-buildx-action@v3
57+
uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3.12.0
5658
with:
5759
driver: remote
5860
endpoint: tcp://localhost:${{ matrix.endpoint_port }}
5961

6062
- name: Build test image
61-
uses: docker/build-push-action@v6
63+
uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2
6264
env:
6365
DOCKER_BUILD_CHECKS_ANNOTATIONS: false
6466
DOCKER_BUILD_SUMMARY: false

.github/workflows/update-major-tag.yml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,28 @@ jobs:
1919
runs-on: ubuntu-latest
2020
steps:
2121
- name: Checkout
22-
uses: actions/checkout@v4
22+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
2323
with:
2424
ref: ${{ inputs.tag || github.ref }}
2525
token: ${{ secrets.GH_PAT_FOR_UPDATE_TAG }}
26+
persist-credentials: false
2627

2728
- name: Extract major version
2829
id: version
30+
env:
31+
TAG: ${{ inputs.tag || github.ref_name }}
2932
run: |
30-
TAG="${{ inputs.tag || github.ref_name }}" # e.g. v1.0.0
31-
MAJOR="${TAG%%.*}" # e.g. v1
33+
MAJOR="${TAG%%.*}"
3234
echo "major=$MAJOR" >> "$GITHUB_OUTPUT"
3335
3436
- name: Update major version tag
37+
env:
38+
MAJOR: ${{ steps.version.outputs.major }}
39+
TAG: ${{ inputs.tag || github.ref_name }}
40+
GH_TOKEN: ${{ secrets.GH_PAT_FOR_UPDATE_TAG }}
3541
run: |
3642
git config user.name "github-actions[bot]"
3743
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
38-
git tag -fa "${{ steps.version.outputs.major }}" -m "Update ${{ steps.version.outputs.major }} to ${{ inputs.tag || github.ref_name }}"
39-
git push origin "${{ steps.version.outputs.major }}" --force
44+
git remote set-url origin "https://x-access-token:${GH_TOKEN}@github.com/${{ github.repository }}"
45+
git tag -fa "$MAJOR" -m "Update $MAJOR to $TAG"
46+
git push origin "$MAJOR" --force

0 commit comments

Comments
 (0)