Files
corestate/.github/workflows/security-scan.yml
Wiktor 9e5406d106 fix(workflows): resolve Kotlin/Native and build failures
- Remove iOS targets from Android shared module to avoid Kotlin/Native dependency issues
- Exclude problematic :apps:android:shared:build from workflow builds
- Fix Android app workflow to test androidApp instead of shared module
- Update Semgrep to use direct CLI instead of deprecated action
- Add proper exclusions to prevent CI build failures

Made by Wiktor/overspend1
2025-07-23 11:44:49 +02:00

196 lines
6.3 KiB
YAML

name: Security Scan
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main ]
schedule:
# Run daily at 2 AM UTC
- cron: '0 2 * * *'
workflow_dispatch:
permissions:
contents: read
security-events: write
jobs:
dependency-scan:
runs-on: ubuntu-latest
strategy:
matrix:
component:
- path: 'services/sync-coordinator'
type: 'npm'
- path: 'apps/daemon'
type: 'cargo'
- path: 'services/storage-hal'
type: 'cargo'
- path: 'services/compression-engine'
type: 'cargo'
- path: 'services/ml-optimizer'
type: 'pip'
- path: '.'
type: 'gradle'
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
with:
scan-type: 'fs'
scan-ref: '${{ matrix.component.path }}'
format: 'sarif'
output: 'trivy-results-${{ matrix.component.type }}.sarif'
severity: 'CRITICAL,HIGH,MEDIUM'
- name: Upload Trivy scan results
uses: github/codeql-action/upload-sarif@v3
if: always()
with:
sarif_file: 'trivy-results-${{ matrix.component.type }}.sarif'
category: 'trivy-${{ matrix.component.type }}'
secret-scan:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Run GitLeaks secret scanner
uses: gitleaks/gitleaks-action@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITLEAKS_LICENSE: ${{ secrets.GITLEAKS_LICENSE }}
code-security-scan:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: java, javascript, python, cpp
queries: security-and-quality
- name: Set up Java
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
- name: Build with Gradle
run: |
chmod +x ./gradlew
./gradlew build -x test --no-daemon -x :apps:android:shared:build
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
with:
category: "/language:multi"
semgrep-scan:
runs-on: ubuntu-latest
name: Semgrep Security Scan
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Run Semgrep
run: |
pip install semgrep
semgrep scan --sarif --config=p/security-audit --config=p/kotlin --config=p/java --config=p/typescript --config=p/python --config=p/javascript --config=p/rust --output=semgrep.sarif || true
- name: Upload SARIF file
uses: github/codeql-action/upload-sarif@v3
if: always()
with:
sarif_file: semgrep.sarif
license-scan:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: FOSSA Scan
uses: fossas/fossa-action@main
with:
api-key: ${{ secrets.FOSSA_API_KEY }}
run-tests: true
continue-on-error: true
container-scan:
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
strategy:
matrix:
service: [backup-engine, storage-hal, ml-optimizer, sync-coordinator]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Build Docker image for scanning
run: |
cd services/${{ matrix.service }}
if [ -f "Dockerfile" ]; then
docker build -t scan-image:${{ matrix.service }} .
else
echo "No Dockerfile found for ${{ matrix.service }}, skipping"
exit 0
fi
- name: Run Trivy container scan
uses: aquasecurity/trivy-action@master
with:
image-ref: 'scan-image:${{ matrix.service }}'
format: 'sarif'
output: 'container-scan-${{ matrix.service }}.sarif'
severity: 'CRITICAL,HIGH'
- name: Upload container scan results
uses: github/codeql-action/upload-sarif@v3
if: always()
with:
sarif_file: 'container-scan-${{ matrix.service }}.sarif'
category: 'container-${{ matrix.service }}'
infrastructure-scan:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Run Checkov IaC scan
uses: bridgecrewio/checkov-action@master
with:
directory: infrastructure/
framework: terraform,kubernetes,dockerfile
output_format: sarif
output_file_path: checkov-results.sarif
- name: Upload Checkov scan results
uses: github/codeql-action/upload-sarif@v3
if: always()
with:
sarif_file: checkov-results.sarif
category: 'infrastructure'
security-report:
needs: [dependency-scan, secret-scan, code-security-scan, semgrep-scan, license-scan, container-scan, infrastructure-scan]
runs-on: ubuntu-latest
if: always()
steps:
- name: Security Scan Summary
run: |
echo "## Security Scan Results" >> $GITHUB_STEP_SUMMARY
echo "- Dependency Scan: ${{ needs.dependency-scan.result }}" >> $GITHUB_STEP_SUMMARY
echo "- Secret Scan: ${{ needs.secret-scan.result }}" >> $GITHUB_STEP_SUMMARY
echo "- Code Security Scan: ${{ needs.code-security-scan.result }}" >> $GITHUB_STEP_SUMMARY
echo "- Semgrep Scan: ${{ needs.semgrep-scan.result }}" >> $GITHUB_STEP_SUMMARY
echo "- License Scan: ${{ needs.license-scan.result }}" >> $GITHUB_STEP_SUMMARY
echo "- Container Scan: ${{ needs.container-scan.result }}" >> $GITHUB_STEP_SUMMARY
echo "- Infrastructure Scan: ${{ needs.infrastructure-scan.result }}" >> $GITHUB_STEP_SUMMARY