Skip to main content

Dockerfiles and Kubernetes manifests

deaconguard config scan checks the files that build and deploy containers, before anything is built or deployed: Dockerfiles (and Containerfiles), and Kubernetes manifests. It reads them as text, and builds, applies and runs nothing. It needs DeaconGuard 1.4.0 or later.

deaconguard config scan .
deaconguard config scan Dockerfile deploy/ --fail-on high
helm template shop ./chart | deaconguard config scan - --fail-on high
kubectl kustomize deploy/production | deaconguard config scan -

A folder is searched for Dockerfile, Containerfile, Dockerfile.*, *.dockerfile, *.yaml and *.yml; hidden folders, node_modules and vendor are left out. YAML files that aren't Kubernetes objects, such as CI workflows or Compose files, are skipped. - reads standard input.

Helm charts are templates, so render them first with helm template, with the values you deploy, and pipe the output in. A template file met in a folder is skipped, and the command says so.

Output and failing the build​

As for images in pipelines: --fail-on critical|high|medium|low exits with status 4 when a finding is at or above that severity, and --format table|json|sarif|junit with --output FILE writes a report. SARIF results point at the file and line, so GitHub code scanning shows them on the pull request's diff.

Checked 3 files: 4 findings (1 critical, 2 high, 1 low)
CRITICAL deploy/app.yaml:17 Deployment shop: container app is privileged [DG-K8S-001]
A privileged container has every capability and the node's devices: it is root on the node. …

Accepting a finding​

Some findings are true and intended: a node agent needs the node's processes, for example. Accept them where they are, so the reason stays next to the file:

  • Kubernetes: the annotation deaconguard.io/ignore on the object, or on its pod template, lists the rules to leave out:

    metadata:
    annotations:
    deaconguard.io/ignore: "DG-K8S-002, DG-K8S-003" # a node agent: reads the node's processes and files
  • Dockerfile: a comment anywhere in it: # deaconguard:ignore DG-DF-011.

  • Everywhere: --skip DG-DF-011,DG-K8S-013 leaves rules out of one run.

Rules​

deaconguard config rules lists them. The Kubernetes rules follow the Kubernetes Pod Security Standards (baseline, then restricted) and the NSA/CISA Kubernetes Hardening Guidance (version 1.2); the Dockerfile rules, Docker's build best practices. Each finding says how to fix it. Secret values are never shown, only their names.

Dockerfiles​

Only the last stage becomes the image, so the user and health check are checked there; every stage's base image is checked.

RuleSeverityFinding
DG-DF-001HighThe image runs as root
DG-DF-002MediumThe base image isn't pinned to a version
DG-DF-003HighA secret is set in the image
DG-DF-004MediumA script is downloaded and run without being checked
DG-DF-005MediumADD downloads a file from a URL
DG-DF-006LowADD copies local files; COPY is clearer
DG-DF-007MediumThe image uses sudo
DG-DF-008MediumThe image exposes SSH
DG-DF-009MediumFiles are made writable by everyone
DG-DF-010LowNo .dockerignore: the build context may include secrets
DG-DF-011LowNo HEALTHCHECK

Kubernetes​

Pods and the workloads that run them (Deployment, StatefulSet, DaemonSet, ReplicaSet, Job, CronJob, ReplicationController, and Lists of them), and RBAC roles and bindings. A running cluster gets more checks, such as namespaces without network policies and the Kubernetes version: see Kubernetes clusters. A privileged container gets DG-K8S-001 rather than the capability and privilege-escalation findings it implies. Rules that match a DISA Kubernetes STIG rule name it; see Kubernetes clusters.

RuleSeverityFindingSourceDISA STIG
DG-K8S-001CriticalA container is privilegedPod Security Standards (baseline)
DG-K8S-002HighThe pod shares the node's network, process or IPC namespacePod Security Standards (baseline)
DG-K8S-003HighThe pod mounts a folder of the node (hostPath)Pod Security Standards (baseline)
DG-K8S-004HighA container adds a dangerous Linux capabilityPod Security Standards (baseline)
DG-K8S-005MediumA container uses a port on the node (hostPort)Pod Security Standards (baseline)V-242414
DG-K8S-006HighA container turns off seccomp, AppArmor or /proc maskingPod Security Standards (baseline)
DG-K8S-007MediumA container may gain more privileges than its process hasPod Security Standards (restricted)
DG-K8S-008MediumA container may run as rootPod Security Standards (restricted)
DG-K8S-009HighA container runs as root (runAsUser: 0)Pod Security Standards (restricted)
DG-K8S-010LowA container keeps Linux capabilities it doesn't dropPod Security Standards (restricted)
DG-K8S-011LowNo seccomp profile is setPod Security Standards (restricted)
DG-K8S-012LowA container's root file system is writableNSA/CISA Hardening Guide
DG-K8S-013LowA container has no memory limitNSA/CISA Hardening Guide
DG-K8S-014MediumA container image isn't pinned to a versionNSA/CISA Hardening Guide
DG-K8S-015HighA secret is written into the manifestNSA/CISA Hardening GuideV-274883
DG-K8S-016LowThe pod gets a service account token it may not needNSA/CISA Hardening Guide
DG-K8S-020HighA binding grants cluster-adminRBAC good practices
DG-K8S-021HighA role grants every action on every resourceRBAC good practices
DG-K8S-022MediumA role can read secretsRBAC good practicesV-274884
DG-K8S-023HighA role can escalate privilegesRBAC good practices