-
Notifications
You must be signed in to change notification settings - Fork 173
feat(workflows): add weekly GitHub code scanning automation #1495
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
Open
rezatnoMsirhC
wants to merge
18
commits into
main
Choose a base branch
from
feat/1329-gh-security-weekly-scanning-workflow
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
7c4baf8
feat(workflows): add weekly-security-scanning workflow
rezatnoMsirhC 1206f8f
refactor(workflows): extract gh-security-scanning reusable workflow
rezatnoMsirhC 5c764c2
feat(workflows): extract security scanning issue creation into reusab…
rezatnoMsirhC 9882e45
refactor(workflows): replace owner/repo inputs with github context vars
rezatnoMsirhC 96f79d8
chore(scripts): remove unused symlink for Get-CodeScanningAlerts.ps1
rezatnoMsirhC 2dc5520
feat(workflows): rename gh-security-scanning to gh-code-scanning and …
rezatnoMsirhC 24c5303
test(workflows): add temporary pull_request trigger for live validation
rezatnoMsirhC 8e1cce4
fix(workflows): improve code scanning issue quality
rezatnoMsirhC 01413f1
docs(skills): update gh-code-scanning SKILL.md output shape
rezatnoMsirhC bc030f7
Removing ms.date from gh-code-scanning skill
rezatnoMsirhC 30d556c
fix(workflows): fix gh issue edit missing title, labels, and duplicat…
rezatnoMsirhC 9d1e51e
fix(workflows): omit severity bracket when unknown, add Severity fall…
rezatnoMsirhC cf56d7e
test(skills): update gh-code-scanning tests for AffectedPaths rename
rezatnoMsirhC 902d65f
revert(workflows): remove temporary pull_request trigger from weekly …
rezatnoMsirhC ab37e93
Merge branch 'main' into feat/1329-gh-security-weekly-scanning-workflow
rezatnoMsirhC 20b33ea
fix(workflows): address pr-1495 review comments
rezatnoMsirhC 1bd8039
Merge branch 'main' of https://github.com/microsoft/hve-core into fea…
rezatnoMsirhC 8292306
Merge branch 'main' of https://github.com/microsoft/hve-core into fea…
rezatnoMsirhC File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| name: Create GitHub Code Scanning Issues | ||
|
|
||
| on: | ||
| workflow_call: | ||
| inputs: | ||
| artifact-name: | ||
| description: 'Name of the artifact containing code scanning alerts' | ||
| required: false | ||
| type: string | ||
| default: gh-code-scanning-alerts | ||
|
|
||
| permissions: | ||
|
rezatnoMsirhC marked this conversation as resolved.
|
||
| issues: write | ||
|
rezatnoMsirhC marked this conversation as resolved.
|
||
| actions: read | ||
|
|
||
| jobs: | ||
| create-gh-code-scanning-issues: | ||
| name: Create GitHub Code Scanning Issues | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| issues: write | ||
| actions: read | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| OWNER: ${{ github.repository_owner }} | ||
| REPO: ${{ github.event.repository.name }} | ||
| GITHUB_SERVER_URL: ${{ github.server_url }} | ||
| GITHUB_REPOSITORY: ${{ github.repository }} | ||
| GITHUB_RUN_ID: ${{ github.run_id }} | ||
| steps: | ||
| - name: Download alerts artifact | ||
| uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 | ||
| with: | ||
| name: ${{ inputs.artifact-name }} | ||
|
|
||
| - name: Create backlog issues for new findings | ||
| shell: bash | ||
| run: | | ||
| set -euo pipefail | ||
| while IFS= read -r alert; do | ||
| RULE_ID=$(echo "$alert" | jq -r '.RuleId') | ||
| RULE_DESC=$(echo "$alert" | jq -r '.RuleDescription') | ||
| SEVERITY=$(echo "$alert" | jq -r '.SecuritySeverity // .Severity // empty') | ||
| TOOL=$(echo "$alert" | jq -r '.Tool') | ||
| COUNT=$(echo "$alert" | jq -r '.Count') | ||
| HAS_FILE_PATHS=$(echo "$alert" | jq -r '.HasFilePaths') | ||
| ALERT_URL=$(echo "$alert" | jq -r '.AlertUrl // ""') | ||
| FINDING_DESC=$(echo "$alert" | jq -r '.FindingDescription // ""') | ||
| MARKER="automation:security-scan:${RULE_ID}" | ||
| if [[ -n "$SEVERITY" ]]; then | ||
| ISSUE_TITLE="[Security][${SEVERITY}] ${RULE_DESC}" | ||
| else | ||
| ISSUE_TITLE="[Security] ${RULE_DESC}" | ||
| fi | ||
| OCCURRENCE_WORD="$([ "$COUNT" = "1" ] && echo "occurrence" || echo "occurrences")" | ||
| DETECTION_DATE=$(date -u '+%Y-%m-%d') | ||
| RUN_URL="${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}" | ||
| REPO_BASE="https://github.com/${OWNER}/${REPO}/blob/main" | ||
|
|
||
| if [[ "$HAS_FILE_PATHS" == "true" ]]; then | ||
| AFFECTED_LIST=$(echo "$alert" | jq -r --arg base "$REPO_BASE" '.AffectedPaths[] | "- [\(.)](\($base + "/" + .))"') | ||
| PATHS_SECTION=$'### Affected paths\n\n'"${AFFECTED_LIST}" | ||
| else | ||
| PATHS_SECTION=$'### Repository configuration finding\n\nThis alert refers to a repository-level configuration setting with no associated source file.' | ||
| fi | ||
|
|
||
| existing=$(gh issue list \ | ||
| --repo "${OWNER}/${REPO}" \ | ||
| --search "\"${MARKER}\" in:body" \ | ||
| --state open --json number --jq '.[0].number // empty') | ||
|
|
||
| ISSUE_BODY=$(cat <<EOF | ||
| <!-- ${MARKER} --> | ||
| ## Code Scanning Alert: ${RULE_DESC} | ||
|
|
||
| **Rule:** \`${RULE_ID}\` | ||
| $([ -n "${SEVERITY}" ] && echo "**Severity:** ${SEVERITY}") | ||
| **Tool:** ${TOOL} | ||
| **Occurrences:** ${COUNT} ${OCCURRENCE_WORD} | ||
| $([ -n "${ALERT_URL}" ] && echo "**Alert:** ${ALERT_URL}") | ||
|
|
||
| ### What was found | ||
| $([ -n "${FINDING_DESC}" ] && echo "${FINDING_DESC}" || echo "See the linked alert for details.") | ||
|
|
||
| ${PATHS_SECTION} | ||
|
|
||
| --- | ||
| **Detection Date:** ${DETECTION_DATE} | ||
| **Workflow Run:** ${RUN_URL} | ||
|
|
||
| ### Action Required | ||
| - [ ] Review the alert and confirm it is not a false positive | ||
| - [ ] Remediate or dismiss the finding with a documented reason | ||
| - [ ] Close this issue after the fix is merged | ||
| EOF | ||
| ) | ||
|
|
||
| if [[ -z "$existing" ]]; then | ||
| gh issue create \ | ||
| --repo "${OWNER}/${REPO}" \ | ||
| --title "${ISSUE_TITLE}" \ | ||
| --label "security,automated,needs-triage" \ | ||
| --body "${ISSUE_BODY}" | ||
| else | ||
| gh issue edit "${existing}" \ | ||
| --repo "${OWNER}/${REPO}" \ | ||
| --title "${ISSUE_TITLE}" \ | ||
| --body "${ISSUE_BODY}" \ | ||
| --add-label "automated,needs-triage" | ||
| gh issue comment "${existing}" \ | ||
| --repo "${OWNER}/${REPO}" \ | ||
| --body "Weekly scan update: ${COUNT} ${OCCURRENCE_WORD} as of ${DETECTION_DATE}." | ||
| fi | ||
| done < <(jq -c '.[]' alerts.json) | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.