Slide 1

Slide 1 text

@deepu105 | deepu.tech Mastering Kubernetes Security: From Containers to Cluster Fortresses Deepu K Sasidharan Staff Developer Advocate @ Okta

Slide 2

Slide 2 text

@deepu105 | deepu.tech Understanding Kubernetes Security

Slide 3

Slide 3 text

@deepu105 | deepu.tech Transport security All API communication is done via TLS using valid certificates

Slide 4

Slide 4 text

@deepu105 | deepu.tech Authentication All API requests are authenticated with one of the several authentication mechanisms supported by Kubernetes

Slide 5

Slide 5 text

@deepu105 | deepu.tech Authorization All authenticated requests are authorized using one or more of the supported authorization models

Slide 6

Slide 6 text

@deepu105 | deepu.tech Admission control All authorized requests, except read/get requests, are validated by admission control modules

Slide 7

Slide 7 text

@deepu105 | deepu.tech Kubernetes Security Best practices https://a0.to/k8s-security-best-practices

Slide 8

Slide 8 text

@deepu105 | deepu.tech Use RBAC

Slide 9

Slide 9 text

© Okta and/or its affiliates. All rights reserved. Confidential Information of Okta – For Recipient’s Internal Use Only Why? ● Most secure Authorization mechanism for Kubernetes ● Most widely used and most flexible ● Ideal for enterprise and medium-large orgs ● Easy to model business rules

Slide 10

Slide 10 text

© Okta and/or its affiliates. All rights reserved. Confidential Information of Okta – For Recipient’s Internal Use Only How? ● Check if RBAC is enabled ○ kubectl cluster-info dump | grep authorization-mode ● Use --authorization-mode flag for the API server to enable RBAC ● Create Role/ClusterRole and RoleBinding/ClusterRoleBinding as required

Slide 11

Slide 11 text

© Okta and/or its affiliates. All rights reserved. Confidential Information of Okta – For Recipient’s Internal Use Only How? apiVersion : rbac.authorization.k8s.io/v1 kind: Role metadata : namespace : fancy-namespace name: pod-service-reader rules: - apiGroups : [""] # "" indicates the core API group resources : ["pods", "services” ] verbs: [ "get", "watch", "list"] — apiVersion : rbac.authorization.k8s.io/v1 kind: RoleBinding metadata : name: read-pods-services namespace : fancy-namespace roleRef: kind: Role #this must be Role or ClusterRole name: pod-service-reader # this must match the name of the Role or ClusterRole you wish to bind to apiGroup : rbac.authorization.k8s.io subjects : # subject can be individual users or a group of users. Group is defined in the external authentication service, in this case, an OIDC server - kind: Group name: k8s-restricted-users

Slide 12

Slide 12 text

@deepu105 | deepu.tech Use OpenID Connect

Slide 13

Slide 13 text

© Okta and/or its affiliates. All rights reserved. Confidential Information of Okta – For Recipient’s Internal Use Only Why? ● Most secure Authentication mechanism ● Most scalable ● Ideal for clusters accessed by large teams as it provides a single sign-on solution ● Easy to onboard and offboard users

Slide 14

Slide 14 text

© Okta and/or its affiliates. All rights reserved. Confidential Information of Okta – For Recipient’s Internal Use Only How?

Slide 15

Slide 15 text

© Okta and/or its affiliates. All rights reserved. Confidential Information of Okta – For Recipient’s Internal Use Only How? How to Secure Your Kubernetes Cluster with OpenID Connect and RBAC https://a0.to/k8s-api-server-oidc

Slide 16

Slide 16 text

@deepu105 | deepu.tech Use Secure Secrets

Slide 17

Slide 17 text

© Okta and/or its affiliates. All rights reserved. Confidential Information of Okta – For Recipient’s Internal Use Only Why? ● Kubernetes Secrets are not very secure as its just base64 encoded strings ● Kubernetes Secrets cannot be stored in version control ● Kubernetes Secrets does not work with external secret managers

Slide 18

Slide 18 text

© Okta and/or its affiliates. All rights reserved. Confidential Information of Okta – For Recipient’s Internal Use Only How? ● Use Sealed Secrets ○ Uses asymmetric crypto encryption and supports certificate rotation ○ Can be stored in version control ○ Encrypted using unique key per cluster, namespace and secret ○ Can manage existing secrets ○ Ideal for small teams

Slide 19

Slide 19 text

© Okta and/or its affiliates. All rights reserved. Confidential Information of Okta – For Recipient’s Internal Use Only How?

Slide 20

Slide 20 text

