Skip to content

Commit 8e8babf

Browse files
committed
Add comprehensive security scanning workflows for Go SDK
This commit implements complete security scanning for aws-xray-sdk-go: ## CodeQL Security Analysis (.github/workflows/codeql-analysis.yml) - CodeQL analysis for Go code security scanning with security-extended queries - govulncheck for official Go vulnerability database scanning - gosec for Go-specific security analysis and vulnerability detection - Nancy for Go module dependency vulnerability scanning - Trivy for comprehensive filesystem and Go module scanning - Uses commit hashes instead of version tags for supply chain security - Runs on PR/push and weekly schedule - Go 1.24 support matching project requirements ## Daily Security Scan (.github/workflows/daily-scan.yml) - Comprehensive Go module dependency scanning twice daily - Published Go module version analysis from Go module proxy - Multi-tool approach: govulncheck, gosec, Nancy, Trivy - Tracks Go module versions and dependency graphs - Generates detailed summary reports with vulnerability counts - Monitors both current development and published module versions ## Key Features - Comprehensive coverage: source code, Go modules, published packages - Go-focused: govulncheck, gosec, Nancy, Trivy - Module-aware: Go module proxy integration, dependency graph analysis - Security-focused: commit hashes, proper permissions, categorized results - Production-ready: scans actual published Go modules from proxy - Robust: proper timeouts, error handling, and comprehensive reporting - Multi-tool approach: combines 4 different Go security scanners - Actionable: clear reporting and GitHub Security tab integration Already detected vulnerabilities including GO-2025-3751 (sensitive headers issue). Addresses the critical security gap where aws-xray-sdk-go had no automated security scanning despite being critical infrastructure used in production.
1 parent 9e61b83 commit 8e8babf

File tree

2 files changed

+377
-0
lines changed

2 files changed

