# Kubernetes Security - [Introduction](#introduction) - [Service Accounts](#service-accounts) - [Kubernetes Secrets](#kubernetes-secrets) - [Encrypting the certificate for Kubernetes. SSL certificates with Let's Encrypt in Kubernetes Ingress via cert-manager](#encrypting-the-certificate-for-kubernetes-ssl-certificates-with-lets-encrypt-in-kubernetes-ingress-via-cert-manager) - [RBAC and Access Control](#rbac-and-access-control) - [Admission Control](#admission-control) - [Kubernetes Security Best Practices](#kubernetes-security-best-practices) - [Kubernetes Authentication and Authorization](#kubernetes-authentication-and-authorization) - [Kubernetes Authentication Methods](#kubernetes-authentication-methods) - [X.509 client certificates](#x509-client-certificates) - [Static HTTP Bearer Tokens](#static-http-bearer-tokens) - [OpenID Connect](#openid-connect) - [Implementing a custom Kubernetes authentication method](#implementing-a-custom-kubernetes-authentication-method) - [Pod Security Policies (SCCs - Security Context Constraints in OpenShift)](#pod-security-policies-sccs---security-context-constraints-in-openshift) - [Security Profiles Operator](#security-profiles-operator) - [EKS Security](#eks-security) - [CVE](#cve) - [Videos](#videos) - [Tweets](#tweets) ## Introduction * [cilium.io](https://cilium.io/) * [Dzone - devops security at scale](https://dzone.com/articles/devops-security-at-scale) * [Dzone - Kubernetes Policy Management with Kyverno](https://dzone.com/articles/kubernetes-policy-management-with-kyverno) * [github Kyverno - Kubernetes Native Policy Management](https://github.com/nirmata/kyverno/) * [nirmata.com: Auto-labeling Kubernetes resources with Kyverno](https://nirmata.com/2020/10/30/auto-labeling-kubernetes-resources-with-kyverno) * [Dzone - OAuth 2.0](https://dzone.com/articles/oauth-20-beginners-guide) * [Kubernetes Security Best Practices π](https://github.com/freach/kubernetes-security-best-practice/blob/master/README.md#firewall-ports-fire) * [jeffgeerling.com: Everyone might be a cluster-admin in your Kubernetes cluster](https://www.jeffgeerling.com/blog/2020/everyone-might-be-cluster-admin-your-kubernetes-cluster) * [Microsoft.com: Attack matrix for Kubernetes π](https://www.microsoft.com/security/blog/2020/04/02/attack-matrix-kubernetes/) * [codeburst.io: 7 Kubernetes Security Best Practices You Must Follow](https://codeburst.io/7-kubernetes-security-best-practices-you-must-follow-ae32f1ed6444) * [thenewstack.io: Laying the Groundwork for Kubernetes Security, Across Workloads, Pods and Users](https://thenewstack.io/laying-the-groundwork-for-kubernetes-security-across-workloads-pods-and-users/) * [horovits.wordpress.com: Kubernetes Security Best Practices](https://horovits.wordpress.com/2020/07/15/kubernetes-security-best-practices/) * [containerjournal.com: How to Secure Your Kubernetes Cluster π](https://containerjournal.com/topics/container-security/how-to-secure-your-kubernetes-cluster/) * [medium: How to Harden Your Kubernetes Cluster for Production π](https://medium.com/better-programming/how-to-harden-your-kubernetes-cluster-for-production-7e47990efc2a) * [kubernetes.io: Cloud native security for your clusters](https://kubernetes.io/blog/2020/11/18/cloud-native-security-for-your-clusters/) * [tldrsec.com: Risk8s Business: Risk Analysis of Kubernetes Clusters π](https://tldrsec.com/guides/kubernetes/) A zero-to-hero guide for assessing the security risk of your Kubernetes cluster and hardening it. * [microsoft.com: Threat matrix for Kubernetes π](https://www.microsoft.com/security/blog/2020/04/02/attack-matrix-kubernetes/) * [labs.bishopfox.com: Bad Pods: Kubernetes Pod Privilege Escalation π](https://labs.bishopfox.com/tech-blog/bad-pods-kubernetes-pod-privilege-escalation) What are the risks associated with overly permissive pod creation in Kubernetes? The answer varies based on which of the hostβs namespaces and security contexts are allowed. In this post, I will describe eight insecure pod configurations and the corresponding methods to perform privilege escalation. This article and the accompanying repository were created to help penetration testers and administrators better understand common misconfiguration scenarios. * [sysdig.com: Kubernetes Security Guide π](https://sysdig.com/resources/ebooks/kubernetes-security-guide/) Best practices, guidance and steps for implementing Kubernetes security. * [resources.whitesourcesoftware.com: Kubernetes Security Best Practices π](https://resources.whitesourcesoftware.com/blog-whitesource/kubernetes-security) * [sysdig.com: Getting started with Kubernetes audit logs and Falco π](https://sysdig.com/blog/kubernetes-audit-log-falco/) * [thenewstack.io: Jetstack Secure Promises to Ease Kubernetes TLS Security](https://thenewstack.io/jetstack-secure-promises-to-ease-kubernetes-tls-security/) * [thenewstack.io: Best Practices for Securely Setting up a Kubernetes Cluster](https://thenewstack.io/best-practices-for-securely-setting-up-a-kubernetes-cluster/) * [stackrox/Kubernetes_Security_Specialist_Study_Guide π](https://github.com/stackrox/Kubernetes_Security_Specialist_Study_Guide) * [thenewstack.io: A Security Comparison of Docker, CRI-O and Containerd π](https://thenewstack.io/a-security-comparison-of-docker-cri-o-and-containerd/) * [github.com/stackrox: Certified Kubernetes Security Specialist Study Guide π](https://github.com/stackrox/Kubernetes_Security_Specialist_Study_Guide) * [youtube: Kubernetes Security: Attacking and Defending K8s Clusters - by Magno Logan](https://www.youtube.com/watch?v=OOHmg1J_8ck&ab_channel=RedTeamVillage) * [cncf.io: Kubernetes Security π](https://www.cncf.io/blog/2021/03/22/kubernetes-security/) * [microsoft.com: Secure containerized environments with updated threat matrix for Kubernetes](https://www.microsoft.com/security/blog/2021/03/23/secure-containerized-environments-with-updated-threat-matrix-for-kubernetes/) * [kyverno.io π](https://kyverno.io/) Kubernetes Native Policy Management. Open Policy Agent? Thatβs old school. Securely manage workloads on your kubernetesio clusters with this handy new tool, Kyverno.Kyverno is a policy engine designed for Kubernetes. With Kyverno, policies are managed as Kubernetes resources and no new language is required to write policies. This allows using familiar tools such as kubectl, git, and kustomize to manage policies. Kyverno policies can validate, mutate, and generate Kubernetes resources. The Kyverno CLI can be used to test policies and validate resources as part of a CI/CD pipeline. [youtube: The Way of the Future | Kubernetes Policy Management with Kyverno](https://www.youtube.com/watch?v=8fgrjBnxqi0&t=270s&ab_channel=AppSecEngineer) - [youtube: Securing and Automating Kubernetes with Kyverno](https://www.youtube.com/watch?v=0cJAfmQ7Emg&ab_channel=CloudNativeIslamabad) * [==kyverno.io/policies== π](https://kyverno.io/policies/) K8s policies available in the community repository * [cyberark.com: Attacking Kubernetes Clusters Through Your Network Plumbing: Part 1](https://www.cyberark.com/resources/threat-research-blog/attacking-kubernetes-clusters-through-your-network-plumbing-part-1?utm_sq=goa40uvlx1) * [redkubes.com: 10 Kubernetes Security Risks & Best Practices](https://redkubes.com/10-kubernetes-security-risks-best-practices/) * [thenewstack.io: Defend the Core: Kubernetes Security at Every Layer](https://thenewstack.io/defend-the-core-kubernetes-security-at-every-layer/) * [techmanyu.com: Kubernetes Security with Kube-bench and Kube-hunter π](https://www.techmanyu.com/kubernetes-security-with-kube-bench-and-kube-hunter-6765bf44ebc6) * [kube-bench π](https://github.com/aquasecurity/kube-bench) Checks whether Kubernetes is deployed according to security best practices as defined in the CIS Kubernetes Benchmark * [kube-hunter π](https://github.com/aquasecurity/kube-hunter) Hunt for security weaknesses in Kubernetes clusters * [k21academy.com: Secure and Harden Kubernetes, AKS and EKS Cluster with kube-bench, kube-hunter and CIS Benchmarks π](https://k21academy.com/docker-kubernetes/kubernetes-security/kube-bench-cis/) * [Analyze Kubernetes Audit logs using Falco π](https://github.com/developer-guy/falco-analyze-audit-log-from-k3s-cluster) Detect intrusions that happened in your Kubernetes cluster through audit logs using Falco * [blog.kasten.io: Kubernetes Ransomware Protection with Kasten K10 v4.0](https://blog.kasten.io/ransomware-protection-kasten-k10-v4) * [helpnetsecurity.com: Kubestriker: A security auditing tool for Kubernetes clusters π](https://www.helpnetsecurity.com/2021/05/04/security-kubernetes/) Kubestriker is an open-source, platform-agnostic tool for identifying security misconfigurations in Kubernetes clusters. * [Kubernetes Goat π](https://madhuakula.com/kubernetes-goat) is designed to be an intentionally vulnerable cluster environment to learn and practice Kubernetes security. * [itnext.io: How-To: Kubernetes Cluster Network Security π](https://itnext.io/how-to-kubernetes-cluster-network-security-f19bc99161f5) * [gist.github.com: How to protect your ~/.kube/ configuration](https://gist.github.com/PatrLind/e651d3cbc3bf68e4bd9fcc9568cbd3fb) * [levelup.gitconnected.com: Enforce Audit Policy in Kubernetes (k8s)](https://levelup.gitconnected.com/enforce-audit-policy-in-kubernetes-k8s-34e504733300) * [snyk.io: 10 Kubernetes Security Context settings you should understand](https://snyk.io/blog/10-kubernetes-security-context-settings-you-should-understand/) * [magalix.com: Top 8 Kubernetes Security Best Practices π](https://www.magalix.com/blog/top-8-kubernetes-security-best-practices) * [redhat.com: The State of Kubernetes Security](https://www.redhat.com/en/blog/state-kubernetes-security) * [igorzhivilo.com: Network policy and Calico CNI to Secure a Kubernetes cluster](https://igorzhivilo.com/saas/network-policy-calico-kubernetes/) * [fairwinds.com: Discover the Top 5 Kubernetes Security Mistakes You're (Probably) Making](https://www.fairwinds.com/blog/top-5-kubernetes-security-mistakes) * [tigera.io: Kubernetes security policy design: 10 critical best practices π](https://www.tigera.io/blog/kubernetes-security-policy-10-critical-best-practices/) * [empresas.blogthinkbig.com: Descubierta una vulnerabilidad en Kubernetes que permite acceso a redes restringidas (CVE-2020-8562)](https://empresas.blogthinkbig.com/descubierta-vulnerabilidad-kubernetes-permite-acceso-redes-restringidas-cve-2020-8562/) * [thenewstack.io: Kubernetes: An Examination of Major Attacks π](https://thenewstack.io/kubernetes-an-examination-of-major-attacks/) Constant vigilance is required to ensure that cloud infrastructure is locked down and that DevSecOps teams have the right tools for the job. * [nsa.gov: NSA, CISA release Kubernetes Hardening Guidance ππ](https://www.nsa.gov/News-Features/Feature-Stories/Article-View/Article/2716980/nsa-cisa-release-kubernetes-hardening-guidance/) * [Kubernetes Hardening Guidance ππ](https://media.defense.gov/2021/Aug/03/2002820425/-1/-1/1/CTR_KUBERNETES%20HARDENING%20GUIDANCE.PDF) * [thenewstack.io: The NSA Can Help Secure Your Kubernetes Clusters](https://thenewstack.io/the-nsa-can-help-you-secure-your-kubernetes-clusters/) * [therecord.media: NSA, CISA publish Kubernetes hardening guide ππ](https://therecord.media/nsa-cisa-publish-kubernetes-hardening-guide/) - Scan containers and Pods for vulnerabilities or misconfigurations. - Run containers and Pods with the least privileges possible. - Use network separation to control the amount of damage a compromise can cause. - Use firewalls to limit unneeded network connectivity and encryption to protect confidentiality. - Use strong authentication and authorization to limit user and administrator access as well as to limit the attack surface. - Use log auditing so that administrators can monitor activity and be alerted to potential malicious activity. - Periodically review all Kubernetes settings and use vulnerability scans to help ensure risks are appropriately accounted for and security patches are applied. * [cloud.redhat.com: OpenShift and the NSA-CISA βKubernetes Hardening Guidanceβ](https://cloud.redhat.com/blog/openshift-and-the-nsa-cisa-kubernetes-hardening-guidance) Red Hat OpenShift is the quickest path to meeting the NSAβs Kubernetes hardening guidance * [==Kubescape== π](https://github.com/armosec/kubescape) **kubescape is the first tool for testing if Kubernetes is deployed securely as defined in Kubernetes Hardening Guidance by to NSA and CISA.** Tests are configured with YAML files, making this tool easy to update as test specifications evolve. * [infoq.com: Armo Releases Kubescape K8s Security Testing Tool: Q&A with VP Jonathan Kaftzan](https://www.infoq.com/news/2021/09/kubescape/) * [infoq.com](https://www.infoq.com/news/2021/09/kubernetes-hardening-guidance/) NSA and CISA Publish Kubernetes Hardening Guidance * [csoonline.com: Kubernetes hardening: Drilling down on the NSA/CISA guidance](https://www.csoonline.com/article/3629049/kubernetes-hardening-drilling-down-on-the-nsa-cisa-guidance.html) The new guidance gives a solid foundation for hardening Kubernetes container environments. These are its key components and why they are important. * [armosec.io: Kubescape - As βleftβ as it can get β find Kubernetes security issues while coding, not after](https://www.armosec.io/blog/find-kubernetes-security-issues-while-coding/) * [cloud.redhat.com: Top Open Source Kubernetes Security Tools of 2021 ππ](https://cloud.redhat.com/blog/top-open-source-kubernetes-security-tools-of-2021) * [==cncf.io: How to secure your Kubernetes control plane and node components==](https://www.cncf.io/blog/2021/08/20/how-to-secure-your-kubernetes-control-plane-and-node-components/) * [redhat.com: State of Kubernetes Security Report - Spring 2021 (PDF) π](https://www.redhat.com/rhdc/managed-files/cl-state-kubernetes-security-report-ebook-f29117-202106-en.pdf) * [kubernetes.io: Overview of Cloud Native Security ππ](https://kubernetes.io/docs/concepts/security/overview/) This overview defines a model for thinking about Kubernetes security in the context of Cloud Native security. * [elastisys.com: NSA and CISA Kubernetes Security Guidance: Summarized and Explained](https://elastisys.com/nsa-and-cisa-kubernetes-security-guidance-summarized-and-explained/) * [learn.hashicorp.com: Integrate a Kubernetes Cluster with an External Vault π](https://learn.hashicorp.com/tutorials/vault/kubernetes-external-vault) * [talkingquickly.co.uk: Kubernetes Single Sign On - A detailed guide π](http://www.talkingquickly.co.uk/kubernetes-sso-a-detailed-guide) * [armosec.io: A Practical Guide to the Different Compliance Kubernetes Security Frameworks and How They Fit Together ππ](https://www.armosec.io/blog/kubernetes-security-frameworks-and-guidance) * [thenewstack.io: How to Secure Kubernetes, the OS of the Cloud](https://thenewstack.io/how-to-secure-kubernetes-the-os-of-the-cloud/) * [akhilsharma.work: The 4C's of Kubernetes Security](https://akhilsharma.work/the-4cs-of-kubernetes-security/) * Kubernetes security thing: Always be careful of what you are letting your users choose for usernames. If someone has a username of **system:kube-controller-manager** on an external Identity system, Kubernetes will quite happily give them the rights of the controller manager. The **--oidc-username-prefix** and **--oidc-groups-prefix** flags are userful for preventing this in OIDC integrations. * [medium: Securing the Kubernetes cluster | Lessandro Z. Ugulino](https://medium.com/@lessandro.ugulino/securing-the-kubernetes-cluster-c5ab43fe0dd0) * [==infoworld.com: The race to secure Kubernetes at run time==](https://www.infoworld.com/article/3639829/the-race-to-secure-kubernetes-at-runtime.html) A new wave of startups is looking to help developers secure their containerized applications after they go into production. Is this the future of application security? * [==goteleport.com: Kubernetes API Access Security Hardening==](https://goteleport.com/blog/kubernetes-api-access-security) * [infoworld.com: Securing the Kubernetes software supply chain with Microsoft's Ratify](https://www.infoworld.com/article/3644808/securing-the-kubernetes-software-supply-chain.html) Microsoftβs **Ratify** proposal adds a verification workflow to Kubernetes container deployment. The Ratify team has some demo code in their GitHub repository that shows how to use Ratify with Gatekeeper in Kubernetes. [Ratify installs using a Helm chart](https://github.com/deislabs/ratify#quick-start), bringing along some sample configuration templates. * [amazicworld.com: Top 5 security threats unique to a Kubernetes and Cloud Native stack](https://amazicworld.com/top-5-security-threats-unique-to-a-kubernetes-and-cloud-native-stack/) * [==peoplactive.com: Kubernetes and Container Security Checklist to Build Secure Apps==](https://peoplactive.com/kubernetes-security-best-practices/) * [venturebeat.com: Kubernetes security will have a breakout year in 2022](https://venturebeat.com/2021/12/27/kubernetes-security-will-have-a-breakout-year-in-2022/) * [==medium: Comparing Kubernetes Security Frameworks and Guidance== π](https://medium.com/@jonathan_37674/comparing-kubernetes-security-frameworks-and-guidance-f1c2821ea733) Comparing popular Kubernetes security and compliance frameworks, how they differ, when to use, common goals, and suggested tools. * [==aninditabasak.medium.com: A Lap around Kubernetes Security & Vulnerability scanning Tools β checkov, kube-hunter, kube-bench & Starboard==](https://aninditabasak.medium.com/a-lap-around-kubernetes-security-vulnerability-scanning-tools-checkov-kube-hunter-kube-bench-4ffda92c4cf1) * [==blog.gitguardian.com: Hardening Your Kubernetes Cluster - Threat Model (Pt. 1)== π](https://blog.gitguardian.com/hardening-your-k8-pt-1/) The NSA and CISA recently released a guide on Kubernetes hardening. We'll cover this guide in a three part series. First, let's explore the Threat Model and how it maps to K8s components. * [==blog.gitguardian.com: Hardening Your Kubernetes Cluster - Guidelines (Pt. 2)== π](https://blog.gitguardian.com/hardening-your-k8s-pt-2/) In this second episode, we will go through the NSA/CISA security recommendations and explain every piece of the guidelines. * [blog.devgenius.io: How is security managed in Kubernetes clusters?](https://blog.devgenius.io/how-is-security-managed-in-kubernetes-clusters-addefffd2b0) Best practices for managing security in Kubernetes at various layers * [blog.gitguardian.com: Kubernetes Hardening Tutorial Part 1: Pods](https://blog.gitguardian.com/kubernetes-tutorial-part-1-pods/) Get a deeper understanding of Kubernetes Pods security with this first tutorial. * [blog.gitguardian.com: Kubernetes Hardening Tutorial Part 2: Network](https://blog.gitguardian.com/kubernetes-tutorial-part-2-network/) How to achieve Control Plane security, true resource separation with network policies, and use Kubernetes Secrets more securely. * [infoworld.com: 10 steps to automating security in Kubernetes pipelines](https://www.infoworld.com/article/3545337/10-steps-to-automating-security-in-kubernetes-pipelines.html) DevOps teams donβt need to sacrifice the speed of containerized development if they know what can be automated, why itβs important, and how to do it * [==medium.com/@jonathan_37674: Kubernetes Security Best Practices: Definitive Guide==](https://medium.com/@jonathan_37674/kubernetes-security-best-practices-definitive-guide-bcb546e9f529) * [isovalent.com: Detecting a Container Escape with Cilium and eBPF](https://isovalent.com/blog/post/2021-11-container-escape) In this article youβll learn how an attacker with access to a Kubernetes cluster can escape from a container and: * run a pod to gain root privileges * escape to the host * persist the attack with invisible pods and fileless executions * [mattermost.com: The Top 7 Open Source Tools for Securing Your Kubernetes Cluster](https://mattermost.com/blog/the-top-7-open-source-tools-for-securing-your-kubernetes-cluster/) * [==infoworld.com: 10 steps to automating security in Kubernetes pipelines==](https://www.infoworld.com/article/3545337/10-steps-to-automating-security-in-kubernetes-pipelines.html) DevOps teams donβt need to sacrifice the speed of containerized development if they know what can be automated, why itβs important, and how to do it. * [towardsdatascience.com: How to Secure your Kubernetes Deployment π](https://towardsdatascience.com/how-to-secure-your-kubernetes-deployment-5f52c2b67c1) It takes 20 years to build a reputation and few minutes of cyber-incident to ruin it. β Stephane Nappo. Kubernetes deployments are not safe by default and you should go the extra mile and secure the gates. Fortunately, tools like **kube-bench** let us focus our attention on specific areas of the cluster.
Kubernetes base64 encodes secrets because that makes arbitrary data play nice with JSON. It had nothing to do with the security model (or lack thereof). It did not occur to us at the time that people could mistake base64 for some form of encryption.
— Daniel Smith (@originalavalamp) July 4, 2021
#OAuth has 4 Flows for retrieving an Access Token.
— Rohit (@sec_r0) January 8, 2021
If you have worked with it, you know how difficult is it to remember what is what.
A Zine says a lot, seriously a lot. Check this out.
Idea credits @b0rk #IAM #security #infosec #webdev #web #webcomic #webcomics
RT if useful pic.twitter.com/fbrls0V08K
Kubernetes security best practices in short -
— Rakesh Jain (@devops_tech) October 9, 2021
A Thread π pic.twitter.com/kehRjXuiEw
Kubernetes security thing: Always be careful of what you are letting your users choose for usernames. If somone has a username of system:kube-controller-manager on an external Identity system, Kubernetes will quite happily give them the rights of the controller manager :)
— Rory McCune (@raesene) November 1, 2021