Kubernetes Security Best Practices you need to know | THE Guide for securing your K8s cluster!

TechWorld with Nana
3 May 202229:41

Summary

TLDRDans cette vidéo, nous explorons les meilleures pratiques de sécurité pour les clusters Kubernetes. Nous discutons de la sécurité dans le cloud, des vulnérabilités de Kubernetes par défaut, et des stratégies pour sécuriser les images, les secrets, la communication entre les pods, et les données d'application. Nous soulignons également l'importance des sauvegardes, de la restauration et des politiques de sécurité pour prévenir les attaques et minimiser les dommages.

Takeaways

  • 🛡️ La sécurité dans Kubernetes est cruciale, mais souvent considérée comme une après-pensée en raison de la complexité de la configuration initiale.
  • ☁️ Il est une tendance croissante à déplacer des charges de travail vers le cloud, mais le cloud n'est pas sécurisé par défaut et nécessite une gestion active de la sécurité.
  • 🔒 Kubernetes n'est pas sécurisé par défaut et présente des vulnérabilités qui doivent être comblées par des pratiques de sécurité appropriées.
  • 🏗️ La sécurité doit être intégrée dès la phase de construction des images de conteneurs dans le pipeline CI/CD pour éviter d'introduire des vulnérabilités.
  • 🔍 L'analyse d'image (image scanning) est une pratique clé pour identifier et corriger les vulnérabilités avant le déploiement dans un cluster Kubernetes.
  • 👥 Kubernetes utilise le contrôle d'accès basé sur les rôles (RBAC) pour gérer les permissions des utilisateurs et des applications au sein du cluster.
  • 🚫 Il est important d'éviter d'exécuter des conteneurs avec des privilèges élevés ou en tant qu'utilisateur root pour réduire les risques d'attaques.
  • 🔄 Les secrets dans Kubernetes sont stockés en clair par défaut, donc il est essentiel de mettre en place des mesures de sécurité et de chiffrement pour ces données sensibles.
  • 🔗 Les communications entre les pods Kubernetes sont non chiffrées par défaut, offrant une cible aux attaquants qui peuvent intercepter le trafic interne.
  • 🔄 La mise en place de politiques de sécurité peut aider à automatiser la validation des configurations sécurisées et à prévenir les erreurs humaines.
  • 📚 Une stratégie de sauvegarde et de restauration efficace est indispensable pour récupérer rapidement après une attaque ou une défaillance.

Q & A

  • Quels sont les principaux défis de la sécurité dans Kubernetes?

    -Les principaux défis de la sécurité dans Kubernetes sont la complexité de la configuration initiale et le fait que la sécurité est souvent considérée comme une après-pensée, ajoutant une couche de complexité à une configuration déjà complexe.

  • Pourquoi les applications cloud deviennent-elles une cible attrayante pour les hackers?

    -Les applications cloud deviennent une cible attrayante pour les hackers car elles sont souvent mal configurées en termes de sécurité, et de plus, elles sont de plus en plus nombreuses avec l'adoption croissante des applications natives du cloud utilisant Kubernetes.

  • Quel est le statut de sécurité par défaut de Kubernetes et quels sont les écarts de sécurité potentiels?

    -Kubernetes n'est pas sécurisé par défaut. Il existe des écarts de sécurité tels que l'accès à partir de la plateforme Kubernetes au système d'exploitation sous-jacent, ce qui peut causer des dégâts importants en cas de failles de sécurité non corrigées.

  • Pourquoi est-il important de scanner les images Docker pour les vulnérabilités?

    -Il est important de scanner les images Docker pour les vulnérabilités afin d'identifier et de corriger les problèmes de sécurité potentiels, comme les outils obsolètes, les paquets avec des vulnérabilités connues, ou des configurations non sécurisées, avant leur déploiement dans un cluster Kubernetes.

  • Quelle est la différence entre les rôles et les ClusterRoles dans RBAC de Kubernetes?

    -Dans RBAC de Kubernetes, les rôles (Roles) définissent des autorisations pour une portée de namespace spécifique, tandis que les ClusterRoles offrent les mêmes types d'autorisations mais avec une portée étendue à l'ensemble du cluster, ignorant les namespaces.

  • Pourquoi faut-il éviter d'exécuter des conteneurs avec des privilèges élevés ou en tant qu'utilisateur root?

    -Exécuter des conteneurs avec des privilèges élevés ou en tant qu'utilisateur root rend les vulnérabilités potentielles plus dangereuses, car elles peuvent permettre à un attaquant de s'échapper du conteneur et d'accéder au nœud hôte, augmentant ainsi les dégâts potentiels.

  • Quels sont les avantages de l'utilisation des NetworkPolicies dans Kubernetes?

    -Les NetworkPolicies permettent de définir des règles de communication strictes entre les pods, limitant l'accès à d'autres applications et services uniquement à ce qui est nécessaire, améliorant ainsi la sécurité du cluster.

  • Comment les secrets dans Kubernetes peuvent-ils être sécurisés contre la lecture non autorisée?

    -Pour sécuriser les secrets dans Kubernetes, on peut utiliser des outils tiers comme AWS KMS pour gérer les clés de chiffrement ou HashiCorp Vault pour stocker et gérer les secrets de manière sécurisée, empêchant ainsi la lecture non autorisée après le décodage.

  • Pourquoi est-il important de sécuriser le magasin de clés etcd dans Kubernetes?

    -Le magasin de clés etcd contient toutes les données de configuration du cluster Kubernetes. Sécuriser etcd est crucial pour éviter que les attaquants ne fassent des modifications directes aux ressources Kubernetes, ce qui pourrait mener à des changements destructeurs ou non autorisés.

  • Quels sont les avantages d'un système de sauvegarde et de restauration automatisé pour les clusters Kubernetes?

    -Un système de sauvegarde et de restauration automatisé assure la continuité des opérations en cas de sinistre, en permettant de restaurer rapidement le cluster à partir des sauvegardes régulières, réduisant ainsi l'impact sur l'expérience utilisateur et la disponibilité de l'application.

  • Quels sont les mécanismes de récupération de sinistre proposés par les outils comme k10 de Kasten?

    -Les outils comme k10 de Kasten offrent des mécanismes de récupération de sinistre automatisés, qui permettent de restaurer le cluster à partir des sauvegardes immuables et sécurisées, avec la possibilité de tester les plans de récupération pour s'assurer de leur efficacité.

  • Quels sont les avantages d'utiliser un service mesh comme Istio pour la sécurité des communications au sein d'un cluster Kubernetes?

    -Un service mesh comme Istio permet de définir et de contrôler les règles de communication entre les services au niveau logique, en addition à l'activation du protocole mTLS pour chiffrer les communications internes, offrant ainsi une couche supplémentaire de sécurité.

  • Quels sont les principes clés à appliquer lors de la gestion des identités et des rôles dans Kubernetes?

    -Les principes clés à appliquer lors de la gestion des identités et des rôles dans Kubernetes sont l'utilisation du contrôle d'accès basé sur les rôles (RBAC), l'application de la méthode du privilège minimum et la connaissance précise de qui a accès à quoi dans le cluster.

  • Comment les politiques de sécurité Kubernetes peuvent-elles aider à assurer la sécurité des déploiements?

    -Les politiques de sécurité Kubernetes définissent des règles et des restrictions pour les déploiements, et sont utilisées par des outils tiers comme le contrôleur d'admission pour valider automatiquement les déploiements contre ces politiques, garantissant ainsi que les bonnes pratiques de sécurité sont appliquées.