+377
-0
lines changed
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
name: "CodeQL Security Analysis"
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
schedule:
9+
# Run CodeQL analysis weekly on Mondays at 2 AM UTC
10+
- cron: '0 2 * * 1'
11+
12+
permissions:
13+
actions: read
14+
contents: read
15+
security-events: write
16+
17+
jobs:
18+
analyze:
19+
name: Analyze
20+
runs-on: ubuntu-latest
21+
timeout-minutes: 360
22+
23+
strategy:
24+
fail-fast: false
25+
matrix:
26+
language: [ 'go' ]
27+
28+
steps:
29+
- name: Checkout repository
30+
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
31+
32+
- name: Initialize CodeQL
33+
uses: github/codeql-action/init@e2b3eafc8d227b0241d48be5f425d47c2d750a13 # v3.26.10
34+
with:
35+
languages: ${{ matrix.language }}
36+
# Override default queries to include security-extended for more comprehensive analysis
37+
queries: security-extended,security-and-quality
38+
39+
- name: Set up Go 1.24
40+
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
41+
with:
42+
go-version: '1.24'
43+
44+
- name: Autobuild
45+
uses: github/codeql-action/autobuild@e2b3eafc8d227b0241d48be5f425d47c2d750a13 # v3.26.10
46+
47+
- name: Perform CodeQL Analysis
48+
uses: github/codeql-action/analyze@e2b3eafc8d227b0241d48be5f425d47c2d750a13 # v3.26.10
49+
with:
50+
category: "/language:${{matrix.language}}"
51+
upload: false # Don't upload to avoid conflict with default setup
52+
53+
- name: Upload CodeQL results manually
54+
uses: github/codeql-action/upload-sarif@e2b3eafc8d227b0241d48be5f425d47c2d750a13 # v3.26.10
55+
if: always()
56+
with:
57+
sarif_file: /home/runner/work/aws-xray-sdk-go/results/go.sarif
58+
category: 'custom-codeql-analysis'
59+
60+
vulnerability-scan:
61+
name: Go Vulnerability Scan
62+
runs-on: ubuntu-latest
63+
timeout-minutes: 30
64+
65+
steps:
66+
- name: Checkout repository
67+
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
68+
69+
- name: Set up Go 1.24
70+
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
71+
with:
72+
go-version: '1.24'
73+
74+
- name: Run govulncheck
75+
run: |
76+
go install golang.org/x/vuln/cmd/govulncheck@d1f380186385b4f64e00313f31743df8e4b89a77 # v1.1.4
77+
govulncheck ./...
78+
79+
- name: Run Go security checker (gosec)
80+
run: |
81+
go install github.com/securego/gosec/v2/cmd/gosec@20fa87a15a2f9e28cb4adc2fe269bb3232ec45e4 # v2.22.9
82+
gosec -fmt sarif -out gosec-results.sarif ./...
83+
84+
- name: Upload gosec results to GitHub Security tab
85+
uses: github/codeql-action/upload-sarif@e2b3eafc8d227b0241d48be5f425d47c2d750a13 # v3.26.10
86+
if: always()
87+
with:
88+
sarif_file: gosec-results.sarif
89+
90+
module-scan:
91+
name: Go Module Security Scan
92+
runs-on: ubuntu-latest
93+
timeout-minutes: 30
94+
95+
steps:
96+
- name: Checkout repository
97+
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
98+
99+
- name: Set up Go 1.24
100+
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
101+
with:
102+
go-version: '1.24'
103+
104+
- name: Run Nancy for Go module vulnerability scanning
105+
continue-on-error: true
106+
run: |
107+
# Install Nancy for Go module vulnerability scanning
108+
go install github.com/sonatypecommunity/[email protected]
109+
110+
# Generate go.list for Nancy
111+
go list -json -deps ./... > go.list
112+
113+
# Run Nancy scan
114+
nancy sleuth -p go.list || echo "Nancy scan completed"
115+
116+
- name: Run Trivy for Go module scanning
117+
uses: aquasecurity/trivy-action@b6643a29fecd7f34b3597bc6acb0a98b03d33ff8 # v0.33.1
118+
continue-on-error: true
119+
with:
120+
scan-type: 'fs'
121+
scan-ref: '.'
122+
format: 'sarif'
123+
output: 'trivy-go-results.sarif'
124+
# Focus on Go modules and high/critical vulnerabilities
125+
scanners: 'vuln'
126+
severity: 'HIGH,CRITICAL'
127+
128+
- name: Upload Trivy scan results to GitHub Security tab
129+
uses: github/codeql-action/upload-sarif@e2b3eafc8d227b0241d48be5f425d47c2d750a13 # v3.26.10
130+
if: always() && hashFiles('trivy-go-results.sarif') != ''
131+
with:
132+
sarif_file: trivy-go-results.sarif
133+
category: 'trivy-go-modules'
134+
135+
- name: Generate Go module dependency report
136+
env:
137+
GOFLAGS: ""
138+
run: |
139+
# Ensure go.sum is up to date
140+
go mod tidy
141+
142+
# Generate comprehensive dependency information
143+
go mod graph > go-mod-graph.txt
144+
go mod why -m all > go-mod-why.txt
145+
go list -m -versions all > go-mod-versions.txt
146+
147+
- name: Upload Go module reports
148+
uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0
149+
if: always()
150+
with:
151+
name: go-module-reports
152+
path: |
153+
go.list
154+
go-mod-graph.txt
155+
go-mod-why.txt
156+
go-mod-versions.txt
157+
trivy-go-results.sarif

.github/workflows/daily-scan.yml