© Okta and/or its affiliates. All rights reserved. Confidential Information of Okta – For Recipient’s Internal Use Only How? ● Use External Secrets Operator ○ Secrets are stored in external secret managers and is much more secure ○ Secrets are kept in sync ○ Works with HashiCorp Vault, Google Secrets Manager, AWS Secrets Manager and so on

Slide 21

Slide 21 text

© Okta and/or its affiliates. All rights reserved. Confidential Information of Okta – For Recipient’s Internal Use Only How?

Slide 22

Slide 22 text

© Okta and/or its affiliates. All rights reserved. Confidential Information of Okta – For Recipient’s Internal Use Only How? ● Use Secrets Store CSI driver ○ Secrets are stored in external secret managers and is much more secure ○ Secrets are mounted as volume on the pod ○ Secrets are kept in sync ○ Supports secret rotation ○ Works with HashiCorp Vault, Google Secrets Manager, AWS Secrets Manager and so on

Slide 23

Slide 23 text

© Okta and/or its affiliates. All rights reserved. Confidential Information of Okta – For Recipient’s Internal Use Only How?

Slide 24

Slide 24 text

© Okta and/or its affiliates. All rights reserved. Confidential Information of Okta – For Recipient’s Internal Use Only How? Shhhh... Kubernetes Secrets Are Not Really Secret! https://auth0.com/blog/kubernetes-secrets-management/

Slide 25

Slide 25 text

@deepu105 | deepu.tech Keep Kubernetes version up to date

Slide 26

Slide 26 text

© Okta and/or its affiliates. All rights reserved. Confidential Information of Okta – For Recipient’s Internal Use Only Why? ● Fix CVEs and other security bugs ● Latest features and security updates

Slide 27

Slide 27 text

© Okta and/or its affiliates. All rights reserved. Confidential Information of Okta – For Recipient’s Internal Use Only How? ● Check the Kubernetes security and disclosure information website to see if there are known security vulnerabilities for your version ● If you are using a managed PaaS, upgrade using built-in mechanism ● For on-prem installations, use tools like kOps, kubeadm, and so on, for easy upgrades

Slide 28

Slide 28 text

@deepu105 | deepu.tech Restrict kubelet, API, and SSH access

Slide 29

Slide 29 text

© Okta and/or its affiliates. All rights reserved. Confidential Information of Okta – For Recipient’s Internal Use Only Why? ● Restrict unintended access ● Non-admin users should not have API, SSH access

Slide 30

Slide 30 text

© Okta and/or its affiliates. All rights reserved. Confidential Information of Okta – For Recipient’s Internal Use Only How? ● Secure API server using OIDC and RBAC ● Disable SSH for non-admin users ● Secure kubeletʼs HTTP endpoints

Slide 31

Slide 31 text

@deepu105 | deepu.tech Control traffic between pods and clusters

Slide 32

Slide 32 text

© Okta and/or its affiliates. All rights reserved. Confidential Information of Okta – For Recipient’s Internal Use Only Why? ● A compromised pod could compromise another leading to a chain reaction ● Larger attack surface ● Better traffic control and better security

Slide 33

Slide 33 text

© Okta and/or its affiliates. All rights reserved. Confidential Information of Okta – For Recipient’s Internal Use Only How? ● Use Kubernetes network policies to control traffic between pods and clusters ● Allow only necessary traffic between pods

Slide 34

Slide 34 text

@deepu105 | deepu.tech Use namespaces to isolate workloads

Slide 35

Slide 35 text

© Okta and/or its affiliates. All rights reserved. Confidential Information of Okta – For Recipient’s Internal Use Only Why? ● Isolating workloads in namespaces reduces attack surface ● Easier to manage with RBAC

Slide 36

Slide 36 text

© Okta and/or its affiliates. All rights reserved. Confidential Information of Okta – For Recipient’s Internal Use Only How? ● Avoid using default namespace ● Tune RBAC to restrict access to only required namespaces ● Use Kubernetes network policies to control traffic between namespaces

Slide 37

Slide 37 text

@deepu105 | deepu.tech Limit resource usages

Slide 38

Slide 38 text

© Okta and/or its affiliates. All rights reserved. Confidential Information of Okta – For Recipient’s Internal Use Only Why? ● Avoid denial of service (DoS) attacks ● Reduce attack surface

Slide 39

Slide 39 text

© Okta and/or its affiliates. All rights reserved. Confidential Information of Okta – For Recipient’s Internal Use Only How? ● Use resources quotas and limit ranges to set limits at the namespace level ● Set resource limits at container level as well

Slide 40

Slide 40 text

@deepu105 | deepu.tech Use monitoring tools and enable audit logging

Slide 41

Slide 41 text

© Okta and/or its affiliates. All rights reserved. Confidential Information of Okta – For Recipient’s Internal Use Only Why? ● Detect unauthorized access attempts ● Keep an eye on the traffic ● Prevent breaches before with alarms

