Kubernetes Security Optimisation: SecOps Best Practices for Robust Container Platforms

Dive into #gettingStarted guide on Kubernetes Security and SecOps optimisation. Learn how to fortify your container platform by exploring essential tools, projects, and best practices to mitigate security risks and ensure compliance.

Jaroslav Pantsjoha
Contino Engineering
8 min readMar 25, 2023

--

The intent of this write up is to offer the list of security features for considerations against security risks, for your production grade Kubernetes cluster whether you are managing it.

If you are preparing for your Kubernetes Security Specialisation certification — this would be quite relevant for you. 💪 And in any case, even this is a great starting place to review your cluster capabilities before production workload can make runtime.

Day One Cluster Security

If the cluster is already built, you should and could bench mark it. This largely covers the fundamental best practices for your kubernetes cluster orchestration, particularly if you are managing such cluster in-house (🤕)

Here are a list of great tools to get started with synopsis of security risk areas they are designed tackle. Start by familiarizing yourself and your team with container security best practices, and assess your current security posture using tools like Kube-Bench and Falco as foundations. Then, as you can build up the CICD Implement security measures at various stages of your container lifecycle, such as image scanning, signing, and policy enforcement. The next stage would be continuously monitor and audit your cluster for security events and compliance. Be advised that each At each stage of cluster security enhancement and evolution you may need to involved more stakeholders from the wider organisation to ensure you’re adopting a consistent security framework with a known list of Functional and Non-Functional Requirements.

The Risks, Considerations and Standards

Naturally, before getting into the hands-on deep-dive mode with theSecOps optimisation for a Kubernetes container platform, you ought to consider the following security risks, considerations, and frameworks:

First, The Security Risks:

  1. Misconfigurations: Improperly configured Kubernetes components can expose the cluster to attacks or unauthorized access.
  2. Vulnerable container images: Deploying containers with known vulnerabilities can lead to security breaches.
  3. Insecure communication: Lack of encryption and mutual authentication between services can result in data leaks and man-in-the-middle attacks.
  4. Insider threats: Malicious or negligent actions by employees or contractors can compromise the security of the container platform.
  5. Supply chain attacks: Infiltration of malicious code or compromised dependencies during the software development lifecycle can lead to compromised applications and infrastructure.

Next, given the Container Cluster is typically a managed offering with every Cloud Vendor (AWS, Azure, GCP), there an additional list of considerations to explore;

  1. Access control: Implement Role-Based Access Control (RBAC) to limit access to Kubernetes resources based on the principle of least privilege.
  2. Network segmentation: Implement network policies to isolate and control communication between services and namespaces.
  3. Secrets management: Securely store, manage, and rotate secrets, such as API keys, tokens, and certificates.
  4. Monitoring and auditing: Continuously monitor the container platform for security events, and maintain audit logs to ensure accountability and traceability.
  5. Disaster recovery and incident response: Establish processes for detecting, containing, and recovering from security incidents, as well as mitigating their impact.

Let’s pay a visit to the Big Picture — The Security Frameworks and Standards. Afterall, WHY are you doing all this “SecOps”, right?

  1. CIS Kubernetes Benchmark: It’s the 101 Starting Point — and provides a comprehensive set of security best practices and recommendations for configuring and securing a Kubernetes cluster.
  2. NIST SP 800–190 Application Container Security Guide: Offers guidelines for securing containerised applications and the underlying infrastructure. AquaSec Did a great (Best Bits) Container Application Security walk-through Guide in practice and is a recommended read.
  3. PCI DSS, HIPAA, GDPR, and other industry-specific regulations: Ensure compliance with applicable data protection and security standards relevant to your organisation and industry. If you have any of these requirements — you’re doing this SecOps hands-on for a wee longer. SysDig did a PCI Compliance Guide for Container Security, another recommended read.
  4. ISO/IEC 27001 Information Security Management: Adopt an internationally recognised information security management system to ensure a systematic and risk-based approach to securing your container platform. High level, — I hope you have a CISO and a SecOps dedicated team for this one. Just thought i’d mention that it’s on the list.
  5. Lastly — Keep up-to-date with Cloud Native Computing Foundation (CNCF) landscape: Explore CNCF projects and tools designed to enhance security in Kubernetes environments. It’s an evolving landscape with graduating Projects in the ecosystem, some of which may be better suited to adopt in your organisation.

Minimum set of Tools to explore (CNCF)

