Skip to content

Security & secrets: Scans & code quality

Security & secrets commands for scans & code quality (tags: #vulnerabilities #quality #sbom #iac #ci).

Index
7 items

Trivy4

Trivy: Scan an image for high and critical CVEs

Safe

Only vulnerabilities that actually have a fix available.

trivy image --severity HIGH,CRITICAL --ignore-unfixed <image>:<tag>
What each part does
  1. trivy imagescan a container image (OS packages + app dependencies)
  2. --severity HIGH,CRITICALonly show these severities
  3. --ignore-unfixedhide vulnerabilities with no fix available
  4. <image>:<tag>the image

Also known as: cve scan · image scan

Trivy: Fail CI on critical vulnerabilities

Safe

Non-zero exit when a fixable critical CVE is found: use as a pipeline gate.

trivy image --exit-code 1 --severity CRITICAL --ignore-unfixed <image>:<tag>
What each part does
  1. trivy imagescan a container image
  2. --exit-code 1exit with 1 if anything is found, so the CI job fails
  3. --severity CRITICALonly count critical findings
  4. --ignore-unfixedskip vulnerabilities with no fixed version yet
  5. <image>:<tag>the image to scan

Also known as: security gate · pipeline scan

Trivy: Scan Terraform or Kubernetes manifests

Safe

Misconfiguration checks for Terraform, Kubernetes YAML, Helm charts and Dockerfiles.

trivy config <path>
What each part does
  1. trivy configscan IaC files: Terraform, Kubernetes YAML, Helm, Dockerfiles, CloudFormation
  2. <path>directory or file to scan

Also known as: tfsec · iac scan · kubernetes misconfig

Trivy: Generate an SBOM for an image

Safe

Software bill of materials in CycloneDX format (use spdx-json for SPDX).

trivy image --format cyclonedx --output sbom.json <image>:<tag>
What each part does
  1. trivy imagescan a container image
  2. --format cyclonedxoutput a CycloneDX SBOM (or spdx-json)
  3. --output sbom.jsonwrite to this file
  4. <image>:<tag>the image
  • #trivy
  • #sbom

Also known as: sbom · cyclonedx · spdx

SonarQube3

SonarQube: Run an analysis with sonar-scanner

Safe

Analyse the current directory and upload results.

sonar-scanner -Dsonar.projectKey=<project-key> -Dsonar.host.url=<sonar-url> -Dsonar.token=$SONAR_TOKEN
What each part does
  1. sonar-scannerthe standalone scanner; also reads sonar-project.properties
  2. -Dsonar.projectKey=<project-key>the project in SonarQube
  3. -Dsonar.host.url=<sonar-url>the SonarQube server
  4. -Dsonar.token=$SONAR_TOKENauth token from an env var
  • #sonarqube
  • #ci
  • #quality

Also known as: sonar scan · code quality

SonarQube: Run an analysis with Maven

Safe

Build, test and analyse a Maven project so coverage is included.

mvn verify sonar:sonar -Dsonar.projectKey=<project-key> -Dsonar.host.url=<sonar-url> -Dsonar.token=$SONAR_TOKEN
What each part does
  1. mvn verifybuild and run tests first (so coverage reports exist)
  2. sonar:sonarrun the SonarScanner for Maven
  3. -Dsonar.projectKey=<project-key>the project in SonarQube
  4. -Dsonar.host.url=<sonar-url>the SonarQube server
  5. -Dsonar.token=$SONAR_TOKENauth token from an env var
  • #sonarqube
  • #ci
  • #quality

Also known as: sonar maven

SonarQube: Check the quality gate status

Safe

OK or ERROR for the latest analysis. Add -Dsonar.qualitygate.wait=true to the scanner to block CI instead.

curl -s -u "$SONAR_TOKEN:" "<sonar-url>/api/qualitygates/project_status?projectKey=<project-key>" | jq -r .projectStatus.status
What each part does
  1. curl -sHTTP request, quiet
  2. -u "$SONAR_TOKEN:"token as the user name, empty password
  3. /api/qualitygates/project_status?projectKey=<project-key>quality gate result for the project
  4. | jq -r .projectStatus.statusprint just OK, WARN, ERROR or NONE

Also known as: quality gate failed · sonar gate

My DevOps Playbook by Angelo John Calleja

New runbook

GitHub not connected

Saving is handled by the site: the GitHub token is stored in Cloudflare, not in your browser. Enter the editor password (the EDITOR_PASSWORD secret) to unlock saving in this browser.

Saving commits to gelogrammer/My_DevOps_Playbook. Create a fine-grained token with access to only this repo andContents: Read and write, then paste it here. It is stored only in this browser.

src/content/docs/…