Outlines

00:00

🔒 Sécurité dans Kubernetes

Le script aborde la sécurité dans Kubernetes, soulignant l'importance de cette dernière dans les clusters complexes. Il est mentionné que la sécurité est souvent considérée comme une après-pensée en raison de la complexité de la configuration de Kubernetes. Le texte met en évidence que les applications cloud deviennent des cibles attrayantes pour les hackers et que la connaissance de la sécurisation des clusters Kubernetes est essentielle. Il est question de la vulnérabilité des systèmes lorsque l'accès à l'OS sous-jacent est obtenu à partir de la plateforme Kubernetes et de la nécessité de combiner plusieurs mécanismes de sécurité pour protéger chaque point d'attaque.

05:02

🛠 Pratiques de sécurité pour les images Docker

Le script se concentre sur la sécurité des images Docker utilisées dans Kubernetes, expliquant les problèmes de sécurité liés à l'utilisation de code non approuvé, de paquets avec des vulnérabilités et de base images potentiellement compromises. Il est recommandé d'éliminer les paquets, bibliothèques et dépendances inutiles et de choisir des images de base plus légères. L'importance de la numérisation des images pour détecter les vulnérabilités est soulignée, ainsi que l'utilisation de tools comme Snyk et Clair pour effectuer ces scans. La pratique de ne pas exécuter les conteneurs en tant qu'utilisateur root est également recommandée pour réduire les risques d'accès à l'hôte en cas de vulnérabilité.

10:02

👥 Gestion des utilisateurs et des rôles dans Kubernetes

La partie du script traite de la gestion des utilisateurs, des rôles et des permissions dans Kubernetes à travers le contrôle d'accès basé sur les rôles (RBAC). Il est important de limiter les permissions autant que possible et d'appliquer l'approche du moindre privilège. Le texte explique comment les rôles et les cluster rôles sont créés et attribués à des utilisateurs spécifiques ou à des comptes de service pour contrôler l'accès aux ressources Kubernetes. L'importance de la sécurité des clés d'API et des certificats clients est également abordée.

15:03

🌐 Règles de communication et politiques réseau

Le script insiste sur la nécessité de limiter la communication entre les pods Kubernetes et d'utiliser des politiques réseau pour définir précisément les règles de communication autorisées. Il est également question de l'utilisation de maillages de services comme Istio pour contrôler la communication au niveau des services, en plus de l'application de l'encryptage mutual TLS pour sécuriser la communication interne du cluster.

20:05

🗝️ Sécurisation des secrets et de l'API Kubernetes

La partie du script traite de la sécurisation des secrets Kubernetes, qui sont stockés en clair par défaut, et de l'importance de les chiffrer. Il est question de l'utilisation de services tiers comme AWS KMS ou HashiCorp Vault pour gérer les clés de chiffrement ou stocker les secrets de manière sécurisée. La sécurisation de l'API Kubernetes et de l'accès à l'état de cluster stocké dans etcd est également une pratique recommandée pour prévenir les attaques directes sur la configuration du cluster.

25:06

🛡️ Sauvegarde et restauration des données

Le script met en évidence la nécessité d'un système de sauvegarde et de restauration automatisé pour protéger contre la perte ou la corruption des données en cas d'attaque. Il est question de l'outil Kubernetes natif K10, qui offre des fonctionnalités de sauvegarde et de restauration sécurisées, y compris l'immuabilité des sauvegardes pour empêcher leur altération. La possibilité de récupérer le cluster dans un environnement différent est également soulignée.

🏛️ Politiques de sécurité et récupération de sinistre

