|
| 1 | +# FIPS Compatibility Check |
| 2 | +# Checks code and dependencies for FIPS 140-2/140-3 compliance issues. |
| 3 | +# Requires scripts/check_fips_compatibility.py at repo root. |
| 4 | +# |
| 5 | +# FIPS mode restricts cryptographic algorithms to NIST-approved ones, required for: |
| 6 | +# - US Government systems, Healthcare (HIPAA), Financial services |
| 7 | +# - Ubuntu LTS with fips-updates package |
| 8 | +# |
| 9 | +# Security note: workflow_dispatch inputs are passed via env vars (not direct |
| 10 | +# expression interpolation) to prevent command injection. |
| 11 | +name: FIPS Compatibility |
| 12 | + |
| 13 | +on: |
| 14 | + push: |
| 15 | + branches: [main, master] |
| 16 | + paths: |
| 17 | + - 'src/**/*.py' |
| 18 | + - 'pyproject.toml' |
| 19 | + - 'requirements*.txt' |
| 20 | + - '.github/workflows/fips-compatibility.yml' |
| 21 | + pull_request: |
| 22 | + branches: [main, master] |
| 23 | + paths: |
| 24 | + - 'src/**/*.py' |
| 25 | + - 'pyproject.toml' |
| 26 | + - 'requirements*.txt' |
| 27 | + schedule: |
| 28 | + - cron: '0 10 * * 1' |
| 29 | + workflow_dispatch: |
| 30 | + inputs: |
| 31 | + strict_mode: |
| 32 | + description: 'Treat warnings as errors' |
| 33 | + required: false |
| 34 | + default: 'false' |
| 35 | + type: string |
| 36 | + |
| 37 | +concurrency: |
| 38 | + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} |
| 39 | + cancel-in-progress: true |
| 40 | + |
| 41 | +permissions: |
| 42 | + contents: read |
| 43 | + pull-requests: write |
| 44 | + |
| 45 | +jobs: |
| 46 | + fips-check: |
| 47 | + name: FIPS Compliance Check |
| 48 | + runs-on: ubuntu-latest |
| 49 | + steps: |
| 50 | + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 51 | + |
| 52 | + - name: Install uv |
| 53 | + uses: astral-sh/setup-uv@1e862dfacbd1d6d858c55d9b792c756523627244 # v7.1.4 |
| 54 | + with: |
| 55 | + enable-cache: true |
| 56 | + |
| 57 | + - name: Set up Python |
| 58 | + run: uv python install 3.12 |
| 59 | + |
| 60 | + - name: Install dependencies |
| 61 | + run: uv sync --frozen |
| 62 | + |
| 63 | + - name: Run FIPS compatibility check |
| 64 | + id: fips-check |
| 65 | + env: |
| 66 | + STRICT_MODE: ${{ github.event.inputs.strict_mode }} |
| 67 | + run: | |
| 68 | + STRICT_FLAG="" |
| 69 | + if [ "$STRICT_MODE" = "true" ]; then |
| 70 | + STRICT_FLAG="--strict" |
| 71 | + fi |
| 72 | +
|
| 73 | + set +e |
| 74 | + uv run python scripts/check_fips_compatibility.py \ |
| 75 | + --fix-hints \ |
| 76 | + --include-tests \ |
| 77 | + $STRICT_FLAG \ |
| 78 | + 2>&1 | tee fips-report.txt |
| 79 | + EXIT_CODE=${PIPESTATUS[0]} |
| 80 | + set -e |
| 81 | +
|
| 82 | + uv run python scripts/check_fips_compatibility.py \ |
| 83 | + --json \ |
| 84 | + --include-tests \ |
| 85 | + > fips-report.json 2>/dev/null || true |
| 86 | +
|
| 87 | + echo "exit_code=$EXIT_CODE" >> "$GITHUB_OUTPUT" |
| 88 | +
|
| 89 | + if [ -f fips-report.json ]; then |
| 90 | + ERRORS=$(jq -r '.summary.errors' fips-report.json) |
| 91 | + WARNINGS=$(jq -r '.summary.warnings' fips-report.json) |
| 92 | + INFO=$(jq -r '.summary.info' fips-report.json) |
| 93 | + echo "errors=$ERRORS" >> "$GITHUB_OUTPUT" |
| 94 | + echo "warnings=$WARNINGS" >> "$GITHUB_OUTPUT" |
| 95 | + echo "info=$INFO" >> "$GITHUB_OUTPUT" |
| 96 | + fi |
| 97 | +
|
| 98 | + exit $EXIT_CODE |
| 99 | +
|
| 100 | + - name: Upload FIPS report |
| 101 | + if: always() |
| 102 | + uses: actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b # v4.5.0 |
| 103 | + with: |
| 104 | + name: fips-compatibility-report |
| 105 | + path: | |
| 106 | + fips-report.txt |
| 107 | + fips-report.json |
| 108 | + retention-days: 30 |
| 109 | + |
| 110 | + - name: Comment on PR |
| 111 | + if: always() && github.event_name == 'pull_request' |
| 112 | + uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 |
| 113 | + with: |
| 114 | + script: | |
| 115 | + const errors = parseInt('${{ steps.fips-check.outputs.errors }}') || 0; |
| 116 | + const warnings = parseInt('${{ steps.fips-check.outputs.warnings }}') || 0; |
| 117 | + const info = parseInt('${{ steps.fips-check.outputs.info }}') || 0; |
| 118 | +
|
| 119 | + let status = 'PASSED'; |
| 120 | + let emoji = 'PASS'; |
| 121 | + if (errors > 0) { |
| 122 | + status = 'FAILED'; |
| 123 | + emoji = 'FAIL'; |
| 124 | + } else if (warnings > 0) { |
| 125 | + status = 'NEEDS REVIEW'; |
| 126 | + emoji = 'WARN'; |
| 127 | + } |
| 128 | +
|
| 129 | + const body = `## FIPS Compatibility Check: ${status}\n\n` + |
| 130 | + `| Metric | Count |\n|--------|-------|\n` + |
| 131 | + `| Errors | ${errors} |\n` + |
| 132 | + `| Warnings | ${warnings} |\n` + |
| 133 | + `| Info | ${info} |\n\n` + |
| 134 | + (errors > 0 ? 'This PR introduces FIPS-incompatible code or dependencies. ' + |
| 135 | + `Review the [workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) for details.\n\n` : '') + |
| 136 | + (warnings > 0 && errors === 0 ? 'Some packages may need verification for FIPS compliance. See workflow artifacts for details.\n\n' : ''); |
| 137 | +
|
| 138 | + github.rest.issues.createComment({ |
| 139 | + owner: context.repo.owner, |
| 140 | + repo: context.repo.repo, |
| 141 | + issue_number: context.issue.number, |
| 142 | + body: body |
| 143 | + }); |
0 commit comments