Documentation
¶
Overview ¶
Package kubebench assesses a Kubernetes cluster against a subset of the CIS Kubernetes Benchmark (CAPABILITY_SPEC domain 10). Like dockerbench it is a read-only auditor that runs against a collected evidence snapshot — control- plane component flags, kubelet config, file permissions, and RBAC/pod-security objects — so assessment is deterministic and works offline. On a live cluster a collector produces the same document from the API server, the static-pod manifests, and the node config; tests commit it as a fixture.
The benchmark is version- and platform-aware: the profile machinery (profile.go) picks a version-matched CIS revision and, on managed clusters (EKS/GKE/AKS), scopes scoring to the controls the customer actually owns.
Index ¶
- func Assess(e *Evidence) *compliance.Report
- func Benchmark(p Profile) compliance.Benchmark
- func Register(r *engine.Registry)
- func RunCommand(args []string) int
- type Component
- type Evidence
- type FileStat
- type Module
- type PodSecurity
- type PolicyRule
- type Profile
- type RBAC
- type Role
- type RoleBinding
- type ServiceAccount
- type Subject
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Assess ¶
func Assess(e *Evidence) *compliance.Report
Assess resolves the profile from the evidence, then runs the version-matched CIS Kubernetes Benchmark. This is the single entry point for both the module and the `dsecrat bench k8s` command.
func Benchmark ¶
func Benchmark(p Profile) compliance.Benchmark
Benchmark builds the CIS Kubernetes Benchmark catalogue for the resolved profile. The version and profile name come from profile resolution; the control set is the same catalogue, with per-section scoping applied by the checks (managed control-plane/etcd controls become INFO). Controls are pure data; pass/fail logic lives in the checks_*.go files keyed by control id.
func Register ¶
Register adds this module to the registry. The master agent calls this from modules.Default(); this package never edits the shared registry file. See NOTES.md for the exact one-line wiring.
func RunCommand ¶
RunCommand implements `dsecrat bench k8s [flags] <evidence-path>`. It is the exported command body the master wires into cli.go (see NOTES.md). As a frontend it may read the wall clock, unlike Analyze.
Types ¶
type Component ¶
Component is one control-plane/node binary's effective command-line flags, keyed without the leading "--". List-valued flags keep their comma form.
type Evidence ¶
type Evidence struct {
// Version is the reported Kubernetes server version, e.g. "1.29.3". Used to
// select the version-matched benchmark profile.
Version string `json:"version,omitempty"`
// Platform is the distribution: "self-managed", "eks", "gke", "aks", or ""
// (auto-detected as self-managed). Drives managed-variant scoping.
Platform string `json:"platform,omitempty"`
APIServer Component `json:"apiserver,omitempty"`
ControllerManager Component `json:"controller_manager,omitempty"`
Scheduler Component `json:"scheduler,omitempty"`
Etcd Component `json:"etcd,omitempty"`
Kubelet Component `json:"kubelet,omitempty"`
// Files are permission/ownership stats for manifests and config files.
Files []FileStat `json:"files,omitempty"`
// RBAC is a reduced view of cluster roles/bindings and service accounts.
RBAC RBAC `json:"rbac,omitempty"`
// PodSecurity captures the Pod Security Admission posture.
PodSecurity PodSecurity `json:"pod_security,omitempty"`
// NetworkPolicyNamespaces lists namespaces that have at least one
// NetworkPolicy; namespaces absent here are treated as having none.
NetworkPolicyNamespaces []string `json:"network_policy_namespaces,omitempty"`
// Namespaces is the set of (non-system) namespaces, for default-namespace checks.
Namespaces []string `json:"namespaces,omitempty"`
Notes []string `json:"notes,omitempty"`
}
Evidence is the offline-assessable snapshot of a Kubernetes cluster.
type FileStat ¶
type FileStat struct {
Path string `json:"path"`
Exists bool `json:"exists"`
Mode string `json:"mode,omitempty"`
Owner string `json:"owner,omitempty"`
Group string `json:"group,omitempty"`
}
FileStat is a config file's ownership and mode (octal string).
type Module ¶
type Module struct{}
Module is the CIS Kubernetes Benchmark capability (CAPABILITY_SPEC domain 10). It audits a cluster from a collected evidence snapshot, auto-selecting a version- and platform-matched profile, and projects each control result into the unified Finding model.
func (*Module) Analyze ¶
Analyze loads the cluster evidence and runs the version-matched benchmark. Missing/unreadable inputs degrade to INFO rather than erroring. The continuous-compliance narrative (AI-age feature) stays OFF unless the caller opts in via target metadata "compliance.narrative"="true".
func (*Module) Description ¶
func (*Module) Supports ¶
func (m *Module) Supports(t engine.TargetType) bool
Supports handles filesystem targets (a cluster evidence directory/file). There is no dedicated cluster TargetType today; see NOTES.md for the proposed engine addition. The module stays quiet when the target holds no cluster evidence, so a plain filesystem scan is unaffected.
type PodSecurity ¶
type PodSecurity struct {
// AdmissionEnabled is true when the PodSecurity admission plugin is on.
AdmissionEnabled bool `json:"admission_enabled,omitempty"`
// NamespaceEnforce maps namespace → the enforce level label value
// (privileged|baseline|restricted). Missing means unlabeled.
NamespaceEnforce map[string]string `json:"namespace_enforce,omitempty"`
}
PodSecurity captures the Pod Security Admission posture.
type PolicyRule ¶
type PolicyRule struct {
APIGroups []string `json:"api_groups,omitempty"`
Resources []string `json:"resources,omitempty"`
Verbs []string `json:"verbs,omitempty"`
}
PolicyRule mirrors an RBAC rule (apiGroups/resources/verbs).
type Profile ¶
type Profile struct {
// Name is the profile slug reported to the auditor, e.g. "self-managed",
// "eks". It becomes the benchmark Profile field.
Name string
// BenchmarkVersion is the version-matched CIS Kubernetes Benchmark revision.
BenchmarkVersion string
// contains filtered or unexported fields
}
Profile is the resolved assessment scope for a cluster.
type RBAC ¶
type RBAC struct {
ClusterRoleBindings []RoleBinding `json:"cluster_role_bindings,omitempty"`
Roles []Role `json:"roles,omitempty"`
ServiceAccounts []ServiceAccount `json:"service_accounts,omitempty"`
}
RBAC is the least-privilege-relevant slice of cluster authorization state.
type Role ¶
type Role struct {
Name string `json:"name"`
Rules []PolicyRule `json:"rules,omitempty"`
}
Role is a (cluster)role reduced to its rules.
type RoleBinding ¶
type RoleBinding struct {
Name string `json:"name"`
RoleRef string `json:"role_ref"`
Subjects []Subject `json:"subjects,omitempty"`
}
RoleBinding binds subjects to a role (RoleRef is "ClusterRole/name" etc.).
type ServiceAccount ¶
type ServiceAccount struct {
Namespace string `json:"namespace"`
Name string `json:"name"`
AutomountServiceAccountToken *bool `json:"automount_service_account_token,omitempty"`
}
ServiceAccount records automount posture for the default-SA checks.