DMCA.com Protection Status Trending Topics About Devops

Tuesday, 9 March 2021

Great CKS Kubernetes Security Exam preparation guide to help you pass

 Recapping how was my exam, and the study process I followed, so it can help you pass too

If at first you don’t succeed, Just keep trying.

I hope to share my exam experience, offer some study tips and resources as well as offer some insights into your very own exam  (You see what I did there?)

What Is the Certified Kubernetes Security Specialist Exam?

According to the CNFC, the CKS Exam “provides assurance that a CKS has the skills, knowledge, and competence on a broad range of best practices for securing container-based applications and Kubernetes platforms during build, deployment and runtime.”

With a great number of features that are available in the vanilla standalone Kubernetes versus the managed service offering, you earn a great deal of SecOps brownie points by staying on top of the security posture of your Kubernetes Cluster, whatever the cloud platform.

The Certified Kubernetes Administrator certification is a prerequisite for the Certified Kubernetes Security Certification. As you likely have seen through the Kubernetes documentation, there is a great amount of implementation detail in every aspect of admission control, advanced policies, and never-ending custom resource definitions, which can be created and managed by third parties

This certification is yet another great opportunity to validate your skills and knowledge, which now has security as an integral part of the Kubernetes focused certification track.

SIGN UP FOR EXAM

It is a personal challenge to wrap up the CNCF Kubernetes Certification track [CKA,CKAD and now CKS]. That and Containerisation and Service Mesh are my keen area of on-going interest.

Exam Experiences

From my point of view, this was a tough-but-fair certification accomplishment.

I have been working in Kubernetes and containerisation for around three years, with recent work effort in service mesh implementation. The CKA, being a pre-requisite for the CKS exam, provides a great foundational framework to get started with.

This certification not only covers general kubernetes cluster administration knowledge, but there’s also a certain degree of depth particularly in self-managed master api-server configuration you should be well versed in.

The exam material brings together the security best practices of the  manifest management as well as static (SAST), and runtime (DAST) vulnerability assessment and prevention. Interestingly, some of the tools featured are developed by teams and vendors outside the immediate kubernetes configuration ecosystem. This is why this is a great all rounder of certification and should seriously be considered for senior professionals working in this space.

I’ve written a number of blog posts in the past which touch on some of the CKS tested elements like Taints & Toleration [Why separate your Kubernetes workload with nodepool segregation and affinity options] and Cluster Network Security posts in particular. Finally, from a Service Mesh perspective — a tad more advanced but good-to-know if you want to dive deeper on the topic.
And if you want to dive deeper with KubeCon and ServiceMeshCon, I have recently covered the best key conference takeaway notes here, and deeper-yet on GitOps, here.

Exam Prep

The exam prep to be a great validator of existing knowledge, and highlight the areas which, while not used regularly, such as Pod Security Policies, was found to be most helpful to clarify and learn the gaps for.

The depth and breadth of the exam knowledge is sensible with the following areas covered to a great degree:

Study Resources

I have found the following resources extremely helpful preparing for the CKS exam. Start with videos over weekend, easier to get into the study mode. Follow-up by the reading material. you can mix and match that as it works better.

Videos to consume, and get into the :

Supplemental Reading Material:

Practice exam with the CKS exam Sim:

Main Exam Tips

  • Take care with time keeping
    The exam does not have a countdown timer, which would be extremely helpful. There is a time bar, but it’s hard to assess where it is at, we’re used to seeing the actual time remaining after all.
  • Watch out for question/exam environment bugs
    I wish I could say it was straight forward questions, but be prepared to have an exam window crash, exam restarted and, worse, some questions will be referring to question components incorrectly named. i.e. “Allow” versus “Ally”, if in doubt IMO save it with both names.

Kubernetes-native exam material

Third-Party Tools Examinable material

The following are mentioned thoroughly in the CKS criteria.

These are some examples of open source tools and projects, outside the immediate kubernetes ecosystem that are recommended to get hands-on with in order to successfully pass the exam.

  • AquaSec OpenSource Kube-Bench
    Easy to execute against your cluster. Pull down binaries on worker (and master) nodes and run the binary  worker|master to have your cluster inspection report. This would be a great starting point.
  • Aquasec/trivy
    Image scanning tool — is a very simple image scanning tool.
  • AppArmor
    Practice loading new profiles and then using it with your pods. AppArmor would be pre-installed.
  • Falco
    Practice finding all  rules and search for specific ones and change their output and capture specific output.

Start with — Booking that Exams

If you’re anything like me, you will probably organise your time schedule to ensure you sit the exam, by booking the exam first. Remember that pre-requisite is the CKA certification.

One Final Tip to remember — it’s an open book exam. BUT you wont have time to start “searching” for answers. You need to already know where to go and get them. Practice that search, and you’ll be fine.

Don’t worry — this is unlikely to happen. You just need to be THAT prepared. :)

Already passed the exam? How did it go, share your experience in the comments section below. In fact, get in touch, you may want to get working on cloud native Kubernetes work stream right away. We’re always hiring!

ITNEXT

ITNEXT is a platform for IT developers & software engineers…

Docker 101: Fundamentals & The Dockerfile

Image for post
  • Docker Compose, and
  • Docker Swarm

What is Docker?

The Docker website itself simply describes Docker as:

Why Docker?

I can’t tell you how many times I’ve heard a developer (myself included) say, “It works on my machine, I don’t know why it won’t work on yours.” — any developer, ever

