GithubHelp home page GithubHelp logo

contrast-security-oss / contrastscan-action Goto Github PK

View Code? Open in Web Editor NEW
19.0 15.0 4.0 139 KB

Contrast Scan GitHub action

License: Apache License 2.0

kotlin contrast-security security sast static-analysis dockerfile sca

contrastscan-action's Introduction

Use Contrast Scan to analyze your code

This GitHub action lets you use Contrast Security's industry leading Code Scanner (Contrast Scan) to find vulnerabilities in your code. The Action compares the code scanning analysis of the PR to the last code scan analysis of the destination branch. GitHub fails the check if new vulnerabilities have been introduced.

  • Supported languages: Java, Javascript and .NET

Initial steps for using the action

If you are not familiar with GitHub actions read the GitHub Actions documentation to learn what GitHub Actions are and how to set them up. After which, complete the following steps:

  1. Configure the following GitHub secrets CONTRAST_API_KEY, CONTRAST_ORGANIZATION_ID, CONTRAST_AUTH_HEADER and CONTRAST_API_URL

    image

  • CodeSec by Contrast Security users: Retrieve authentication details for the secrets using the CLI.

  • Licensed Contrast Security users: Get your authentication details for the secrets from the 'User Settings' menu in the Contrast web interface: You will need the following

    • Organization ID
    • Your API key
    • Authorization header
    • You will also need the URL of your Contrast UI host. This input includes the protocol section of the URL (https://).

    image

  1. Copy sample workflow below and create a branch of your code to add Contrast security Scan. This branch is typically located at .github/workflows/build.yml

  2. Update the workflow file to specify when the action should run (for example on pull_request, on push)

    on:
      # Trigger analysis when pushing to main or an existing pull requests.  Also trigger on
      # new pull requests
      push:
        branches:
          - main
      pull_request:
          types: [opened, synchronize, reopened]
  3. Update the filepath in the workflow file to specfy the location of the built artifact or file to scan

    with:
      artifact: mypath/target/myartifact.jar 
  1. To fail based on severity of vulnerability found set severity (critical/high/medium or low) and fail to true

         severity: high
         fail: true   
  2. In order for GitHub to list vulnerabilities in the Security Tab of the repo, the contrast action must be accompanied by this GitHub action

        - name: Upload SARIF file
          uses: github/codeql-action/upload-sarif@v2
          with:
            sarif_file: results.sarif

    The value of sarif_file must be results.sarif which is the name that Contrast Scan Action will write the sarif to.

  3. After committing, create a Pull Request (PR) to merge the update back to your main branch. Creating the PR triggers the scan to run. The extra "Code Scanning" check appears in the PR

Since it’s likely there will be new findings when you add Contrast Scan, we don't want to fail and block merging the PR that adds Contrast Scan, forcing the owner of the PR to now fix all the newly exposed vulnerabilities that already existed in the code base.

After Contrast Scan runs on the main branch, all new PRs that you create where the Contrast Scan is run fail the code scanning check if they introduce new vulnerabilities beyond the baseline you just established.

Usage

All Contrast-related account secrets should be configured as GitHub secrets and will be passed to the scanner via environment variables in the GitHub runner. A simple workflow to get going is:

on:
  # Trigger analysis when pushing to main or an existing pull requests.  Also trigger on
  # new pull requests
  push:
    branches:
      - main
  pull_request:
      types: [opened, synchronize, reopened]
name: Contrast Security Scan
jobs:
  build_and_scan:
    permissions:
        contents: read # for actions/checkout
        security-events: write # for github/codeql-action/upload-sarif
        actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status
    runs-on: ubuntu-latest
    # check out project
    steps:
    - uses: actions/checkout@v2
    # steps to build the artifact you want to scan
    # -name: Build Project
    # ...
    # Scan Artifact    
    - name: Contrast Scan Action
      uses: Contrast-Security-OSS/[email protected]
      with:
        artifact: mypath/target/myartifact.jar
        apiKey: ${{ secrets.CONTRAST_API_KEY }}
        orgId: ${{ secrets.CONTRAST_ORGANIZATION_ID }}
        authHeader: ${{ secrets.CONTRAST_AUTH_HEADER }}
        severity: high
        fail: true
    # To list vulnerabilities in the GitHub Security Tab of the repo include GitHub upload-sarif action
    # The value of `sarif_file` must be `results.sarif` 
    - name: Upload SARIF file
      uses: github/codeql-action/upload-sarif@v2
      with:
        sarif_file: results.sarif

Required inputs

  • apiKey - An API key from the Contrast platform.
  • authHeader - User authorization credentials from Contrast.
  • orgId - The ID of your organization in Contrast.
  • artifact - The artifact to scan on the Contrast platform.

Optional inputs

  • apiUrl - The URL of the host. This input includes the protocol section of the URL (https://). The default value is https://ce.contrastsecurity.com (Contrast Community Edition).
  • severity - Specify severity of vulnerability. Values for severity are critical, high, medium or low. Fail must also be set to true to fail the check
  • fail - When set to true, fails the check if vulnerabilities have been detected that match at least the severity option specified.
  • projectName - The name of the scan project in Contrast. If you don’t specify a project name, Contrast Scan uses the artifact file name for the project name.
  • projectId - The ID of your project in Contrast.
    • If a project ID already exists, Contrast Scan uses that ID instead of one you specify.
    • If you don’t specify a project ID, Contrast Scan creates a project ID for the specified project name.
  • timeout - Sets a specific time span (in seconds) before the function times out. The default timeout is five minutes.

If you are using the Contrast Maven plugin

This GitHub action and the Contrast Maven plugin accomplish the same thing. You cannot use both at the same time. For example, if you are using maven to build your code and you run org.contrastsecurity.maven:scan during the build, do not use the Contrast Scan GitHub action.

contrastscan-action's People

Contributors

awshanks avatar codebylogan avatar contrastandrew avatar dawidoskwarek avatar gilday avatar markkuu avatar noahcontrast avatar seschis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

contrastscan-action's Issues

Unable to build action container

I'm trying to integrate the Contrast Scan Action to a pipeline but the GH execution is stuck building the action container
I'm using this version Contrast-Security-OSS/contrastscan-action@v2

Mon, 27 Jun 2022 18:02:50 GMT
Build container for action use: '/home/runner/work/_actions/Contrast-Security-OSS/contrastscan-action/v2/Dockerfile'.
Mon, 27 Jun 2022 18:02:50 GMT   /usr/bin/docker build -t 72882e:57d707e2ad494ed981317346c426b508 -f "/home/runner/work/_actions/Contrast-Security-OSS/contrastscan-action/v2/Dockerfile" "/home/runner/work/_actions/Contrast-Security-OSS/contrastscan-action/v2"
Mon, 27 Jun 2022 18:02:52 GMT   Sending build context to Docker daemon  26.11kB
Mon, 27 Jun 2022 18:02:52 GMT   
Mon, 27 Jun 2022 18:02:52 GMT   Step 1/4 : FROM ubuntu:latest
Mon, 27 Jun 2022 18:02:53 GMT   latest: Pulling from library/ubuntu
Mon, 27 Jun 2022 18:02:53 GMT   405f018f9d1d: Pulling fs layer
Mon, 27 Jun 2022 18:02:54 GMT   405f018f9d1d: Verifying Checksum
Mon, 27 Jun 2022 18:02:54 GMT   405f018f9d1d: Download complete
Mon, 27 Jun 2022 18:02:55 GMT   405f018f9d1d: Pull complete
Mon, 27 Jun 2022 18:02:55 GMT   Digest: sha256:b6b83d3c331794420340093eb706a6f152d9c1fa51b262d9bf34594887c2c7ac
Mon, 27 Jun 2022 18:02:55 GMT   Status: Downloaded newer image for ubuntu:latest
Mon, 27 Jun 2022 18:02:55 GMT    ---> 27941809078c
Mon, 27 Jun 2022 18:02:55 GMT   Step 2/4 : RUN apt-get update && apt-get install -y wget      && wget https://pkg.contrastsecurity.com/artifactory/cli/1.0.2/linux/contrast     && chmod +x contrast && mv contrast /usr/bin
Mon, 27 Jun 2022 18:02:55 GMT    ---> Running in f56ddc75f029
Mon, 27 Jun 2022 18:02:56 GMT   Get:1 http://archive.ubuntu.com/ubuntu jammy InRelease [270 kB]
Mon, 27 Jun 2022 18:02:56 GMT   Get:2 http://archive.ubuntu.com/ubuntu jammy-updates InRelease [109 kB]
Mon, 27 Jun 2022 18:02:56 GMT   Get:3 http://archive.ubuntu.com/ubuntu jammy-backports InRelease [99.8 kB]
Mon, 27 Jun 2022 18:02:56 GMT   Get:4 http://security.ubuntu.com/ubuntu jammy-security InRelease [110 kB]
Mon, 27 Jun 2022 18:02:56 GMT   Get:5 http://archive.ubuntu.com/ubuntu jammy/main amd64 Packages [1792 kB]
Mon, 27 Jun 2022 18:02:56 GMT   Get:6 http://archive.ubuntu.com/ubuntu jammy/restricted amd64 Packages [164 kB]
Mon, 27 Jun 2022 18:02:56 GMT   Get:7 http://archive.ubuntu.com/ubuntu jammy/universe amd64 Packages [17.5 MB]
Mon, 27 Jun 2022 18:02:56 GMT   Get:8 http://archive.ubuntu.com/ubuntu jammy/multiverse amd64 Packages [266 kB]
Mon, 27 Jun 2022 18:02:56 GMT   Get:9 http://archive.ubuntu.com/ubuntu jammy-updates/universe amd64 Packages [162 kB]
Mon, 27 Jun 2022 18:02:56 GMT   Get:10 http://archive.ubuntu.com/ubuntu jammy-updates/restricted amd64 Packages [250 kB]
Mon, 27 Jun 2022 18:02:56 GMT   Get:11 http://archive.ubuntu.com/ubuntu jammy-updates/multiverse amd64 Packages [4648 B]
Mon, 27 Jun 2022 18:02:56 GMT   Get:12 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 Packages [406 kB]
Mon, 27 Jun 2022 18:02:56 GMT   Get:13 http://archive.ubuntu.com/ubuntu jammy-backports/universe amd64 Packages [5797 B]
Mon, 27 Jun 2022 18:02:57 GMT   Get:14 http://security.ubuntu.com/ubuntu jammy-security/universe amd64 Packages [94.9 kB]
Mon, 27 Jun 2022 18:02:57 GMT   Get:15 http://security.ubuntu.com/ubuntu jammy-security/main amd64 Packages [238 kB]
Mon, 27 Jun 2022 18:02:57 GMT   Get:16 http://security.ubuntu.com/ubuntu jammy-security/multiverse amd64 Packages [4648 B]
Mon, 27 Jun 2022 18:02:57 GMT   Get:17 http://security.ubuntu.com/ubuntu jammy-security/restricted amd64 Packages [212 kB]
Mon, 27 Jun 2022 18:02:57 GMT   Fetched 21.7 MB in 2s (13.1 MB/s)
Mon, 27 Jun 2022 18:02:58 GMT   Reading package lists...
Mon, 27 Jun 2022 18:02:59 GMT   Reading package lists...
Mon, 27 Jun 2022 18:02:59 GMT   Building dependency tree...
Mon, 27 Jun 2022 18:02:59 GMT   Reading state information...
Mon, 27 Jun 2022 18:02:59 GMT   The following additional packages will be installed:
Mon, 27 Jun 2022 18:02:59 GMT     ca-certificates libpsl5 openssl publicsuffix
Mon, 27 Jun 2022 18:02:59 GMT   The following NEW packages will be installed:
Mon, 27 Jun 2022 18:02:59 GMT     ca-certificates libpsl5 openssl publicsuffix wget
Mon, 27 Jun 2022 18:02:59 GMT   0 upgraded, 5 newly installed, 0 to remove and 8 not upgraded.
Mon, 27 Jun 2022 18:02:59 GMT   Need to get 1889 kB of archives.
Mon, 27 Jun 2022 18:02:59 GMT   After this operation, 3929 kB of additional disk space will be used.
Mon, 27 Jun 2022 18:02:59 GMT   Get:1 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 openssl amd64 3.0.2-0ubuntu1.5 [1186 kB]
Mon, 27 Jun 2022 18:02:59 GMT   Get:2 http://archive.ubuntu.com/ubuntu jammy/main amd64 ca-certificates all 20211016 [148 kB]
Mon, 27 Jun 2022 18:02:59 GMT   Get:3 http://archive.ubuntu.com/ubuntu jammy/main amd64 libpsl5 amd64 0.21.0-1.2build2 [58.4 kB]
Mon, 27 Jun 2022 18:02:59 GMT   Get:4 http://archive.ubuntu.com/ubuntu jammy/main amd64 publicsuffix all 20211207.1025-1 [129 kB]
Mon, 27 Jun 2022 18:02:59 GMT   Get:5 http://archive.ubuntu.com/ubuntu jammy/main amd64 wget amd64 1.21.2-2ubuntu1 [367 kB]
Mon, 27 Jun 2022 18:02:59 GMT   debconf: delaying package configuration, since apt-utils is not installed
Mon, 27 Jun 2022 18:02:59 GMT   Fetched 1889 kB in 0s (7319 kB/s)
Mon, 27 Jun 2022 18:02:59 GMT   Selecting previously unselected package openssl.
Mon, 27 Jun 2022 18:02:59 GMT   (Reading database ... 
Mon, 27 Jun 2022 18:02:59 GMT   (Reading database ... 5%
Mon, 27 Jun 2022 18:02:59 GMT   (Reading database ... 10%
Mon, 27 Jun 2022 18:02:59 GMT   (Reading database ... 15%
Mon, 27 Jun 2022 18:02:59 GMT   (Reading database ... 20%
Mon, 27 Jun 2022 18:02:59 GMT   (Reading database ... 25%
Mon, 27 Jun 2022 18:02:59 GMT   (Reading database ... 30%
Mon, 27 Jun 2022 18:02:59 GMT   (Reading database ... 35%
Mon, 27 Jun 2022 18:02:59 GMT   (Reading database ... 40%
Mon, 27 Jun 2022 18:02:59 GMT   (Reading database ... 45%
Mon, 27 Jun 2022 18:02:59 GMT   (Reading database ... 50%
Mon, 27 Jun 2022 18:02:59 GMT   (Reading database ... 55%
Mon, 27 Jun 2022 18:02:59 GMT   (Reading database ... 60%
Mon, 27 Jun 2022 18:02:59 GMT   (Reading database ... 65%
Mon, 27 Jun 2022 18:02:59 GMT   (Reading database ... 70%
Mon, 27 Jun 2022 18:02:59 GMT   (Reading database ... 75%
Mon, 27 Jun 2022 18:02:59 GMT   (Reading database ... 80%
Mon, 27 Jun 2022 18:02:59 GMT   (Reading database ... 85%
Mon, 27 Jun 2022 18:02:59 GMT   (Reading database ... 90%
Mon, 27 Jun 2022 18:02:59 GMT   (Reading database ... 95%
Mon, 27 Jun 2022 18:02:59 GMT   (Reading database ... 100%
Mon, 27 Jun 2022 18:02:59 GMT   (Reading database ... 4395 files and directories currently installed.)
Mon, 27 Jun 2022 18:02:59 GMT   Preparing to unpack .../openssl_3.0.2-0ubuntu1.5_amd64.deb ...
Mon, 27 Jun 2022 18:02:59 GMT   Unpacking openssl (3.0.2-0ubuntu1.5) ...
Mon, 27 Jun 2022 18:02:59 GMT   Selecting previously unselected package ca-certificates.
Mon, 27 Jun 2022 18:02:59 GMT   Preparing to unpack .../ca-certificates_20211016_all.deb ...
Mon, 27 Jun 2022 18:02:59 GMT   Unpacking ca-certificates (20211016) ...
Mon, 27 Jun 2022 18:02:59 GMT   Selecting previously unselected package libpsl5:amd64.
Mon, 27 Jun 2022 18:02:59 GMT   Preparing to unpack .../libpsl5_0.21.0-1.2build2_amd64.deb ...
Mon, 27 Jun 2022 18:02:59 GMT   Unpacking libpsl5:amd64 (0.21.0-1.2build2) ...
Mon, 27 Jun 2022 18:02:59 GMT   Selecting previously unselected package publicsuffix.
Mon, 27 Jun 2022 18:02:59 GMT   Preparing to unpack .../publicsuffix_20211207.1025-1_all.deb ...
Mon, 27 Jun 2022 18:02:59 GMT   Unpacking publicsuffix (20211207.1025-1) ...
Mon, 27 Jun 2022 18:02:59 GMT   Selecting previously unselected package wget.
Mon, 27 Jun 2022 18:02:59 GMT   Preparing to unpack .../wget_1.21.2-2ubuntu1_amd64.deb ...
Mon, 27 Jun 2022 18:02:59 GMT   Unpacking wget (1.21.2-2ubuntu1) ...
Mon, 27 Jun 2022 18:02:59 GMT   Setting up libpsl5:amd64 (0.21.0-1.2build2) ...
Mon, 27 Jun 2022 18:02:59 GMT   Setting up wget (1.21.2-2ubuntu1) ...
Mon, 27 Jun 2022 18:02:59 GMT   Setting up openssl (3.0.2-0ubuntu1.5) ...
Mon, 27 Jun 2022 18:02:59 GMT   Setting up publicsuffix (20211207.1025-1) ...
Mon, 27 Jun 2022 18:02:59 GMT   Setting up ca-certificates (20211016) ...
Mon, 27 Jun 2022 18:02:59 GMT   debconf: unable to initialize frontend: Dialog
Mon, 27 Jun 2022 18:02:59 GMT   debconf: (TERM is not set, so the dialog frontend is not usable.)
Mon, 27 Jun 2022 18:02:59 GMT   debconf: falling back to frontend: Readline
Mon, 27 Jun 2022 18:02:59 GMT   debconf: unable to initialize frontend: Readline
Mon, 27 Jun 2022 18:02:59 GMT   debconf: (Can't locate Term/ReadLine.pm in @INC (you may need to install the Term::ReadLine module) (@INC contains: /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.34.0 /usr/local/share/perl/5.34.0 /usr/lib/x86_64-linux-gnu/perl5/5.34 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl-base /usr/lib/x86_64-linux-gnu/perl/5.34 /usr/share/perl/5.34 /usr/local/lib/site_perl) at /usr/share/perl5/Debconf/FrontEnd/Readline.pm line 7.)
Mon, 27 Jun 2022 18:02:59 GMT   debconf: falling back to frontend: Teletype
Mon, 27 Jun 2022 18:03:00 GMT   Updating certificates in /etc/ssl/certs...
Mon, 27 Jun 2022 18:03:00 GMT   127 added, 0 removed; done.
Mon, 27 Jun 2022 18:03:00 GMT   Processing triggers for libc-bin (2.35-0ubuntu3) ...
Mon, 27 Jun 2022 18:03:00 GMT   Processing triggers for ca-certificates (20211016) ...
Mon, 27 Jun 2022 18:03:00 GMT   Updating certificates in /etc/ssl/certs...
Mon, 27 Jun 2022 18:03:01 GMT   0 added, 0 removed; done.
Mon, 27 Jun 2022 18:03:01 GMT   Running hooks in /etc/ca-certificates/update.d...
Mon, 27 Jun 2022 18:03:01 GMT   done.
Mon, 27 Jun 2022 18:03:01 GMT   --2022-06-27 18:03:01--  https://pkg.contrastsecurity.com/artifactory/cli/1.0.2/linux/contrast
Mon, 27 Jun 2022 18:03:01 GMT   Resolving pkg.contrastsecurity.com (pkg.contrastsecurity.com)... 54.85.114.59, 54.174.213.68, 54.147.240.236, ...
Mon, 27 Jun 2022 18:03:01 GMT   Connecting to pkg.contrastsecurity.com (pkg.contrastsecurity.com)|54.85.114.59|:443... connected.
Mon, 27 Jun 2022 18:15:00 GMT   HTTP request sent, awaiting response... 
Mon, 27 Jun 2022 18:15:00 GMT   Error: The operation was canceled.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.