La dernière partie du script traite de la mise en place de politiques de sécurité pour valider automatiquement les configurations de sécurité lors du déploiement des applications. Il est également question de la préparation à la récupération de sinistre en cas d'attaque, en utilisant des outils comme K10 pour restaurer le cluster à partir des sauvegardes et minimiser les impacts sur l'expérience utilisateur. L'importance de tester les plans de récupération est soulignée pour s'assurer de leur efficacité.

Mindmap

Keywords

💡Sécurité

La sécurité fait référence à la protection contre les menaces et les vulnérabilités qui pourraient nuire aux systèmes, aux données ou aux applications. Dans la vidéo, la sécurité est le thème central, abordé à travers la mise en pratique de meilleures pratiques pour sécuriser un cluster Kubernetes. L'importance de la sécurité est soulignée par le biais des défis et des vulnérabilités rencontrés dans les configurations de Kubernetes.

💡Kubernetes

Kubernetes est un système open-source pour automatiser le déploiement, la mise à l'échelle et la gestion des applications conteneurisées. La vidéo se concentre sur la sécurité de Kubernetes, en expliquant qu'il s'agit d'une plateforme très ciblé par les hackers en raison de son utilisation croissante pour les applications cloud natives.

💡Méthodes de sécurité

Les méthodes de sécurité sont les approches et les pratiques utilisées pour protéger les systèmes contre les attaques. La vidéo présente une dizaine de meilleures pratiques de sécurité Kubernetes, allant de l'analyse d'images conteneur à la gestion des rôles et des autorisations, en passant par la sécurisation des secrets et la mise en place de politiques de sécurité.

💡Analyse d'images

L'analyse d'images est le processus de détection des vulnérabilités dans les images conteneur avant leur déploiement. Dans le script, l'analyse d'images est mentionnée comme une première étape clé pour construire des images sécurisées et éviter les failles de sécurité dans les applications déployées sur Kubernetes.

