Skip to content

Commit bfe30f1

Browse files
authored
ci: pinned commit shas to github workflows (#1770)
1 parent bb5d676 commit bfe30f1

File tree

9 files changed

+152
-31
lines changed

9 files changed

+152
-31
lines changed

.github/workflows/codeql-analysis.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,16 @@ jobs:
4444
with:
4545
egress-policy: audit
4646
- name: Checkout repository
47-
uses: actions/checkout@v4
47+
uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4
4848

4949
- name: Setup go
50-
uses: actions/setup-go@v5
50+
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5
5151
with:
5252
go-version-file: go.mod
5353

5454
# Initializes the CodeQL tools for scanning.
5555
- name: Initialize CodeQL
56-
uses: github/codeql-action/init@v3
56+
uses: github/codeql-action/init@d6bbdef45e766d081b84a2def353b0055f728d3e # v3.29.3
5757
with:
5858
languages: ${{ matrix.language }}
5959
# If you wish to specify custom queries, you can do so here or in a config file.
@@ -64,7 +64,7 @@ jobs:
6464
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
6565
# If this step fails, then you should remove it and run the build manually (see below)
6666
- name: Autobuild
67-
uses: github/codeql-action/autobuild@v3
67+
uses: github/codeql-action/autobuild@d6bbdef45e766d081b84a2def353b0055f728d3e # v3.29.3
6868

6969
# ℹ️ Command-line programs to run using the OS shell.
7070
# 📚 https://git.io/JvXDl
@@ -78,4 +78,4 @@ jobs:
7878
# make release
7979

8080
- name: Perform CodeQL Analysis
81-
uses: github/codeql-action/analyze@v3
81+
uses: github/codeql-action/analyze@d6bbdef45e766d081b84a2def353b0055f728d3e # v3.29.3

.github/workflows/integration-enterprise.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ jobs:
4343
with:
4444
egress-policy: audit
4545
- name: Checkout repository
46-
uses: actions/checkout@v4
46+
uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4
4747
- name: Setup go
48-
uses: actions/setup-go@v5
48+
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5
4949
with:
5050
go-version-file: go.mod
5151
- name: Login to Docker Hub
52-
uses: docker/login-action@v3
52+
uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef
5353
with:
5454
username: ${{secrets.DOCKERHUB_PULL_USERNAME}}
5555
password: ${{secrets.DOCKERHUB_PULL_TOKEN}}

.github/workflows/integration-konnect.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ jobs:
2626
with:
2727
egress-policy: audit
2828
- name: Checkout repository
29-
uses: actions/checkout@v4
29+
uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4
3030
- name: Setup go
31-
uses: actions/setup-go@v5
31+
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5
3232
with:
3333
go-version-file: go.mod
3434
- name: Run integration tests

.github/workflows/integration.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ jobs:
3636
with:
3737
egress-policy: audit
3838
- name: Checkout repository
39-
uses: actions/checkout@v4
39+
uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4
4040
- name: Setup go
41-
uses: actions/setup-go@v5
41+
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5
4242
with:
4343
go-version-file: go.mod
4444
- name: Setup Kong

.github/workflows/release.yaml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ jobs:
1717
with:
1818
egress-policy: audit
1919
- name: Checkout
20-
uses: actions/checkout@v4
20+
uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4
2121
with:
2222
fetch-depth: 0
2323
- name: Set up Go
24-
uses: actions/setup-go@v5
24+
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5
2525
with:
2626
go-version-file: go.mod
2727
- name: Run GoReleaser
28-
uses: goreleaser/goreleaser-action@v6
28+
uses: goreleaser/goreleaser-action@e435ccd777264be153ace6237001ef4d979d3a7a # v6
2929
with:
3030
# either 'goreleaser' (default) or 'goreleaser-pro'
3131
distribution: goreleaser
@@ -34,7 +34,7 @@ jobs:
3434
env:
3535
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3636
- name: Upload assets
37-
uses: actions/upload-artifact@v4
37+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
3838
with:
3939
name: dist
4040
path: dist/*
@@ -56,22 +56,22 @@ jobs:
5656
echo 'type=semver,pattern={{raw}}' >> $GITHUB_ENV
5757
echo 'EOF' >> $GITHUB_ENV
5858
- name: Set up Docker Buildx
59-
uses: docker/setup-buildx-action@v3
59+
uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3
6060
- name: Cache Docker layers
61-
uses: actions/cache@v4
61+
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4
6262
with:
6363
path: /tmp/.buildx-cache
6464
key: ${{ runner.os }}-buildx-${{ github.sha }}
6565
restore-keys: |
6666
${{ runner.os }}-buildx-
6767
- name: Login to DockerHub
68-
uses: docker/login-action@v3
68+
uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef
6969
with:
7070
username: ${{ secrets.DOCKER_USERNAME_JAN_2025 }}
7171
password: ${{ secrets.DOCKER_TOKEN_JAN_2025 }}
7272
- name: Docker meta
7373
id: meta
74-
uses: docker/metadata-action@v5.7.0
74+
uses: docker/metadata-action@902fa8ec7d6ecbf8d84d538b9b233a880e428804 # v5.7.0
7575
with:
7676
images: kong/deck
7777
tags: ${{ env.TAGS_STANDARD }}${{ env.TAGS_SUPPLEMENTAL }}
@@ -80,7 +80,7 @@ jobs:
8080
- name: Build and push
8181
timeout-minutes: 120
8282
id: docker_build
83-
uses: docker/build-push-action@v6
83+
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6
8484
with:
8585
push: true
8686
file: Dockerfile

.github/workflows/security.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
on: push
2+
3+
name: Security
4+
5+
jobs:
6+
ensure-pinned-actions:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- name: Harden Runner
10+
uses: step-security/harden-runner@f4a75cfd619ee5ce8d5b864b0d183aff3c69b55a # v2.13.1
11+
with:
12+
egress-policy: audit
13+
- name: Checkout code
14+
uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4
15+
- name: Ensure SHA pinned actions
16+
uses: zgosalvez/github-actions-ensure-sha-pinned-actions@fc87bb5b5a97953d987372e74478de634726b3e5 # v3
17+
with:
18+
allowlist: |
19+
Kong/

.github/workflows/test.yaml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ jobs:
2121
uses: step-security/harden-runner@c6295a65d1254861815972266d5933fd6e532bdf # v2.11.1
2222
with:
2323
egress-policy: audit
24-
- uses: actions/checkout@v4
25-
- uses: actions/setup-go@v5
24+
- uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4
25+
- uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5
2626
with:
2727
go-version-file: go.mod
2828
- name: Run tests with Coverage
2929
run: make coverage
3030
- name: Upload Code Coverage
31-
uses: codecov/codecov-action@v5
31+
uses: codecov/codecov-action@5a1091511ad55cbe89839c7260b706298ca349f7 # v5
3232
with:
3333
name: codecov-deck
3434
token: ${{ secrets.CODECOV_TOKEN }}
@@ -42,11 +42,11 @@ jobs:
4242
uses: step-security/harden-runner@c6295a65d1254861815972266d5933fd6e532bdf # v2.11.1
4343
with:
4444
egress-policy: audit
45-
- uses: actions/checkout@v4
46-
- uses: actions/setup-go@v5
45+
- uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4
46+
- uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5
4747
with:
4848
go-version-file: go.mod
49-
- uses: golangci/golangci-lint-action@v6.2.0
49+
- uses: golangci/golangci-lint-action@ec5d18412c0aeab7936cb16880d708ba2a64e1ae # v6.2.0
5050

5151
build:
5252
timeout-minutes: ${{ fromJSON(vars.GHA_DEFAULT_TIMEOUT) }}
@@ -56,8 +56,8 @@ jobs:
5656
uses: step-security/harden-runner@c6295a65d1254861815972266d5933fd6e532bdf # v2.11.1
5757
with:
5858
egress-policy: audit
59-
- uses: actions/checkout@v4
60-
- uses: actions/setup-go@v5
59+
- uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4
60+
- uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5
6161
with:
6262
go-version-file: go.mod
6363
- name: Build

.github/workflows/validate-kong-release.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ jobs:
3030
echo "Kong Gateway Image = ${{ inputs.kong_image }}"
3131
echo "decK Branch = ${{ inputs.branch }}"
3232
- name: Checkout repository
33-
uses: actions/checkout@v4
33+
uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4
3434
with:
3535
ref: ${{ inputs.branch }}
3636
- name: Setup go
37-
uses: actions/setup-go@v5
37+
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5
3838
with:
3939
go-version-file: go.mod
4040
- uses: Kong/kong-license@master

scripts/get-action-commit-shas.sh

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
#!/bin/bash
2+
3+
# Script to get commit SHAs for GitHub Actions
4+
# Usage: ./get-action-commit-shas.sh
5+
6+
set -e
7+
8+
# Colors for output
9+
RED='\033[0;31m'
10+
GREEN='\033[0;32m'
11+
YELLOW='\033[1;33m'
12+
NC='\033[0m' # No Color
13+
14+
echo -e "${YELLOW}Fetching commit SHAs for GitHub Actions...${NC}"
15+
echo
16+
17+
# Function to get commit SHA for a GitHub action
18+
get_commit_sha() {
19+
local action_ref=$1
20+
local repo=$(echo $action_ref | cut -d'@' -f1)
21+
local tag_or_sha=$(echo $action_ref | cut -d'@' -f2)
22+
23+
# Skip if already a commit SHA (40 characters)
24+
if [[ ${#tag_or_sha} -eq 40 ]]; then
25+
echo -e "${GREEN}$action_ref${NC} (already pinned)"
26+
return
27+
fi
28+
29+
# Skip master/main branches for now
30+
if [[ "$tag_or_sha" == "master" || "$tag_or_sha" == "main" ]]; then
31+
echo -e "${YELLOW}$action_ref${NC} (branch reference - consider pinning)"
32+
return
33+
fi
34+
35+
echo -n "Fetching SHA for $repo@$tag_or_sha... "
36+
37+
# Try multiple GitHub API endpoints to get the commit SHA
38+
local sha=""
39+
40+
# First try as a tag reference
41+
local api_url="https://api.github.com/repos/$repo/git/refs/tags/$tag_or_sha"
42+
local response=$(curl -s -w "%{http_code}" "$api_url" 2>/dev/null)
43+
local http_code="${response: -3}"
44+
local body="${response%???}"
45+
46+
if [[ "$http_code" == "200" ]]; then
47+
sha=$(echo "$body" | python3 -c "import sys, json; data=json.load(sys.stdin); print(data['object']['sha'] if data['object']['type'] == 'commit' else '')" 2>/dev/null)
48+
if [[ -z "$sha" ]]; then
49+
# It's a tag object, get the commit it points to
50+
local tag_sha=$(echo "$body" | python3 -c "import sys, json; data=json.load(sys.stdin); print(data['object']['sha'])" 2>/dev/null)
51+
if [[ -n "$tag_sha" ]]; then
52+
local tag_response=$(curl -s "https://api.github.com/repos/$repo/git/tags/$tag_sha" 2>/dev/null)
53+
sha=$(echo "$tag_response" | python3 -c "import sys, json; data=json.load(sys.stdin); print(data['object']['sha'])" 2>/dev/null)
54+
fi
55+
fi
56+
fi
57+
58+
# If tag approach didn't work, try as a branch/commit reference
59+
if [[ -z "$sha" ]]; then
60+
api_url="https://api.github.com/repos/$repo/commits/$tag_or_sha"
61+
response=$(curl -s -w "%{http_code}" "$api_url" 2>/dev/null)
62+
http_code="${response: -3}"
63+
body="${response%???}"
64+
65+
if [[ "$http_code" == "200" ]]; then
66+
sha=$(echo "$body" | python3 -c "import sys, json; data=json.load(sys.stdin); print(data['sha'])" 2>/dev/null)
67+
fi
68+
fi
69+
70+
if [[ -n "$sha" && ${#sha} -eq 40 ]]; then
71+
echo -e "${GREEN}${NC}"
72+
echo " $repo@$sha # $tag_or_sha"
73+
else
74+
echo -e "${RED}✗ (could not fetch SHA)${NC}"
75+
echo -e " ${YELLOW}Manual lookup: https://github.com/$repo/releases/tag/$tag_or_sha${NC}"
76+
fi
77+
}
78+
79+
# Extract all GitHub Actions from workflow files
80+
echo "Scanning workflow files for GitHub Actions..."
81+
echo
82+
83+
# Find all unique action references
84+
actions=$(grep -h "uses:" .github/workflows/*.yaml | \
85+
sed 's/.*uses: *//' | \
86+
sed 's/ *#.*//' | \
87+
sort -u)
88+
89+
echo "Found the following actions:"
90+
echo "$actions"
91+
echo
92+
echo "Fetching commit SHAs:"
93+
echo
94+
95+
# Process each action
96+
while IFS= read -r action; do
97+
get_commit_sha "$action"
98+
done <<< "$actions"
99+
100+
echo
101+
echo -e "${YELLOW}Note: You can copy the output above to update your workflow files.${NC}"
102+
echo -e "${YELLOW}Remember to also update the comment with the version tag.${NC}"

0 commit comments

Comments
 (0)