CG
SkillsScanning Kubernetes Manifests with Kubesec
Start Free
Back to Skills Library
Container & Cloud-Native Security🔴 Advanced

Scanning Kubernetes Manifests with Kubesec

Perform security risk analysis on Kubernetes resource manifests using Kubesec to identify misconfigurations, privilege escalation risks, and deviations from security best practices.

4 min read10 code examples

Prerequisites

  • Kubernetes manifest files (YAML/JSON) for Deployments, Pods, DaemonSets, StatefulSets
  • Docker or Go runtime for local installation
  • kubectl access for scanning live cluster resources
  • CI/CD pipeline access for automated scanning integration

Scanning Kubernetes Manifests with Kubesec

Overview

Kubesec is an open-source security risk analysis tool developed by ControlPlane that inspects Kubernetes resource manifests for common exploitable risks such as privilege escalation, writable host mounts, and excessive capabilities. It assigns a numerical security score to each resource and provides actionable recommendations for hardening. Kubesec can be used as a CLI binary, Docker container, kubectl plugin, admission webhook, or REST API endpoint.

Prerequisites

  • Kubernetes manifest files (YAML/JSON) for Deployments, Pods, DaemonSets, StatefulSets
  • Docker or Go runtime for local installation
  • kubectl access for scanning live cluster resources
  • CI/CD pipeline access for automated scanning integration

Core Concepts

Security Scoring System

Kubesec assigns a score to each Kubernetes resource based on security checks:

  • Positive scores: Awarded for security-enhancing configurations (readOnlyRootFilesystem, runAsNonRoot)
  • Zero or negative scores: Indicate missing security controls or dangerous configurations
  • Critical advisories: Flagged configurations that represent immediate security risks

Check Categories

  1. Privilege Controls: Checks for privileged containers, host PID/network access, root execution
  2. Capabilities: Identifies excessive Linux capabilities (SYS_ADMIN, NET_RAW)
  3. Volume Mounts: Detects dangerous host path mounts and writable sensitive paths
  4. Resource Limits: Validates presence of CPU/memory resource constraints
  5. Security Context: Verifies seccomp profiles, AppArmor annotations, SELinux contexts

Installation

Binary Installation

# Linux/macOS
curl -sSL https://github.com/controlplaneio/kubesec/releases/latest/download/kubesec_linux_amd64.tar.gz | \
  tar xz -C /usr/local/bin/ kubesec

# Verify installation
kubesec version

Docker Installation

docker pull kubesec/kubesec:v2

# Scan a manifest file
docker run -i kubesec/kubesec:v2 scan /dev/stdin < deployment.yaml

kubectl Plugin

kubectl krew install kubesec-scan
kubectl kubesec-scan pod mypod -n default

Practical Scanning

Scanning a Single Manifest

# Scan a deployment manifest
kubesec scan deployment.yaml

# Scan with JSON output
kubesec scan -o json deployment.yaml

# Scan from stdin
cat pod.yaml | kubesec scan -

Sample Output

[
  {
    "object": "Pod/web-app.default",
    "valid": true,
    "fileName": "pod.yaml",
    "message": "Passed with a score of 3 points",
    "score": 3,
    "scoring": {
      "passed": [
        {
          "id": "ReadOnlyRootFilesystem",
          "selector": "containers[] .securityContext .readOnlyRootFilesystem == true",
          "reason": "An immutable root filesystem prevents applications from writing to their local disk",
          "points": 1
        },
        {
          "id": "RunAsNonRoot",
          "selector": "containers[] .securityContext .runAsNonRoot == true",
          "reason": "Force the running image to run as a non-root user",
          "points": 1
        },
        {
          "id": "LimitsCPU",
          "selector": "containers[] .resources .limits .cpu",
          "reason": "Enforcing CPU limits prevents DOS via resource exhaustion",
          "points": 1
        }
      ],
      "advise": [
        {
          "id": "ApparmorAny",
          "selector": "metadata .annotations .\"container.apparmor.security.beta.kubernetes.io/nginx\"",
          "reason": "Well defined AppArmor policies reduce the attack surface of the container",
          "points": 3
        },
        {
          "id": "ServiceAccountName",
          "selector": ".spec .serviceAccountName",
          "reason": "Service accounts restrict Kubernetes API access and should be configured",
          "points": 3
        }
      ]
    }
  }
]

Scanning Multiple Resources

