Skip to content

Commands: Security & secrets

Trivy, SonarQube and Vault commands: scanning, quality gates, secrets.

Index
  • #trivy
  • #sonarqube
  • #vault
  • #security
Updated

Also:devsecops · cve · vulnerability scan · sast · secrets

11 items

Trivy6

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 a repo for secrets and misconfigurations

Safe

Dependencies, hard-coded secrets and IaC misconfigurations in a directory.

trivy fs --scanners vuln,secret,misconfig <path>
What each part does
  1. trivy fsscan a local directory
  2. --scanners vuln,secret,misconfigdependency CVEs, hard-coded secrets, and IaC / Dockerfile misconfigurations
  3. <path>the directory, e.g. .

Also known as: leaked secret · secret scanning

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

Trivy: Scan the current Kubernetes cluster

Safe

Vulnerabilities and misconfigurations across workloads in the current kube context.

trivy k8s --report summary
What each part does
  1. trivy k8sscan the cluster in the current kubeconfig context: workload images, configs, RBAC
  2. --report summaryone table of counts per resource instead of every finding (all for full detail)

Also known as: cluster scan · k8s

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

Vault2

Vault: Log in with OIDC

Safe

Browser-based SSO login; stores a token in ~/.vault-token.

vault login -method=oidc role=<role>
What each part does
  1. vault loginauthenticate and store a token in ~/.vault-token
  2. -method=oidcsign in through the browser with your SSO provider
  3. role=<role>the OIDC role configured in Vault (decides your policies)

Also known as: vault login · permission denied vault

Vault: Read a KV secret

Caution

Read the latest version of a KV v2 secret. Add -field=<key> for a single value.

vault kv get -mount=<mount> <path>
What each part does
  1. vault kv getread a secret from a KV engine (v1 or v2)
  2. -mount=<mount>where the engine is mounted, e.g. secret
  3. <path>path inside the mount, e.g. myapp/db; add -field=password for one value

Also known as: vault kv · read secret

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/…