-
Notifications
You must be signed in to change notification settings - Fork 28
refactor: use centralized script and config for sensitive files check #139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| .github/ | ||
| CNAME$ | ||
| static/CNAME | ||
| package.json | ||
| sidebar | ||
| docusaurus.config.js | ||
| babel.config.js | ||
| CODEOWNERS | ||
| LICENSE | ||
| ./*.md | ||
| package-lock.json | ||
| tsconfig.json | ||
| pnpm-lock.yaml | ||
| .gitignore | ||
| .prettierignore | ||
| .prettierrc | ||
| ^src/.* | ||
| ^.gitignore$ | ||
| .node-version$ | ||
| .eslintrc.json$ | ||
| .eslintignore$ | ||
| CODEOWNERS$ | ||
| LICENSE$ | ||
| .coderabbit.yaml$ | ||
| .*.pem$ | ||
| .*.key$ | ||
| .*.cert$ | ||
| .*.password$ | ||
| .*.secret$ | ||
| .*.credentials$ | ||
| .nojekyll$ | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -82,6 +82,13 @@ jobs: | |||||||||||||||||||||||||||||||||
| with: | ||||||||||||||||||||||||||||||||||
| fetch-depth: 0 # Fetch all history for all branches and tags | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| - name: Checkout centralized CI/CD scripts | ||||||||||||||||||||||||||||||||||
| uses: actions/checkout@v4 | ||||||||||||||||||||||||||||||||||
| with: | ||||||||||||||||||||||||||||||||||
| repository: PalisadoesFoundation/.github | ||||||||||||||||||||||||||||||||||
| ref: main | ||||||||||||||||||||||||||||||||||
| path: .github-central | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+85
to
+90
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pinning to Any push to the - name: Checkout centralized CI/CD scripts
uses: actions/checkout@v4
with:
repository: PalisadoesFoundation/.github
- ref: main
+ ref: <commit-sha-or-tag>
path: .github-central🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| - name: Get PR labels | ||||||||||||||||||||||||||||||||||
| id: check-labels | ||||||||||||||||||||||||||||||||||
| env: | ||||||||||||||||||||||||||||||||||
|
|
@@ -101,6 +108,12 @@ jobs: | |||||||||||||||||||||||||||||||||
| echo "skip=false" >> $GITHUB_OUTPUT | ||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| - name: Set up Python | ||||||||||||||||||||||||||||||||||
| if: steps.check-labels.outputs.skip != 'true' | ||||||||||||||||||||||||||||||||||
| uses: actions/setup-python@v5 | ||||||||||||||||||||||||||||||||||
| with: | ||||||||||||||||||||||||||||||||||
| python-version: 3.11 | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| - name: Get Changed Unauthorized files | ||||||||||||||||||||||||||||||||||
| if: steps.check-labels.outputs.skip != 'true' | ||||||||||||||||||||||||||||||||||
| id: changed-unauth-files | ||||||||||||||||||||||||||||||||||
|
|
@@ -116,75 +129,13 @@ jobs: | |||||||||||||||||||||||||||||||||
| HEAD_SHA="${{ github.event.pull_request.head.sha || github.sha }}" | ||||||||||||||||||||||||||||||||||
| BASE_SHA=$(git merge-base "${{ github.event.pull_request.base.sha }}" "$HEAD_SHA") | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| # Define sensitive files patterns as a bash array | ||||||||||||||||||||||||||||||||||
| SENSITIVE_PATTERNS=( | ||||||||||||||||||||||||||||||||||
| ".github/" | ||||||||||||||||||||||||||||||||||
| "CNAME$" | ||||||||||||||||||||||||||||||||||
| "static/CNAME" | ||||||||||||||||||||||||||||||||||
| "package.json" | ||||||||||||||||||||||||||||||||||
| "sidebar" | ||||||||||||||||||||||||||||||||||
| "docusaurus.config.js" | ||||||||||||||||||||||||||||||||||
| "babel.config.js" | ||||||||||||||||||||||||||||||||||
| "CODEOWNERS" | ||||||||||||||||||||||||||||||||||
| "LICENSE" | ||||||||||||||||||||||||||||||||||
| "./*.md" | ||||||||||||||||||||||||||||||||||
| "package-lock.json" | ||||||||||||||||||||||||||||||||||
| "tsconfig.json" | ||||||||||||||||||||||||||||||||||
| "pnpm-lock.yaml" | ||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||||||||||||||||||||||||||||
| ".gitignore" | ||||||||||||||||||||||||||||||||||
| ".prettierignore" | ||||||||||||||||||||||||||||||||||
| ".prettierrc" | ||||||||||||||||||||||||||||||||||
| '^src/.*' | ||||||||||||||||||||||||||||||||||
| '^.gitignore$' | ||||||||||||||||||||||||||||||||||
| '.node-version$' | ||||||||||||||||||||||||||||||||||
| '.eslintrc.json$' | ||||||||||||||||||||||||||||||||||
| '.eslintignore$' | ||||||||||||||||||||||||||||||||||
| 'CODEOWNERS$' | ||||||||||||||||||||||||||||||||||
| 'LICENSE$' | ||||||||||||||||||||||||||||||||||
| '.coderabbit.yaml$' | ||||||||||||||||||||||||||||||||||
| '.*.pem$' | ||||||||||||||||||||||||||||||||||
| '.*.key$' | ||||||||||||||||||||||||||||||||||
| '.*.cert$' | ||||||||||||||||||||||||||||||||||
| '.*.password$' | ||||||||||||||||||||||||||||||||||
| '.*.secret$' | ||||||||||||||||||||||||||||||||||
| '.*.credentials$' | ||||||||||||||||||||||||||||||||||
| '.nojekyll$' | ||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| # Check for changes in sensitive files | ||||||||||||||||||||||||||||||||||
| CHANGED_UNAUTH_FILES="" | ||||||||||||||||||||||||||||||||||
| for pattern in "${SENSITIVE_PATTERNS[@]}"; do | ||||||||||||||||||||||||||||||||||
| FILES=$(git diff --name-only --diff-filter=ACMRD "$BASE_SHA" "$HEAD_SHA" | grep -E "$pattern" || true) | ||||||||||||||||||||||||||||||||||
| if [ ! -z "$FILES" ]; then | ||||||||||||||||||||||||||||||||||
| CHANGED_UNAUTH_FILES="$CHANGED_UNAUTH_FILES $FILES" | ||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||
| done | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| # Trim and format output | ||||||||||||||||||||||||||||||||||
| CHANGED_UNAUTH_FILES=$(echo "$CHANGED_UNAUTH_FILES" | xargs) | ||||||||||||||||||||||||||||||||||
| echo "all_changed_files=$CHANGED_UNAUTH_FILES" >> $GITHUB_OUTPUT | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| # Check if any unauthorized files changed | ||||||||||||||||||||||||||||||||||
| if [ ! -z "$CHANGED_UNAUTH_FILES" ]; then | ||||||||||||||||||||||||||||||||||
| echo "any_changed=true" >> $GITHUB_OUTPUT | ||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||
| echo "any_changed=false" >> $GITHUB_OUTPUT | ||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||
| # Get all changed files between base and head | ||||||||||||||||||||||||||||||||||
| mapfile -d '' ALL_CHANGED_FILES < <(git diff --name-only -z --diff-filter=ACMR "$BASE_SHA" "$HEAD_SHA") | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| - name: List all changed unauthorized files | ||||||||||||||||||||||||||||||||||
| if: steps.changed-unauth-files.outputs.any_changed == 'true' | ||||||||||||||||||||||||||||||||||
| env: | ||||||||||||||||||||||||||||||||||
| CHANGED_UNAUTH_FILES: ${{ steps.changed-unauth-files.outputs.all_changed_files }} | ||||||||||||||||||||||||||||||||||
| run: | | ||||||||||||||||||||||||||||||||||
| echo "::error::Unauthorized changes detected in sensitive files:" | ||||||||||||||||||||||||||||||||||
| echo "" | ||||||||||||||||||||||||||||||||||
| for file in $CHANGED_UNAUTH_FILES; do | ||||||||||||||||||||||||||||||||||
| echo "- $file" | ||||||||||||||||||||||||||||||||||
| done | ||||||||||||||||||||||||||||||||||
| echo "" | ||||||||||||||||||||||||||||||||||
| echo "To override:" | ||||||||||||||||||||||||||||||||||
| echo "Add the 'ignore-sensitive-files-pr' label to this PR." | ||||||||||||||||||||||||||||||||||
| exit 1 | ||||||||||||||||||||||||||||||||||
| # Check for sensitive files using the python script | ||||||||||||||||||||||||||||||||||
| if [ ${#ALL_CHANGED_FILES[@]} -gt 0 ]; then | ||||||||||||||||||||||||||||||||||
| python3 .github-central/.github/workflows/scripts/sensitive_file_check.py --config .github/workflows/config/sensitive_files.txt --files "${ALL_CHANGED_FILES[@]}" | ||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+136
to
+138
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial No guard against Python script or config file being absent. If the centralized-repo checkout (line 85-90) fails silently or the path changes upstream, this step will fail with a cryptic "No such file or directory" error. Consider adding a brief existence check to surface a clearer message. Proposed improvement # Check for sensitive files using the python script
if [ ${`#ALL_CHANGED_FILES`[@]} -gt 0 ]; then
+ SCRIPT=".github-central/.github/workflows/scripts/sensitive_file_check.py"
+ CONFIG=".github/workflows/config/sensitive_files.txt"
+ if [ ! -f "$SCRIPT" ]; then
+ echo "::error::Centralized sensitive-file check script not found at $SCRIPT"
+ exit 1
+ fi
+ if [ ! -f "$CONFIG" ]; then
+ echo "::error::Sensitive files config not found at $CONFIG"
+ exit 1
+ fi
- python3 .github-central/.github/workflows/scripts/sensitive_file_check.py --config .github/workflows/config/sensitive_files.txt --files "${ALL_CHANGED_FILES[@]}"
+ python3 "$SCRIPT" --config "$CONFIG" --files "${ALL_CHANGED_FILES[@]}"
fi📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| Test-Docusaurus-Deployment: | ||||||||||||||||||||||||||||||||||
| name: Test Deployment to https://developer.palisadoes.org | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Credential-file patterns are incorrect regex — they match far more than intended.
.*.pem$in regex means "any character, then anything, ending inpem" — this matches strings likemy_problem,ecosystem, etc. The literal dot before the extension is not escaped.Similarly affected:
.*.key$,.*.cert$,.*.password$,.*.secret$,.*.credentials$.🐛 Proposed fix — escape the dot before the extension
🤖 Prompt for AI Agents