segrep-k8s scanner

Opt-in Kubernetes manifest security scanner for RBAC, pod security, and deployment configs

Opt-in Kubernetes manifest security scanner for Segrep that detects RBAC misconfigurations, pod security issues, container privilege escalation risks, and missing resource limits — no external binary required.

Why use segrep-k8s

  • Detects 20 categories of Kubernetes security misconfigurations across deployments, pods, statefulsets, daemonsets, jobs, and cronjobs.
  • Runs locally with zero dependencies — no Kubescape or kube-linter binary required.
  • Flags privileged containers, host namespace sharing, wildcard RBAC, missing network policies, and docker socket mounts.
  • Maps every finding to CIS Kubernetes Benchmark and NSA Kubernetes Hardening Guidance references.

Scanner behavior

segrep-k8s runs as an opt-in scanner.

pnpm segrep scan . --scanners segrep-k8s

It walks the scan root and scans .yaml and .yml files that contain Kubernetes manifests (files with both apiVersion: and kind: top-level fields).

Rules

Privilege & Security Context

Rule IDSeverityWhat it detects
k8s-privileged-containercriticalContainer with privileged: true
k8s-allow-privilege-escalationhighContainer with allowPrivilegeEscalation: true
k8s-running-as-roothighContainer with runAsNonRoot: false
k8s-writable-root-filesystemmediumContainer with readOnlyRootFilesystem: false
k8s-no-security-contextmediumContainer with no securityContext block

Host Namespace

Rule IDSeverityWhat it detects
k8s-host-networkhighPod with hostNetwork: true
k8s-host-pidhighPod with hostPID: true
k8s-host-ipchighPod with hostIPC: true
k8s-host-portshighContainer with hostPort set

Images & Supply Chain

Rule IDSeverityWhat it detects
k8s-image-latest-tagmediumContainer image using :latest tag or no tag
k8s-image-digest-pinninglowImage not pinned by @sha256: digest

Capabilities & Networking

Rule IDSeverityWhat it detects
k8s-added-capabilitieshighAdded Linux capabilities (excluding NET_BIND_SERVICE)
k8s-docker-socket-mountcriticalMount of /var/run/docker.sock

Resource Management

Rule IDSeverityWhat it detects
k8s-no-resource-limitsmediumContainer with no resources block
k8s-no-memory-limitmediumlimits block present but no memory limit

Liveness & Readiness

Rule IDSeverityWhat it detects
k8s-no-liveness-probemediumContainer with no livenessProbe

RBAC & Service Accounts

Rule IDSeverityWhat it detects
k8s-default-service-accountmediumserviceAccountName: default or automountServiceAccountToken: true
k8s-wildcard-clusterrolecriticalWildcard * in apiGroups, resources, or verbs of a ClusterRole
k8s-automount-tokenlowautomountServiceAccountToken: true

Secrets & Network Policy

Rule IDSeverityWhat it detects
k8s-secret-in-envlowSecret mounted as environment variable via secretKeyRef
k8s-no-network-policymediumWorkload resource present but no NetworkPolicy in the same file

Volumes

Rule IDSeverityWhat it detects
k8s-hostpath-mounthighhostPath volume mount

Finding output

Each finding includes:

  • ruleId — the matched rule (e.g., k8s-privileged-container)
  • cweId — CWE reference
  • line — line number where the issue was found
  • snippet — the matched line

Example finding:

{
  "id": "segrep-k8s:k8s-privileged-container:deployment.yaml:15",
  "title": "Container running in privileged mode",
  "severity": "critical",
  "filePath": "deployment.yaml",
  "scanner": "segrep-k8s",
  "category": "iac",
  "ruleId": "k8s-privileged-container",
  "cweId": "CWE-250",
  "line": 15,
  "snippet": "privileged: true"
}

CIS & NSA mappings

Each rule maps to the relevant CIS Kubernetes Benchmark and NSA Kubernetes Hardening Guidance control:

RuleCISNSA
k8s-privileged-container5.2.1NS-C-0001
k8s-allow-privilege-escalation5.2.5NS-C-0002
k8s-running-as-root5.2.6NS-C-0003
k8s-host-network5.2.4NS-C-0004
k8s-host-pid5.2.2NS-C-0005
k8s-host-ipc5.2.3NS-C-0006
k8s-added-capabilities5.2.7NS-C-0007
k8s-docker-socket-mountNS-C-0008
k8s-default-service-account5.1.1NS-C-0009
k8s-wildcard-clusterrole5.1.2NS-C-0010
k8s-secret-in-envNS-C-0011
k8s-no-network-policyNS-C-0012
k8s-hostpath-mount5.2.12NS-C-0013

Policy integration

scanners:
  - segrep-k8s

# Allowlist known-good findings by rule ID
allowlist:
  - k8s-image-latest-tag

# Ignore test fixtures
ignore_paths:
  - "fixtures/**"
  - "**/*.test.*"

Examples

Kubernetes manifests only:

docker run --rm -v "$(pwd):/repo:ro" security-scanner:local \
  scan /repo --scanners segrep-k8s

Combine with IaC scanning:

docker run --rm -v "$(pwd):/repo:ro" security-scanner:local \
  scan /repo --scanners segrep-k8s,segrep-iac --format json

Fail CI on any critical or high finding:

docker run --rm -v "$(pwd):/repo:ro" security-scanner:local \
  scan /repo --scanners segrep-k8s --fail-on high