Slide 42

Slide 42 text

© Okta and/or its affiliates. All rights reserved. Confidential Information of Okta – For Recipient’s Internal Use Only How? ● Enable audit logging for the cluster ● Use a monitoring tool to monitor ingress/egress networking traffic

Slide 43

Slide 43 text

@deepu105 | deepu.tech Infrastructure best practices

Slide 44

Slide 44 text

© Okta and/or its affiliates. All rights reserved. Confidential Information of Okta – For Recipient’s Internal Use Only How? ● Ensure that all communication is done via TLS. ● Protect etcd with TLS, Firewall, and Encryption and restrict access to it using strong credentials. ● Set up IAM access policies in a supported environment like a PaaS. ● Secure the Kubernetes Control Plane. ● Rotate infrastructure credentials frequently. ● Restrict cloud metadata API access when running in a PaaS like AWS, Azure, or GCP.

Slide 45

Slide 45 text

@deepu105 | deepu.tech Container Best practices https://a0.to/container-security

Slide 46

Slide 46 text

@deepu105 | deepu.tech Do not run containers as root

Slide 47

Slide 47 text

© Okta and/or its affiliates. All rights reserved. Confidential Information of Okta – For Recipient’s Internal Use Only Why? ● Principle of least privilege to reduce attack surface ● Avoid container escape and privilege escalations

Slide 48

Slide 48 text

© Okta and/or its affiliates. All rights reserved. Confidential Information of Okta – For Recipient’s Internal Use Only How? ● Use a least privileged user ● Use --chown=user:user when using Docker copy commands

Slide 49

Slide 49 text

@deepu105 | deepu.tech Use minimal up-to-date official base images

Slide 50

Slide 50 text

© Okta and/or its affiliates. All rights reserved. Confidential Information of Okta – For Recipient’s Internal Use Only Why? ● Reduce attack surface ● Latest bug fixes and security patches

Slide 51

Slide 51 text

© Okta and/or its affiliates. All rights reserved. Confidential Information of Okta – For Recipient’s Internal Use Only How? ● Use deterministic image tags - FROM node:14.2.0-alpine3.11 instead of FROM node:14-alpine ● Install only production dependencies ● Use official verified images for popular software. Prefer LTS versions. ● Use a trusted registry for non-official images and always verify the image publisher

Slide 52

Slide 52 text

@deepu105 | deepu.tech Prevent loading unwanted kernel modules

Slide 53

Slide 53 text

© Okta and/or its affiliates. All rights reserved. Confidential Information of Okta – For Recipient’s Internal Use Only Why? ● Reduce attack surface ● Better performance

Slide 54

Slide 54 text

© Okta and/or its affiliates. All rights reserved. Confidential Information of Okta – For Recipient’s Internal Use Only How? ● Restrict using rules in /etc/modprobe.d/kubernetes-blacklist.conf of the node ● Uninstall the unwanted modules from the node

Slide 55

Slide 55 text

@deepu105 | deepu.tech Enable container image scanning in your CI/CD phase

Slide 56

Slide 56 text

© Okta and/or its affiliates. All rights reserved. Confidential Information of Okta – For Recipient’s Internal Use Only Why? ● Detect known vulnerabilities before they are exploited

Slide 57

Slide 57 text

© Okta and/or its affiliates. All rights reserved. Confidential Information of Okta – For Recipient’s Internal Use Only How? ● Enable image scanning in CI/CD phase ● Use OSS tools like clair, Anchore or commercial tools like Snyk

Slide 58

Slide 58 text

@deepu105 | deepu.tech Audit images

Slide 59

Slide 59 text

© Okta and/or its affiliates. All rights reserved. Confidential Information of Okta – For Recipient’s Internal Use Only Why? ● Check for security best practices

Slide 60

Slide 60 text

© Okta and/or its affiliates. All rights reserved. Confidential Information of Okta – For Recipient’s Internal Use Only How? ● Use Docker Bench for Security to audit your container images

Slide 61

Slide 61 text

@deepu105 | deepu.tech Use pod security policies

Slide 62

Slide 62 text

© Okta and/or its affiliates. All rights reserved. Confidential Information of Okta – For Recipient’s Internal Use Only Why? ● Reduce attack surface ● Prevent privilege escalation

Slide 63

Slide 63 text

© Okta and/or its affiliates. All rights reserved. Confidential Information of Okta – For Recipient’s Internal Use Only How? ● Use Pod Security Admission to limit a containerʼs access to the host further

Slide 64

Slide 64 text

@deepu105 | deepu.tech Thank you! Deepu K Sasidharan @deepu105@bsky.social | deepu.tech