Blog by Saw Win Naung

Official

Kubernetes Security: A Deep Dive


Kubernetes Security: A Deep Dive with Falco

Introduction to Kubernetes

Before we dive into security, let’s recap the core components of a Kubernetes cluster:

Diagram of the components of a Kubernetes cluster

The 4C Model of Cloud Native Security

To effectively secure your Kubernetes environment, it’s crucial to adopt a holistic approach. The 4C model provides a framework for addressing security across different layers:

4C Model of Cloud Native Security

  1. Cloud: Secure the underlying cloud infrastructure on which your cluster resides. This includes configuring network security, access controls, and identity management.
  2. Clusters: Secure the Kubernetes cluster itself by implementing strong authentication and authorization, network policies, and resource quotas.
  3. Containers: Ensure your container images are free of vulnerabilities and adhere to security best practices. This involves scanning images, using minimal base images, and implementing least privilege principles.
  4. Code: Develop secure applications by following secure coding practices, performing regular security testing, and addressing vulnerabilities promptly.

Attack Vectors

Common Kubernetes attack vectors:

Vulnerable Applications (Code)

Applications with vulnerabilities like SQL injection, insecure deserialization, or SSRF can be exploited to gain a foothold in the cluster.

Hands-on Labs with Kubernetes Goat

To gain practical experience with Kubernetes security, I recommend exploring Kubernetes Goat, a deliberately vulnerable cluster environment:

This platform allows you to experiment with various attack scenarios and learn how to detect them using Falco.

eBPF for Kubernetes Security

Traditional security tools often struggle in containerized environments due to limited visibility, the dynamic nature of pods, and the prevalence of encrypted traffic. eBPF addresses these challenges by providing deep visibility into container activity at the kernel level.

eBPF allows for:

Implementing Falco for Runtime Security

Falco is an open-source runtime security tool that uses eBPF to monitor system calls and detect anomalous behavior. It provides a powerful rules engine for defining security policies and generating alerts.

Installation

helm repo add falcosecurity https://falcosecurity.github.io/charts
helm install falco falcosecurity/falco --set "falcoctl.config.artifact.install.refs={falco-rules:2,falco-incubating-rules:2,falco-sandbox-rules:2}" --set "falcoctl.config.artifact.follow.refs={falco-rules:2,falco-incubating-rules:2,falco-sandbox-rules:2}" --set "falco.rules_file={/etc/falco/k8s_audit_rules.yaml,/etc/falco/rules.d,/etc/falco/falco_rules.yaml,/etc/falco/falco-incubating_rules.yaml,/etc/falco/falco-sandbox_rules.yaml}"

Usage

k logs -f daemonset.apps/falco

Falco Sidekick

For advanced log management and alerting, integrate Falco with Falco Sidekick:

Falco Sidekick allows you to forward Falco events to various outputs like Slack, Elasticsearch, and Kafka.

Example Falco Logs

15:56:24.543183236: Warning Sensitive file opened for reading by non-trusted program (file=/etc/shadow gparent=containerd-shim ggparent=systemd gggparent=<NA> evt_type=open user=root user_uid=0 user_loginuid=-1 process=cat proc_exepath=/usr/bin/coreutils parent=bash command=cat /etc/shadow terminal=34816 exe_flags=O_LARGEFILE|O_RDONLY container_id=bb74e3dc000c container_image=docker.io/madhuakula/hacker-container container_image_tag=latest container_name=hacker-container k8s_ns=default k8s_pod_name=hacker-container)

15:56:31.936939624: Notice Unexpected UDP Traffic Seen (connection=10.244.1.160:44136->142.250.65.196:65535 lport=44136 rport=65535 fd_type=ipv4 fd_proto=fd.l4proto evt_type=connect user=root user_uid=0 user_loginuid=-1 process=curl proc_exepath=/usr/bin/curl parent=bash command=curl -I https://www.google.com terminal=34816 exe_flags=<NA> container_id=bb74e3dc000c container_image=docker.io/madhuakula/hacker-container container_image_tag=latest container_name=hacker-container k8s_ns=default k8s_pod_name=hacker-container)

Integrating Falco with Elasticsearch

To centralize Falco logs and enable powerful searching and visualization, integrate Falco with Elasticsearch:

helm install falco falcosecurity/falco \
--set "falcoctl.config.artifact.install.refs={falco-rules:2,falco-incubating-rules:2,falco-sandbox-rules:2}" \
--set "falcoctl.config.artifact.follow.refs={falco-rules:2,falco-incubating-rules:2,falco-sandbox-rules:2}" \
--set "falco.rules_file={/etc/falco/k8s_audit_rules.yaml,/etc/falco/rules.d,/etc/falco/falco_rules.yaml,/etc/falco/falco-incubating_rules.yaml,/etc/falco/falco-sandbox_rules.yaml}" \
--set falcosidekick.enabled=true \
--set falcosidekick.config.elasticsearch.hostport="https://es_url:443" \
--set falcosidekick.config.elasticsearch.customheaders="Authorization: ApiKey api_key"

ref: