Skip to content

Commit c2254ed

Browse files
thpiercejj22ee
authored andcommitted
feat: prevent versioned 3P GitHub actions in PR builds (aws-observability#475)
Add validation step to require commit SHAs instead of version tags for third-party GitHub actions in workflow files. Also fix the one we missed: `aquasecurity/trivy-action` - depending on `master` is pretty unusual and not trivial to catch, ultimately the Repo config `Require actions to be pinned to a full-length commit SHA` will protect against this if we missed any others. ### Testing done * `Python Instrumentation PR Build / static-code-checks (pull_request)` passes * `Check CHANGELOG` fails, causing PR-build to fail, but `Check for versioned GitHub action` passes: https://github.com/aws-observability/aws-otel-python-instrumentation/actions/runs/17924516041/job/50967250100?pr=475 * Added various [`@v` in code](aws-observability@f2f0523), only finds uncommented ones: https://github.com/aws-observability/aws-otel-python-instrumentation/actions/runs/17925754982/job/50971348934?pr=475 ``` Found versioned GitHub actions. Use commit SHAs instead: .github/actions/lambda_artifacts_build/action.yml:30: - uses: actions/checkout@v4 .github/actions/lambda_artifacts_build/action.yml:42: - uses: actions/checkout@v4 #v4 .github/workflows/daily-scan.yml:54: - uses: actions/checkout@v4 #v4 .github/workflows/daily-scan.yml:106: - uses: actions/checkout@v4 ``` By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
1 parent 72dc99a commit c2254ed

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

.github/actions/image_scan/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ runs:
3232
run: docker logout public.ecr.aws
3333

3434
- name: Run Trivy vulnerability scanner on image
35-
uses: aquasecurity/trivy-action@master
35+
uses: aquasecurity/trivy-action@b6643a29fecd7f34b3597bc6acb0a98b03d33ff8 # v0.33.1
3636
with:
3737
image-ref: ${{ inputs.image-ref }}
3838
severity: ${{ inputs.severity }}

.github/workflows/pr-build.yml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@ permissions:
1010
contents: read
1111

1212
jobs:
13-
changelog-check:
13+
static-code-checks:
1414
runs-on: ubuntu-latest
1515
steps:
1616
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 #5.0.0
1717
with:
1818
fetch-depth: 0
1919

2020
- name: Check CHANGELOG
21+
if: always()
2122
run: |
2223
# Check if PR is from workflows bot or dependabot
2324
if [[ "${{ github.event.pull_request.user.login }}" == "aws-application-signals-bot" ]]; then
@@ -46,6 +47,24 @@ jobs:
4647
echo "It looks like you didn't add an entry to CHANGELOG.md. If this change affects the SDK behavior, please update CHANGELOG.md and link this PR in your entry. If this PR does not need a CHANGELOG entry, you can add the 'Skip Changelog' label to this PR."
4748
exit 1
4849
50+
- name: Check for versioned GitHub actions
51+
if: always()
52+
run: |
53+
# Get changed GitHub workflow/action files
54+
CHANGED_FILES=$(git diff --name-only origin/${{ github.base_ref }}..HEAD | grep -E "^\.github/(workflows|actions)/.*\.ya?ml$" || true)
55+
56+
if [ -n "$CHANGED_FILES" ]; then
57+
# Check for any versioned actions, excluding comments and this validation script
58+
VIOLATIONS=$(grep -Hn "uses:.*@v" $CHANGED_FILES | grep -v "grep.*uses:.*@v" | grep -v "#.*@v" || true)
59+
if [ -n "$VIOLATIONS" ]; then
60+
echo "Found versioned GitHub actions. Use commit SHAs instead:"
61+
echo "$VIOLATIONS"
62+
exit 1
63+
fi
64+
fi
65+
66+
echo "No versioned actions found in changed files"
67+
4968
build:
5069
runs-on: ubuntu-latest
5170
strategy:

0 commit comments

Comments
 (0)