Skip to main content

Gitleaks scanner reference

You can scan your code repositories using Gitleaks, an open-source tool designed to find common security issues in Python code.

Gitleaks can publish results to Static Analysis Results Interchange Format (SARIF), an open data format supported by many scan tools.

For a description of the end-to-end workflow, go to Ingest SARIF data.

GitLeaks step configuration

The recommended workflow is to add a GitLeaks step to a Security Tests or CI Build stage and then configure it as described below.

Scan Mode

The orchestration mode to use for the scan. The following list includes the UI and YAML values for the supported options.

  • Ingestion Ingestion scans are not orchestrated. The Security step ingest results from a previous scan (for a scan run in an previous step) and then normallizes and compresses the results.

Scan Configuration

The predefined configuration to use for the scan. All scan steps have at least one configuration.

Target

Type

  • Repository Scan a codebase repo.

    In most cases, you specify the codebase using a code repo connector that connects to the Git account or repository where your code is stored. For information, go to Create and configure a codebase.

Name

The Identifier that you want to assign to the target you’re scanning in the pipeline. Use a unique, descriptive name such as codebaseAlpha or jsmith/myalphaservice. Using descriptive target names will make it much easier to navigate your scan data in the STO UI.

Variant

An identifier for a specific variant to scan, such as the branch name or image tag. This identifier is used to differentiate or group results for a target. Harness maintains a historical trend for each variant.

You can see the target name, type, and variant in the Test Targets UI:

Target name, type, and branch

Workspace (repository)

The workspace path on the pod running the Security step. The workspace path is /harness by default.

You can override this if you want to scan only a subset of the workspace. For example, suppose the pipeline publishes artifacts to a subfolder /tmp/artifacts and you want to scan these artifacts only. In this case, you can specify the workspace path as /harness/tmp/artifacts.

Ingestion File

The results data file to use when running an Ingestion scan.

Generally an Ingestion scan consists of a scan step (to generate the data file) and an ingestion step (to ingest the data file).

In addition to ingesting scan data in the external scanner's native format, STO steps can also ingest data in SARIF and Harness Custom JSON format.

For more information, go to Ingest Scan Results into an STO Pipeline.

Log Level, CLI flags, and Fail on Severity

Log Level

The minimum severity of the messages you want to include in your scan logs. You can specify one of the following:

  • DEBUG
  • INFO
  • WARNING
  • ERROR

Additional CLI flags

You can use this field to customize the scan with specific command-line arguments supported by that scanner.

Fail on Severity

Every Security step has a Fail on Severity setting. If the scan finds any vulnerability with the specified severity level or higher, the pipeline fails automatically. You can specify one of the following:

  • CRITICAL
  • HIGH
  • MEDIUM
  • LOW
  • INFO
  • NONE — Do not fail on severity

The YAML definition looks like this: fail_on_severity : critical # | high | medium | low | info | none

Settings

You can add a tool_args setting to run the Gitleaks scanner binary with specific command-line arguments. For example, you can redact secrets from the scanner output using -redact: tool_args : --redact

Additional Configuration

In the Additional Configuration settings, you can use the following options:

Advanced settings

In the Advanced settings, you can use the following options:

Gitleaks step configuration example

Here's an example of a configured Gitleaks step.

- step:
type: Gitleaks
name: gitleaks
identifier: gitleaks
spec:
mode: ingestion
config: default
target:
name: nodegoat
type: repository
variant: dev
advanced:
log:
level: debug
ingestion:
file: /path/of/file.sarif
description: gitleaks step

Gitleaks ingestion pipeline example

The following pipeline shows an end-to-end ingestion workflow. The pipeline consists of a Build stage with two steps:

  1. A Run step that sends a gitleaks detect command to the local Gitleaks container to scan the codebase specified for the pipeline. This command specifies the output file for the scan results: /shared/customer_artifacts/sarif_simple.sarif.

  2. A Gitleaks step that auto-detects the data file type (SARIF) and then ingests and normalizes the data from the output file.


pipeline:
projectIdentifier: STO
orgIdentifier: default
tags: {}
stages:
- stage:
name: gitleaks-build-stage
identifier: gitleaksbuildstage
type: CI
spec:
cloneCodebase: true
execution:
steps:
- stepGroup:
name: Ingestion Workflow with a runs step
identifier: Generation
steps:
- step:
type: Run
name: gitleaks
identifier: Run_1
spec:
connectorRef: mydockerhubconnector
image: zricethezav/gitleaks:latest
shell: Sh
command: |
gitleaks detect --source /harness --report-path /shared/customer_artifacts/ingest-data.sarif --report-format 'sarif' --exit-code 0 --redact -v
resources:
limits:
memory: 2048Mi
cpu: 2000m
when:
stageStatus: Success
- step:
type: Gitleaks
name: gitleaks_ingest
identifier: gitleaks_ingest
spec:
mode: ingestion
config: default
target:
name: gitleaks-example
type: repository
variant: master
advanced:
log:
level: info
ingestion:
file: /shared/customer_artifacts/ingest-data.sarif
sharedPaths:
- /shared/customer_artifacts
caching:
enabled: false
paths: []
infrastructure:
type: KubernetesDirect
spec:
connectorRef: myk8sconnector
namespace: harness-delegate-ng
automountServiceAccountToken: true
nodeSelector: {}
os: Linux
properties:
ci:
codebase:
connectorRef: wwdvpwa
repoName: dvpwa
build: <+input>
identifier: Gitleaks_docsexample_INGESTION
name: Gitleaks docs-example INGESTION