# Scan all YAML files in a directory
for file in manifests/*.yaml; do
  echo "=== Scanning $file ==="
  kubesec scan "$file"
done

# Scan multi-document YAML
kubesec scan multi-resource.yaml

Using the HTTP API

# Scan via the public API
curl -sSX POST --data-binary @deployment.yaml \
  https://v2.kubesec.io/scan

# Run a local API server
kubesec http --port 8080 &

# Scan against local server
curl -sSX POST --data-binary @deployment.yaml \
  http://localhost:8080/scan

CI/CD Integration

GitHub Actions

name: Kubesec Scan
on: [pull_request]
jobs:
  kubesec:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Install Kubesec
        run: |
          curl -sSL https://github.com/controlplaneio/kubesec/releases/latest/download/kubesec_linux_amd64.tar.gz | \
            tar xz -C /usr/local/bin/ kubesec
      - name: Scan Manifests
        run: |
          FAIL=0
          for file in k8s/*.yaml; do
            SCORE=$(kubesec scan "$file" | jq '.[0].score')
            echo "$file: score=$SCORE"
            if [ "$SCORE" -lt 0 ]; then
              echo "FAIL: $file has critical issues (score: $SCORE)"
              FAIL=1
            fi
          done
          exit $FAIL

GitLab CI

kubesec-scan:
  stage: security
  image: kubesec/kubesec:v2
  script:
    - |
      for file in k8s/*.yaml; do
        kubesec scan "$file" > /tmp/result.json
        SCORE=$(cat /tmp/result.json | jq '.[0].score')
        if [ "$SCORE" -lt 0 ]; then
          echo "CRITICAL: $file scored $SCORE"
          cat /tmp/result.json | jq '.[0].scoring.critical'
          exit 1
        fi
      done
  artifacts:
    paths:
      - kubesec-results/

Admission Webhook

Deploy Kubesec as a ValidatingWebhookConfiguration to reject insecure manifests at deploy time:

apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingWebhookConfiguration
metadata:
  name: kubesec-webhook
webhooks:
  - name: kubesec.controlplane.io
    rules:
      - apiGroups: [""]
        apiVersions: ["v1"]
        operations: ["CREATE", "UPDATE"]
        resources: ["pods"]
      - apiGroups: ["apps"]
        apiVersions: ["v1"]
        operations: ["CREATE", "UPDATE"]
        resources: ["deployments", "daemonsets", "statefulsets"]
    clientConfig:
      service:
        name: kubesec-webhook
        namespace: kube-system
        path: /scan
    failurePolicy: Fail
    sideEffects: None
    admissionReviewVersions: ["v1"]

Security Checks Reference

Critical Checks (Negative Score)

CheckSelectorRisk
PrivilegedsecurityContext.privileged == trueFull host access
HostPIDspec.hostPID == trueProcess namespace escape
HostNetworkspec.hostNetwork == trueNetwork namespace escape
SYS_ADMINcapabilities.add contains SYS_ADMINNear-root capability

Best Practice Checks (Positive Score)

CheckPointsDescription
ReadOnlyRootFilesystem+1Prevents filesystem writes
RunAsNonRoot+1Non-root process execution
RunAsUser > 10000+1High UID reduces collision risk
LimitsCPU+1Prevents CPU resource exhaustion
LimitsMemory+1Prevents memory resource exhaustion
RequestsCPU+1Ensures scheduler resource awareness
ServiceAccountName+3Explicit service account
AppArmor annotation+3Kernel-level MAC enforcement
Seccomp profile+4Syscall filtering

Compliance Framework Mapping

This skill supports compliance evidence collection across multiple frameworks:

  • SOC 2: CC6.1 (Logical Access), CC7.1 (Monitoring), CC8.1 (Change Management)
  • ISO 27001: A.14.2 (Secure Development), A.12.6 (Technical Vulnerability Mgmt)
  • NIST 800-53: CM-7 (Least Functionality), SI-2 (Flaw Remediation), SC-28 (Protection at Rest)
  • NIST CSF: PR.IP (Information Protection), PR.DS (Data Security)

Claw GRC Tip: When this skill is executed by a registered agent, compliance evidence is automatically captured and mapped to the relevant controls in your active frameworks.

Deploying This Skill with Claw GRC

Agent Execution

Register this skill with your Claw GRC agent for automated execution:

# Install via CLI
npx claw-grc skills add scanning-kubernetes-manifests-with-kubesec

# Or load dynamically via MCP
grc.load_skill("scanning-kubernetes-manifests-with-kubesec")

Audit Trail Integration

When executed through Claw GRC, every step of this skill generates tamper-evident audit records:

  • SHA-256 chain hashing ensures no step can be modified after execution
  • Evidence artifacts (configs, scan results, logs) are automatically attached to relevant controls
  • Trust score impact — successful execution increases your agent's trust score

Continuous Compliance

Schedule this skill for recurring execution to maintain continuous compliance posture. Claw GRC monitors for drift and alerts when re-execution is needed.

References

  • Kubesec GitHub Repository
  • Kubesec Online Scanner
  • ControlPlane Security Tools
  • CIS Kubernetes Benchmark
  • Kubernetes Pod Security Standards

Use with Claw GRC Agents

This skill is fully compatible with Claw GRC's autonomous agent system. Deploy it to any registered agent via MCP, and every execution will be logged in the tamper-evident audit trail.

// Load this skill in your agent
npx claw-grc skills add scanning-kubernetes-manifests-with-kubesec
// Or via MCP
grc.load_skill("scanning-kubernetes-manifests-with-kubesec")

Tags

kubeseckubernetesmanifest-scanningsecurity-scanningdevsecopsmisconfigurationstatic-analysisci-cd

Related Skills

Container & Cloud-Native Security

Performing Container Security Scanning with Trivy

3m·intermediate
Container & Cloud-Native Security

Detecting Container Escape Attempts

5m·advanced
Container & Cloud-Native Security

Detecting Container Escape with Falco Rules

5m·advanced
Container & Cloud-Native Security

Detecting Privilege Escalation in Kubernetes Pods

4m·advanced
Container & Cloud-Native Security

Implementing Runtime Security with Tetragon

3m·advanced
Container & Cloud-Native Security

Performing Kubernetes Penetration Testing

4m·advanced

Skill Details

Domain
Container & Cloud-Native Security
Difficulty
advanced
Read Time
4 min
Code Examples
10

On This Page

OverviewPrerequisitesCore ConceptsInstallationPractical ScanningCI/CD IntegrationSecurity Checks ReferenceReferencesCompliance Framework MappingDeploying This Skill with Claw GRC

Deploy This Skill

Add this skill to your Claw GRC agent and start automating.

Get Started Free →