This topic tells you how to use Grype in air-gapped (offline) environments for Supply Chain Security Tools (SCST) - Scan.
The grype CLI attempts to perform two over the Internet calls:
For the grype CLI to function in an offline or air-gapped environment, the vulnerability database must be hosted within the environment. You must configure the grype CLI with the internal URL.
The grype CLI accepts environment variables to satisfy these needs.
For information about setting up an offline vulnerability database, see the Anchore Grype README in GitHub.
Add the following to your tap-values.yaml file:
grype:
db:
dbUpdateUrl: INTERNAL-VULN-DB-URL
Where INTERNAL-VULN-DB-URL is the URL that points to the internal file server.
Update Tanzu Application Platform:
tanzu package installed update tap -f tap-values.yaml -n tap-install
NoteIf you are using the Namespace Provisioner to provision a new developer namespace and want to apply a package overlay for Grype, you must complete additional configuration steps. See Grype package overlays are not applied to scantemplates created by Namespace Provisioner.
NoteThis message is a warning and the Grype scan still runs with this message.
The Grype CLI checks for later versions of the CLI by contacting the anchore endpoint over the Internet.
ERROR failed to fetch latest version: Get "https://toolbox-data.anchore.io/grype/releases/latest/VERSION": dial tcp: lookup toolbox-data.anchore.io on [::1]:53: read udp [::1]:65010->[::1]:53: read: connection refused
To deactivate this check, set the environment variable GRYPE_CHECK_FOR_APP_UPDATE to false by using a package overlay with the following steps:
Create a secret that contains the ytt overlay to add the Grype environment variable to the ScanTemplates.
apiVersion: v1
kind: Secret
metadata:
name: grype-airgap-deactivate-cli-check-overlay
namespace: tap-install #! namespace where tap is installed
stringData:
patch.yaml: |
#@ load("@ytt:overlay", "overlay")
#@overlay/match by=overlay.subset({"kind":"ScanTemplate"}),expects="1+"
---
spec:
template:
initContainers:
#@overlay/match by=overlay.subset({"name": "scan-plugin"}), expects="1+"
- name: scan-plugin
#@overlay/match missing_ok=True
env:
#@overlay/append
- name: GRYPE_CHECK_FOR_APP_UPDATE
value: "false"
Configure tap-values.yaml to use package_overlays. Add the following to your tap-values.yaml file:
package_overlays:
- name: "grype"
secrets:
- name: "grype-airgap-deactivate-cli-check-overlay"
Update Tanzu Application Platform:
tanzu package installed update tap -f tap-values.yaml -n tap-install
1 error occurred:
* db could not be loaded: the vulnerability database was built N days/weeks ago (max allowed age is 5 days)
Grype needs up-to-date vulnerability information to provide accurate matches. By default, it fails to run if the local database was not built in the last 5 days.
Two options to resolve this:
Stale databases weaken your security posture. VMware recommends updating the database daily as the first recommended solution.
If updating the database daily is not an option, the data staleness check is configurable by using the environment variable GRYPE_DB_MAX_ALLOWED_BUILT_AGE and is addressed using a package overlay with the following steps:
Create a secret that contains the ytt overlay to add the Grype environment variable to the ScanTemplates.
apiVersion: v1
kind: Secret
metadata:
name: grype-airgap-override-stale-db-overlay
namespace: tap-install #! namespace where tap is installed
stringData:
patch.yaml: |
#@ load("@ytt:overlay", "overlay")
#@overlay/match by=overlay.subset({"kind":"ScanTemplate"}),expects="1+"
---
spec:
template:
initContainers:
#@overlay/match by=overlay.subset({"name": "scan-plugin"}), expects="1+"
- name: scan-plugin
#@overlay/match missing_ok=True
env:
#@overlay/append
- name: GRYPE_DB_MAX_ALLOWED_BUILT_AGE #! see note on best practices
value: "120h"
NoteThe default maximum allowed built age of Grype’s vulnerability database is 5 days. This means that scanning with a 6 day old database causes the scan to fail. You can use the
GRYPE_DB_MAX_ALLOWED_BUILT_AGEparameter to override the default in accordance with your security posture.
Configure tap-values.yaml to use package_overlays. Add the following to your tap-values.yaml file:
package_overlays:
- name: "grype"
secrets:
- name: "grype-airgap-override-stale-db-overlay"
Update Tanzu Application Platform:
tanzu package installed update tap -f tap-values.yaml -n tap-install
If you used the Namespace Provisioner to provision a new developer namespace and want to apply a package overlay for Grype, see Import overlay secrets.
scan-pod[scan-plugin] 1 error occurred:
scan-pod[scan-plugin] * failed to load vulnerability db: vulnerability database is invalid (run db update to correct): database metadata not found: /.cache/grype/db/5
Examine the listing.json file you created. This matches the format of the listing file. The listing file is located at Anchore Grype’s public endpoint. See the Grype README.md in GitHub.
Here is an example of a properly formatted listing.json:
#@ load("@ytt:overlay", "overlay")
#@ def matchGrypeScanners(index, left, right):
#@ if left["apiVersion"] != "packaging.carvel.dev/v1alpha1" or left["kind"] != "PackageInstall":
#@ return False
#@ end
#@ return left["metadata"]["name"].startswith("grype-scanner")
#@ end
#@ def customize():
#@overlay/match by=matchGrypeScanners, expects="0+"
---
metadata:
annotations:
#@overlay/match missing_ok=True
ext.packaging.carvel.dev/ytt-paths-from-secret-name.0: SECRET-NAME
#@ end
Where:
5 refers to the Grype’s vulnerability database schema.built is the build timestamp in the format yyyy-MM-ddTHH:mm:ssZ.url is the download URL for the tarball containing the database. This points at your internal endpoint. The tarball contains the following files:
vulnerability.db is an SQLite file that is Grype’s vulnerability database. Each time the data shape of the vulnerability database changes, a new schema is created. Different Grype versions require specific database schema versions. For example, Grype v0.54.0 requires database schema version v5.metadata.json filechecksum is the SHA used to verify the database’s integrity.Verify these possible reasons why the vulnerability database is not valid:
The database schema is invalid. Confirm that the required database schema for the installed Grype version is used. Confirm that the top level version key matches the nested version. For example, the top level version 1 in the following snippet does not match the nested version: 5.
{
"available": {
"1": [{
"built": "2023-02-08T08_17_20Z",
"version": 5,
"url": "https://INTERNAL-ENDPOINT/PATH-TO-TARBALL/vulnerability-db_v5_2023-02-08T08_17_20Z_6ef73016d160043c630f.tar.gz",
"checksum": "sha256:aab8d369933c845878ef1b53bb5c26ee49b91ddc5cd87c9eb57ffb203a88a72f"
}]
}
}
Where PATH-TO-TARBALL is the path to the tarball containing the vulnerability database.
As stale databases weaken your security posture, VMware recommends using the newest entry of the relevant schema version in the listing.json file. See Anchore’s grype-db in GitHub.
The built parameters in the listing.json file are incorrectly formatted. The proper format is yyyy-MM-ddTHH:mm:ssZ.
The url that you modified to point at an internal endpoint is not reachable from within the cluster. For information about verifying connectivity, see Debug Grype database in a cluster.
Describe the failed source scan or image scan to verify the name of the ScanTemplate being used.
For sourcescan, run:
kubectl describe sourcescan SCAN-NAME -n DEV-NAMESPACE
For imagescan, run:
kubectl describe imagescan SCAN-NAME -n DEV-NAMESPACE
Where SCAN-NAME is the name of the source or image scan that failed.
Edit the ScanTemplate’s scan-plugin container to include a “sleep” entrypoint which allows you to troubleshoot inside the container:
- name: scan-plugin
volumeMounts:
...
image: #@ data.values.scanner.image
imagePullPolicy: IfNotPresent
env:
...
command: ["/bin/bash"]
args:
- "sleep 1800" # insert 30 min sleep here
Re-run the scan.
Get the name of the scan-plugin pod.
kubectl get pods -n DEV-NAMESPACE
Get a shell to the container. See the Kubernetes documentation:
kubectl exec --stdin --tty SCAN-PLUGIN-POD -c step-scan-plugin -- /bin/bash
Where SCAN-PLUGIN-POD is the name of the scan-plugin pod.
Inside the container, run Grype CLI commands to report database status and verify connectivity from cluster to mirror. See the Grype documentation in GitHub.
Report current status of Grype’s database (location, build date, and checksum):
grype db status
Ensure that the built parameters in the listing.json has timestamps in this proper format yyyy-MM-ddTHH:mm:ssZ.