M8-Security Weaknesses in Kubernetes Manifests

Description

Use an existing tool to find security misconfigurations in Kubernetes configuration files.

Courses Where This Module Is Integrated

Activities 

Pre-lab Content Dissemination

In our lecture, we learned that tools now exist to manage configurations automatically. One such tool is Kubernetes, https://kubernetes.io/. With Kubernetes, a lot of clusters can be managed automatically. Kubernetes uses configuration files called manifests that are executed using a tool called `kubectl`. These manifests are developed in a language called the "Yet Another Markup Language", i.e., YAML (https://yaml.org/). 


In this workshop, we will use a tool called SLI-KUBE (https://hub.docker.com/repository/docker/akondrahman/sli-kube) to find security misconfigurations. According to the U.S. National Institute of Standards and Technology, NIST (https://www.nist.gov/), a security misconfiguration is a setting within a computer program that violates a configuration policy or that permits unintended behavior that impacts the security posture of a system`. The goal of this workshop is to understand how we can use a tool to identify security misconfigurations in Kubernetes manifests. 


In-class Hands-on Experience

docker rm $(docker ps -a -f status=exited -f status=created -q)

The command docker rm $(docker ps -a -f status=exited -f status=created -q) is used to remove Docker containers that are in either an "exited" or "created" state. Here's a breakdown of the command:


      docker rmi -f $(docker images -a -q) 

The command docker rmi -f $(docker images -a -q) is used to forcefully remove (force-delete) all Docker images, both active and inactive, from your local Docker environment. Let's break down the command:

The part in parentheses $(docker images -a -q) is a subcommand that does the following:

So, when you put it all together, the command docker rmi -f $(docker images -a -q) forcefully removes all Docker images that are currently present on your local system, cleaning up your Docker image repository. This is useful for reclaiming disk space and ensuring that you're not carrying unnecessary or obsolete images. However, be very cautious when using the -f flag, as it doesn't provide any confirmation and can lead to the permanent removal of images.


         docker pull akondrahman/sli-kube 

The command docker pull akondrahman/sli-kube is used to download (pull) a Docker image from the Docker Hub or another container registry. Here's a breakdown of the command:


        docker images -a

The command docker images -a is used to list all Docker images that are currently available on your local Docker environment, including both active and inactive images. Here's what this command means:


        docker run --rm -it akondrahman/sli-kube bash 

The command docker run --rm -it akondrahman/sli-kube bash is used to run a Docker container interactively with a Bash shell as the entry point. Let's break down this command:

       cd SLI-KUBE-WORK/KubeSec-master/


       python3 main.py` or `python main.py


Locate the output file generated by the tool. The output file is stored at `/SLI-KUBE-WORK/DEMO-OUTPUT.csv` 

The output file is a CSV file that has multiple columns. The first two columns correspond to the directory and the path of a Kubernetes configuration file. The rest corresponds to the count of instances for a specific category. We will use this count to determine the three most frequent ones. The `Total` column corresponds to the total instances of misconfigurations for a configuration file. 

A video recording of this hands-on experience is available here.


Post Lab Experience