Skip to content

Commit 1683d3a

Browse files
committed
ci: Harden workflows
Address the following list of scorecard-detected issues: - https://github.com/urunc-dev/urunc/security/code-scanning/72 - https://github.com/urunc-dev/urunc/security/code-scanning/71 - https://github.com/urunc-dev/urunc/security/code-scanning/3 - https://github.com/urunc-dev/urunc/security/code-scanning/2 - https://github.com/urunc-dev/urunc/security/code-scanning/1 Also, apply security best practices from stepsecurity.io. Signed-off-by: StepSecurity Bot <bot@stepsecurity.io> Signed-off-by: Anastassios Nanos <ananos@nubificus.co.uk>
1 parent 5dfc94a commit 1683d3a

16 files changed

+217
-75
lines changed

.github/workflows/add-git-trailers.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,19 @@ jobs:
2727
run: exit 1
2828

2929
- name: Checkout code
30-
uses: actions/checkout@v4
30+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
3131
with:
3232
fetch-depth: 0
3333
ref: ${{ github.event.pull_request.head.sha }}
3434

3535
- name: Append git trailers
36-
uses: nubificus/git-trailers@feat_use_rebase
36+
uses: nubificus/git-trailers@8e08c91bb4c1fd9cb1ccbd9cc8029c31acf8da66 # feat_use_rebase
3737
with:
3838
user_info: .github/contributors.yaml
3939

4040
- name: Generate urunc-bot token
4141
id: generate-token
42-
uses: actions/create-github-app-token@v2
42+
uses: actions/create-github-app-token@df432ceedc7162793a195dd1713ff69aefc7379e # v2.0.6
4343
with:
4444
app-id: ${{ vars.URUNC_BOT_APP_ID }}
4545
private-key: ${{ secrets.URUNC_BOT_PRIVATE_KEY }}
@@ -50,7 +50,7 @@ jobs:
5050
git config --global user.email "urunc-bot[bot]@users.noreply.github.com"
5151
5252
- name: Append git trailers
53-
uses: nubificus/git-trailers@feat_auto_merge
53+
uses: nubificus/git-trailers@18fd322f3fbfd505b4de728974a4ac1f32f758a7 # feat_auto_merge
5454
with:
5555
user_info: .github/contributors.yaml
5656

.github/workflows/build-latest.yml

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,27 +70,35 @@ jobs:
7070
tags: |
7171
type=sha,prefix=${{ env.ARCH }}-
7272
73-
- name: Get revision SHA and branch
73+
- name: Get revision SHA and branch (safe)
7474
id: get-rev
75+
env:
76+
EVENT_NAME: ${{ github.event_name }}
77+
IS_MERGED: ${{ github.event.pull_request.merged }}
78+
GITHUB_SHA: ${{ github.sha }}
79+
PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }}
80+
PR_HEAD_REF: ${{ github.event.pull_request.head.ref }}
81+
PR_BASE_REF: ${{ github.event.pull_request.base.ref }}
82+
REF_NAME: ${{ github.ref_name }}
7583
run: |
76-
if [ "${{ github.event_name }}" == "pull_request" ]; then
77-
if [ "${{ github.event.pull_request.merged }}" == true ]; then
78-
sha="${{ github.sha }}"
79-
branch="${{ github.base_ref }}"
84+
if [ "$EVENT_NAME" == "pull_request" ]; then
85+
if [ "$IS_MERGED" == "true" ]; then
86+
sha="$GITHUB_SHA"
87+
branch="$PR_BASE_REF"
8088
echo "PR merged. SHA: ${sha}, Branch: ${branch}"
8189
else
82-
sha="${{ github.event.pull_request.head.sha }}"
83-
branch="${{ github.event.pull_request.head.ref }}"
90+
sha="$PR_HEAD_SHA"
91+
branch="$PR_HEAD_REF"
8492
echo "PR not yet merged. SHA: ${sha}, Branch: ${branch}"
8593
fi
8694
else
87-
sha="${{ github.sha }}"
88-
branch="${{ github.ref_name }}"
89-
echo "${{ github.event_name }} event. SHA: ${sha}, Branch: ${branch}"
95+
sha="$GITHUB_SHA"
96+
branch="$REF_NAME"
97+
echo "$EVENT_NAME event. SHA: ${sha}, Branch: ${branch}"
9098
fi
99+
91100
echo "sha=${sha}" >> "$GITHUB_OUTPUT"
92101
echo "branch=${branch}" >> "$GITHUB_OUTPUT"
93-
shell: bash
94102
95103
- name: Build and push urunc-deploy-${{ matrix.arch}}
96104
id: build-and-push

.github/workflows/build-trigger.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
version: ${{ steps.check.outputs.version_changed }}
2525
steps:
2626
- name: Checkout
27-
uses: actions/checkout@v4
27+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
2828

2929
- name: Check if VERSION file changed
3030
id: check

.github/workflows/build.yml

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,9 @@ jobs:
2525
steps:
2626

2727
- name: Checkout code
28-
uses: actions/checkout@v4
29-
with:
30-
ref: ${{ github.event.pull_request.head.sha }}
28+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
3129

32-
- uses: actions/setup-go@v5
30+
- uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
3331
with:
3432
go-version: '1.24.1'
3533
cache: false
@@ -38,30 +36,49 @@ jobs:
3836
run: |
3937
go version
4038
41-
- name: Set ref and repo from PR or dispatch
42-
id: set-ref
39+
- name: Get revision SHA and branch (safe)
40+
id: get-rev
41+
env:
42+
EVENT_NAME: ${{ github.event_name }}
43+
IS_MERGED: ${{ github.event.pull_request.merged }}
44+
GITHUB_SHA: ${{ github.sha }}
45+
PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }}
46+
PR_HEAD_REF: ${{ github.event.pull_request.head.ref }}
47+
PR_BASE_REF: ${{ github.event.pull_request.base.ref }}
48+
REF_NAME: ${{ github.ref_name }}
4349
run: |
44-
if [[ "${{ github.event_name }}" == "pull_request" || "${{ github.event_name }}" == "pull_request_target" ]]; then
45-
echo "ref=${{ github.event.pull_request.head.ref }}" >> "$GITHUB_OUTPUT"
46-
echo "repo=${{ github.event.pull_request.head.repo.full_name }}" >> "$GITHUB_OUTPUT"
50+
if [ "$EVENT_NAME" == "pull_request" ]; then
51+
if [ "$IS_MERGED" == "true" ]; then
52+
sha="$GITHUB_SHA"
53+
branch="$PR_BASE_REF"
54+
echo "PR merged. SHA: ${sha}, Branch: ${branch}"
55+
else
56+
sha="$PR_HEAD_SHA"
57+
branch="$PR_HEAD_REF"
58+
echo "PR not yet merged. SHA: ${sha}, Branch: ${branch}"
59+
fi
4760
else
48-
echo "ref=${{ github.ref_name }}" >> "$GITHUB_OUTPUT"
49-
echo "repo=${{ github.repository }}" >> "$GITHUB_OUTPUT"
61+
sha="$GITHUB_SHA"
62+
branch="$REF_NAME"
63+
echo "$EVENT_NAME event. SHA: ${sha}, Branch: ${branch}"
5064
fi
5165
66+
echo "sha=${sha}" >> "$GITHUB_OUTPUT"
67+
echo "branch=${branch}" >> "$GITHUB_OUTPUT"
68+
5269
- name: Build urunc binaries
5370
id: build-urunc-binaries
5471
run: |
5572
make
5673
5774
- name: Upload urunc_${{ matrix.arch }}
58-
uses: actions/upload-artifact@v4
75+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
5976
with:
6077
name: urunc_${{ matrix.arch }}-${{ github.run_id }}
6178
path: dist/urunc_static_${{ matrix.arch }}
6279

