LM Kubernetes
LM Kubernetes
#RSAC
Yossi Weizman
Senior Security Researcher
Microsoft
#RSAC
Disclaimer
Presentations are intended for educational purposes only and do not replace independent professional
judgment. Statements of fact and opinions expressed are those of the presenters individually and,
unless expressly stated to the contrary, are not the opinion or position of RSA Conference™ or any other
co-sponsors. RSA Conference does not endorse or approve, and assumes no responsibility for, the
content, accuracy or completeness of the information presented.
Attendees should note that sessions may be audio- or video-recorded and may be published in various
media, including print, audio and video formats without further notice. The presentation template and
any media capture are subject to copyright protection.
© 2023 RSA Conference LLC or its affiliates. The RSA Conference logo and other trademarks are proprietary. All rights reserved.
2
#RSAC
Agenda
3
Kubernetes:
Overview & identities
#RSAC
#RSAC
Kubernetes – overview
Containers - A unit of software that packages the code and all its dependencies. The
executable package is called image. At runtime, containers run as isolated software in
the host OS. Containers run by a container engine such as Docker or ContainerD
5
#RSAC
• How users (or applications) from outside the cluster authenticate with the cluster.
• How workloads in the cluster authenticate with resources in the cloud outside the
cluster.
9
#RSAC
• How users (or applications) from outside the cluster authenticate with the cluster.
• How workloads in the cluster authenticate with resources in the cloud outside the
cluster.
10
#RSAC
11
#RSAC
12
#RSAC
• Service accounts are mounted to pods, allowing them to authenticate with the API
server.
13
#RSAC
#RSAC
#RSAC
17
#RSAC
23
#RSAC
Pod’s A service
account token
25
#RSAC
26
#RSAC
27
#RSAC
Change the
application
configuration
Pod 𝑨𝑨∗𝟐𝟐
#RSAC
Permission Allows to
Create pod\controllers Use a privileged service account in a new pod
33
Cluster-to-cloud lateral movement
#RSAC
#RSAC
• Workloads in Kubernetes may need access to cloud resources (for example: cloud
storage \ cloud secret store etc.)
35
#RSAC
36
#RSAC
• In this method, each Kubernetes node stores a file with service principal (SPN) credentials.
SPNs are Azure application identities.
• By default, this SPN has Contributor role for the node resource group.
• Users can bring their own SPN or grant more permissions to the SPN if their applications need
access to more cloud resources. For example: add permissions to a cloud storage.
37
#RSAC
• In this method, each Kubernetes node stores a file with service principal (SPN) credentials.
SPNs are Azure application identities.
• By default, this SPN has Contributor role for the node resource group.
• Users can bring their own SPN or grant more permissions to the SPN if their applications need
access to more cloud resources. For example: add permissions to a cloud storage.
38
#RSAC
• The metadata service is a special endpoint that is accessible to VMs, allowing them to retrieve
information about the VM.
• Metadata service allows retrieving tokens for the cloud identity that is attached to the VM:
– Azure: 169.254.169.254/metadata/identity/oauth2
– AWS: 169.254.169.254/latest/meta-data/iam/security-credentials
– GCP: metadata.google.internal/computeMetadata/v1/instance/service-accounts
44
#RSAC
• In managed K8s clusters, the nodes are VM which can access to their metadata service.
• Thus, pods can acquire tokens of cloud identities attached to the nodes.
• The permissions of the identities depend on the cloud provider and the specific environment.
45
#RSAC
• Users can change the default permissions of those identities, or alternatively attach additional
managed identities to the nodes.
46
#RSAC
47
#RSAC
• Users can add more policies, if their containers require access to cloud resources.
48
#RSAC
• By default, all the VMs in a project, including the Kubernetes nodes, share a default SA.
• While the access scope limits the permissions, they are still powerful by default:
49
#RSAC
How does lateral movement from the cluster to the cloud would look like?
50
#RSAC
Node 1
Metadata
Pod A
service
Pod B
#RSAC
Node 1
Get token
Metadata
Pod A
service
Pod B
#RSAC
Node 1
Returns cloud
identity token
Metadata
Pod A
service
Pod B
#RSAC
Metadata
Pod A
service
Pod B
#RSAC
Node 1
Metadata
Pod A
service
Pod B
#RSAC
Get credentials of
Kubernetes clusters
Node 1
Metadata
Pod A
service
Pod B
#RSAC
The problem:
• Pods can freely access to their node’s cloud identities.
• All pods share the same cloud identities (the node’s identities).
What we want:
• Allocate a specific identity to each pod (that needs access to cloud resources) with the minimal
needed permissions.
• Make sure pods can only acquire tokens for their own identities.
58
#RSAC
2. When pods query IMDS, the traffic is intercepted and redirected to a local server in the cluster.
3. The local server is K8s-aware, thus can identify the querying pod.
4. The local server queries IMDS on behalf of the pod and request the pod-specific identity.
5. This concept was implemented in Azure by AAD Pod Identity [recently deprecated].
59
#RSAC
Pod A
Metadata 3
1
service 2 3
Pod B
Local server
(NMI)
#RSAC
Limitations
1. Works only for Linux containers (uses IPTables).
2. Not supported by all Kubernetes network configuration
(Prone to ARP poisoning) Node 1
Pod A
Metadata 3
1
service 2 3
Pod B
Local server
(NMI)
#RSAC
• Trust relation is created such as the cloud identity service (e.g. AAD, AWS IAM, GCP IAM) trusts the
service accounts issued by the K8s cluster.
• This trust relation allows applications in the cluster to exchange a K8s service account token with a cloud
identity token.
62
#RSAC
Cluster’s
Kubelet Pod Cloud identity service OIDC endpoint
63
#RSAC
• Meaning, there’s a single binding of a K8s service account (namespace + SA name) to a cloud identity.
Cluster A Cluster B
Namespace: Namespace:
monitoring monitoring
MyCloudApp
Cluster A Cluster B
Namespace: Namespace:
monitoring monitoring
MyCloudApp
#RSAC
Cluster A Cluster B
Namespace: Namespace:
monitoring monitoring
MyCloudApp
#RSAC
Cluster A Cluster B
Namespace: Namespace:
monitoring monitoring
MyCloudApp
Cross-cloud lateral movement
#RSAC
#RSAC
69
#RSAC
70
#RSAC
Azure AWS
Pull images
71
#RSAC
Azure AWS
Push image
Pull images
72
#RSAC
Azure AWS
Push image
Cluster-to-
cloud lateral
movement
Pull images
73
#RSAC
Azure AWS
AKS
Push image
Cluster-to-
cloud lateral
movement
Pull images
74
#RSAC
75
Detections & Mitigations
#RSAC
#RSAC
Detections
Monitor suspicious activity in the cluster using K8s Monitor suspicious activity of cloud identities used by K8s
Audit log (kube-audit). Examples: workloads\nodes. Examples:
1. Deployment of abnormal images 1. Abnormal behavior of cloud identities. Usually, the cloud
identities used by the workloads have a consistent
2. Pods with suspicious configurations behavior.
(sensitive volume mounts, privileged etc.)
2. Suspicious access to sensitive cloud services (e.g. storage,
3. Reconnaissance activity secret store etc.)
(for example: SelfSubjectRulesReview API call).
4. Sensitive API calls, such as “get secret”
77
#RSAC
Detections
Monitor suspicious activity in the cluster using K8s Monitor suspicious activity of cloud identities used by K8s
Audit log (kube-audit). Examples: workloads\nodes. Examples:
1. Deployment of abnormal images 1. Abnormal behavior of cloud identities. Usually, the cloud
identities used by the workloads have a consistent
2. Pods with suspicious configurations behavior.
(sensitive volume mounts, privileged etc.)
2. Suspicious access to sensitive cloud services (e.g. storage,
3. Reconnaissance activity secret store etc.)
(for example: SelfSubjectRulesReview API call).
4. Sensitive API calls, such as “get secret”
78
#RSAC
Mitigations
• In December, a new version of the Threat Matrix for Kubernetes was released (v3): an open-source
knowledge base of attacking techniques of K8s.
• http://aka.ms/KubernetesThreatMatrix
79
#RSAC
Mitigations
80
#RSAC
Mitigations
81
#RSAC
Mitigations
82
#RSAC
Mitigations
83
#RSAC
Mitigations
84
#RSAC
Mitigations
85
#RSAC
Mitigations
86
#RSAC
Mitigations
87
#RSAC
Mitigations
88
#RSAC
Mitigations
89
#RSAC
Mitigations
90
#RSAC
Mitigations
91
Key takeaways
#RSAC
#RSAC
Key takeaways
• Implement a holistic strategy for K8s security by considering both the cluster and cloud levels.
• Identities are a key aspect of K8s security: Monitor their activity using auditing tools.
93
Thank you!
#RSAC