Gitleaks scanner reference for STO
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.
For more information
The following topics contain useful information for setting up scanner integrations in STO:
Gitleaks step settings for STO scans
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
- Ingestion Configure the step to read scan results from a data file and then ingest, normalize, and deduplicate the data.
- Orchestration Configure the step to run a scan and then ingest, normalize, and deduplicate 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 Configure codebase.
Name
The identifier for the target, such as codebaseAlpha
or jsmith/myalphaservice
. Descriptive target names make it much easier to navigate your scan data in the STO UI.
It is good practice to specify a baseline for every target.
Variant
The identifier for the specific variant to scan. This is usually the branch name, image tag, or product version. Harness maintains a historical trend for each variant.
Workspace (repository)
The workspace path on the pod running the scan 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 path to your scan results when running an Ingestion scan, for example /shared/scan_results/myscan.latest.sarif
.
-
The data file must be in a supported format for the scanner.
-
The data file must be accessible to the scan step. It's good practice to save your results files to a shared path in your stage. In the visual editor, go to the stage where you're running the scan. Then go to Overview > Shared Paths. You can also add the path to the YAML stage definition like this:
- stage:
spec:
sharedPaths:
- /shared/scan_results
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
You can also use tool_args
to speed up your Gitleaks scans.
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:
Speeding up Gitleaks scans
A Gitleaks scan might take a long time if your repository is very large or has a long commit history. To speed up your scans, you can use the tool_args
setting to run gitleaks detect
with the following command-line option:
-
tool_args : --log-opts="-n 1000"
You can use
--log-opts
to narrow the range of commits that Gitleaks scans in a Pull Request. For example,-n 1000
limits the scan to the last 1000 commits. You can also scan a range of commits using a command such as:tool_args : --log-opts=="--all commitA..commitF"
Gitleaks step configuration example for STO
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 for STO
The following pipeline shows an end-to-end ingestion workflow. The pipeline consists of a Build stage with two steps:
-
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/scan_results/sarif_simple.sarif
. -
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: CONTAINER_IMAGE_REGISTRY_CONNECTOR
image: zricethezav/gitleaks:latest
shell: Sh
command: |
gitleaks detect --source /harness --report-path /shared/scan_results/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/scan_results/ingest-data.sarif
sharedPaths:
- /shared/scan_results
caching:
enabled: false
paths: []
infrastructure:
type: KubernetesDirect
spec:
connectorRef: K8S_DELEGATE_CONNECTOR
namespace: harness-delegate-ng
automountServiceAccountToken: true
nodeSelector: {}
os: Linux
properties:
ci:
codebase:
connectorRef: CODEBASE_CONNECTOR
repoName: dvpwa
build: <+input>
identifier: Gitleaks_docsexample_INGESTION
name: Gitleaks docs-example INGESTION
Gitleaks orchestration pipeline example for STO
The following pipeline illustrates an orchestration workflow where the Gitleaks step scans the codebase and ingests the results in one step.
pipeline:
projectIdentifier: STO
orgIdentifier: default
tags: {}
stages:
- stage:
name: gitleaks-build-stage
identifier: gitleaksbuildstage
type: CI
spec:
cloneCodebase: true
execution:
steps:
- stepGroup:
name: "STO Orchestration "
identifier: Orchestration
steps:
- step:
type: Gitleaks
name: gitleaks_orch
identifier: gitleaks_orch
spec:
mode: orchestration
config: default
target:
name: gitleaks-example
type: repository
variant: master
advanced:
log:
level: info
settings:
tool_args: "--log-opts=\"-n 1000\"`"
resources:
limits:
memory: 2048Mi
cpu: 2000m
sharedPaths:
- /shared/scan_results
caching:
enabled: false
paths: []
infrastructure:
type: KubernetesDirect
spec:
connectorRef: K8S_DELEGATE_CONNECTOR
namespace: harness-delegate-ng
automountServiceAccountToken: true
nodeSelector: \{}
os: Linux
properties:
ci:
codebase:
connectorRef: CODEBASE_CONNECTOR
repoName: dvpwa
build: <+input>
identifier: gitleaks_docs_example_ORCHESTRATION
name: gitleaks docs example - ORCHESTRATION