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.
Which files reach this pack
Section titled “Which files reach this pack”Core routes each diff file by path first. This pack claims:
| Glob | Matches |
|---|---|
*k8s/*.yaml, *k8s/*.yml | k8s/api.yaml, infra/k8s/apps/api.yml |
*manifests/*.yaml, *manifests/*.yml | manifests/rbac.yaml |
*deploy/*.yaml, *deploy/*.yml | services/shop/deploy/deployment.yml |
*kustomization.yaml, *kustomization.yml | overlays/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:
| Field | Value |
|---|---|
type | The object’s kind, such as Deployment; unknown if the diff does not show it |
name | kind/namespace/name, or kind/name when no namespace is shown |
action | add, delete, or modify, based on the + and - lines |
body | The object’s hunk lines, with their +, -, and space markers |
metadata.source_path | The 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.
Context block
Section titled “Context block”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:
| Kind | Fields |
|---|---|
| Service | spec.selector |
| HorizontalPodAutoscaler | spec.scaleTargetRef, resource metrics |
| PodDisruptionBudget | spec.selector.matchLabels, minAvailable, maxUnavailable |
| Deployment, StatefulSet | spec.replicas, pod template labels |
| Any other kind | Name 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.
Effective security context
Section titled “Effective security context”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 ID | Area | What it catches |
|---|---|---|
| K8S-001 | Pod security | A privileged container or pod-level hostNetwork, hostPID, or hostIPC |
| K8S-002 | Pod security | A hostPath volume; paths such as /, /etc, /proc, /var/lib/kubelet, and container runtime sockets are CRITICAL |
| K8S-003 | Pod security | hostPort or procMount: Unmasked |
| K8S-004 | Pod security | Effective runAsNonRoot false or unset, runAsUser: 0, or allowPrivilegeEscalation: true |
| K8S-005 | Pod security | A capability outside the approved list (default: NET_BIND_SERVICE); SYS_ADMIN and ALL are CRITICAL |
| K8S-006 | Pod security | Effective seccompProfile: Unconfined, or a removed seccompProfile |
| K8S-007 | Supply chain | A mutable image tag without a digest; a full version tag alone is not a finding unless the organization requires digests |
| K8S-008 | RBAC | * verbs, resources, or API groups, or get, list, or watch access to secrets |
| K8S-009 | RBAC | A binding to system:anonymous or system:unauthenticated, or system:authenticated with more than read access |
| K8S-010 | Exposure | Review prompt for a new LoadBalancer or NodePort Service, or a Service changed to one of those types |
| K8S-011 | Exposure | Review prompt for an Ingress host without a tls section |
| K8S-012 | Secrets | A Secret committed with values in data or stringData; placeholders, empty values, and sealed or encrypted values are excluded |
| K8S-013 | Destructive | A deleted Namespace or PersistentVolumeClaim, or a StatefulSet volumeClaimTemplates change |
| K8S-014 | Network | A deleted NetworkPolicy or one widened to all sources |
| K8S-015 | Kustomize | A patch that removes a securityContext field |
| K8S-016 | Admission | A Namespace label that lowers Pod Security enforcement or removes its enforce label |
| K8S-PERF-001 to -007 | Performance | Missing 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 -008 | Reliability | Missing 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.
Worked example
Section titled “Worked example”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.