|
| 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@6e7b7d1fd3e4fef0c5fa8cce1229c54b9c9a2fa0 # v0.24.0 |
| 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