Kubernetes is everywhere, and developers are expected to work with it at some level. Whether you are packaging your code as a container image that is deployed in Kubernetes or running your own Kubernetes cluster, you need to understand Kubernetes basics.

One of the basics of running Kubernetes in a production environment is security—how to ensure container images, pods, specific microservices, and the entire Kubernetes cluster, are all locked down and protected against cyber attacks.

What is Kubernetes Security?

Kubernetes security is founded on the 4C's of cloud-native security:

Security Essentials for a Kubernetes Developer

Securing a Cluster

If you manage your own cluster, you’ll need to restrict access to it. The first step is to restrict access to kubectl, the command-line tools used to control a Kubernetes cluster. Every request to kubectl must be authenticated and validated, either through token-based authentication or via a public-private key pair.

You can implement more advanced access models using role based access control (RBAC). Kubernetes RBAC functionality lets you ensure each request is authorized depending on the role of the current user or service account. Properly configuring RBAC ensures that even if a Kubernetes component is compromised, the damage is limited to the specific user’s access permissions.

Keep in mind that Kubernetes RBAC supports Normal roles, which are limited to a specific namespace in the Kubernetes cluster, and Cluster roles that have access to all namespaces. Use Cluster roles sparingly because they can provide broad access to your cluster if compromised by an attacker.

Security Hygiene

Here are a few ways you can practice security hygiene in a Kubernetes cluster:

Securing workloads

Securing Networking

Once a Kubernetes cluster is breached, everything in the network - including services and machines - becomes vulnerable to attack. You prevent a network-wide breach by limiting communication and isolating nodes.

Isolate Kubernetes Nodes

Here are several practices to implement when isolating Kubernetes nodes:

Monitor Network Traffic to Limit Communications

Here are key tips to help you secure containerized applications:

Incident Response for Kubernetes and the Kubernetes Audit Log

Security teams need logs to identify and investigate attacks on production Kubernetes infrastructure. As part of incident response planning, you may utilize the built-in Kubernetes Audit Log feature to prepare much of the data needed to detect malicious behavior in your cluster.

Kubernetes Audit Logging is known as a cluster-level capability, which organizations should initiate for production clusters. The audit log records Kubernetes API requests chronologically. Kubernetes audit log entries may assist incident response teams, helping them look into suspicious API requests, generate monitoring alerts for undesirable API calls, and collect statistics.

Audit policies define which events must be logged and what information must appear in the logs. The audit policy object’s structure is defined in the audit.k8s.io API group.

When events are processed, they are compared sequentially against the list of rules defined in the policy.

To support incident response, define audit policies covering critical activities such as:

Conclusion

In this article, I covered a few security essentials for a Kubernetes developer:

In addition, I showed how to prepare for an actual security incident against your Kubernetes cluster by ensuring you have logging of events critical to security. I hope this will be useful as you improve your security game when developing containerized applications.