-
Notifications
You must be signed in to change notification settings - Fork 247
Add PSScriptAnalyzer and OpenGrep security workflows #1776
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
SamErde
wants to merge
5
commits into
main
Choose a base branch
from
samerde/scaling-meme
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.
+167
−0
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
25c41de
Add PSScriptAnalyzer and OpenGrep security workflows
SamErde 09d1d3f
Merge branch 'main' into samerde/scaling-meme
SamErde f71de27
Address Copilot PR review feedback on security workflows
SamErde 3b59ae1
Merge branch 'main' into samerde/scaling-meme
SamErde e4e5f8c
Address fresh Copilot review: clarify version input and verify SHA256
SamErde 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| name: "OpenGrep" | ||
|
|
||
| # OpenGrep is an LGPL 2.1 fork of Semgrep CE, backed by a consortium of | ||
| # AppSec vendors. It is rule-compatible with Semgrep, so existing rule packs | ||
| # (p/security-audit, p/javascript, p/typescript, p/github-actions) work | ||
| # unchanged. See https://opengrep.dev for project details. | ||
| # | ||
| # This workflow currently runs on workflow_dispatch only while we evaluate | ||
| # the tool's effectiveness for the Maester codebase. If results are valuable, | ||
| # add push/pull_request triggers in a follow-up PR. | ||
|
|
||
| permissions: {} | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| inputs: | ||
| opengrep_version: | ||
| description: 'OpenGrep release tag to install. Defaults to the pinned, checksum-verified version below; override only if you also provide a matching opengrep_sha256.' | ||
| required: false | ||
| default: 'v1.21.0' | ||
| opengrep_sha256: | ||
| description: 'SHA256 of opengrep_manylinux_x86 for the chosen version. Leave blank to use the built-in checksum for the default version.' | ||
| required: false | ||
| default: '' | ||
| config: | ||
| description: 'Rule config(s) to run (space- or comma-separated).' | ||
| required: false | ||
| default: 'p/security-audit p/javascript p/typescript p/github-actions' | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.ref }} | ||
| cancel-in-progress: false | ||
|
|
||
| jobs: | ||
| scan: | ||
| name: Scan with OpenGrep | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| security-events: write | ||
| contents: read | ||
| actions: read | ||
|
|
||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | ||
|
|
||
| # Install OpenGrep by downloading the release binary directly from | ||
| # GitHub Releases (pinned by tag) and verifying its SHA256 before | ||
| # executing it. Avoids piping a moving `install.sh` into bash and | ||
| # closes the integrity gap left by trusting a mutable release tag. | ||
| - name: Install OpenGrep | ||
| env: | ||
| OPENGREP_VERSION: ${{ inputs.opengrep_version }} | ||
| OPENGREP_SHA256_INPUT: ${{ inputs.opengrep_sha256 }} | ||
| # Pinned checksum for opengrep_manylinux_x86 at the default version | ||
| # (v1.21.0). Update both the version default above and this value | ||
| # in lockstep when bumping the pinned release. | ||
| DEFAULT_OPENGREP_VERSION: 'v1.21.0' | ||
| DEFAULT_OPENGREP_SHA256: '9ed0ceee4a3a406d27d40894bcce85ea151be21e6d4b180689689224faff2a3e' | ||
| run: | | ||
| set -euo pipefail | ||
| version="${OPENGREP_VERSION:-${DEFAULT_OPENGREP_VERSION}}" | ||
| expected_sha="${OPENGREP_SHA256_INPUT}" | ||
| if [[ -z "${expected_sha}" ]]; then | ||
| if [[ "${version}" != "${DEFAULT_OPENGREP_VERSION}" ]]; then | ||
| echo "::error::Custom opengrep_version '${version}' supplied without opengrep_sha256. Refusing to install an unverified binary." >&2 | ||
| exit 1 | ||
| fi | ||
| expected_sha="${DEFAULT_OPENGREP_SHA256}" | ||
| fi | ||
| asset="opengrep_manylinux_x86" | ||
| base="https://github.com/opengrep/opengrep/releases/download/${version}" | ||
| echo "Downloading OpenGrep ${version} (${asset})" | ||
| curl -fsSL --retry 3 -o /tmp/opengrep "${base}/${asset}" | ||
| echo "${expected_sha} /tmp/opengrep" | sha256sum --check --status | ||
| chmod +x /tmp/opengrep | ||
| sudo mv /tmp/opengrep /usr/local/bin/opengrep | ||
| opengrep --version | ||
|
|
||
| - name: Run OpenGrep scan | ||
| id: scan | ||
| continue-on-error: true | ||
| env: | ||
| OPENGREP_CONFIG: ${{ inputs.config }} | ||
| run: | | ||
| set -euo pipefail | ||
| # Build a bash array of --config flags from the space/comma-separated | ||
| # input so values are passed as discrete argv entries (no | ||
| # word-splitting surprises). | ||
| args=() | ||
| normalized="${OPENGREP_CONFIG//,/ }" | ||
| for cfg in ${normalized}; do | ||
| args+=(--config "${cfg}") | ||
| done | ||
| opengrep scan \ | ||
| "${args[@]}" \ | ||
| --sarif \ | ||
| --sarif-output=results.sarif \ | ||
| --error \ | ||
| --no-suppress-errors \ | ||
| . | ||
|
|
||
| - name: Upload SARIF results | ||
| if: always() && hashFiles('results.sarif') != '' | ||
| uses: github/codeql-action/upload-sarif@68bde559dea0fdcac2102bfdf6230c5f70eb485e # v4.35.4 | ||
| with: | ||
| sarif_file: results.sarif | ||
| category: opengrep | ||
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,59 @@ | ||
| name: "PSScriptAnalyzer" | ||
|
|
||
| permissions: {} | ||
|
|
||
| on: | ||
| push: | ||
| branches: [ "main" ] | ||
| paths: | ||
| - '**/*.ps1' | ||
| - '**/*.psm1' | ||
| - '**/*.psd1' | ||
| - '**/*.ps1xml' | ||
| - '.github/workflows/psscriptanalyzer.yml' | ||
| pull_request: | ||
| branches: [ "main" ] | ||
| paths: | ||
| - '**/*.ps1' | ||
| - '**/*.psm1' | ||
| - '**/*.psd1' | ||
| - '**/*.ps1xml' | ||
| - '.github/workflows/psscriptanalyzer.yml' | ||
| schedule: | ||
| - cron: '28 13 * * 2' | ||
| workflow_dispatch: | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.ref }} | ||
| cancel-in-progress: ${{ github.event_name == 'pull_request' }} | ||
|
|
||
| jobs: | ||
| analyze: | ||
| name: Analyze PowerShell | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| security-events: write | ||
| contents: read | ||
| actions: read | ||
|
|
||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | ||
|
|
||
| # Scans the entire repository recursively. PSScriptAnalyzer only | ||
| # analyzes files with PowerShell extensions (.ps1, .psm1, .psd1, .ps1xml), | ||
| # so non-PowerShell content under powershell/, tools/, build/, etc. is | ||
| # automatically ignored. This avoids per-directory invocations and | ||
| # transparently picks up any future PowerShell files added to the repo. | ||
| - name: Run PSScriptAnalyzer | ||
| uses: microsoft/psscriptanalyzer-action@6b2948b1944407914a58661c49941824d149734f # v1.1 | ||
| with: | ||
| path: . | ||
| recurse: true | ||
| output: results.sarif | ||
|
|
||
| - name: Upload SARIF results | ||
| uses: github/codeql-action/upload-sarif@68bde559dea0fdcac2102bfdf6230c5f70eb485e # v4.35.4 | ||
| with: | ||
| sarif_file: results.sarif | ||
| category: psscriptanalyzer |
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.