By integrating the following tools and capabilities into your Kubernetes environment, you’ll be well-equipped to create a secure, scalable, and compliant container platform that supports your organization’s growth and success.

  • AquaSec OpenSource Kube-Bench tool — https://github.com/aquasecurity/kube-bench — is a great starting point. Easy to execute against your cluster. Pull down binaries on worker (and master) nodes and run the binary kube-bench worker|master to have your cluster inspection report. This would be a great starting point.
  • Falco https://github.com/falcosecurity/falco - An open-source, behavioral activity monitor designed to detect anomalous activity in your applications. Falco can be used to monitor and alert on any suspicious behavior in your Kubernetes environment.
  • OPA/Gatekeeper https://github.com/open-policy-agent/gatekeeper - Open Policy Agent (OPA) is a general-purpose policy engine that unifies policy enforcement across the stack. Gatekeeper is a customizable Kubernetes admission webhook that enforces policies executed by OPA.
  • Trivy https://github.com/aquasecurity/trivy - A simple and comprehensive vulnerability scanner for containers, compatible with CI/CD environments. Trivy detects vulnerabilities in OS packages and application dependencies, ensuring your images are secure before deployment.
  • SPIRE https://github.com/spiffe/spire - The SPIFFE Runtime Environment (SPIRE) is a CNCF project that provides a secure, production-ready implementation of the SPIFFE specification for service identity. It helps you automate and manage the issuance and rotation of short-lived, cryptographically secure certificates (called SVIDs) for services in your cluster. By integrating SPIRE with your workloads, you can improve security by enabling mutual authentication and secure communication between services. This could be and should be explored as an alternative for cluster wide Service Mesh (Istio) rollout.
  • Cilium https://github.com/cilium/cilium - Cilium is a CNI plugin and eBPF-based networking, observability, and security project for Kubernetes. It provides API-aware network security, load balancing, and visibility. With Cilium, you can enforce network policies at the API level, rather than just IP or port-based rules. This allows for fine-grained control over the communication between your services and helps prevent unauthorized access. This is a great security optimiser but it would require a technical team and operating model (SRE leadership) to maintain this — and troubleshoot — over time.
  • Kyverno https://github.com/kyverno/kyverno - Kyverno is another policy engine designed specifically for Kubernetes. It’s similar to OPA-Gatekeeper in terms of it’s purpose, but IMHO I think it’s more easier to get started with. Similarly, Kyverno policies are expressed as Kubernetes resources, making them easy to manage and integrate with your existing infrastructure.
Example from Official Website.

Personally, I am finding that Kyverno sets a lower barrier to entry for small teams to get started with compliance/control policies as code over OPA-Gatekeeper option. So much so, that I’ve decided to explore this more in detail recently on my newest project being tasked building out Secure and Consumable Container Platform Architecture (on EKS).

Similar to OPA-Gatekeeper, with Kyverno, you can enforce those best practices, enhance security, and automate resource management tasks in your cluster and example use cases for Kyverno include;

  • Automatically injecting sidecar containers into pods, such as service mesh proxies, log forwarders, or monitoring agents.
  • Enforcing pod security policies, such as disallowing privileged containers, ensuring images are pulled from trusted registries, or restricting the use of host namespaces.
  • Validating that resources have specific labels, annotations, or resource limits set.

A Word on the Supply Chain Security

Supply Chain Security: Supply chain security is a critical aspect of container security, as it helps you ensure that the software you deploy in your cluster is free from vulnerabilities and malicious code. Securing the supply chain involves implementing security measures at various stages, such as source code management, artifact repository management, and image scanning.

Here are some best practices for supply chain security, to get started in your project and organisation;

  • Scanning images for vulnerabilities: Regularly scan your container images using tools like Trivy or Clair (https://github.com/quay/clair) to identify and remediate security vulnerabilities. We’ve covered this in the previous list and it’s a great way to get started
  • Implementing image signing and verification: Sign your container images with tools like Docker Content Trust or Notary (https://github.com/theupdateframework/notary), and verify the signatures before deploying them in your cluster. This ensures the integrity and authenticity of your images.
  • Enforcing policy-based deployments: Use OPA/Gatekeeper to enforce policies related to image provenance, container resource usage, and other security concerns during the deployment process.

Strategic and Tactical Security Adoption Guide

I hope you found the list of tools and capabilities as a useful starting point and an insight about where to get started first when designing this “Secure Container Platform with Bells & Whistles” as i tend to dubb it.

I do want to draw your attention to the SRE and Team Topology aspect to ensure successful platform adoption and a sustainable long term run is achieved with an appropriate Operating Model in place. This will ensure a strong strategic drive and long term sustainable adoption of Practices & Processes, for people — never mind the technology.

Start by forming a dedicated cross-functional team, comprising members with diverse skill sets such as developers, security engineers, DevOps specialists, and SREs, who will work together to manage and maintain the Kubernetes environment. There is a fantastic little book on Team Topologies which can fast track you and your organisation getting started.

Some quick tips would be to;

  • Encourage close collaboration between this team and other teams in the organization through regular communication channels and joint initiatives.
  • Establish a culture of continuous learning & Provide training, workshops, and access to relevant resources that empower individuals to expand their expertise and drive the adoption of security measures across the organization.
  • Implement feedback loops to measure the effectiveness of the tools and practices in place, and iteratively improve the security posture.
  • Incorporate the security tooling and practices into the organization’s CI/CD pipeline, ensuring that security checks and validations are an integral part of the development process.

Tactically & Technically speaking, great way to start start securing your container platform, follow these initial steps:

  1. Educate yourself and your team about container security best practices. Familiarize yourself with resources like the CIS Kubernetes Benchmark (https://www.cisecurity.org/benchmark/kubernetes/) and the NIST SP 800–190 Application Container Security Guide (https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-190.pdf).
  2. Assess your current security posture using tools like Kube-Bench and Falco. Identify areas that need improvement and prioritize them based on risk.
  3. Implement security measures at various stages of your container lifecycle, such as image scanning, signing, and policy enforcement.
  4. Continuously monitor and audit your cluster for security events and compliance. Leverage tools like Falco, Kyverno/Gatekeeper, and Kubernetes Audit

Good luck!

If you enjoyed the read and It helped you on your Container Cluster Security journey, give it a like, clap and share on your socials to help others on their journey. Connect on linkedIn, we’re always hiring!

--

--

Jaroslav Pantsjoha
Contino Engineering

Google Cloud CoP Lead @ Cognizant. All Content and Views are my own.