💡RBAC (Contrôle d'accès basé sur les rôles)

Le RBAC est une méthode de sécurité qui permet de contrôler l'accès aux ressources en fonction des rôles attribués aux utilisateurs. La vidéo explique comment utiliser le RBAC pour gérer les permissions des utilisateurs et des applications au sein d'un cluster Kubernetes, en suivant l'approche du privilège minimum.

💡Secrets

Les secrets dans Kubernetes sont utilisés pour stocker des informations sensibles telles que les mots de passe et les clés d'API. La vidéo souligne que les secrets doivent être chiffrés et sécurisés pour éviter que des informations sensibles ne soient lues ou manipulées par des attaquants.

💡Politiques de sécurité

Les politiques de sécurité sont des règles définies pour valider et contrôler les configurations et les déploiements au sein d'un cluster Kubernetes. Elles sont mentionnées dans la vidéo comme un moyen d'automatiser la validation des configurations de sécurité et d'assurer que les bonnes pratiques sont appliquées.

💡Sauvegarde et restauration

La sauvegarde et la restauration sont des processus essentiels pour la continuité des activités et la récupération après une attaque ou une panne. La vidéo met en avant l'importance d'avoir un système automatisé de sauvegarde et de restauration pour protéger les données et la configuration du cluster Kubernetes.

💡Service Mesh

Un service mesh, tel qu'Istio mentionné dans la vidéo, est une couche de réseau qui facilite la communication entre les services dans un cluster Kubernetes. Il permet de définir et de contrôler les règles de communication au niveau de l'application, en offrant une sécurité supplémentaire en chiffrant les communications internes.

💡Disaster Recovery

La récupération d'urgence est le plan et les mesures prises pour restaurer rapidement les opérations en cas de sinistre. La vidéo insiste sur l'importance d'un plan de récupération d'urgence testé et automatisé, pour minimiser les effets d'une attaque et de restaurer rapidement les services.

💡Étcd

Étcd est un magasin clé-valeur utilisé par Kubernetes pour stocker et gérer l'état de la configuration du cluster. La vidéo souligne l'importance de sécuriser l'accès à l'Étcd, car toute modification directe dans ce magasin peut avoir un impact sur l'ensemble du cluster.

Highlights

L'importance de la sécurité dans Kubernetes et les meilleures pratiques pour sécuriser un cluster.

La tendance actuelle vers le cloud et la nécessité de sécuriser l'infrastructure et les applications cloud de la même manière que les installations locales.

La vulnérabilité des applications cloud et la cible qu'elles représentent pour les hackers.

L'importance de la sécurité dès la configuration initiale de Kubernetes plutôt que comme une pensée secondaire.

La nécessité de scanner les images Docker pour détecter les vulnérabilités avant leur déploiement dans Kubernetes.

L'avantage de ne pas exécuter les conteneurs en tant qu'utilisateur root pour réduire les risques d'attaques.

La gestion des utilisateurs, rôles et permissions avec RBAC pour limiter les privilèges au sein du cluster Kubernetes.

L'utilisation de Network Policies pour restreindre la communication entre les pods et améliorer la sécurité du cluster.

La mise en place d'un service mesh comme Istio pour contrôler la communication entre les services au niveau logique.

L'importance de l'encryption des communications internes du cluster pour protéger les données contre les interceptions.

La sécurisation des secrets Kubernetes à l'aide de solutions tierces pour éviter l'accès non autorisé aux données sensibles.

La protection de l'état de cluster stocké dans etcd en utilisant des mesures de sécurité appropriées.

La mise en place d'un système de sauvegarde et de restauration automatisé pour préparer aux scénarios de récupération après une attaque.

L'utilisation de la fonctionnalité de sauvegarde immuable de k10 pour protéger les sauvegardes contre la corruption.

La création de politiques de sécurité Kubernetes pour valider automatiquement les configurations de sécurité lors du déploiement des applications.

L'importance d'un plan de récupération de disaster bien testé et automatisé pour minimiser l'impact des attaques.

La possibilité de récupérer un cluster Kubernetes dans un environnement différent avec k10, offrant une flexibilité dans la restauration après une attaque.

Transcripts

play00:00

in this video we're going to talk about

play00:01

a super important topic which is

play00:03

security in kubernetes and what are some

play00:06

of the best practices for securing your

play00:08

kubernetes cluster

play00:10

the big challenge that we see in terms

play00:12

of granite security is that it's already

play00:14

so challenging to set up a kubernetes

play00:16

cluster and to configure it to deploy

play00:18

the applications in it that security

play00:21

often becomes the afterthought adding on

play00:24

top of that already complex

play00:26

configuration

play00:27

however we can't deny the importance of

play00:30

security especially when the systems are

play00:32

so complex so first of all let's talk

play00:34

about security in cloud in general we

play00:37

have a trend that more and more

play00:39

workloads are moving to the cloud and

play00:41

often there is a misconception that

play00:43

cloud is secure by default so people

play00:46

think that because the application is on

play00:48

cloud it is protected but it's important

play00:51

to understand that you have to secure

play00:53

and manage the infrastructure and your

play00:55

applications on the cloud just the way

play00:58

you manage them on premise the

play01:00

difference is that on cloud you simply

play01:03

have different tools and technologies to

play01:06

configure that security and often many

play01:09

organizations aren't aware of those

play01:11

tools or aren't using the tools that are

play01:14

available for

play01:16

making your cloud environment secure

play01:19

so with all these things combined cloud

play01:21

applications actually become

play01:23

a very attractive target to a lot of

play01:26

hackers

play01:27

and this growing number of cloud native

play01:29

applications

play01:31

mostly use kubernetes as a platform and

play01:34

that's where the relevance of knowing

play01:35

how to secure kubernetes clusters comes

play01:38

into play so the question is how secure

play01:41

is kubernetes by default so if i don't

play01:44

do anything explicitly and take the

play01:46

defaults what is my security status so

play01:49

what are we starting from and what are

play01:52

the vulnerabilities or security gaps

play01:54

that we have in kubernetes and what are

play01:57

the security best practices to protect

play01:59

and close those gaps in kubernetes to

play02:02

secure our systems

play02:04

the common number one issue is when

play02:06

someone gets access

play02:08

from kubernetes platform to the

play02:10

underlying operating system

play02:12

in which case an attacker can do a lot

play02:14

of damage to the whole system and this

play02:17

can happen because of various

play02:18

misconfigurations and we're going to

play02:20

talk about those and how to protect your

play02:22

kubernetes so that this doesn't happen

play02:25

in this video when we talk about

play02:27

security it's also important to

play02:28

understand that security is a

play02:31

combination of multiple things on

play02:33

multiple levels so it's not just one or

play02:35

two things that you do that basically

play02:38

just secure everything in case of

play02:40

kubernetes we have the underlying

play02:43

infrastructure then the kubernetes

play02:45

platform that is running on that

play02:46

infrastructure and the applications

play02:49

running inside kubernetes platform so

play02:51

all these levels need to be secured

play02:53

individually which is quite a

play02:55

challenging job

play02:57

and one of the main challenges of

play02:58

security in general is that the

play03:00

attackers have an advantage because they

play03:03

just need to find one security weak link

play03:05

in the system to attack

play03:08

while a defender has to defend every

play03:11

single point maybe multiple times

play03:14

to prevent that from happening in many

play03:16

cases we would need to defend each point

play03:19

with multiple different mechanisms so

play03:22

while coding best practice is not to

play03:24

repeat logic security best practice

play03:26

generally is actually to be redundant

play03:30

so use many security mechanisms in place

play03:33

to protect

play03:34

every attack point so this way an

play03:36

attacker will have to do multiple things

play03:38

in order to get into your system or

play03:41

access your valuable resources and

play03:44

basically do some damage to your whole

play03:46

environment now before we dive in the 10

play03:48

security best practices i want to say a

play03:50

huge thanks to castin for sponsoring and

play03:53

making this video possible they have an

play03:56

amazing tool called k10 which is the

play03:59

kubernetes backup and restore solution

play04:01

it is a kubernetes native application

play04:03

and has a lot of really good features

play04:06

for backup and restore use cases and

play04:09

apart from backup and restore being an

play04:11

important part of

play04:13

security mechanism itself and we're

play04:15

going to talk about that in this video

play04:17

k10 actually has a big focus on all the

play04:19

security aspects in kubernetes so it

play04:22

integrates with various tools and is

play04:24

basically engineered to make it easy for

play04:27

kubernetes administrators to secure the

play04:29

k10 service itself in the cluster so

play04:32

with that let's dive in our 10 security

play04:36

best practices for kubernetes

play04:42

first of all what is the main purpose of

play04:44

kubernetes it is to run applications

play04:46

inside right so we have built an

play04:49

application and we need to deploy it in

play04:50

kubernetes as a container and securing

play04:53

workloads in kubernetes starts before

play04:55

they even get deployed there when we

play04:57

build a container image which will

play04:59

eventually run in the cluster so

play05:01

building a secure image in the cicd

play05:04

pipeline is the first step so what

play05:07

security issues do we have here

play05:09

images are built in layers and each

play05:12

layer contains a command or a tool

play05:14

configuration etc so they're things that

play05:17

basically go into building the image

play05:20

we install different tools maybe we

play05:22

create some users and so on

play05:25

so we need to be thinking about

play05:26

everything that goes inside that image

play05:28

and what is the security impact of that

play05:31

first of all

play05:32

code from untrusted registries

play05:34

we may be using a code or a library in

play05:38

our application

play05:39

which comes from an untrusted source so

play05:42

we have an untrusted code that may

play05:44

include some virus or backdoors that

play05:47

could unintentionally grant access to an

play05:50

attacker we may also be using some

play05:52

packages for an operating system in our

play05:55

docker image so these dependencies and

play05:58

tools may also have some vulnerabilities

play06:00

or the base image that we're using to

play06:02

build our own application image may have

play06:04

some vulnerabilities

play06:06

so this means we need to be careful what

play06:08

goes inside the image what libraries and

play06:10

dependencies and tools we're using when

play06:13

putting together our application image

play06:16

generally when we're building images

play06:18

developers should eliminate any

play06:19

unnecessary packages libraries

play06:22

and dependencies that application

play06:25

doesn't necessarily need

play06:26

or it may need in a build time but not

play06:29

necessarily in runtime and also they

play06:32

should choose leaner and smaller base

play06:34

images

play06:36

with less tools inside to build the

play06:38

application image because mostly you

play06:40

don't need so many tools to run your

play06:42

applications if we do build an

play06:44

application image with some

play06:46

vulnerabilities and it gets deployed to

play06:48

the cluster that may introduce serious

play06:51

security issues for example an attacker

play06:55

may use a vulnerability in an image

play06:57

to break out of the container and get

play07:00

access to the host

play07:02

or the kubernetes worker node and from

play07:04

the host they can access all the other

play07:07

containers running on that host

play07:09

so they will be able to do much more

play07:11

damage if they

play07:13

manage to break out of the container

play07:15

they can read data in the host volumes

play07:18

they can read the file system and so on

play07:21

they could also read the configuration

play07:23

of cubelet that is running on that host

play07:26

including cubelet's authentication token

play07:28

and the certificates that it uses to

play07:30

talk to the kubernetes api server and

play07:33

that will give an attacker a chance to

play07:36

further damage the cluster and escalate

play07:38

privileges

play07:40

so a lot of serious security issues may

play07:42

arise if you have vulnerabilities in

play07:44

your image that will allow an attacker

play07:47

to access the underlying host from a

play07:49

container for example so how do we

play07:52

prevent any such vulnerabilities and

play07:54

issues from slipping in to the image

play07:57

when we're building that well we should

play07:59

do what's called image scanning so the

play08:02

first security best practice is to do

play08:04

image scanning and make sure to build

play08:06

secure images and there are a lot of

play08:08

tools out there that can help you in

play08:10

that for example you have systick and

play08:12

sneak etc that basically have a database

play08:15

of vulnerabilities that get updated

play08:17

regularly and they will basically do the

play08:19

scanning of your image against those

play08:21

known vulnerabilities so you need to

play08:24

make sure you're constantly scanning for

play08:26

vulnerabilities so how do you do image

play08:29

scanning exactly using the image

play08:31

scanning tools that i mentioned you can

play08:33

scan the images in the ci cd pipeline

play08:35

for example before pushing the image to

play08:38

the repository so once the image is

play08:41

built you can run a command of that

play08:43

image scanning tool that checks the

play08:45

image for any insecure tools or packages

play08:48

for dependencies with any

play08:49

vulnerabilities as well as it also

play08:52

checks for an insecure configuration and

play08:55

any hard-coded secrets for example so

play08:58

once the image is built and it basically

play09:00

passes that vulnerability scan or

play09:03

security scan it can be pushed to a

play09:05

repository however it could happen that

play09:08

a vulnerability gets discovered after an

play09:10

image was scanned and pushed to the

play09:12

repository as i said tools like sneak

play09:15

for example they have a database of

play09:17

vulnerabilities that gets updated

play09:19

constantly when new ones get discovered

play09:22

so a lot of image registries like docker

play09:25

hub and so on actually have a feature

play09:29

for scanning images in the repository

play09:32

itself which means it's also important

play09:34

to scan images

play09:36

regularly that have already been pushed

play09:38

to a registry to make sure there are no

play09:41

vulnerabilities that appeared after the

play09:44

image was built another security best

play09:47

practice is to avoid using root user in

play09:49

your containers and running your

play09:51

containers with privileges if you have a

play09:54

vulnerability in an image and it's

play09:56

running with a root user the attacker

play09:58

can much more easily use that to break

play10:02

out from the container and access the

play10:03

host or the kubernetes worker node so

play10:06

when building your image you should

play10:08

create a service user and run the

play10:10

application with that user instead of

play10:13

using the root user but note that even

play10:15

if you build the image like that you

play10:18

could actually override that in the pod

play10:20

configuration itself so you might have

play10:22

an image that runs with a service user

play10:24

but you can actually configure or

play10:26

misconfigure a pod to allow it to run

play10:29

with root or run it as a privileged

play10:32

container or even allow access to the

play10:34

host network which is not a good thing

play10:37

and if this kind of misconfiguration

play10:39

slips into the cluster your pod now

play10:41

becomes very insecure

play10:44

so avoid running privileged containers

play10:46

to make it harder to break out from it

play10:49

because this way the attacker will have

play10:51

to first get access to the root user

play10:54

inside the container and then they will

play10:56

be able to break out and access the host

play11:00

now once our application is deployed and

play11:02

running in kubernetes we have a number

play11:04

of things to secure inside the cluster

play11:06

itself

play11:11

first of all who can access the cluster

play11:13

which human or application users

play11:16

once inside the cluster what can these

play11:18

actors do what are their privileges this

play11:21

becomes more relevant if an attacker

play11:24

steals an identity of one of these

play11:26

authorized parties because the question

play11:29

is what can an attacker do in the

play11:30

cluster what permissions do they have

play11:33

therefore we need to manage users

play11:36

roles and their permissions in

play11:38

kubernetes and we need to keep these

play11:40

permissions as restricted as possible if

play11:44

someone in the team needs access to

play11:45

troubleshoot or debug

play11:47

pods in myapp namespace then they should

play11:50

be given read-only permission to

play11:53

kubernetes resources in that namespace

play11:55

only so how do we manage users and their

play11:58

permissions in kubernetes for that we

play12:00

have rbac or role-based access control

play12:05

and these are kubernetes resources that

play12:07

allows you to create roles in kubernetes

play12:10

with certain permissions for example a

play12:12

role that allows viewing creating and

play12:15

updating deployments

play12:17

services config maps in a namespace

play12:20

called database

play12:22

so there will be one role right so what

play12:24

can you do with which resources in which

play12:27

namespace

play12:28

or you may have a role that allows only

play12:30

viewing and listing pods in a my app

play12:33

namespace

play12:35

now the roles need to be attached to

play12:38

actual users like a team member sarah

play12:41

who is deploying and managing database

play12:43

services in a cluster can get the first

play12:46

role associated to her user and a junior

play12:49

developer tom can be granted the view

play12:51

only role to be able to see what pods

play12:54

are running in a my app namespace

play12:56

in kubernetes there is actually no

play12:59

resource for user so you can directly

play13:02

create user components in kubernetes

play13:06

instead the users are indirectly created

play13:09

by either importing a list of

play13:12

users into your cluster or for example

play13:15

by generating a client certificate for

play13:18

the kubernetes api server

play13:20

for a specific user so in our example

play13:23

client certificates will be generated

play13:25

for both sarah and tom for the

play13:27

kubernetes cluster and the user for that

play13:30

certificate will be registered as a user

play13:33

in kubernetes and once you have that

play13:35

user sarah user tom both with their own

play13:38

client certificates associated to the

play13:41

cluster you can then attach those roles

play13:45

with the respective users now you also

play13:48

have a kubernetes administrator that

play13:50

needs to be able to create and update

play13:52

resources in multiple namespaces or

play13:55

maybe the whole cluster and for that we

play13:57

actually have cluster roles which are

play14:00

the same as rows but they apply to the

play14:02

whole cluster instead of a specific

play14:04

namespace so for example kubernetes

play14:06

administrators kate and mark can both

play14:09

get cluster rows associated to their

play14:12

users that allow them to create

play14:15

view and delete a list of different

play14:17

resources in all the namespaces in the

play14:20

cluster as i mentioned you also have

play14:22

non-human users for example if you're

play14:25

deploying to kubernetes cluster from a

play14:27

jenkins pipeline or running a

play14:29

third-party service like istio for

play14:32

example that needs access to kubernetes

play14:33

resources and needs to talk to

play14:36

kubernetes api server you need to give

play14:38

those tools access to the cluster as

play14:41

well and for non-human users there is

play14:44

actually a kubernetes resource dedicated

play14:46

for that called service account so the

play14:49

way it works is that every pod in

play14:51

kubernetes gets a service account which

play14:54

they can use to talk to kubernetes and

play14:57

service account just like human users

play15:00

has roles associated to it with some

play15:02

permissions and while users have clan

play15:05

certificate to authenticate with api

play15:07

server the service account uses token to

play15:10

authenticate so it's important to know

play15:13

exactly and limit the permissions a

play15:15

service account has because if an

play15:17

attacker got access to a pod they can

play15:20

use the service account token of that

play15:22

pod to send requests to the api server

play15:26

and create change and delete resources

play15:29

if they have permission to do it so as a

play15:31

security best practice you need to use

play15:34

rbac to manage access permissions in

play15:36

your cluster and know exactly who has

play15:38

access to what and also use the least

play15:41

privilege approach

play15:46

now using rbac will manage the

play15:48

permissions of external users and what

play15:50

they can do inside your kubernetes

play15:53

cluster but what about inside the

play15:55

cluster itself the communication between

play15:57

the services by default in kubernetes

play16:00

each pod can talk to any other pod

play16:03

inside the cluster this means if an

play16:06

attacker gets access to one port they

play16:08

can access any other application pod

play16:11

now in reality not every pod needs to

play16:13

talk to all others so we can actually

play16:16

limit the communication between them and

play16:18

create network rules in the kubernetes

play16:22

network layer that determines exactly

play16:25

which pods can talk to which other pods

play16:28

and also which parts they can receive

play16:30

traffic from and you can do that with a

play16:32

current this resource called network

play16:35

policies

play16:36

so using network policies you can define

play16:38

a rule that for example a front-end

play16:41

service can only talk to the back-end

play16:43

service but it cannot talk to database

play16:46

or an authentication service that

play16:49

are running in the cluster and you can

play16:51

define the database pod can only receive

play16:53

traffic from backend pod and so on so

play16:57

for maximum security you can apply the

play16:59

least access allowed rules here

play17:02

so you define each and every

play17:04

communication rule between all the parts

play17:07

so now if an attacker gets access to one

play17:10

of the parts they won't be able to talk

play17:12

to all others that may be running

play17:15

sensitive applications and holding some

play17:17

sensitive data and also know that

play17:19

network policy resource itself is

play17:22

actually implemented by a kubernetes

play17:24

network plug-in like calico or weave etc

play17:27

that you deploy in the cluster

play17:30

now network policies configure

play17:32

communication rules on a network level

play17:35

but if we want to define these rules on

play17:37

a service level or an application level

play17:40

which is a more logical level so to say

play17:43

we can use a service mesh like istio for

play17:46

that so istio uses proxies in each

play17:49

application pod that will control the

play17:52

traffic coming into the application as

play17:54

well as traffic going out of the

play17:56

application so you can configure

play17:59

communication rules between the services

play18:02

on a logical level that will then be

play18:05

controlled or checked by the proxies

play18:07

that istio uses so using network

play18:10

policies or service mesh

play18:12

to define stricter communication rules

play18:15

between the pods is another security

play18:17

best practice

play18:22

another part of pod communication is

play18:24

that by default

play18:25

the communication between pods in

play18:28

kubernetes is unencrypted so if an

play18:30

attacker manages to get inside the

play18:32

cluster they will be able to see all the

play18:34

internal communication between the pods

play18:36

in plain text because none of it is

play18:39

encrypted with service mesh like istio

play18:41

in addition to defining the

play18:43

service communication rules you can also

play18:46

enable mutual tls between the services

play18:49

so all the communication between them

play18:51

will be encrypted and that means if an

play18:53

attacker sees the traffic inside the

play18:55

cluster they won't be able to read it so

play18:58

encrypting cluster internal

play18:59

communication is another good security

play19:02

practice that will give you an

play19:04

additional layer of security another

play19:07

thing which is not secure in kubernetes

play19:09

by default is the secrets you probably

play19:12

already know that for sensitive data

play19:14

like credentials secret tokens private

play19:17

keys etc we have a secret resource in

play19:20

kubernetes however by default secrets

play19:23

are stored unencrypted they are

play19:26

basically for encoded so anyone who has

play19:29

permission to view the secrets can

play19:31

simply decode the contents of a secret

play19:34

and see them in plain text so again if

play19:37

an attacker gets in a cluster with an

play19:39

access to the secrets they will be able

play19:42

to read all the sensitive content so how

play19:45

can we secure secrets in kubernetes well

play19:47

there are several ways the kubernetes

play19:50

own solution is to enable

play19:52

and configure encryption using the

play19:55

encryption configuration resource

play19:57

however this still has an issue because

play20:00

you still have to manage the encryption

play20:02

key itself and store it somewhere

play20:04

securely so some third-party tools can

play20:07

be used for this like aws kms which is

play20:10

key management service for example can

play20:13

be used to manage the encryption keys or

play20:15

a service like volt from hashicorp can

play20:18

be used to securely store the secrets

play20:21

themselves and vault would actually take

play20:24

over storing and managing the secret

play20:26

data so securing and encrypting secrets

play20:30

is important and another security best

play20:33

practice

play20:37

now secrets and all other kubernetes

play20:39

configuration data are actually stored

play20:41

in a key value store in kubernetes

play20:44

called etcd

play20:46

so kubernetes uses this lcd store to

play20:48

keep track of and update its

play20:50

configuration and all the resources like

play20:53

services deployments pods etc and every

play20:56

single update gets saved into the cd

play20:59

store and the same way any change

play21:01

directly to that city will lead to

play21:03

changes in the cluster this means if an

play21:06

attacker can get access to that cd they

play21:09

can bypass the api server and make

play21:12

changes directly to that city store

play21:15

which will then result in kubernetes

play21:17

resources being updated and this would

play21:20

be actually an equivalent of having

play21:22

unlimited access to the whole cluster

play21:24

where they can do anything they want

play21:27

destroy update resources get access to

play21:30

the data and so on so another good

play21:32

security practice is to secure your etcd

play21:35

store there are a lot of ways to do that

play21:37

there are a lot of alternatives of how

play21:39

an lcd can be run for your kubernetes

play21:42

cluster whether inside the cluster

play21:44

itself or outside managed separately but

play21:47

generally speaking it's a good practice

play21:49

to put your hcd behind a firewall and

play21:52

allow only the api server to access it

play21:55

with proper authentication in addition

play21:58

to that the whole etsy data can be

play21:59

encrypted so even if the attacker gets

play22:02

access to it they won't be able to read

play22:04

it

play22:08

now etcd stores the cluster

play22:10

configuration data so these are all the

play22:12

kubernetes manifests that define the

play22:15

kubernetes resources like deployment

play22:17

services pods etc but we also have the

play22:20

application data like data stored by

play22:22

database services and the biggest

play22:24

security damages for any company are

play22:27

related to data especially the personal

play22:29

data stealing data like credit card

play22:31

information of your users or medical

play22:34

records or leaking of any private data

play22:36

is the worst scenario for any company

play22:39

when an attack happens but in addition

play22:42

to that you also have risks of attackers

play22:45

wiping out your data or corrupting it so

play22:47

you basically lose all your application

play22:49

data this means you can't recover your

play22:52

application after the attack because all

play22:54

the data is gone so one thing that

play22:56

attackers commonly do is taking your

play22:59

data and requesting a ransom for it so

play23:02

you have to pay them to get your data

play23:03

back and you have to be protected for

play23:06

all these scenarios and that's the next

play23:08

security best practice to have a proper

play23:11

automated backup and restore system in

play23:13

place for your cluster that regularly

play23:16

backs up your data and stores them

play23:19

safely so that you can use it to restore

play23:22

your cluster when a disaster happens and

play23:25

castings k-10 is actually a kubernetes

play23:28

native

play23:29

tool

play23:30

that you can use to configure this

play23:33

automated backup and restore and since

play23:36

as i mentioned k10 is so focused on

play23:38

security they have all the mechanisms in

play23:41

place to both transfer the data as well

play23:44

as store that backup data securely and

play23:47

encrypting it throughout

play23:49

now in addition to attackers corrupting

play23:51

or stealing your data the attacks may be

play23:54

so advanced that they will try to get

play23:57

the backups as well so they will corrupt

play24:00

the database data plus all the backups

play24:02

that you have for the data this means

play24:05

again you are not able to recover your

play24:07

application and maybe have to pay ransom

play24:10

to get back the data so you need to

play24:12

protect those backups as well

play24:15

and what k10 offers as a solution is

play24:17

that you have immutable backups which

play24:20

means they can't be manipulated or

play24:22

corrupted and a big advantage of k10 is

play24:25

also that you can backup all the

play24:27

kubernetes related data with it so not

play24:30

only the application data in kubernetes

play24:31

but also the data outside kubernetes

play24:34

plus the etsy store data and this is

play24:36

great because you have one tool and one

play24:39

automated mechanism for all your

play24:41

relevant backups for your cluster if you

play24:44

want to know exactly how k10's backup

play24:46

and restore mechanism works i actually

play24:48

have a separate video on that so you can

play24:50

check out the link here or in the video

play24:52

description

play24:57

now let's say as a kubernetes

play24:58

administrator you know and apply all

play25:01

these security practices and try to

play25:03

protect your data and your cluster by

play25:06

configuring everything properly

play25:08

but kubernetes cluster is usually used

play25:10

by developer teams who deploy their

play25:12

applications and services in it so you

play25:15

may be doing everything right but how

play25:17

can you make sure that all these

play25:19

developers also apply these security

play25:21

practices when deploying their

play25:23

applications maybe their pod

play25:24

configurations are super insecure

play25:26

because they don't have enough knowledge

play25:28

about security configuration best

play25:30

practices and you can't just manually

play25:33

check everything they deploy to the

play25:35

cluster so how can you deal with such a

play25:38

scenario well for that there are what's

play25:40

called security policies in kubernetes

play25:44

with security policies you can define

play25:46

some rules such as

play25:48

pods that run privileged containers or

play25:51

container with root user cannot be

play25:53

deployed or that a network policy needs

play25:56

to be defined for every pod and so on

play25:59

security policy resources in kubernetes

play26:02

are implemented by third-party tools

play26:04

like open policy agent or caverno and

play26:08

usually the way it works with these

play26:09

tools is that you create this security

play26:11

policy definition in kubernetes with all

play26:13

the rules and security policies hook

play26:16

into the kubernetes admissions

play26:19

controller component

play26:21

which decides whether the deployment can

play26:24

go through based on the policies that

play26:27

you defined so it's like a gatekeeper

play26:30

that validates deployments against the

play26:32

policies defined by you and this way you

play26:35

can have automated validations for

play26:38

various security configurations so

play26:40

creating security policies to automate

play26:43

validation for security configuration is

play26:47

another security best practice

play26:50

now let's say we apply all the security

play26:53

practices but you cannot always 100

play26:55

percent protect everything right as i

play26:58

said in the beginning an attacker just

play27:00

needs to find one weak spot to succeed

play27:03

in the attack and do some damage so you

play27:06

may still get an attack that messes up

play27:08

your cluster and here it's important to

play27:10

have a proper strategy and mechanism for

play27:14

disaster recovery so what do you want to

play27:16

do in an attack scenario well you want

play27:18

to restore your cluster with the backup

play27:21

data and get it up and running within a

play27:23

short time and make your application

play27:25

available to your users again with

play27:28

minimal effect on user experience so the

play27:31

last security best practice is to have a

play27:33

mechanism

play27:34

when an attack actually happens

play27:36

and for that you need a tool that allows

play27:38

you to recover the cluster in the same

play27:41

state with the latest backup so again

play27:44

tool like k10 has a feature to take the

play27:48

last backup and let you do the disaster

play27:50

recovery in an automated way an

play27:52

important emphasis here is on the

play27:54

automated recovery because in such a

play27:57

scenario when your system is under

play27:59

attack you don't want to be manually

play28:01

recovering your cluster under time

play28:04

pressure instead you want to have a tool

play28:06

that automatically does that for you and

play28:08

ideally you actually test your k10

play28:11

recovery so you know exactly how it will

play28:14

work and what results it will give you

play28:17

when you run it in case of a disaster so

play28:19

executing an automated well-tested

play28:22

recovery plan can minimize the effect of

play28:25

the attack and get your application up

play28:27

and running very fast and note that k10

play28:31

also allows you to recover your cluster

play28:33

to any environment

play28:35

so it doesn't have to be exactly the

play28:37

same environment with the exact same

play28:39

kubernetes version as you had instead

play28:42

you actually have a freedom to choose to

play28:44

recover your system in a completely

play28:46

different environment using maybe a

play28:48

different storage class etc so you're

play28:51

not tied to a specific type of

play28:54

underlying storage infrastructure or

play28:57

even a specific governance distribution

play28:59

now i could talk for hours about

play29:01

security practices in kubernetes and

play29:03

going into detail because there are a

play29:06

lot of topics around it which we will

play29:09

actually be covering in our upcoming

play29:11

devsecops course if you're interested

play29:14

generally in security in devops then you

play29:16

can sign up for the waiting list and be

play29:18

notified when we release the course

play29:21

well i hope the security practices that

play29:23

i explained in this video were already

play29:25

super helpful please comment and share

play29:28

your experiences with security in

play29:30

kubernetes and which security practice

play29:33

that i haven't mentioned here is also

play29:36

very important and with that thank you

play29:38

for watching and see you in the next

play29:39

video

Rate This

5.0 / 5 (0 votes)

Related Tags
SécuritéKubernetesCloudApplicationsMécanismes de sécuritéGestion des identitésContrôle d'accèsPolitiques de sécuritéSauvegardeRécupération de désastre
Do you need a summary in English?