Skip to content

Commit 0d05262

Browse files
nddqlakshk98
authored andcommitted
chore(ci): harden CI pipelines and fix devcontainer (microsoft#2060)
## Description Comprehensive CI hardening across all workflow files, devcontainer fixes, and coverage reporting. ### Actions pinned to SHA - Pin all 50+ GitHub Action references to SHA digests with version comments - Bump to latest versions: CodeQL v4.32.3, golangci-lint-action v9.2.0, goreleaser-action v6.4.0, markdownlint-cli2-action v22.0.0, trivy-action 0.34.0, create-pull-request v8.1.0, stale v10.1.1, and others - Eliminates supply chain risk from mutable version tags (including `actions/stale@main`) ### Workflow hardening - **Concurrency groups** added to 8 workflows to cancel duplicate runs - **timeout-minutes** added to all 37 jobs across all workflows - **Explicit permissions** added to workflows missing them (commit-message, test-multicloud, markdownlint, release-validation) - **Permissions reduced** in test.yaml (removed unnecessary issues/pull-requests/security-events write) - **Path filters** added to docs and markdownlint workflows ### Bug fixes - **Trivy**: skip scan when triggering release workflow failed (eliminates ~82% of trivy failures); use latest release tag for scheduled/manual scans instead of HEAD SHA - **Merge queue bypass removed**: golangci-lint and CodeQL now run on merge_group events - **Shell expansion fix**: `$(make version)` and `$(curl ...)` in YAML `with:` blocks don't execute — restructured perf-schedule.yaml with a `get-tag` job and fixed images.yaml perf-test calls - **Release validation**: only runs when triggering workflow succeeded - **Stale outputs**: quoted to prevent injection - **Coverage scripts**: fixed hardcoded `owner = "azure"` → `"microsoft"`, fixed workflow filename `"retina-test.yaml"` → `"test.yaml"`, added guard for empty workflow runs - **Makefile coverage target**: fixed grep pattern that silently failed to filter `_generated.go` files (mixed escaped/unescaped `|` in BRE mode) ### Test coverage reporting - **Step summary**: every test run now posts total coverage percentage and lowest-coverage packages to `$GITHUB_STEP_SUMMARY` - **PR comment**: on pull requests, fetches main branch coverage, diffs it, and posts/updates a coverage comparison comment showing per-file increases/decreases - Handles 403 gracefully for fork PRs (insufficient `GITHUB_TOKEN` permissions) — falls back to step summary - Wires up the existing but disconnected `scripts/coverage/` infrastructure ### GoReleaser - Added `checksum` and `sboms` sections for release artifact integrity ### Devcontainer - Upgraded base image from Ubuntu Jammy (22.04) to Noble (24.04) - Pinned Go version to 1.24.11 (matches go.mod) - Fixed LLVM/Clang from version 14 to 16 (matches project requirements) - Added `clang` and `llvm-strip` symlinks - Installed `gofumpt` (required by `make fmt`) - Added docker readiness check before `kind create cluster` - Hardened install script with `set -euo pipefail` - Removed redundant `common-utils` feature ## Related Issue N/A — proactive hardening based on CI failure analysis. ## Checklist - [x] I have read the [contributing documentation](https://retina.sh/docs/Contributing/overview). - [x] I signed and signed-off the commits (`git commit -S -s ...`). - [x] I have correctly attributed the author(s) of the code. - [x] I have tested the changes locally. - [x] I have followed the project's style guidelines. - [x] I have updated the documentation, if necessary. - [x] I have added tests, if applicable. ## Screenshots (if applicable) or Testing Completed - Verified zero unpinned actions remain (`grep` for `@v\d` and `@main` returns no matches) - Verified zero `IS_NOT_MERGE_GROUP` references remain - Verified all 37 jobs have `timeout-minutes` set - YAML syntax validated across all workflow files Signed-off-by: Quang Nguyen <nguyenquang@microsoft.com>
1 parent 89604a3 commit 0d05262

26 files changed

Lines changed: 327 additions & 99 deletions

.devcontainer/devcontainer.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
{
22
"name": "retina",
3-
"image": "mcr.microsoft.com/devcontainers/base:jammy",
3+
"image": "mcr.microsoft.com/devcontainers/base:noble",
44
"features": {
5-
"ghcr.io/devcontainers/features/common-utils:2": {},
65
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
76
"ghcr.io/devcontainers/features/github-cli:1": {},
8-
"ghcr.io/devcontainers/features/go:1": {},
7+
"ghcr.io/devcontainers/features/go:1": {
8+
"version": "1.24.11"
9+
},
910
"ghcr.io/devcontainers/features/kubectl-helm-minikube:1": {},
10-
"ghcr.io/devcontainers-contrib/features/kind:1": {},
11+
"ghcr.io/devcontainers-extra/features/kind:1": {},
1112
"ghcr.io/devcontainers/features/azure-cli:1": {}
1213
},
13-
"postCreateCommand": "bash .devcontainer/installMoreTools.sh && kind create cluster",
14+
"postCreateCommand": "bash .devcontainer/installMoreTools.sh && while ! docker info >/dev/null 2>&1; do sleep 1; done && kind create cluster",
1415
"customizations": {
1516
"vscode": {
1617
"extensions": [

.devcontainer/installMoreTools.sh

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,25 @@
11
#!/bin/bash
2+
set -euo pipefail
3+
4+
LLVM_VERSION=16
25

36
# Install the required tools and dependencies
4-
sudo apt-get update && sudo apt-get install -y lsb-release wget software-properties-common gnupg clang-14 lldb-14 lld-14 clangd-14 man-db
7+
sudo apt-get update && sudo apt-get install -y \
8+
lsb-release \
9+
wget \
10+
software-properties-common \
11+
gnupg \
12+
man-db
13+
14+
# Install LLVM/Clang (version must match project requirements)
15+
curl -fsSL https://apt.llvm.org/llvm.sh -o /tmp/llvm.sh
16+
chmod +x /tmp/llvm.sh
17+
sudo /tmp/llvm.sh "$LLVM_VERSION"
18+
rm /tmp/llvm.sh
19+
20+
# Create unversioned symlinks so the build system finds clang and llvm-strip
21+
sudo ln -sf "/usr/bin/clang-${LLVM_VERSION}" /usr/bin/clang
22+
sudo ln -sf "/usr/bin/llvm-strip-${LLVM_VERSION}" /usr/bin/llvm-strip
523

6-
# Install LLVM 14
7-
export LLVM_VERSION=14
8-
curl -sL https://apt.llvm.org/llvm.sh | sudo bash -s "$LLVM_VERSION"
24+
# Install gofumpt (used by make fmt)
25+
go install mvdan.cc/gofumpt@latest

.github/workflows/codeql.yaml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ on:
66
branches: [main]
77
pull_request:
88
branches: [main]
9+
10+
permissions:
11+
contents: read
12+
13+
concurrency:
14+
group: ${{ github.workflow }}-${{ github.ref }}
15+
cancel-in-progress: true
16+
917
jobs:
1018
analyze:
1119
name: Analyze
@@ -17,7 +25,6 @@ jobs:
1725
language: [go]
1826
runs-on: ubuntu-latest
1927
env:
20-
IS_NOT_MERGE_GROUP: ${{ github.event_name != 'merge_group' }}
2128
GOOS: ${{ matrix.goos }}
2229
GOARCH: ${{ matrix.goarch }}
2330
timeout-minutes: 90
@@ -27,23 +34,18 @@ jobs:
2734
security-events: write
2835
steps:
2936
- name: Checkout repository
30-
if: env.IS_NOT_MERGE_GROUP
3137
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
3238
- name: Setup go
33-
if: env.IS_NOT_MERGE_GROUP
3439
uses: actions/setup-go@7a3fe6cf4cb3a834922a1244abfce67bcef6a0c5 # v6.2.0
3540
with:
3641
go-version-file: go.mod
3742
- name: Initialize CodeQL
38-
if: env.IS_NOT_MERGE_GROUP
39-
uses: github/codeql-action/init@e296a935590eb16afc0c0108289f68c87e2a89a5 # v4.30.7
43+
uses: github/codeql-action/init@9e907b5e64f6b83e7804b09294d44122997950d6 # v4.32.3
4044
with:
4145
languages: ${{ matrix.language }}
4246
- name: Autobuild
43-
if: env.IS_NOT_MERGE_GROUP
44-
uses: github/codeql-action/autobuild@e296a935590eb16afc0c0108289f68c87e2a89a5 # v4.30.7
47+
uses: github/codeql-action/autobuild@9e907b5e64f6b83e7804b09294d44122997950d6 # v4.32.3
4548
- name: Perform CodeQL Analysis
46-
if: env.IS_NOT_MERGE_GROUP
47-
uses: github/codeql-action/analyze@e296a935590eb16afc0c0108289f68c87e2a89a5 # v4.30.7
49+
uses: github/codeql-action/analyze@9e907b5e64f6b83e7804b09294d44122997950d6 # v4.32.3
4850
with:
4951
category: "/language:${{matrix.language}}"

.github/workflows/commit-message.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,15 @@ on:
88
- synchronize
99
- edited
1010
- reopened
11+
12+
permissions:
13+
contents: read
14+
1115
jobs:
1216
commit-message:
1317
if: ${{ github.event_name != 'merge_group' }}
1418
runs-on: ubuntu-24.04
19+
timeout-minutes: 5
1520
steps:
1621
- name: verify_commit_message
1722
env:

.github/workflows/docs.yaml

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,14 @@ name: Build and Deploy Retina.sh
33
on:
44
push:
55
branches: ["main"]
6+
paths:
7+
- 'site/**'
8+
- 'docs/**'
69
pull_request:
710
branches: ["main"]
11+
paths:
12+
- 'site/**'
13+
- 'docs/**'
814
workflow_dispatch:
915
merge_group:
1016
permissions:
@@ -17,10 +23,11 @@ concurrency:
1723
jobs:
1824
build:
1925
runs-on: ubuntu-latest
26+
timeout-minutes: 15
2027
steps:
2128
- name: Checkout
2229
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
23-
- uses: actions/setup-node@v6
30+
- uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0
2431
with:
2532
node-version: 20
2633
- name: build
@@ -29,20 +36,21 @@ jobs:
2936
npm run build --prefix site/
3037
- name: Upload build artifact
3138
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
32-
uses: actions/upload-pages-artifact@v4
39+
uses: actions/upload-pages-artifact@7b1f4a764d45c48632c6b24a0339c27f5614fb0b # v4.0.0
3340
with:
3441
path: "./site/build"
3542

3643
deploy:
3744
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
3845
needs: build
3946
environment:
40-
name: retina.sh
47+
name: retina.sh
4148
url: ${{ steps.deployment.outputs.page_url }}
4249
runs-on: ubuntu-latest
50+
timeout-minutes: 10
4351
steps:
4452
- name: Setup Pages
45-
uses: actions/configure-pages@v5
53+
uses: actions/configure-pages@983d7736d9b0ae728b81ab479565c72886d7745b # v5.0.0
4654
- name: Deploy to GitHub Pages
4755
id: deployment
48-
uses: actions/deploy-pages@v4
56+
uses: actions/deploy-pages@d6db90164ac5ed86f2b6aed7e0febac5b3c0c03e # v4.0.5

.github/workflows/e2e-test-event-writer.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ jobs:
2020
retina-win-e2e-bpf-images:
2121
name: Build E2E Test Event Writer
2222
runs-on: windows-2022
23+
timeout-minutes: 30
2324

2425
env:
2526
IS_MERGE_GROUP: ${{ (github.event_name == 'merge_group') || (github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/dev/v0.0.33-windows' && github.repository == 'microsoft/retina') }}
@@ -31,4 +32,4 @@ jobs:
3132

3233
steps:
3334
- name: Checkout code
34-
uses: actions/checkout@v6.0.2
35+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2

.github/workflows/e2e.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ jobs:
8383
e2e:
8484
name: E2E
8585
runs-on: ubuntu-latest
86+
timeout-minutes: 120
8687

8788
steps:
8889
- name: Checkout code
@@ -95,7 +96,7 @@ jobs:
9596
- run: go version
9697

9798
- name: Az CLI login
98-
uses: azure/login@v2
99+
uses: azure/login@a457da9ea143d694b1b9c7c869ebb04ebe844ef5 # v2.3.0
99100
with:
100101
client-id: ${{ secrets.AZURE_CLIENT_ID }}
101102
tenant-id: ${{ secrets.AZURE_TENANT_ID }}

.github/workflows/golangci-lint.yaml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ on:
66
branches: [main]
77
pull_request:
88
branches: [main]
9+
10+
permissions:
11+
contents: read
12+
13+
concurrency:
14+
group: ${{ github.workflow }}-${{ github.ref }}
15+
cancel-in-progress: true
16+
917
jobs:
1018
golangci:
1119
strategy:
@@ -15,22 +23,19 @@ jobs:
1523
goarch: ["amd64", "arm64"]
1624
name: Lint
1725
runs-on: ubuntu-latest
26+
timeout-minutes: 30
1827
env:
19-
IS_NOT_MERGE_GROUP: ${{ github.event_name != 'merge_group' }}
2028
GOOS: ${{ matrix.goos }}
2129
GOARCH: ${{ matrix.goarch }}
2230
steps:
2331
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
24-
if: env.IS_NOT_MERGE_GROUP
2532
with:
2633
fetch-depth: 0
2734
- uses: actions/setup-go@7a3fe6cf4cb3a834922a1244abfce67bcef6a0c5 # v6.2.0
28-
if: env.IS_NOT_MERGE_GROUP
2935
with:
3036
go-version-file: go.mod
3137
- name: golangci-lint
32-
if: env.IS_NOT_MERGE_GROUP
33-
uses: golangci/golangci-lint-action@v9
38+
uses: golangci/golangci-lint-action@1e7e51e771db61008b38414a730f564565cf7c20 # v9.2.0
3439
with:
3540
version: latest
3641
args: --concurrency 4 --verbose --config=.golangci.yaml --timeout=25m

.github/workflows/goreleaser.yaml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,21 @@ on:
44
branches: [main]
55
push:
66
tags: ["v*"]
7+
78
permissions:
89
contents: write
910
packages: write
11+
12+
concurrency:
13+
group: ${{ github.workflow }}-${{ github.ref }}
14+
cancel-in-progress: true
15+
1016
jobs:
1117
build:
1218
name: Build kubectl-retina
1319
if: github.ref_type == 'branch'
1420
runs-on: ubuntu-latest
21+
timeout-minutes: 30
1522
steps:
1623
- name: Checkout
1724
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
@@ -22,7 +29,7 @@ jobs:
2229
with:
2330
go-version-file: go.mod
2431
- name: Run GoReleaser build
25-
uses: goreleaser/goreleaser-action@v6
32+
uses: goreleaser/goreleaser-action@e435ccd777264be153ace6237001ef4d979d3a7a # v6.4.0
2633
env:
2734
MCR_AGENT_IMAGE_NAME: mcr.microsoft.com/containernetworking/retina-agent
2835
with:
@@ -32,6 +39,7 @@ jobs:
3239
release:
3340
name: Release kubectl-retina
3441
runs-on: ubuntu-latest
42+
timeout-minutes: 30
3543
if: github.ref_type == 'tag'
3644
steps:
3745
- name: Checkout
@@ -43,7 +51,7 @@ jobs:
4351
with:
4452
go-version-file: go.mod
4553
- name: Run GoReleaser release
46-
uses: goreleaser/goreleaser-action@v6
54+
uses: goreleaser/goreleaser-action@e435ccd777264be153ace6237001ef4d979d3a7a # v6.4.0
4755
with:
4856
distribution: goreleaser
4957
version: latest
@@ -53,4 +61,4 @@ jobs:
5361
MCR_AGENT_IMAGE_NAME: mcr.microsoft.com/containernetworking/retina-agent
5462
- name: Update new version in krew-index
5563
if: github.repository_owner == 'microsoft'
56-
uses: rajatjindal/krew-release-bot@v0.0.47
64+
uses: rajatjindal/krew-release-bot@3d9faef30a82761d610544f62afddca00993eef9 # v0.0.47

0 commit comments

Comments
 (0)