Skip to content

Commit c78424f

Browse files
committed
github actions: Add FIPS protected directory check for PRs
Adds a workflow that runs on PRs targeting ciq-*-next branches and checks whether new upstream commits touch FIPS protected directories. Posts a PR comment alerting reviewers if changes are found. Uses check_fips_changes.py from kernel-src-tree-tools (clk-fips-check branch) to perform the check.
1 parent 0ad59df commit c78424f

1 file changed

Lines changed: 158 additions & 0 deletions

File tree

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
# FIPS Protected Directory Check
2+
#
3+
# This workflow runs on PRs targeting ciq-*-next branches and checks
4+
# whether the new upstream commits (the stable release delta) touch
5+
# any FIPS protected directories. If so, it posts a comment on the
6+
# PR alerting reviewers to involve the FIPS / Security team.
7+
#
8+
# How it works:
9+
# PR base branch: ciq-X.Y.y-next (created from stable_X.Y.y)
10+
# Old branch: ciq-X.Y.y (previous CIQ branch, derived by stripping "-next")
11+
# merge-base(old, next) = last common upstream commit
12+
# merge-base..ciq-X.Y.y-next = new upstream commits to check
13+
#
14+
# TODO: remove ref: clk-fips-check once kernel-src-tree-tools merges that branch
15+
16+
name: FIPS Protected Directory Check
17+
18+
on:
19+
pull_request:
20+
types: [opened, synchronize, reopened]
21+
branches:
22+
- 'ciq-*-next'
23+
24+
permissions:
25+
contents: read
26+
pull-requests: write
27+
28+
jobs:
29+
fips-check:
30+
name: FIPS Directory Check
31+
runs-on: ubuntu-latest
32+
33+
steps:
34+
- name: Generate GitHub App token
35+
id: generate_token
36+
uses: actions/create-github-app-token@1b10c78c7865c340bc4f6099eb2f838309f1e8c3 # v3.1.1
37+
with:
38+
client-id: ${{ secrets.APP_ID }}
39+
private-key: ${{ secrets.APP_PRIVATE_KEY }}
40+
repositories: |
41+
kernel-src-tree
42+
kernel-src-tree-tools
43+
44+
- name: Checkout kernel source
45+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
46+
with:
47+
fetch-depth: 1
48+
token: ${{ steps.generate_token.outputs.token }}
49+
50+
- name: Checkout kernel-src-tree-tools
51+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
52+
with:
53+
repository: ctrliq/kernel-src-tree-tools
54+
ref: clk-fips-check
55+
path: kernel-src-tree-tools
56+
token: ${{ steps.generate_token.outputs.token }}
57+
58+
- name: Install Python dependencies
59+
run: pip install gitpython
60+
61+
- name: Fetch branches and run FIPS check
62+
id: fips_check
63+
env:
64+
PYTHONPATH: ${{ github.workspace }}/kernel-src-tree-tools
65+
BASE_REF: ${{ github.event.pull_request.base.ref }}
66+
run: |
67+
OLD_BRANCH="${BASE_REF%-next}"
68+
echo "Derived old branch: $OLD_BRANCH from PR base: $BASE_REF"
69+
70+
# Fetch both branches (full history needed for merge-base)
71+
git fetch origin "$BASE_REF:refs/remotes/origin/$BASE_REF"
72+
git fetch origin "$OLD_BRANCH:refs/remotes/origin/$OLD_BRANCH" 2>/dev/null || {
73+
echo "::warning::Could not fetch branch $OLD_BRANCH — skipping FIPS check"
74+
echo "result=skip" >> "$GITHUB_OUTPUT"
75+
exit 0
76+
}
77+
78+
MERGE_BASE=$(git merge-base "origin/$OLD_BRANCH" "origin/$BASE_REF" 2>/dev/null) || {
79+
echo "::warning::Could not compute merge-base between $OLD_BRANCH and $BASE_REF"
80+
echo "result=skip" >> "$GITHUB_OUTPUT"
81+
exit 0
82+
}
83+
84+
echo "Merge base: $MERGE_BASE"
85+
echo "Checking upstream commits: $MERGE_BASE..origin/$BASE_REF"
86+
87+
python3 kernel-src-tree-tools/check_fips_changes.py \
88+
--repo . \
89+
--base-ref "$MERGE_BASE" \
90+
--target-ref "origin/$BASE_REF" \
91+
--fips-override 2>&1 | tee fips_report.txt
92+
93+
if grep -q "FIPS protected changes detected" fips_report.txt; then
94+
echo "result=found" >> "$GITHUB_OUTPUT"
95+
else
96+
echo "result=clean" >> "$GITHUB_OUTPUT"
97+
fi
98+
99+
- name: Post or update PR comment
100+
if: always()
101+
env:
102+
GH_TOKEN: ${{ steps.generate_token.outputs.token }}
103+
PR_NUMBER: ${{ github.event.pull_request.number }}
104+
RESULT: ${{ steps.fips_check.outputs.result }}
105+
run: |
106+
MARKER="<!-- fips-protected-directory-check -->"
107+
REPO="${{ github.repository }}"
108+
109+
# Find any existing FIPS check comment
110+
EXISTING_ID=$(gh api "repos/$REPO/issues/$PR_NUMBER/comments" \
111+
--jq ".[] | select(.body | contains(\"$MARKER\")) | .id" | head -1)
112+
113+
if [ "$RESULT" = "found" ]; then
114+
REPORT=$(cat fips_report.txt)
115+
BODY=$(cat <<EOF
116+
$MARKER
117+
## :warning: FIPS Protected Directory Changes Detected
118+
119+
New upstream commits in this rebase touch FIPS protected directories.
120+
Please consult the CIQ FIPS / Security team before merging.
121+
122+
<details>
123+
<summary>Details</summary>
124+
125+
\`\`\`
126+
$REPORT
127+
\`\`\`
128+
129+
</details>
130+
EOF
131+
)
132+
elif [ "$RESULT" = "clean" ]; then
133+
BODY=$(cat <<EOF
134+
$MARKER
135+
## :white_check_mark: FIPS Check: No Protected Directory Changes
136+
137+
No FIPS protected directories were modified in the new upstream commits.
138+
EOF
139+
)
140+
else
141+
BODY=$(cat <<EOF
142+
$MARKER
143+
## :x: FIPS Check: Unable to Run
144+
145+
Could not determine the upstream delta for this PR. The FIPS protected
146+
directory check was skipped. Please verify manually.
147+
EOF
148+
)
149+
fi
150+
151+
if [ -n "$EXISTING_ID" ]; then
152+
gh api "repos/$REPO/issues/comments/$EXISTING_ID" \
153+
-X PATCH -f body="$BODY"
154+
echo "Updated existing comment $EXISTING_ID"
155+
else
156+
gh pr comment "$PR_NUMBER" --repo "$REPO" --body "$BODY"
157+
echo "Created new comment"
158+
fi

0 commit comments

Comments
 (0)