|
| 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-published-artifacts: |
| 15 | + name: Scan Published Maven Artifacts |
| 16 | + runs-on: ubuntu-latest |
| 17 | + timeout-minutes: 45 |
| 18 | + |
| 19 | + strategy: |
| 20 | + fail-fast: false |
| 21 | + matrix: |
| 22 | + include: |
| 23 | + - artifact: "com.amazonaws:aws-xray-recorder-sdk-core" |
| 24 | + name: "core" |
| 25 | + - artifact: "com.amazonaws:aws-xray-recorder-sdk-aws-sdk" |
| 26 | + name: "aws-sdk" |
| 27 | + - artifact: "com.amazonaws:aws-xray-recorder-sdk-apache-http" |
| 28 | + name: "apache-http" |
| 29 | + |
| 30 | + steps: |
| 31 | + - name: Checkout repository |
| 32 | + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 |
| 33 | + |
| 34 | + - name: Set up JDK 11 |
| 35 | + uses: actions/setup-java@8df1039502a15bceb9433410b1a100fbe190c53b # v4.5.0 |
| 36 | + with: |
| 37 | + java-version: '11' |
| 38 | + distribution: 'temurin' |
| 39 | + |
| 40 | + - name: Download latest published artifact |
| 41 | + continue-on-error: true |
| 42 | + timeout-minutes: 10 |
| 43 | + run: | |
| 44 | + # Create temp directory for artifact analysis |
| 45 | + mkdir -p temp-scan/${{ matrix.name }} |
| 46 | + cd temp-scan/${{ matrix.name }} |
| 47 | + |
| 48 | + # Get latest version from Maven Central |
| 49 | + LATEST_VERSION=$(curl -s "https://search.maven.org/solrsearch/select?q=g:com.amazonaws+AND+a:$(echo '${{ matrix.artifact }}' | cut -d: -f2)&rows=1&wt=json" | jq -r '.response.docs[0].latestVersion // "UNKNOWN"') |
| 50 | + echo "Latest version: $LATEST_VERSION" |
| 51 | + |
| 52 | + if [ "$LATEST_VERSION" != "UNKNOWN" ] && [ "$LATEST_VERSION" != "null" ]; then |
| 53 | + # Download the JAR file |
| 54 | + ARTIFACT_PATH=$(echo '${{ matrix.artifact }}' | sed 's/:/\//g' | sed 's/\./\//g') |
| 55 | + JAR_NAME=$(echo '${{ matrix.artifact }}' | cut -d: -f2) |
| 56 | + |
| 57 | + curl -L -o "${JAR_NAME}-${LATEST_VERSION}.jar" "https://repo1.maven.org/maven2/${ARTIFACT_PATH}/${LATEST_VERSION}/${JAR_NAME}-${LATEST_VERSION}.jar" || echo "Failed to download JAR" |
| 58 | + |
| 59 | + # Download POM for dependency analysis |
| 60 | + curl -L -o "${JAR_NAME}-${LATEST_VERSION}.pom" "https://repo1.maven.org/maven2/${ARTIFACT_PATH}/${LATEST_VERSION}/${JAR_NAME}-${LATEST_VERSION}.pom" || echo "Failed to download POM" |
| 61 | + |
| 62 | + echo "Downloaded artifacts for ${{ matrix.artifact }} version $LATEST_VERSION" |
| 63 | + ls -la |
| 64 | + else |
| 65 | + echo "Could not determine latest version for ${{ matrix.artifact }}" |
| 66 | + fi |
| 67 | +
|
| 68 | + - name: Run OWASP Dependency Check on published artifact |
| 69 | + continue-on-error: true |
| 70 | + timeout-minutes: 20 |
| 71 | + run: | |
| 72 | + cd temp-scan/${{ matrix.name }} |
| 73 | + |
| 74 | + # Download and run OWASP Dependency Check |
| 75 | + curl -L -o dependency-check-11.1.0-release.zip https://github.com/jeremylong/DependencyCheck/releases/download/v11.1.0/dependency-check-11.1.0-release.zip |
| 76 | + unzip -q dependency-check-11.1.0-release.zip |
| 77 | + |
| 78 | + # Scan the downloaded artifacts |
| 79 | + if ls *.jar 1> /dev/null 2>&1; then |
| 80 | + ./dependency-check/bin/dependency-check.sh \ |
| 81 | + --project "aws-xray-sdk-java-${{ matrix.name }}" \ |
| 82 | + --scan . \ |
| 83 | + --format SARIF \ |
| 84 | + --out "dependency-check-${{ matrix.name }}-results.sarif" \ |
| 85 | + --failOnCVSS 7 \ |
| 86 | + --enableRetired || echo "Dependency check completed with findings" |
| 87 | + else |
| 88 | + echo "No JAR files found to scan" |
| 89 | + fi |
| 90 | +
|
| 91 | + - name: Upload OWASP Dependency Check results to GitHub Security tab |
| 92 | + uses: github/codeql-action/upload-sarif@e2b3eafc8d227b0241d48be5f425d47c2d750a13 # v3.26.10 |
| 93 | + if: always() |
| 94 | + with: |
| 95 | + sarif_file: 'temp-scan/${{ matrix.name }}/dependency-check-${{ matrix.name }}-results.sarif' |
| 96 | + category: 'daily-scan-${{ matrix.name }}' |
| 97 | + |
| 98 | + - name: Generate summary report |
| 99 | + if: always() |
| 100 | + run: | |
| 101 | + echo "## Daily Security Scan Results for ${{ matrix.artifact }}" >> $GITHUB_STEP_SUMMARY |
| 102 | + echo "Scan completed at $(date)" >> $GITHUB_STEP_SUMMARY |
| 103 | + echo "Artifact: ${{ matrix.artifact }}" >> $GITHUB_STEP_SUMMARY |
| 104 | + echo "Component: ${{ matrix.name }}" >> $GITHUB_STEP_SUMMARY |
| 105 | + |
| 106 | + # Check if vulnerabilities were found |
| 107 | + SARIF_FILE="temp-scan/${{ matrix.name }}/dependency-check-${{ matrix.name }}-results.sarif" |
| 108 | + if [ -f "$SARIF_FILE" ]; then |
| 109 | + VULN_COUNT=$(jq '.runs[0].results | length' "$SARIF_FILE" 2>/dev/null || echo "0") |
| 110 | + echo "Vulnerabilities found: $VULN_COUNT" >> $GITHUB_STEP_SUMMARY |
| 111 | + |
| 112 | + if [ "$VULN_COUNT" -gt "0" ]; then |
| 113 | + echo "⚠️ **Action Required**: Vulnerabilities detected in published artifact" >> $GITHUB_STEP_SUMMARY |
| 114 | + echo "Check the Security tab for detailed findings" >> $GITHUB_STEP_SUMMARY |
| 115 | + else |
| 116 | + echo "✅ No high/critical vulnerabilities found" >> $GITHUB_STEP_SUMMARY |
| 117 | + fi |
| 118 | + else |
| 119 | + echo "❌ Scan failed or artifact not accessible" >> $GITHUB_STEP_SUMMARY |
| 120 | + fi |
| 121 | +
|
| 122 | + scan-latest-dependencies: |
| 123 | + name: Scan Latest Dependencies |
| 124 | + runs-on: ubuntu-latest |
| 125 | + timeout-minutes: 30 |
| 126 | + |
| 127 | + steps: |
| 128 | + - name: Checkout repository |
| 129 | + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 |
| 130 | + |
| 131 | + - name: Set up JDK 11 |
| 132 | + uses: actions/setup-java@8df1039502a15bceb9433410b1a100fbe190c53b # v4.5.0 |
| 133 | + with: |
| 134 | + java-version: '11' |
| 135 | + distribution: 'temurin' |
| 136 | + |
| 137 | + - name: Setup Gradle |
| 138 | + uses: gradle/actions/setup-gradle@d156388eb19639ec20ade50009f3d199ce1e2808 # v4.1.0 |
| 139 | + |
| 140 | + - name: Run dependency vulnerability scan |
| 141 | + continue-on-error: true |
| 142 | + run: | |
| 143 | + # Generate current dependency tree |
| 144 | + ./gradlew dependencies --configuration runtimeClasspath > current-dependencies.txt |
| 145 | + |
| 146 | + # Download and run OWASP Dependency Check on current dependencies |
| 147 | + curl -L -o dependency-check-11.1.0-release.zip https://github.com/jeremylong/DependencyCheck/releases/download/v11.1.0/dependency-check-11.1.0-release.zip |
| 148 | + unzip -q dependency-check-11.1.0-release.zip |
| 149 | + |
| 150 | + ./dependency-check/bin/dependency-check.sh \ |
| 151 | + --project "aws-xray-sdk-java-current" \ |
| 152 | + --scan . \ |
| 153 | + --format SARIF \ |
| 154 | + --out dependency-check-current-results.sarif \ |
| 155 | + --failOnCVSS 7 \ |
| 156 | + --enableRetired || echo "Dependency check completed" |
| 157 | +
|
| 158 | + - name: Upload current dependency scan results |
| 159 | + uses: github/codeql-action/upload-sarif@e2b3eafc8d227b0241d48be5f425d47c2d750a13 # v3.26.10 |
| 160 | + if: always() |
| 161 | + with: |
| 162 | + sarif_file: dependency-check-current-results.sarif |
| 163 | + category: 'daily-scan-current-deps' |
| 164 | + |
| 165 | + - name: Upload dependency reports |
| 166 | + uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0 |
| 167 | + if: always() |
| 168 | + with: |
| 169 | + name: daily-dependency-reports |
| 170 | + path: | |
| 171 | + dependency-check-current-results.sarif |
| 172 | + current-dependencies.txt |
0 commit comments