Reader small image

You're reading from  The Kubernetes Workshop

Product typeBook
Published inSep 2020
PublisherPackt
ISBN-139781838820756
Edition1st Edition
Right arrow
Authors (6):
Zachary Arnold
Zachary Arnold
author image
Zachary Arnold

Zachary Arnold works as a software engineer at Ygrene Energy Fund. Zach has an experience of over 10 years in modern web development. He is an active contributor to the Open Source Kubernetes project in both SIG-Release and SIG-Docs currently focusing on security. He has been running clusters in production since Kubernetes 1.7 and has spoken at the previous 4 KubeCons. His passion areas in the project center on building highly stable Kubernetes cluster components and running workloads securely inside of Kubernetes.
Read more about Zachary Arnold

Sahil Dua
Sahil Dua
author image
Sahil Dua

Sahil Dua is a software engineer. He started using Kubernetes to run machine learning workloads. Currently, he is running various types of applications on Kubernetes. He shared his learnings as a keynote session at KubeCon Europe 2018. He is a passionate open source contributor and has contributed to some famous projects such as Git, pandas, hound, go-GitHub, and so on. He has been an open source community leader for over 2 years at DuckDuckGo.
Read more about Sahil Dua

Wei Huang
Wei Huang
author image
Wei Huang

Wei Huang: Wei works as a senior software engineer in IBM. He has over 10 years' experiences around database, data warehouse tooling, cloud, container, monitoring and devops. He started to use Kubernetes since 1.3, including extending Kubernetes LoadBalancer using CRD, networking, scheduling and monitoring. Now he is a core maintainer of Kubernetes SIG-Scheduling.
Read more about Wei Huang

Faisal Masood
Faisal Masood
author image
Faisal Masood

Faisal Masood is a cloud transformation architect at AWS. Faisal's focus is to assist customers in refining and executing strategic business goals. Faisal main interests are evolutionary architectures, software development, ML lifecycle, CD and IaC. Faisal has over two decades of experience in software architecture and development.
Read more about Faisal Masood

Mélony Qin
Mélony Qin
author image
Mélony Qin

Mélony Y. QIN, also known as CloudMelon, is the founder of CloudMelon Vis, a tech media and educational platform for technopreneurs in the cloud-native and serverless space, and a former product manager at Microsoft. With a passion for cloud-native technologies, OSS, DevOps, Kubernetes, serverless, data, and AI, Mélony has authored multiple books, including the Certified Kubernetes Administrator (CKA) Exam Guide, the Kubernetes Workshop, and Microsoft Azure Infrastructure, all published by Packt Publishing. Mélony is a member of the Association for Computing Machinery (ACM) and the Project Management Institute (PMI), leveraging her extensive experience with diverse cloud technologies to drive innovation in the cloud-native, serverless, and generative AI space. She runs the CloudMelonVis YouTube channel and Cloud-Native Innovators newsletter, read by professionals from top tech companies such as Microsoft, Google, Amazon, Dell, and Carrefour.
Read more about Mélony Qin

Mohammed Abu Taleb
Mohammed Abu Taleb
author image
Mohammed Abu Taleb

Mohammed Abu-Taleb works as a Technical Advisor at Microsoft. Working at Microsoft CSS team for troubleshooting complex issues and cases for premier customers that are using Azure Kubernetes Services (AKS). Prior that, Mohammed was a SME (subject matter expert) for the azure managed monitoring service (Azure Monitor) focusing on designing, deploying, and troubleshooting monitoring strategies for containers.
Read more about Mohammed Abu Taleb

View More author details
Right arrow

13. Runtime and Network Security in Kubernetes

Overview

In this chapter, we will look at various resources that we can use to secure workloads running in our cluster. We will also understand a rough threat model and apply it to architect a secure cluster so that we can defend our cluster and application against various types of threats. By the end of this chapter, you will be able to create Role and ClusterRole, as well as RoleBinding and ClusterRoleBinding to control the access of any process or user to the Kubernetes API server and objects. Then, you will learn how to create a NetworkPolicy to restrict communication between your application and the database. You will also learn how to create a PodSecurityPolicy to ensure that the running components of your application are conforming to the defined limits.

Introduction

