1- name : Security Testing and Analysis
1+ name : Security Validation
2+
23on :
3- push :
4- branches : [main, develop]
54 pull_request :
65 branches : [main, develop]
6+ push :
7+ branches : [main]
78 schedule :
8- # Run security tests daily at 2 AM UTC
9- - cron : ' 0 2 * * *'
10- workflow_dispatch :
11- inputs :
12- full_scan :
13- description : ' Run full security scan including CodeQL'
14- required : false
15- default : false
16- type : boolean
9+ # Run weekly security scan (Sundays at 2 AM UTC)
10+ - cron : ' 0 2 * * 0'
1711
1812jobs :
19- security-tests :
13+ security-audit :
14+ name : Security Audit
2015 runs-on : ubuntu-latest
21-
16+
2217 steps :
2318 - name : Checkout code
2419 uses : actions/checkout@v4
20+ with :
21+ fetch-depth : 0
2522
2623 - name : Set up Go
2724 uses : actions/setup-go@v5
2825 with :
29- go-version : 1.25
30-
31- - name : Download Go module dependencies
32- run : go mod download
33-
34- - name : Run security-focused tests
35- run : |
36- echo "Running security validation tests..."
37- go test -v -run "Security|Validation|Auth" ./pkg/...
26+ go-version : ' 1.25.3'
27+ cache : true
3828
39- - name : Run vulnerability scan with govulncheck
40- continue-on-error : true
29+ - name : Install security tools
4130 run : |
31+ go install github.com/securego/gosec/v2/cmd/gosec@latest
4232 go install golang.org/x/vuln/cmd/govulncheck@latest
43- govulncheck ./...
33+ echo "✓ Security tools installed"
4434
45- - name : Run static security analysis with gosec
35+ - name : Run gosec
4636 run : |
47- go install github.com/securego/gosec/v2/cmd/gosec@latest
48- gosec -fmt json -out gosec-report.json -stdout -verbose ./...
49-
50- - name : Run additional security tools
37+ echo "🔍 Running gosec security scanner..."
38+ gosec -fmt=sarif -out=gosec-results.sarif -severity=medium -confidence=medium ./...
5139 continue-on-error : true
52- run : |
53- # Install and run nancy for dependency vulnerability scanning
54- go install github.com/sonatypecommunity/nancy@latest
55- go list -json -m all | nancy sleuth
56-
57- # Install and run staticcheck for additional static analysis
58- go install honnef.co/go/tools/cmd/staticcheck@latest
59- staticcheck -f json ./... > staticcheck-report.json || true
60-
61- # Install and run semgrep for additional security rules
62- pip install semgrep
63- semgrep --config=auto --json --output=semgrep-report.json . || true
6440
65- - name : Validate security configurations
41+ - name : Run govulncheck
6642 run : |
67- echo "Validating security-related configurations..."
68-
69- # Check for proper file permissions in code
70- echo "Checking for secure file permission patterns..."
71- if grep -r "0777\|0666\|0644.*secret\|0644.*token" --include="*.go" . || true; then
72- echo "Warning: Found potentially insecure file permissions"
73- fi
74-
75- # Check for hardcoded secrets patterns
76- echo "Scanning for potential hardcoded secrets..."
77- go install github.com/trufflesecurity/trufflehog/v3@latest
78- trufflehog filesystem . --json > trufflehog-report.json || true
43+ echo "🔍 Scanning for known vulnerabilities..."
44+ govulncheck ./...
7945
80- - name : Upload security artifacts
81- uses : actions/upload-artifact@v4
82- if : always()
83- with :
84- name : security-reports
85- path : |
86- gosec-report.json
87- staticcheck-report.json
88- semgrep-report.json
89- trufflehog-report.json
90-
91- - name : Security report summary
92- if : always()
46+ - name : Custom Security Checks
9347 run : |
94- echo "## Security Scan Summary" >> $GITHUB_STEP_SUMMARY
95- echo "### GoSec Results" >> $GITHUB_STEP_SUMMARY
96- if [ -f gosec-report.json ]; then
97- issues=$(jq '.Issues | length' gosec-report.json 2>/dev/null || echo "0")
98- echo "- Found $issues potential security issues" >> $GITHUB_STEP_SUMMARY
48+ echo "🔍 Running custom security checks..."
49+ ERRORS=0
50+
51+ echo " ├─ Checking VAULT_SKIP_VERIFY..."
52+ if grep -r "VAULT_SKIP_VERIFY.*1" --include="*.go" --exclude-dir=vendor . | grep -v "handleTLSValidationFailure\|Eos_ALLOW_INSECURE_VAULT\|# P0-2"; then
53+ echo " │ ❌ VAULT_SKIP_VERIFY found"
54+ ERRORS=$((ERRORS + 1))
55+ else
56+ echo " │ ✓ PASS"
9957 fi
100-
101- echo "### Vulnerability Scan Results" >> $GITHUB_STEP_SUMMARY
102- echo "- Dependency vulnerability scan completed" >> $GITHUB_STEP_SUMMARY
103-
104- echo "### Configuration Validation" >> $GITHUB_STEP_SUMMARY
105- echo "- Security configuration checks completed" >> $GITHUB_STEP_SUMMARY
10658
107- file-security-validation :
108- runs-on : ubuntu-latest
109-
110- steps :
111- - name : Checkout code
112- uses : actions/checkout@v4
113-
114- - name : Set up Go
115- uses : actions/setup-go@v5
116- with :
117- go-version : 1.25
118-
119- - name : Download Go module dependencies
120- run : go mod download
121-
122- - name : Test file permission validation
123- run : |
124- echo "Testing file security scenarios..."
125- go test -v -run "FileSecurityScenario" ./integration_scenarios_test.go
126-
127- - name : Validate input sanitization
128- run : |
129- echo "Testing input validation..."
130- go test -v -run "Validation" ./pkg/crypto/...
131-
132- - name : Test error handling security
133- run : |
134- echo "Testing error handling security..."
135- go test -v -run "ErrorHandling" ./integration_scenarios_test.go
136-
137- codeql-integration :
138- runs-on : ubuntu-latest
139- if : github.event.inputs.full_scan == 'true' || github.event_name == 'schedule'
140- permissions :
141- actions : read
142- contents : read
143- security-events : write
144-
145- steps :
146- - name : Checkout code
147- uses : actions/checkout@v4
59+ echo " ├─ Checking InsecureSkipVerify..."
60+ if grep -r "InsecureSkipVerify.*true" --include="*.go" --exclude="*_test.go" --exclude-dir=vendor . | grep -v "TestConfig"; then
61+ echo " │ ❌ InsecureSkipVerify found"
62+ ERRORS=$((ERRORS + 1))
63+ else
64+ echo " │ ✓ PASS"
65+ fi
14866
149- - name : Set up Go
150- uses : actions/setup-go@v5
151- with :
152- go-version : ' 1.25'
153- cache : true
67+ echo " ├─ Checking VAULT_TOKEN env var..."
68+ if grep -r 'fmt\.Sprintf.*VAULT_TOKEN.*%s' --include="*.go" --exclude-dir=vendor . | grep -v "VAULT_TOKEN_FILE\|# P0-1"; then
69+ echo " │ ❌ VAULT_TOKEN env var found"
70+ ERRORS=$((ERRORS + 1))
71+ else
72+ echo " │ ✓ PASS"
73+ fi
15474
155- - name : Initialize CodeQL
156- uses : github/codeql-action/init@v3
157- with :
158- languages : go
159- config-file : ./.github/codeql/codeql-config.yml
160- queries : +security-and-quality,security-experimental
75+ echo " └─ Custom checks complete"
16176
162- - name : Build for CodeQL analysis
163- run : |
164- go build -v ./...
77+ if [ $ERRORS -gt 0 ]; then
78+ echo "❌ Security validation FAILED"
79+ exit 1
80+ fi
81+ echo "✓ All checks passed"
16582
166- - name : Perform CodeQL Analysis
167- uses : github/codeql-action/analyze@v3
83+ - name : Upload SARIF
84+ uses : github/codeql-action/upload-sarif@v3
85+ if : always()
16886 with :
169- category : " /language:go"
170- upload : true
87+ sarif_file : gosec-results.sarif
17188
172- security-baseline :
89+ secret-scanning :
90+ name : Secret Scanning
17391 runs-on : ubuntu-latest
174-
17592 steps :
176- - name : Checkout code
177- uses : actions/checkout@v4
178-
179- - name : Set up Go
180- uses : actions/setup-go@v5
93+ - uses : actions/checkout@v4
18194 with :
182- go-version : ' 1.25'
183-
184- - name : Run security baseline tests
185- run : |
186- echo "Running security baseline validation..."
187-
188- # Test that no test tokens or secrets are committed
189- if find . -name "*.go" -exec grep -l "hvs\." {} \; | grep -v test | head -1; then
190- echo "Error: Found potential vault tokens in non-test code"
191- exit 1
192- fi
193-
194- # Ensure proper logging practices
195- if grep -r "fmt\.Print\|log\.Print" --include="*.go" pkg/ cmd/; then
196- echo "Warning: Found non-structured logging in production code"
197- fi
198-
199- # Check for proper error handling
200- echo "Validating error handling patterns..."
201- go test -v -run "Security" ./pkg/...
95+ fetch-depth : 0
96+ - uses : trufflesecurity/trufflehog@main
97+ with :
98+ path : ./
99+ base : ${{ github.event.repository.default_branch }}
100+ head : HEAD
0 commit comments