Git Product home page Git Product logo

container-scan-to-sarif's Introduction

container-scan-to-sarif

Build Lint Go Report Card Release

container-scan-to-sarif converts Azure Container Scan Action output to Static Analysis Results Interchange Format (SARIF), for an easier integration with tools like GitHub Code Scanning.

Rationale

The Azure Container Scan Action combines both Trivy and Dockle tools to scan container images for common vulnerabilities (CVEs) and best practices violations. It also provides with the ability to ignore some checks if needed, via an allowedlist.yaml file.

This is all great, but the resulting output is a non-standard JSON file, which, at this time, makes it hard to read across different CI runs or integrate with other tools.

On the other hand, GitHub Code Scanning integrates very well with external tools that are able to produce Static Analysis Results Interchange Format (SARIF) reports, so users can navigate their reports in the nice "Code Scanning Alerts" interface.

This is where container-scan-to-sarif comes into play, by bridging the gap between Container Scan and other tools that support SARIF standard reports, like GitHub Code Scanning.

It also started as a learning exercise for myself to use Go in practice.

Installation

You can download the latest release of container-scan-to-sarif.

Or, from the sources:

go install github.com/rm3l/container-scan-to-sarif/cmd/container-scan-to-sarif@latest

Usage

In GitHub Workflows

You may want to use the following Action in your Workflows: rm3l/container-scan-to-sarif-action, like so:

  - name: Scan Container Image
    id: scan
    continue-on-error: true
    uses: Azure/[email protected]
    with:
      image-name: my-container-image

  - name: Convert Container Scan Report to SARIF
    id: scan-to-sarif
    uses: rm3l/container-scan-to-sarif-action@v1
    if: ${{ always() }}
    with:
      input-file: ${{ steps.scan.outputs.scan-report-path }}

  - name: Upload SARIF reports to GitHub Security tab
    uses: github/codeql-action/upload-sarif@v1
    if: ${{ always() }}
    with:
      sarif_file: ${{ steps.scan-to-sarif.outputs.sarif-report-path }}

After your Workflow run passes, you should then be able to navigate the container scan report under your "Security > Code scanning alerts" tab.

Standalone executable

Container image

Container images for container-scan-to-sarif are pushed to GitHub Packages. You can therefore run it with Docker, by mounting your Container Scan output inside the container, like so:

The working directory inside the container is set to /data. So you can just mount your Container Scan report under a /data/scanreport.json and run container-scan-to-sarif.

docker container run --rm \
  -v /path/to/my/container-scan-report.json:/data/scanreport.json \
  -t ghcr.io/rm3l/container-scan-to-sarif 

Alternatively, you can specify a different path (in the container), like so:

docker container run --rm \
  -v /path/to/my/container-scan-report.json:/tmp/my-scanreport.json \
  -t ghcr.io/rm3l/container-scan-to-sarif \
  -input /tmp/my-scanreport.json

CLI

container-scan-to-sarif --help

Usage of ./container-scan-to-sarif:
  -input string
        path to the Container Scan JSON Report (default "./scanreport.json")

Building from source

Once you have cloned this repo and installed Go, you can build container-scan-to-sarif with the command below:

# Build
go build -o ./container-scan-to-sarif cmd/container-scan-to-sarif/main.go

# The executable can the be found here: ./container-scan-to-sarif
./container-scan-to-sarif --help

Contribution Guidelines

Contributions and issue reporting are more than welcome. So to help out, do feel free to fork this repo and open up a pull request. I'll review and merge your changes as quickly as possible.

You can use GitHub issues to report bugs. However, please make sure your description is clear enough and has sufficient instructions to be able to reproduce the issue.

Developed by

License

The MIT License (MIT)

Copyright (c) 2021-2022 Armel Soro

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

container-scan-to-sarif's People

Contributors

dependabot[bot] avatar rm3l avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

container-scan-to-sarif's Issues

Creates invalid SARIF file if container scan returns no results

When container scan doesn't find any vulnerabilities the resulting SARIF file has result set to null:

{
  "version": "2.1.0",
  "$schema": "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Documents/CommitteeSpecifications/2.1.0/sarif-schema-2.1.0.json",
  "runs": [
    {
      "tool": {
        "driver": {
          "name": "container-scan",
          "informationUri": "https://github.com/Azure/container-scan",
          "fullName": "Container Scan",
          "version": "0.1",
          "rules": []
        },
        "extensions": [
          {
            "name": "Trivy",
            "version": "latest"
          },
          {
            "name": "Dockle",
            "version": "latest"
          }
        ]
      },
      "results": null
    }
  ]
}

The upload-sarif action expects an array in this case and fails with an error:

instance.runs[0].results is not of a type(s) array

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.