Skip to main content

SecScanner2JUnit

PyPI version Downloads Contributors Activity DockerHub DockerHub Pulls Supports latest GitLab version Open in Gitpod

GitLab offers security scanning and visualization directly via and on their platform.
One nice feature is direct insights on merge requests. However, this feature is only available with the Ultimate tier. To also use this feature on the free tier, one can build around it by taking the security tool output, converting it to the JUnit format, and uploading it as JUnit report.

To summarize, this tool is for you if:

  • You use GitLab's free tier
  • You use Gitlabs security templates
  • You want to easily access security tool output in merge requests

If you are on the GitLabs Ultimate tier, just use their tooling! No need to mess up your .gitlab-ci.yml file. :smile:

Which scanning types are supported?

All scanning types available under the free tier:

  • Secret Scanning
  • Static Application Security Testing (SAST)
  • Container Scanning
  • Infrastructure as Code Scanning

How to use?

Procedure:

  1. Overwrite the existing job so that the report can be used by future jobs.
  2. Convert report
  3. Upload converted report as junit report

Report input types:

You can use following report types as inputs with ss2ju command. (f.e ss2ju sast ....)

Example for Secret Scanning

This example can be used as is.

stages:
  - test
  - convert
  
- include:
  - template: Security/Secret-Detection.gitlab-ci.yml
  
secret_detection:
  artifacts:
    paths:
      - gl-secret-detection-report.json
    when: always
    
secret_convert:
  stage: convert
  dependencies:
    - secret_detection
  script:
    - pip3 install SecScanner2JUnit
    - ss2ju secrets gl-secret-detection-report.json gl-secret-detection-report.xml
  artifacts:
    reports:
      junit: gl-secret-detection-report.xml

Example for SAST

Since GitLab decides dynamically which scanners to use depending on project languages, it makes sense to first perform a testrun only including the template. This way one can see which jobs are executed and then overwrite them.

stages:
  - test
  - convert
  
- include:
  - template: Security/SAST.gitlab-ci.yml
  
semgrep-sast:
  after_script:
    - cp gl-sast-report.json gl-sast-semgrep-report.json
  artifacts:
    paths:
      - gl-sast-semgrep-report.json
    when: always

brakeman-sast:
  after_script:
    - cp gl-sast-report.json gl-sast-brakeman-report.json
  artifacts:
    paths:
      - gl-sast-brakeman-report.json
    when: always

semgrep-sast-convert:
  stage: convert
  dependencies:
    - semgrep-sast
  script:
    - pip3 install SecScanner2JUnit
    - ss2ju sast gl-sast-semgrep-report.json gl-sast-semgrep-report.xml
  artifacts:
    reports:
      junit: gl-sast-semgrep-report.xml
      
brakeman-sast-convert:
  stage: convert
  dependencies:
    - brakeman-sast
  script:
    - pip3 install SecScanner2JUnit
    - ss2ju sast gl-sast-brakeman-report.json gl-sast-brakeman-report.xml
  artifacts:
    reports:
      junit: gl-sast-brakeman-report.xml

Example for Container Scanning

- include:
  - template: Jobs/Build.gitlab-ci.yml #Build and push the container image
  - template: Security/Container-Scanning.gitlab-ci.yml #Scan the built image

container_scanning:
  artifacts:
    paths:
      - gl-container-scanning-report.json
    when: always

container_scanning-convert:
  stage: convert
  dependencies:
    - container_scanning
  script:
    - pip3 install SecScanner2JUnit
    - ss2ju container_scanning gl-container-scanning-report.json gl-container-scanning-report.xml
  artifacts:
    reports:
      junit: gl-container-scanning-report.xml

Suppression

You can provide a file with suppression which will allow to ignore some vulnerabilities.

You have to create a file ss2ju-config.yml f.e. in .gitlab directory which includes:

sast:
  suppressions:
    - type: "cwe"
      value: "2555"
    - type: "find_sec_bugs_type"
      value: "SPRING_ENDPOINT"
    - id: "db914ce5737b49650ae650fc3b0fe38a531eadd8ea780f48a013419c4adec7f0"

And now you can modify execution commands as follows:

    - ss2ju sast gl-sast-semgrep-report.json gl-sast-semgrep-report.xml .gitlab/ss2ju-config.yml

Usage with docker

For easier usage in CI, Secscanner2JUnit is also shipped in a docker container: https://hub.docker.com/r/logchange/secscanner2junit
Its' usage is similar to the ways described above:

...

secret_convert:
  stage: convert
  image:
    name: logchange/secscanner2junit:latest
    entrypoint: [""]
  dependencies:
    - secret_detection
  script:
    - ss2ju secrets gl-secret-detection-report.json gl-secret-detection-report.xml
  artifacts:
    reports:
      junit: gl-secret-detection-report.xml

Development

Create Python Virtual Environment

python -m venv ./venv

Activate Python Virtual Environment

source ./venv/bin/activate

Install dependencies

poetry install

Run tests

poetry run pytest

Release files for secscanner2junit 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for secscanner2junit 1.1.0
File Size Uploaded
secscanner2junit-1.1.0.tar.gz 20.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for secscanner2junit 1.1.0
File Interpreter ABI Platform
secscanner2junit-1.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 43.9 kB

Release files / secscanner2junit-1.1.0.tar.gz

Download URL secscanner2junit-1.1.0.tar.gz
Size 20.9 kB
Tags Source
SHA-256 checksum
How to use checksums
5a9a572f959aada099f2a84de7239d8595420cacdfdc7ccfbd9f0ff247f0a1da
BLAKE2b-256 checksum
How to use checksums
e70f20c4cea31368e216d9a36f856212e4748fd423dd8f9fea9411205e7d64c5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.0.1 CPython/3.10.2 Linux/6.8.0-1020-azure

Release files / secscanner2junit-1.1.0-py3-none-any.whl

Download URL secscanner2junit-1.1.0-py3-none-any.whl
Size 23.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
62e9aaecc509f8af99cae491bf6e606d4a84438e69801d8f41455c5be3427f68
BLAKE2b-256 checksum
How to use checksums
78260ae9fd33e93102d5dde5387925e6116610f42fed883e691ed24d6bf06c13
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.0.1 CPython/3.10.2 Linux/6.8.0-1020-azure

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.1.17

2 release files

0.1.16

2 release files

0.1.15

2 release files

0.1.14

2 release files

0.1.13

2 release files

0.1.9

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page