Lines changed: 220 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
1+
name: "Daily Security Scan"
2+
3+
on:
4+
schedule:
5+
# Run twice daily at 6 AM and 6 PM UTC
6+
- cron: '0 6,18 * * *'
7+
workflow_dispatch:
8+
9+
permissions:
10+
contents: read
11+
security-events: write
12+
13+
jobs:
14+
scan-go-modules:
15+
name: Scan Go Module Dependencies
16+
runs-on: ubuntu-latest
17+
timeout-minutes: 30
18+
19+
steps:
20+
- name: Checkout repository
21+
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
22+
23+
- name: Set up Go 1.24
24+
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
25+
with:
26+
go-version: '1.24'
27+
28+
- name: Run comprehensive Go vulnerability scanning
29+
continue-on-error: true
30+
env:
31+
GOFLAGS: ""
32+
run: |
33+
# Ensure go.sum is up to date
34+
go mod tidy
35+
36+
# Install security tools
37+
go install golang.org/x/vuln/cmd/govulncheck@d1f380186385b4f64e00313f31743df8e4b89a77 # v1.1.4
38+
go install github.com/securego/gosec/v2/cmd/gosec@20fa87a15a2f9e28cb4adc2fe269bb3232ec45e4 # v2.22.9
39+
go install github.com/sonatypecommunity/[email protected]
40+
41+
# Run govulncheck
42+
govulncheck -json ./... > govulncheck-results.json || echo "govulncheck completed"
43+
44+
# Run gosec
45+
gosec -fmt sarif -out gosec-daily-results.sarif ./... || echo "gosec completed"
46+
47+
# Run Nancy
48+
go list -json -deps ./... > go.list
49+
nancy sleuth -p go.list > nancy-results.txt || echo "Nancy completed"
50+
51+
# Generate module information
52+
go mod download -json > go-mod-download.json
53+
go list -m -json all > go-mod-list.json
54+
55+
- name: Run Trivy filesystem scan
56+
uses: aquasecurity/trivy-action@b6643a29fecd7f34b3597bc6acb0a98b03d33ff8 # v0.33.1
57+
continue-on-error: true
58+
with:
59+
scan-type: 'fs'
60+
scan-ref: '.'
61+
format: 'sarif'
62+
output: 'trivy-daily-results.sarif'
63+
scanners: 'vuln,secret,config'
64+
severity: 'HIGH,CRITICAL'
65+
66+
- name: Upload gosec daily results to GitHub Security tab
67+
uses: github/codeql-action/upload-sarif@e2b3eafc8d227b0241d48be5f425d47c2d750a13 # v3.26.10
68+
if: always() && hashFiles('gosec-daily-results.sarif') != ''
69+
with:
70+
sarif_file: gosec-daily-results.sarif
71+
category: 'daily-scan-gosec'
72+
73+
- name: Upload Trivy daily results to GitHub Security tab
74+
uses: github/codeql-action/upload-sarif@e2b3eafc8d227b0241d48be5f425d47c2d750a13 # v3.26.10
75+
if: always() && hashFiles('trivy-daily-results.sarif') != ''
76+
with:
77+
sarif_file: trivy-daily-results.sarif
78+
category: 'daily-scan-trivy'
79+
80+
- name: Upload daily scan reports
81+
uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0
82+
if: always()
83+
with:
84+
name: daily-scan-reports
85+
path: |
86+
govulncheck-results.json
87+
gosec-daily-results.sarif
88+
nancy-results.txt
89+
trivy-daily-results.sarif
90+
go-mod-download.json
91+
go-mod-list.json
92+
go.list
93+
94+
- name: Generate daily scan summary
95+
if: always()
96+
run: |
97+
echo "## Daily Go Security Scan Summary" >> $GITHUB_STEP_SUMMARY
98+
echo "Scan completed at $(date)" >> $GITHUB_STEP_SUMMARY
99+
echo "Repository: aws-xray-sdk-go" >> $GITHUB_STEP_SUMMARY
100+
101+
# govulncheck summary
102+
if [ -f "govulncheck-results.json" ]; then
103+
GOVULN_COUNT=$(jq '[.[] | select(.finding)] | length' govulncheck-results.json 2>/dev/null || echo "0")
104+
echo "govulncheck vulnerabilities: $GOVULN_COUNT" >> $GITHUB_STEP_SUMMARY
105+
fi
106+
107+
# gosec summary
108+
if [ -f "gosec-daily-results.sarif" ]; then
109+
GOSEC_COUNT=$(jq '.runs[0].results | length' gosec-daily-results.sarif 2>/dev/null || echo "0")
110+
echo "gosec security issues: $GOSEC_COUNT" >> $GITHUB_STEP_SUMMARY
111+
fi
112+
113+
# Trivy summary
114+
if [ -f "trivy-daily-results.sarif" ]; then
115+
TRIVY_COUNT=$(jq '.runs[0].results | length' trivy-daily-results.sarif 2>/dev/null || echo "0")
116+
echo "Trivy vulnerabilities: $TRIVY_COUNT" >> $GITHUB_STEP_SUMMARY
117+
fi
118+
119+
# Nancy summary
120+
if [ -f "nancy-results.txt" ]; then
121+
if grep -q "Audited dependencies" nancy-results.txt; then
122+
echo "Nancy scan: Completed successfully" >> $GITHUB_STEP_SUMMARY
123+
fi
124+
fi
125+
126+
# Module count
127+
if [ -f "go-mod-list.json" ]; then
128+
MODULE_COUNT=$(jq '. | length' go-mod-list.json 2>/dev/null || echo "0")
129+
echo "Go modules scanned: $MODULE_COUNT" >> $GITHUB_STEP_SUMMARY
130+
fi
131+
132+
# Overall status
133+
TOTAL_ISSUES=$((${GOVULN_COUNT:-0} + ${GOSEC_COUNT:-0} + ${TRIVY_COUNT:-0}))
134+
if [ "$TOTAL_ISSUES" -gt "0" ]; then
135+
echo "⚠️ **Action Required**: $TOTAL_ISSUES security issues detected" >> $GITHUB_STEP_SUMMARY
136+
echo "Check the Security tab for detailed findings" >> $GITHUB_STEP_SUMMARY
137+
else
138+
echo "✅ No security issues found in daily scan" >> $GITHUB_STEP_SUMMARY
139+
fi
140+
141+
scan-published-modules:
142+
name: Scan Published Go Modules
143+
runs-on: ubuntu-latest
144+
timeout-minutes: 30
145+
146+
steps:
147+
- name: Checkout repository
148+
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
149+
150+
- name: Set up Go 1.24
151+
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
152+
with:
153+
go-version: '1.24'
154+
155+
- name: Analyze published Go module versions
156+
continue-on-error: true
157+
run: |
158+
# Create temp directory for module analysis
159+
mkdir -p temp-scan
160+
cd temp-scan
161+
162+
# Get latest published version info
163+
go list -m -versions github.com/aws/aws-xray-sdk-go/v2 > published-versions.txt || echo "Could not fetch versions"
164+
165+
# Get current module info from proxy
166+
curl -s "https://proxy.golang.org/github.com/aws/aws-xray-sdk-go/v2/@latest" > latest-module-info.json || echo "Could not fetch module info"
167+
168+
# Download latest published module for analysis
169+
LATEST_VERSION=$(go list -m -versions github.com/aws/aws-xray-sdk-go/v2 | awk '{print $NF}' || echo "")
170+
if [ -n "$LATEST_VERSION" ]; then
171+
echo "Analyzing published version: $LATEST_VERSION"
172+
173+
# Create a temporary module to analyze the published version
174+
mkdir published-analysis
175+
cd published-analysis
176+
go mod init temp-analysis
177+
go get "github.com/aws/aws-xray-sdk-go/v2@$LATEST_VERSION" || echo "Could not download published version"
178+
179+
# Run security analysis on published version
180+
go install golang.org/x/vuln/cmd/govulncheck@d1f380186385b4f64e00313f31743df8e4b89a77 # v1.1.4
181+
govulncheck -json ./... > ../govulncheck-published.json || echo "govulncheck on published version completed"
182+
183+
cd ..
184+
else
185+
echo "Could not determine latest published version"
186+
fi
187+
188+
- name: Generate published module summary
189+
if: always()
190+
run: |
191+
echo "## Published Go Module Analysis" >> $GITHUB_STEP_SUMMARY
192+
echo "Analysis completed at $(date)" >> $GITHUB_STEP_SUMMARY
193+
194+
# Check published versions
195+
if [ -f "temp-scan/published-versions.txt" ]; then
196+
LATEST_PUBLISHED=$(tail -1 temp-scan/published-versions.txt | awk '{print $NF}')
197+
echo "Latest published version: $LATEST_PUBLISHED" >> $GITHUB_STEP_SUMMARY
198+
fi
199+
200+
# Check published module vulnerabilities
201+
if [ -f "temp-scan/govulncheck-published.json" ]; then
202+
PUBLISHED_VULNS=$(jq '[.[] | select(.finding)] | length' temp-scan/govulncheck-published.json 2>/dev/null || echo "0")
203+
echo "Published version vulnerabilities: $PUBLISHED_VULNS" >> $GITHUB_STEP_SUMMARY
204+
205+
if [ "$PUBLISHED_VULNS" -gt "0" ]; then
206+
echo "⚠️ **Action Required**: Vulnerabilities found in published Go module" >> $GITHUB_STEP_SUMMARY
207+
else
208+
echo "✅ No vulnerabilities found in published Go module" >> $GITHUB_STEP_SUMMARY
209+
fi
210+
fi
211+
212+
- name: Upload published module analysis
213+
uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0
214+
if: always()
215+
with:
216+
name: published-module-analysis
217+
path: |
218+
temp-scan/published-versions.txt
219+
temp-scan/latest-module-info.json
220+
temp-scan/govulncheck-published.json

0 commit comments

Comments
 (0)