In the last couple of chapters, we had our DevOps hat on and learned how to set up a cluster, as well as how to roll out new application versions safely and without downtime in Kubernetes.

Now, it's time to switch gears a bit, take our DevOps hat off, and put on our security analyst hat. First, we will look at where someone might attack our Kubernetes cluster and how an unauthorized user could potentially wreak havoc in our cluster. After that, we're going to introduce a few of the security primitives of Kubernetes and how we can combat the most common forms of attack. Finally, we'll further modify our application and demonstrate how some of these security primitives work.

But before we get to any of it, let's begin by taking a brief look at the various areas of concern for security in a modern web application, as well as a basic paradigm for implementing effective security for our cluster. We'll start by examining what we call the "...

Threat Modeling

It is far beyond the scope of this chapter to adequately teach many of the necessary disciplines of security so that you have a rigorous understanding of how modern workload security should be implemented and orchestrated. However, we will briefly gain an idea of how we should be thinking about it. Threat modeling is a discipline where we examine the various areas where our applications could be subject to an attack or unauthorized usage.

For example, consider an HTTP web server. It will typically have ports 80 and 443 exposed for serving web traffic, but it also acts as an entry point for any potential attackers. It may have a web management console exposed at a certain port. It may have certain other management ports open and API access to allow other software to manage it for automation purposes. The application runtime may need to regularly handle sensitive data. The entire end-to-end pipeline meant to create and deliver the application could expose various points...

Cluster Security

One way to think about Kubernetes is as a gigantic self-orchestrating pool of compute, networking, and storage. As such, in many respects, Kubernetes is exactly like a cloud platform. It is important to understand this equivalence because this mental abstraction allows us to reason differently as a cluster operator versus a cluster developer. A cluster operator would want to ensure that all the components of the cluster were secure and hardened against any workload. A cluster developer would concern themselves with ensuring that the workload they are defining for Kubernetes is running securely inside the cluster.

Here is where your work becomes a bit easy – most cloud provider offerings from Kubernetes will ensure the security of the Kubernetes control plane for you. If, for whatever reason, you're not able to leverage a cloud provider offering, you'll want to read more in the documentation about securing your cluster at this link: https://kubernetes...

Kubernetes RBAC

Before we dive into RBAC, recall from Chapter 4, How to Communicate with Kubernetes (API Server), how Kubernetes authorizes requests to the API. We learned that there are three stages – Authentication, Authorization, and AdmissionControl. We will learn more about Admission Controllers in Chapter 16, Kubernetes Admission Controllers.

Kubernetes supports multiple different methods of authenticating with the cluster, and you'll want to reference your cloud provider's documentation to get more details on their specific implementation.

Authorization logic is handled through something called RBAC. It stands for role-based access control and it's the foundation of how we constrain certain users and groups to the minimum necessary permissions to perform their job. This is based on a concept in software security called "the principle of least privilege." For example, if you are a software engineer for a credit card processing company, Payment...

NetworkPolicies

NetworkPolicy objects in Kubernetes are essentially Network Access Control Lists but at the Pod and namespace level. They work by using label selection (such as Services) or by indicating a CIDR IP address range to allow on a particular port/protocol.

This is immensely helpful for ensuring security, especially when you have multiple microservices running on a cluster. Now, imagine you have a cluster that hosts many applications for your company. It hosts a marketing website that runs an open-source library, a database server with sensitive data, and an application server that controls access to that data. If the marketing website doesn't need to access the database, then there should be no reason for it to be allowed access to the database. By using a NetworkPolicy, we can prevent an exploit or a bug in the marketing website from allowing an attacker to expand that attack so that they can access your business data by preventing the marketing website Pod from...

PodSecurityPolicy

So far, we have learned about and tested Kubernetes RBAC to prevent unauthorized API server access, and also applied a NetworkPolicy to prevent unnecessary network communication. The next most important area of security outside the network is the application runtime. Attackers need access to the network to get in and out, but they also need a vulnerable runtime to do anything more serious. This is where Kubernetes PodSecurityPolicy objects help prevent that from happening.

PodSecurityPolicy objects overlap with a specific type of AdmissionController and allow a cluster operator to dynamically define the minimum runtime requirements of a Pod that's been admitted for scheduling on the cluster.