6380
- name: Upload containerd-shim-urunc-v2 artifact
64-
uses: actions/upload-artifact@v4
81+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
6582
with:
6683
name: containerd-shim-urunc-v2_${{ matrix.arch }}-${{ github.run_id }}
6784
path: dist/containerd-shim-urunc-v2_static_${{ matrix.arch }}

.github/workflows/ci_on_push.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,14 @@ jobs:
1919
ok_to_test: ${{ steps.set-vars.outputs.ok_to_test }}
2020
takeover: ${{ steps.set-vars.outputs.takeover }}
2121
steps:
22+
- name: Harden the runner (Audit all outbound calls)
23+
uses: step-security/harden-runner@ec9f2d5744a09debf3a187a3f4f675c53b671911 # v2.13.0
24+
with:
25+
egress-policy: audit
26+
2227
- name: Fetch PR Labels
2328
id: get-labels
24-
uses: actions/github-script@v7
29+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
2530
with:
2631
script: |
2732
const prNumber = context.payload.pull_request.number;

.github/workflows/codeql.yml

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# For most projects, this workflow file will not need changing; you simply need
2+
# to commit it to your repository.
3+
#
4+
# You may wish to alter this file to override the set of languages analyzed,
5+
# or to provide custom queries or build logic.
6+
#
7+
# ******** NOTE ********
8+
# We have attempted to detect the languages in your repository. Please check
9+
# the `language` matrix defined below to confirm you have the correct set of
10+
# supported CodeQL languages.
11+
#
12+
name: "CodeQL"
13+
14+
on:
15+
push:
16+
branches: ["main"]
17+
pull_request:
18+
# The branches below must be a subset of the branches above
19+
branches: ["main"]
20+
schedule:
21+
- cron: "0 0 * * 1"
22+
23+
permissions:
24+
contents: read
25+
26+
jobs:
27+
analyze:
28+
name: Analyze
29+
runs-on: ubuntu-latest
30+
permissions:
31+
actions: read
32+
contents: read
33+
security-events: write
34+
35+
strategy:
36+
fail-fast: false
37+
matrix:
38+
language: ["go", "python"]
39+
# CodeQL supports [ $supported-codeql-languages ]
40+
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support
41+
42+
steps:
43+
- name: Harden the runner (Audit all outbound calls)
44+
uses: step-security/harden-runner@ec9f2d5744a09debf3a187a3f4f675c53b671911 # v2.13.0
45+
with:
46+
egress-policy: audit
47+
48+
- name: Checkout repository
49+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
50+
51+
# Initializes the CodeQL tools for scanning.
52+
- name: Initialize CodeQL
53+
uses: github/codeql-action/init@51f77329afa6477de8c49fc9c7046c15b9a4e79d # v3.29.5
54+
with:
55+
languages: ${{ matrix.language }}
56+
# If you wish to specify custom queries, you can do so here or in a config file.
57+
# By default, queries listed here will override any specified in a config file.
58+
# Prefix the list here with "+" to use these queries and those in the config file.
59+
60+
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
61+
# If this step fails, then you should remove it and run the build manually (see below)
62+
- name: Autobuild
63+
uses: github/codeql-action/autobuild@51f77329afa6477de8c49fc9c7046c15b9a4e79d # v3.29.5
64+
65+
# ℹ️ Command-line programs to run using the OS shell.
66+
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
67+
68+
# If the Autobuild fails above, remove it and uncomment the following three lines.
69+
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.
70+
71+
# - run: |
72+
# echo "Run, Build Application using script"
73+
# ./location_of_script_within_repo/buildscript.sh
74+
75+
- name: Perform CodeQL Analysis
76+
uses: github/codeql-action/analyze@51f77329afa6477de8c49fc9c7046c15b9a4e79d # v3.29.5
77+
with:
78+
category: "/language:${{matrix.language}}"
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Dependency Review Action
2+
#
3+
# This Action will scan dependency manifest files that change as part of a Pull Request,
4+
# surfacing known-vulnerable versions of the packages declared or updated in the PR.
5+
# Once installed, if the workflow run is marked as required,
6+
# PRs introducing known-vulnerable packages will be blocked from merging.
7+
#
8+
# Source repository: https://github.com/actions/dependency-review-action
9+
name: 'Dependency Review'
10+
on: [pull_request]
11+
12+
permissions:
13+
contents: read
14+
15+
jobs:
16+
dependency-review:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Harden the runner (Audit all outbound calls)
20+
uses: step-security/harden-runner@ec9f2d5744a09debf3a187a3f4f675c53b671911 # v2.13.0
21+
with:
22+
egress-policy: audit
23+
24+
- name: 'Checkout Repository'
25+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
26+
- name: 'Dependency Review'
27+
uses: actions/dependency-review-action@da24556b548a50705dd671f47852072ea4c105d9 # v4.7.1

