Skip to content
DashboardWebsite

Kubernetes Pack

URL slug: kubernetes

The Kubernetes pack analyzes changes to Kubernetes manifests and Kustomize overlays. It creates one analysis unit per changed object and checks it against security, performance, and reliability rules.

Core routes each diff file by path first. This pack claims:

GlobMatches
*k8s/*.yaml, *k8s/*.ymlk8s/api.yaml, infra/k8s/apps/api.yml
*manifests/*.yaml, *manifests/*.ymlmanifests/rbac.yaml
*deploy/*.yaml, *deploy/*.ymlservices/shop/deploy/deployment.yml
*kustomization.yaml, *kustomization.ymloverlays/prod/kustomization.yaml

Core matches these globs against the whole path with fnmatch. Each pattern starts with * so it can match at any depth.

A file at another path can reach the pack through content detection. For a diff file that no glob claims, core scores the added lines. The Kubernetes pack scores 0.9 when a YAML document opens with apiVersion: and kind: as its first two top-level keys, in either order. Compose files, GitLab CI files, Ansible playbooks, and Helm Chart.yaml files do not match that pattern.

Content detection sees only added lines. A change in the middle of a manifest outside these folders may not include apiVersion:, so core may not detect it. Put manifests under one of the folders above, or add a matching glob for your layout.

The pack also reads a manifest pasted on its own as a new file.

A manifest file can hold multiple objects separated by ---. Each changed object shown in the diff becomes a unit:

FieldValue
typeThe object’s kind, such as Deployment; unknown if the diff does not show it
namekind/namespace/name, or kind/name when no namespace is shown
actionadd, delete, or modify, based on the + and - lines
bodyThe object’s hunk lines, with their +, -, and space markers
metadata.source_pathThe file path from the diff header

The pack reads kind and metadata.name from the new side of the diff. For a deleted object, it reads them from the removed lines. If the diff does not show part of the name, that part is ….

A hunk can start below the object’s kind: line, inside a container. In that case, the unit name uses the change location reported by core’s YAML helper (opentremor_core.libs.yaml_diff), for example spec/…/containers/- name: api/securityContext.

When two hunks in the same file name the same object, they form one unit. The body separates the hunks with @@, so the model sees the changed pod-level and container-level settings together.

Some rules need information from a second object, such as the Service that selects a Deployment, the autoscaler that scales it, or the PodDisruptionBudget that guards it. The pack appends other objects shown in the same file to the unit body as context:

# Other objects in this file (context, not under review):
# Service/prod/api selector: app=api
# HorizontalPodAutoscaler/prod/api targets Deployment/api, metric cpu 70%

The context block lists only fields the cross-object rules read:

KindFields
Servicespec.selector
HorizontalPodAutoscalerspec.scaleTargetRef, resource metrics
PodDisruptionBudgetspec.selector.matchLabels, minAvailable, maxUnavailable
Deployment, StatefulSetspec.replicas, pod template labels
Any other kindName only

Objects in the block can be changed or unchanged in the diff. Objects in other files are not listed. The pack omits an object if the diff does not show its kind:. A unit has no context block if no other named object appears in the same file.

The context block is part of the body and its hash. A change to a listed field changes the unit’s hash.

Security rules read each container’s effective securityContext: the pod’s spec.securityContext plus the container’s own settings, which override pod-level values. If the diff does not show the pod-level settings, the rule reports with LOW confidence and says so.

Rules live in opentremor_pack_kubernetes/rules/kubernetes-rules.md, served at GET /v1/kubernetes/rules.

Rule IDAreaWhat it catches
K8S-001Pod securityA privileged container or pod-level hostNetwork, hostPID, or hostIPC
K8S-002Pod securityA hostPath volume; paths such as /, /etc, /proc, /var/lib/kubelet, and container runtime sockets are CRITICAL
K8S-003Pod securityhostPort or procMount: Unmasked
K8S-004Pod securityEffective runAsNonRoot false or unset, runAsUser: 0, or allowPrivilegeEscalation: true
K8S-005Pod securityA capability outside the approved list (default: NET_BIND_SERVICE); SYS_ADMIN and ALL are CRITICAL
K8S-006Pod securityEffective seccompProfile: Unconfined, or a removed seccompProfile
K8S-007Supply chainA mutable image tag without a digest; a full version tag alone is not a finding unless the organization requires digests
K8S-008RBAC* verbs, resources, or API groups, or get, list, or watch access to secrets
K8S-009RBACA binding to system:anonymous or system:unauthenticated, or system:authenticated with more than read access
K8S-010ExposureReview prompt for a new LoadBalancer or NodePort Service, or a Service changed to one of those types
K8S-011ExposureReview prompt for an Ingress host without a tls section
K8S-012SecretsA Secret committed with values in data or stringData; placeholders, empty values, and sealed or encrypted values are excluded
K8S-013DestructiveA deleted Namespace or PersistentVolumeClaim, or a StatefulSet volumeClaimTemplates change
K8S-014NetworkA deleted NetworkPolicy or one widened to all sources
K8S-015KustomizeA patch that removes a securityContext field
K8S-016AdmissionA Namespace label that lowers Pod Security enforcement or removes its enforce label
K8S-PERF-001 to -007PerformanceMissing CPU request under CPU autoscaling; memory emptyDir without a size limit; missing memory request and limit; low CPU limit on a latency-sensitive service; fixed-size HPA; large rolling update step; Always pull on a digest-pinned image
K8S-REL-001 to -008ReliabilityMissing readiness probe on a Deployment selected by a Service; liveness probe without startup probe in a slow-starting container; deleted or blocking PDB; Recreate strategy or one replica on a Deployment selected by a Service; missing replica spread; shortened termination grace period or removed preStop; replicas set under an HPA

Performance and reliability findings are LOW or MEDIUM severity. They appear in the review and do not fail the merge check on their own.

K8S-PERF-001 and K8S-REL-001, -003, -004, -005, and -008 use the context block. If the block does not show the required object, the finding is a review prompt with LOW confidence.

diff --git a/deploy/api.yaml b/deploy/api.yaml
--- a/deploy/api.yaml
+++ b/deploy/api.yaml
@@ -1,9 +1,10 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: api
namespace: shop
spec:
template:
spec:
+ hostNetwork: true
containers:

This diff creates one unit: type Deployment, name Deployment/shop/api, and action modify. The model reports K8S-001 because the pod now shares the node’s network namespace.

The pack includes a demo sample with a payments Deployment that runs privileged and mounts the Docker socket, a NodePort Service, and a ClusterRole that reads every Secret.