Image for post
The Docker container’s just like Jon Snow when it spins up; it knows nothing.

Docker Tools

Before I dive into the Dockerfile, I’ll give a quick run down of Docker’s suite of tools.

Image for post

The Dockerfile — where it all begins

Docker is a powerful tool, but its power is harnessed through the use of things called Dockerfiles.

Dockerfile Commands

Below, are the commands that will be used 90% of the time when you’re writing Dockerfiles, and what they mean.

  • RUN — will execute any commands in a new layer on top of the current image and commit the results. The resulting committed image will be used for the next step in the Dockerfile.
  • ENV — sets the environment variable <key> to the value <value>. This value will be in the environment for all subsequent instructions in the build stage and can be replaced inline in many as well.
  • EXPOSE — informs Docker that the container listens on the specified network ports at runtime. You can specify whether the port listens on TCP or UDP, and the default is TCP if the protocol is not specified. This makes it possible for the host and the outside world to access the isolated Docker Container
  • VOLUME — creates a mount point with the specified name and marks it as holding externally mounted volumes from the native host or other containers.

Dockerfile Examples

Here are a few sample Dockerfiles, complete with comments explaining each line and what’s happening layer by layer.

# creates a layer from the node:carbon Docker image
FROM
node:carbon
# create the app directory for inside the Docker image
WORKDIR /usr/src/app
# copy and install app dependencies from the package.json (and the package-lock.json) into the root of the directory created above
COPY package*.json ./
RUN
npm install
# bundle app source inside Docker image
COPY . .
# expose port 8080 to have it mapped by Docker daemon
EXPOSE 8080
# define the command to run the app (it's the npm start script from the package.json file)
CMD [ "npm", "start" ]
# creates a layer from the openjdk:8-jdk-alpine Docker image
FROM
openjdk:8-jdk-alpine
# create the directory for where Tomcat creates its working directories
VOLUME /tmp
# copy the project JAR file to the container renamed as 'app.jar'
COPY build/libs /app
# execute that JAR in the entry point below
ENTRYPOINT ["java", "-Djava.security.egd=file:/dev/./urandom", "-jar", "/app/java-example.jar"]
# creates a layer from the ubuntu:16.04 Docker image 
FROM ubuntu:16.04
# adds files from the Docker client’s current directory
COPY . /app
# builds the application with make
RUN make /app
# specifies what command to run within the container
CMD python /app/app.py
# creates a layer from the jenkins:lts Docker image
FROM
jenkins/jenkins:lts
# sets user to root (because Docker always runs as root and Jenkins needs to know this)
USER root

# add and install all the necessary dependencies
RUN apt-get update && \
apt-get install -qy \
apt-utils \
libyaml-dev \
build-essential \
python-dev \
libxml2-dev \
libxslt-dev \
libffi-dev \
libssl-dev \
default-libmysqlclient-dev \
python-mysqldb \
python-pip \
libjpeg-dev \
zlib1g-dev \
libblas-dev\
liblapack-dev \
libatlas-base-dev \
apt-transport-https \
ca-certificates \
zip \
unzip \
gfortran && \
rm -rf /var/lib/apt/lists/*

# install docker
RUN curl -fsSL get.docker.com -o get-docker.sh && sh get-docker.sh

# install docker compose
RUN curl -L https://github.com/docker/compose/releases/download/1.8.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose && \
chmod +x /usr/local/bin/docker-compose
# install pip for python
RUN pip install cffi --upgrade
RUN pip install pip2pi ansible==2.0

# copy groovy executors and plugins for jenkins and run the plugins
COPY executors.groovy /usr/share/jenkins/ref/init.groovy.d/executors.groovy
COPY plugins.txt /usr/share/jenkins/ref/plugins.txt
RUN /usr/local/bin/plugins.sh /usr/share/jenkins/ref/plugins.txt

# add the jenkins user to the docker group so that sudo is not required to run docker commands
RUN groupmod -g 1026 docker && gpasswd -a jenkins docker
USER jenkins

Images vs. Containers

The terms Docker image and Docker container are sometimes used interchangeably, but they shouldn’t be, they mean two different things.

Image for post
Examples of Docker containers. Each one comes from a specific Docker image.

Docker Engine Commands

Once the Dockerfile has been written the Docker image can be built and the Docker container can be run. All of this is taken care of by the Docker Engine that I covered briefly earlier.

Image for post
The CLI uses the Docker REST API to control or interact with the Docker daemon through scripting or direct CLI commands. Many other Docker applications use the underlying API and CLI as well.
  • docker images — displays all Docker images on that machine
  • docker run — starts container and runs any commands in that container
  • there’s multiple options that go along with docker run including
  • -p — allows you to specify ports in host and Docker container
  • -it—opens up an interactive terminal after the container starts running
  • -v — bind mount a volume to the container
  • -e — set environmental variables
  • -d — starts the container in daemon mode (it runs in a background process)
  • docker rmi — removes one or more images
  • docker rm — removes one or more containers
  • docker kill — kills one or more running containers
  • docker ps — displays a list of running containers
  • docker tag — tags the image with an alias that can be referenced later (good for versioning)
  • docker login — login to Docker registry

Conclusion and Part Two: Docker Compose

Now you’ve seen the tip of the iceberg of Docker. It’s a lightweight, isolated runtime environment known as a ‘container’ that you can spin up and configure just about anyway you like with the help of a Dockerfile.