advanced-security / secret-scanning-review-action

Action to detect if a secret is initially detected in a PR commit
MIT License
9 stars 3 forks source link

GitHub GitHub Issues GitHub Issues GitHub Issues GitHub Stars GitHub forks

Latest OpenSSF Scorecard GitHub License

secret-scanning-review-action

Action to provide feedback annotations to the developer when a Secret Scanning alert is initially detected in a PR commit.

The action is intended for private repositories that have GitHub Advanced Security licensed.

Adds a Warning annotation alert to any PR file that has introduced a secret (based on the secret scanning alert initial commit)

Secret Scanning Review Workflow File Annotation

Workflow FailOnAlert configuration to turn those Warnings into Errors!

Secret Scanning Review Workflow File Annotation

Allowing you additional secret scanning trust->but->verify control in your branch protection rules

Secret Scanning Review Workflow Checks

Summary of all secrets from the PR in the Secret Scanning Review workflow job summary

Secret Scanning Review Workflow Checks

Comments on the Pull Request

Secret Scanning Review Workflow Checks

Overview

This action is used to enhance the Advanced Security Secret Scanning experience with:

Security Model Changes

Configuration Options

token

REQUIRED A GitHub Access Token

NOTE:

fail-on-alert

OPTIONAL If provided, will fail the action workflow via non-zero exit code if a matching secret scanning alert is found. Default "false".

fail-on-alert-exclude-closed

OPTIONAL If provided, will handle failure exit code / annotations as warnings if the alert is found and the alert is marked as closed (state: 'resolved'). Default "false".

disable-pr-comment

OPTIONAL If provided, will not put a comment on the Pull Request with a summary of detected secrets. Default "false".

Outputs

N/A

Example usage

Please keep in mind that you need a GitHub Advanced Security license if you're running this action on private repositories.

  1. Add a new YAML workflow to your .github/workflows folder:
name: 'Secret Scanning Review'
on: [pull_request]

jobs:
  secret-scanning-review:
    runs-on: ubuntu-latest
    steps:
      - name: 'Secret Scanning Review Action'
        uses: advanced-security/secret-scanning-review-action@v1
        with:
          token: ${{ secrets.SECRET_SCAN_REVIEW_GITHUB_TOKEN }}
          fail-on-alert: true
          fail-on-alert-exclude-closed: true

Architecture

sequenceDiagram
    autonumber
    participant Repo as Repository
    participant PR as Pull Request
    participant Action as Action Workflow
    participant API_PR as pulls<br/><br/>REST API
    participant API_SECRET as secret-scanning<br/><br/> REST API

    Repo->>PR: Create/Update PR
    PR->>Action: invoke `pull_request` workflow
    Action->>API_PR: GET PR
    Action->>API_PR: GET PR Commits

    loop Commits
        Action->>Action: Build PR Commit SHA list
    end

    Action->>API_SECRET: GET Secret Scanning Alerts

    loop Secret Scanning Alerts
        Action->>API_SECRET: GET Secret Scanning Alert List Locations
        loop Secret Scanning Alert Locations
        Action->>Action:Build List of Alert Initial Location SHAs that are<br/>contained in the PR SHA List (Step 5)
        end
    end

    loop List of matching PR/Alerts
      loop List of Locations for matching PR/Alerts
        Action->>PR:Writes an Annotation to the message log<br/>associated with the file and line/col number.<br/>(Error/Warning based on FailOnAlert setting)
      end
    end

    Note right of PR: Annotations are visible<br/>on the PR Files changed rich diff

    Action->>PR:Writes summary to PR comment and log.<br/>Returns success/failure exit code based on FailOnAlert setting.

    Note right of PR: Fail workflow check<br/>based on FailOnAlert setting.

Environment Variables

Dependencies

REST APIs

FAQ

Why Powershell

A few reasons

  1. I was challanged by a coworker during a Python v PowerShell discussion
  2. To demonstrate GitHub Actions flexibility (pwsh is installed by default on the runners!)
  3. Find current pitfalls and work with platform team to improve!
  4. Powershell is cross-platform automation platform with the power of .NET!