To understand exactly how PodSecurityPolicies can be useful, let's consider the following scenario. You are a Kubernetes cluster admin at a large financial institution. Your company uses ticket-based change management software in an ITIL-compliant fashion (ITIL...

Summary

In our journey of building a production-ready Kubernetes environment, security is a critical aspect. With that in mind, in this chapter, we examined how threat modeling allows us to think in an adversarial way about our application infrastructure and how it informs us of how we can defend it from attack. Then, we looked at the 4Cs of Cloud Native Security to understand where our attack surfaces are, followed by how Kubernetes can help us run workloads securely in the cluster.

Kubernetes has several security features that we can leverage to secure our cluster. We learned about three security measures that are important to leverage: RBAC, NetworkPolicies, and PodSecurityPolicies. We also learned about their various applications when it comes to securing access to your cluster, securing your container network, and securing your container runtimes.

In the next chapter, we're going to examine how to manage storage objects in Kubernetes and deal with apps that are stateful...

lock icon
The rest of the chapter is locked
You have been reading a chapter from
The Kubernetes Workshop
Published in: Sep 2020Publisher: PacktISBN-13: 9781838820756
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at AU $19.99/month. Cancel anytime

Authors (6)

author image
Zachary Arnold

Zachary Arnold works as a software engineer at Ygrene Energy Fund. Zach has an experience of over 10 years in modern web development. He is an active contributor to the Open Source Kubernetes project in both SIG-Release and SIG-Docs currently focusing on security. He has been running clusters in production since Kubernetes 1.7 and has spoken at the previous 4 KubeCons. His passion areas in the project center on building highly stable Kubernetes cluster components and running workloads securely inside of Kubernetes.
Read more about Zachary Arnold

author image
Sahil Dua

Sahil Dua is a software engineer. He started using Kubernetes to run machine learning workloads. Currently, he is running various types of applications on Kubernetes. He shared his learnings as a keynote session at KubeCon Europe 2018. He is a passionate open source contributor and has contributed to some famous projects such as Git, pandas, hound, go-GitHub, and so on. He has been an open source community leader for over 2 years at DuckDuckGo.
Read more about Sahil Dua

author image
Wei Huang

Wei Huang: Wei works as a senior software engineer in IBM. He has over 10 years' experiences around database, data warehouse tooling, cloud, container, monitoring and devops. He started to use Kubernetes since 1.3, including extending Kubernetes LoadBalancer using CRD, networking, scheduling and monitoring. Now he is a core maintainer of Kubernetes SIG-Scheduling.
Read more about Wei Huang

author image
Faisal Masood

Faisal Masood is a cloud transformation architect at AWS. Faisal's focus is to assist customers in refining and executing strategic business goals. Faisal main interests are evolutionary architectures, software development, ML lifecycle, CD and IaC. Faisal has over two decades of experience in software architecture and development.
Read more about Faisal Masood

author image
Mélony Qin

Mélony Y. QIN, also known as CloudMelon, is the founder of CloudMelon Vis, a tech media and educational platform for technopreneurs in the cloud-native and serverless space, and a former product manager at Microsoft. With a passion for cloud-native technologies, OSS, DevOps, Kubernetes, serverless, data, and AI, Mélony has authored multiple books, including the Certified Kubernetes Administrator (CKA) Exam Guide, the Kubernetes Workshop, and Microsoft Azure Infrastructure, all published by Packt Publishing. Mélony is a member of the Association for Computing Machinery (ACM) and the Project Management Institute (PMI), leveraging her extensive experience with diverse cloud technologies to drive innovation in the cloud-native, serverless, and generative AI space. She runs the CloudMelonVis YouTube channel and Cloud-Native Innovators newsletter, read by professionals from top tech companies such as Microsoft, Google, Amazon, Dell, and Carrefour.
Read more about Mélony Qin

author image
Mohammed Abu Taleb

Mohammed Abu-Taleb works as a Technical Advisor at Microsoft. Working at Microsoft CSS team for troubleshooting complex issues and cases for premier customers that are using Azure Kubernetes Services (AKS). Prior that, Mohammed was a SME (subject matter expert) for the azure managed monitoring service (Azure Monitor) focusing on designing, deploying, and troubleshooting monitoring strategies for containers.
Read more about Mohammed Abu Taleb