1717 description : " JSON string of environment variables"
1818 required : true
1919 type : string
20+ enable-nancy :
21+ description : " Enable Nancy security scan"
22+ required : false
23+ type : boolean
24+ default : true
25+ enable-govulncheck :
26+ description : " Enable govulncheck security scan"
27+ required : false
28+ type : boolean
29+ default : true
30+ enable-gitleaks :
31+ description : " Enable Gitleaks security scan"
32+ required : false
33+ type : boolean
34+ default : true
2035 primary-runner :
2136 description : " Primary runner OS"
2237 required : true
4358 ask-nancy :
4459 name : 🛡️ Ask Nancy (Dependency Checks)
4560 runs-on : ${{ inputs.primary-runner }}
61+ if : ${{ inputs.enable-nancy }}
4662 steps :
4763 # ————————————————————————————————————————————————————————————————
4864 # Parse environment variables
@@ -124,6 +140,7 @@ jobs:
124140 govulncheck :
125141 name : 🔐 Run govulncheck (Vulnerability Scan)
126142 runs-on : ${{ inputs.primary-runner }}
143+ if : ${{ inputs.enable-govulncheck }}
127144 steps :
128145 # ————————————————————————————————————————————————————————————————
129146 # Parse environment variables
@@ -229,7 +246,7 @@ jobs:
229246 gitleaks :
230247 name : 🕵️ Run Gitleaks (Secret Scan)
231248 runs-on : ${{ inputs.primary-runner }}
232- if : github.event.pull_request.head.repo.full_name == github.repository
249+ if : ${{ inputs.enable-gitleaks }}
233250 steps :
234251 # ————————————————————————————————————————————————————————————————
235252 # Parse environment variables
@@ -243,6 +260,38 @@ jobs:
243260 echo "$key=$value" >> $GITHUB_ENV
244261 done
245262
263+ # ————————————————————————————————————————————————————————————————
264+ # Check repository security conditions
265+ # ————————————————————————————————————————————————————————————————
266+ - name : 🔍 Check repository security conditions
267+ id : repo-check
268+ env :
269+ GITHUB_EVENT_NAME : ${{ github.event_name }}
270+ GITHUB_ACTOR : ${{ github.actor }}
271+ GITHUB_REPOSITORY : ${{ github.repository }}
272+ GITHUB_HEAD_REF : ${{ github.head_ref }}
273+ PR_HEAD_REPO : ${{ github.event.pull_request.head.repo.full_name }}
274+ run : |
275+ echo "🔍 Checking repository security conditions..."
276+ echo "Event Name: $GITHUB_EVENT_NAME"
277+ echo "Actor: $GITHUB_ACTOR"
278+ echo "Repository: $GITHUB_REPOSITORY"
279+ echo "Head Ref: $GITHUB_HEAD_REF"
280+
281+ # For workflow_call, we typically trust the calling workflow from the same repo
282+ # For pull_request events, check if head repo matches base repo
283+ if [[ "$GITHUB_EVENT_NAME" == "workflow_call" ]]; then
284+ echo "✅ Workflow call from same repository - security scans allowed"
285+ echo "is_same_repo=true" >> $GITHUB_OUTPUT
286+ elif [[ "$PR_HEAD_REPO" == "$GITHUB_REPOSITORY" ]] || [[ -z "$PR_HEAD_REPO" ]]; then
287+ echo "✅ Same repository or push event - security scans allowed"
288+ echo "is_same_repo=true" >> $GITHUB_OUTPUT
289+ else
290+ echo "⚠️ Fork detected - skipping secret-sensitive scans for security"
291+ echo "PR Head Repo: $PR_HEAD_REPO"
292+ echo "is_same_repo=false" >> $GITHUB_OUTPUT
293+ fi
294+
246295 # ————————————————————————————————————————————————————————————————
247296 # Checkout code and set up Go environment
248297 # ————————————————————————————————————————————————————————————————
@@ -252,6 +301,7 @@ jobs:
252301 fetch-depth : 0 # Fetch all history so Gitleaks can scan commits
253302
254303 - name : 🔍 Run gitleaks scan
304+ if : steps.repo-check.outputs.is_same_repo == 'true'
255305 uses : gitleaks/gitleaks-action@ff98106e4c7b2bc287b24eaf42907196329070c7 # v8.27.2
256306 env :
257307 GITHUB_TOKEN : ${{ secrets.github-token }}
@@ -263,6 +313,7 @@ jobs:
263313 GITLEAKS_VERSION : ${{ env.GITLEAKS_VERSION }}
264314
265315 - name : 📊 Job Summary
316+ if : steps.repo-check.outputs.is_same_repo == 'true'
266317 run : |
267318 echo "## 🕵️ Gitleaks Secret Scan Summary" >> $GITHUB_STEP_SUMMARY
268319 echo "" >> $GITHUB_STEP_SUMMARY
@@ -274,3 +325,17 @@ jobs:
274325 echo "| **Result** | ✅ No secrets detected (see logs for details) |" >> $GITHUB_STEP_SUMMARY
275326 echo "" >> $GITHUB_STEP_SUMMARY
276327 echo "🎯 **Secret scan completed successfully.**" >> $GITHUB_STEP_SUMMARY
328+
329+ - name : 📊 Fork Security Notice
330+ if : steps.repo-check.outputs.is_same_repo == 'false'
331+ run : |
332+ echo "## 🕵️ Gitleaks Secret Scan Summary" >> $GITHUB_STEP_SUMMARY
333+ echo "" >> $GITHUB_STEP_SUMMARY
334+ echo "| 🔒 Security Details | ⚠️ Status |" >> $GITHUB_STEP_SUMMARY
335+ echo "|---|---|" >> $GITHUB_STEP_SUMMARY
336+ echo "| **Tool** | Gitleaks |" >> $GITHUB_STEP_SUMMARY
337+ echo "| **Fork Detected** | ${{ github.event.pull_request.head.repo.full_name || 'N/A (not a PR event)' }} |" >> $GITHUB_STEP_SUMMARY
338+ echo "| **Base Repository** | ${{ github.repository }} |" >> $GITHUB_STEP_SUMMARY
339+ echo "| **Result** | ⚠️ Skipped for security (fork cannot access secrets) |" >> $GITHUB_STEP_SUMMARY
340+ echo "" >> $GITHUB_STEP_SUMMARY
341+ echo "🔒 **Secret scanning was skipped because this PR comes from a fork. This is a security feature to prevent secret exposure.**" >> $GITHUB_STEP_SUMMARY
0 commit comments