Beginner Lab blue team icon   aws

Secure Kubernetes using OPA Gatekeeper

Explore how to enhance the security and compliance of our Kubernetes clusters using Open Policy Agent (OPA) and the OPA Gatekeeper project.

Overview

Join us as we explore how to enhance the security and compliance of our Kubernetes clusters using Open Policy Agent (OPA) and the OPA Gatekeeper project. OPA Gatekeeper provides a powerful way to enforce policies and to ensure that Kubernetes environments adhere to organisational and security standards.

Scenario

Your company has been hired by SuperTech who have encountered some recent security challenges with their Kubernetes clusters. The organisation has struggled with misconfigured deployments and non-compliant resource settings, which has led to several security incidents. To address these issues, you are tasked with helping them implement a robust policy enforcement solution using OPA Gatekeeper to ensure the following:

  • Non-Read-Only Filesystem: Ensure that all pods use a read-only filesystem to prevent unauthorized modifications.
  • Privileged Escalation: Block pods where the AllowPrivilegeEscalation option in the security context is set to true, which can allow processes to gain additional privileges.
  • Host Network Usage: Disallow the use of hostNetwork: true in pod specifications to prevent exposing the pod directly to the host network, reducing the risk of network-level attacks.
  • Restrict HostPath Volumes: Restrict the use of hostPath volumes on a k8s pod.
Lab prerequisites
  • Basic understanding of Kubernetes concepts and architecture
  • Familiarity with Kubernetes manifests
  • Whilst not required, basic understanding of a programming language will be beneficial
Learning outcomes
  • You will learn how to create and customise security policies using the Rego policy language.
  • You will be able to able to apply policies to Kubernetes resources and ensure OPA Gatekeeper enforces them.
  • You will learn how to apply best practices for policy management to improve cluster security and compliance.
Real-world context

Kubernetes is a powerful tool for managing large scale containerised applications, but this also makes it highly suspectible to configuration errors. Misconfigurations often arise from the intricate interactions between numerous components, evolving features, and default settings that may not prioritize security. As organisations integrate Kubernetes with other tools and environments, the risk of errors increases, especially if best practices are not well understood or consistently applied.

OPA Gatekeeper provides a vital layer of security for organisations to define and enforce policies consistently across their Kubernetes clusters, such as preventing containers from running with elevated privileges, restrict access to senstive namespaces and by ensuring pods are assigned appropriate resource limits.

platform mock(1)

Cloud Security Training To Protect Your Business

Pwned Labs for Business gives your team access to dedicated business content, including labs and cyber ranges.

We also offer in-person or remote workshops, and our cloud penetration services are helping businesses become more secure!