.github/workflows/kind_test.yml

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,7 @@ jobs:
4141
fail-fast: false
4242
steps:
4343
- name: Checkout repository
44-
uses: actions/checkout@v3
45-
with:
46-
ref: ${{ inputs.ref || github.event.pull_request.head.sha }}
47-
48-
- name: Set up Go
49-
uses: actions/setup-go@v4
50-
with:
51-
go-version: '1.24.1'
52-
cache: false
44+
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
5345

5446
- name: Install base dependencies
5547
run: |
@@ -125,13 +117,13 @@ jobs:
125117
'sed -i "s/snapshotter = \"devmapper\"/snapshotter = \"overlayfs\"/g" /etc/containerd/config.toml'
126118
127119
- name: Download urunc artifact
128-
uses: actions/download-artifact@v4
120+
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
129121
with:
130122
name: urunc_${{ matrix.arch }}-${{ github.run_id }}
131123
path: ./artifacts
132124

133125
- name: Download containerd-shim artifact
134-
uses: actions/download-artifact@v4
126+
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
135127
with:
136128
name: containerd-shim-urunc-v2_${{ matrix.arch }}-${{ github.run_id }}
137129
path: ./artifacts

.github/workflows/lint.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ jobs:
2424
continue-on-error: true
2525

2626
steps:
27-
- uses: actions/checkout@v4
27+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
2828
with:
2929
ref: ${{ github.event.pull_request.head.sha }}
30-
- uses: actions/setup-go@v5
30+
- uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
3131
with:
3232
go-version: '1.24.1'
3333
cache: false
3434
- name: golangci-lint
35-
uses: golangci/golangci-lint-action@v3
35+
uses: golangci/golangci-lint-action@3a919529898de77ec3da873e3063ca4b10e7f5cc # v3.7.0
3636
with:
3737
version: v1.64
3838

.github/workflows/pr-merge.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ on:
55
types:
66
- closed
77

8+
permissions:
9+
contents: read
10+
811
jobs:
912
add-trailers-and-merge:
1013
if: |
@@ -21,20 +24,20 @@ jobs:
2124
git config --global user.email "urunc-bot[bot]@users.noreply.github.com"
2225
2326
- name: Check out repo
24-
uses: actions/checkout@v4
27+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
2528
with:
2629
fetch-depth: 0
27-
ref: ${{ github.event.pull_request.base.ref }}
30+
ref: ${{ github.event.pull_request.base.sha }}
2831

2932
- name: Generate urunc-bot token
3033
id: generate-token
31-
uses: actions/create-github-app-token@v2
34+
uses: actions/create-github-app-token@df432ceedc7162793a195dd1713ff69aefc7379e # v2.0.6
3235
with:
3336
app-id: ${{ vars.URUNC_BOT_APP_ID }}
3437
private-key: ${{ secrets.URUNC_BOT_PRIVATE_KEY }}
3538

3639
- name: Append git trailers
37-
uses: nubificus/git-trailers@feat_auto_merge
40+
uses: nubificus/git-trailers@18fd322f3fbfd505b4de728974a4ac1f32f758a7 # feat_auto_merge
3841
with:
3942
user_info: .github/contributors.yaml
4043

0 commit comments

Comments
 (0)