Guides

Kubernetes hardening guide for production

Kubernetes hardening guide with practical controls to cut exposure, protect workloads, strengthen identities and respond to real incidents.

HandyAuth · Practical guides on authentication, digital fraud and trusted identity. · · 7 min read

A compromised Kubernetes cluster rarely fails because of a single critical vulnerability. The more common scenario combines excessive permissions, unvalidated images, exposed secrets, APIs accessible beyond necessity, and lack of runtime visibility. This Kubernetes hardening guide treats the cluster as part of a larger attack surface connected to pipelines, corporate identities, APIs, sensitive data, and business services.

For organizations that process financial transactions, regulated data, or high-value access, the goal is not merely to satisfy a compliance checklist. It is to reduce viable paths to compromise, limit the impact of an intrusion, and retain response capacity without creating unnecessary friction for engineering teams.

Kubernetes hardening guide: start with risk

Hardening should not begin with indiscriminate application of ready-made manifests. Before defining policies, identify which clusters support critical systems, which namespaces host confidential data, and which external integrations hold privileges in the environment. An isolated development cluster requires different controls from an environment that runs payments, digital onboarding, or authentication services.

Also map trust flows. Who can access the Kubernetes API? Which CI/CD identities deploy code? Which service accounts query databases, queues, or cloud providers? Each answer reveals a point where a compromised credential can become lateral movement.

From that inventory, establish a measurable baseline: supported Kubernetes versions, exposed components, administrative permissions, running images, policy exceptions, and security events. Without that reference, the team fixes point configurations but cannot demonstrate effective risk reduction.

Restrict the control plane and identity

The Kubernetes API is a high-criticality asset. It should not remain open to the public internet when alternatives exist, such as private access, allow lists, corporate VPN, or dedicated connectivity. Even in managed environments, validate who administers the control plane, which logs are available, and how emergency credentials are protected.

Authentication must be tied to the corporate identity provider, with multifactor authentication for privileged profiles. Avoid shared accounts and long-lived certificates distributed manually. Traceability loses value when multiple people operate under the same identity.

In RBAC, apply least privilege. The `cluster-admin` permission should be a temporary exception, not an operational shortcut. Prefer roles scoped by namespace and activity, such as deployment, log reading, or secret management. Review especially permissions to create pods, exec into containers, create role bindings, and access secrets: those privileges frequently allow escalating control over the cluster.

Service accounts deserve the same rigor. Disable automatic token mounting when it is not needed and use scoped workload identities for cloud resource access. A service-account token present in a compromised pod should not open a path to administer the entire environment.

Protect workloads against permissive configurations

Most protection happens at the pod level. Containers should not run as root, receive unnecessary Linux capabilities, or use a writable filesystem without justification. A secure configuration typically requires `runAsNonRoot`, capability dropping, privilege-escalation blocking, and a restrictive Seccomp profile.

Also block privileged containers, access to the Docker socket or container runtime, mounting of sensitive host directories, and sharing of host namespaces. There are specific situations, such as observability agents or networking components, where those accesses are necessary. In those cases, isolate them in dedicated namespaces, document the exception, limit who can change it, and monitor runtime behavior.

Admission policies should prevent insecure manifests from reaching the cluster. Kubernetes offers native mechanisms to enforce pod security standards, while policy-as-code tools allow validating more specific rules before deployment. The decisive point is integrating validation into the pipeline and exception process. Alerting after deploy is useful, but preventing the risky configuration is more effective.

Define CPU and memory limits, plus requests coherent with each application. This is not only an efficiency practice: workloads without limits can facilitate unavailability through resource exhaustion. For critical services, configure replicas, health checks, and update strategies that avoid taking all capacity offline at once.

Treat network and secrets as trust boundaries

By default, many environments allow excessive communication between pods. Segmentation with NetworkPolicies reduces the chance that an exploited application reaches internal services, databases, or administrative components. Start with explicit ingress and egress rules for higher-risk workloads, then gradually expand coverage.

It is not enough to limit inbound traffic. Control where each service can go. An order-processing pod, for example, may need to talk to a payments API and a database, but not to any destination on the internet. Egress restrictions reduce data exfiltration and hinder contact with command-and-control infrastructure.

Secrets should not appear in images, repositories, pipeline variables, or versioned configuration files. Use a centralized secrets-management mechanism with encryption at rest, rotation, and an audit trail. Encrypting secrets in cluster storage is necessary, but it does not solve improper access by an identity that already has read permission.

It is advisable to separate credentials by environment and service. A key used across all namespaces turns a local incident into broad compromise. For sensitive access, combine short-lived credentials, identity federation, and rules that limit credential use to the authorized workload.

Strengthen the software supply chain before deploy

A signed image is not automatically secure, but an image without verifiable origin should not reach production. Restrict use to approved registries, pin versions by digest when possible, and avoid mutable tags such as `latest`. The team needs to know exactly which artifact is running and which pipeline produced it.

Vulnerability analysis should happen during image build and continue after publication, because new flaws are discovered continuously. Prioritize fixes by exploitability, service exposure, container privilege, and criticality of the data processed. Fixing every vulnerability with the same urgency creates noise and delays response to exploitable risks.

Generate a software bill of materials for relevant components and keep signature and provenance evidence. That reduces investigation time when a dependency is compromised. It also helps respond to customer requirements, audits, and supply-chain incidents without relying on manual inventory.

Monitor behavior, not only events

Kubernetes audit logs should record RBAC changes, creation of sensitive resources, remote executions, secret access, and network-configuration changes. Centralize that data on a platform that preserves retention, integrity, and correlation with identity, pipeline, and cloud context.

Still, API logs do not show everything. Runtime detection should identify behaviors such as unexpected shell openings, anomalous process creation, unusual outbound connections, sensitive-file reads, and privilege-escalation attempts. This monitoring is especially relevant because successful attacks often use legitimate tools already in the environment.

Offensive testing complements telemetry. An assessment should verify whether a pod with limited access can reach improper resources, whether tokens can be reused, whether admission policies are bypassable, and whether the team can detect and contain the activity. HandyAuth’s red teaming and security-engineering experience can turn those hypotheses into testable scenarios aligned with business risk and the customer’s operating model.

Implement in phases without interrupting operations

Applying rigid controls all at once can break legacy integrations or deploy flows. A phased approach preserves continuity and produces evidence for prioritization. The work typically advances in four moves:

  • establish inventory, data classification, and visibility into administrative access;
  • apply controls in audit mode to identify incompatible workloads;
  • block new insecure configurations and remediate existing exceptions;
  • test detection, response, and recovery with exercises that simulate credential or container compromise.

Every exception must have an owner, business justification, security compensation, and review deadline. Exceptions without expiry become a permanent part of the attack surface.

Hardening maturity appears when security no longer depends on manual review of every release. Versioned policies, pipelines with validation, well-scoped identities, and actionable telemetry let teams deliver faster without accepting silent exposure. The next deploy should be an opportunity to confirm the environment remains trustworthy, not a new bet on what might fail.

Talk to HandyAuth: contato@handyauth.com