SlideShare a Scribd company logo
Kubernetes Security with Calico and Open Policy Agent
Network policy
• All Pods are non-isolated by default
• Flat network. All pods can talk to other pods
• Accept traffic from anyone
• Multi stage/zone project this could expose security risks
• 3 tier webapp.
• Front end could technically talk directly to DB tier
Azure Kubernetes Network Policies
• Provides micro-segmentation for containers –
like NSGs for VMs
• Label-based selection of Pods
• Policy resource yaml file specifies Ingress and
Egress policies
• Policies defined for a label
• Works in conjunction with Azure CNI
• Supports Linux hosts
• Supported in aks-engine
• Set networkPolicy setting to azure in cluster
definition file
• Supported on AKS in Preview
Azure Policy
Manager
Azure Policy
Manager
Network policy
• Pod Selector
• PolicyTypes
• Ingress, egress
Ingress
• namespaceSelector
• podSelector
• ipBlock
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: test-network-policy
namespace: default
spec:
podSelector:
matchLabels:
role: db
policyTypes:
- Ingress
- Egress
ingress:
- from:
- ipBlock:
cidr: 172.17.0.0/16
except:
- 172.17.1.0/24
- namespaceSelector:
matchLabels:
project: myproject
- podSelector:
matchLabels:
role: frontend
ports:
- protocol: TCP
port: 6379
egress:
- to:
- ipBlock:
cidr: 10.0.0.0/24
ports:
- protocol: TCP
port: 5978
Network policy
• Recommend to create default policies that
apply to all pods
• Default deny all ingress traffic
• Default deny all egress traffic.
• Allow Specific Traffic (Ingress & Egress)
Calico Global
Network Policy
apiVersion: projectcalico.org/v3
kind: GlobalNetworkPolicy
metadata:
name: allow-tcp-6379
spec:
selector: role == 'database'
types:
- Ingress
- Egress
ingress:
- action: Allow
protocol: TCP
source:
selector: role == 'frontend'
destination:
ports:
- 6379
egress:
- action: Allow
Calico Global
Network Set
apiVersion:
projectcalico.org/v3
kind: GlobalNetworkSet
metadata:
name: a-name-for-the-set
labels:
role: external-database
spec:
nets:
- 198.51.100.0/28
- 203.0.113.0/24
<- Single Rule where two conditions must be met
<- two conditions either/or must be met
When to use Azure NSG vs. Kubernetes Network
policy
• Azure Network Security Groups
• Use it to filter North-South traffic, that is, traffic entering and leaving your
cluster subnet
• Kubernetes Network Policies
• Use it to filter East-West traffic, that is, traffic between pods in your cluster
Network Policy Demo
• Fruit Categorization App
• Web Frontend
• ML Backend for image recognition
• Signal R as a managed websocket service between FE/BE
• Default allow
• Create a policy (deny all by default)
• Open a policy to communicate between FE/BE services
Open Policy Agent
Kubernetes Security with Calico and Open Policy Agent
Dynamic Admission Control
• Validating Webhook
o Allows you to intercept and validate requests
o Can be run in parallel, as they don’t mutate objects
o Example use case: restricting resource creation
• Mutating Webhook
o Executes the mutation by sending requests to webhook server
o Matching webhooks are called in serial
o Example use case: injecting side cars
o Policy Enforcement
o Admission Control is policy based on Kubernetes objects.
o Network Policy and PodSecurity Policy focus on data plane policy
o RBAC is policy enforced on the user
That’s awesome! But…
Sample Admission Webhook
Open Policy Agent
Image: openpolicyagent.org
• CNCF Hosted Sandbox Project
• General purpose policy engine
• Can be used across the stack
• Declarative policy language (Rego)
Service refers to:
• Kubernetes API
• Custom API
• SSH Daemon
• Terraform
• Authorization APi
Output can be any JSON value:
”true
”request annotated”
“ “annotations": {
costCenter: 8000
}
Input can be any JSON value:
"kind": "Service",
"metadata": {
"annotations": {
department: dev
}
Service
OPA
Policy
(Rego)
Data
(JSON)
Request
Enforcement
Policy
Query
Policy
Decision
Diagram rewritten from:
www.openpolicyagent.org
Example Rego Policy
• Rego is a policy language and not a programing language, so don’t think about sockets, methods, binary
trees, etc.
• Think about two things: Logic and Data
• Rego logic is all queries. A query finds values for variables that make boolean conditions true.
• You write logic to search and combine JSON/YAML data from different sources.
deny[{
"id": "conditional-annotation",
"resource": {"kind": kind, "namespace": namespace, "name": name},
"resolution": {"patches": p, "message" : "conditional annotation"}, }] {
matches[[kind, namespace, name, matched_object]] matched_object.metadata.annotations[”Mr-T"]
p = [{"op": "add", "path": "/metadata/annotations/cost-center", "value": ”A-Team"}] }
Who manages all this policy?
Ice Kube
Acid Burn
The Governor
Platform Operator
Developer
OPA Policy
Creates And Maintains
Deploys Apps
Audits Platform
Kubernetes Policy Controller
• Kubernetes Policy Controller
• Moving to OPA org, as a standard Kubernetes Policy Controller
• Authorization module makes it possible to implement a blacklist in front of RBAC
• Provides auditing features
• Deployment consist of three containers: OPA, kube-mgmt., and Controller
• Examples:
• Whitelist / blacklist registries.
• Not allow conflicting hosts for ingresses.
• Label objects based on a user from a department.
• Block kubectl exec <pod>
The Good, The Bad, and Gotchas
• Good
• OPA approach allows you to decouple policy from your applications
• General purpose, so can be used outside of Kubernetes context.
• Bad
• There can be a learning curve to Rego.
• Can cause latency, but’s negligible for most apps. (more of a consideration)
• Gotchas
• Mutating objects need to be handled with care. They can cause unexpected
behavior to what the end-user expects.
Takeaways
• Focus on security is a must in any Kubernetes deployment.
• Help educate Security Teams on how to extend Kubernetes to integrate custom
policies.
• Treat the Kubernetes cluster as immutable, just like you do with applications.
• Multiple ways to accomplish policy
• Build all your own logic and utilize dynamic admission control
• Utilize Open Policy Agent to simplify deployment and logic for rule sets.
Example Policies
• https://github.com/open-policy-agent/contrib

More Related Content

PDF
DSO-LG 2021 Reboot: Policy As Code (Anders Eknert)
PPTX
Azure Governance
PPTX
Service mesh
PDF
Introduction to Azure
PDF
Kubernetes Networking
PDF
Tom Grey - Google Cloud Platform
PDF
An overview of the Kubernetes architecture
PDF
CloudStack vs OpenStack
DSO-LG 2021 Reboot: Policy As Code (Anders Eknert)
Azure Governance
Service mesh
Introduction to Azure
Kubernetes Networking
Tom Grey - Google Cloud Platform
An overview of the Kubernetes architecture
CloudStack vs OpenStack

What's hot (20)

PDF
Kinesis + Elasticsearchでつくるさいきょうのログ分析基盤
PDF
AWS Fault Injection Simulator를 통한 실전 카오스 엔지니어링 - 윤석찬 AWS 수석 테크에반젤리스트 / 김신 SW엔...
PPTX
Azure Networking - The First Technical Challenge
PDF
실시간 스트리밍 분석 Kinesis Data Analytics Deep Dive
PPTX
An Intrudction to OpenStack 2017
PDF
[Azure Governance] Lesson 4 : Azure Policy
PDF
Open shift 4 infra deep dive
PDF
What is AWS | AWS Certified Solutions Architect | AWS Tutorial | AWS Training...
PPTX
Azure devops
PPTX
Introduction to Azure monitor
PDF
20명 규모의 팀에서 Vault 사용하기
PDF
Getting Started on Amazon EKS
PDF
OpenStack Architecture
PDF
浸透するサーバーレス 実際に見るユースケースと実装パターン
PPTX
AWS VS AZURE VS GCP.pptx
PPT
Docker introduction
PDF
Introduction to docker
PDF
AWS 기반의 마이크로 서비스 아키텍쳐 구현 방안 :: 김필중 :: AWS Summit Seoul 20
PDF
AWS Transit Gateway를 통한 Multi-VPC 아키텍처 패턴 - 강동환 솔루션즈 아키텍트, AWS :: AWS Summit ...
PDF
Introduction to Google Cloud Platform (GCP) | Google Cloud Tutorial for Begin...
Kinesis + Elasticsearchでつくるさいきょうのログ分析基盤
AWS Fault Injection Simulator를 통한 실전 카오스 엔지니어링 - 윤석찬 AWS 수석 테크에반젤리스트 / 김신 SW엔...
Azure Networking - The First Technical Challenge
실시간 스트리밍 분석 Kinesis Data Analytics Deep Dive
An Intrudction to OpenStack 2017
[Azure Governance] Lesson 4 : Azure Policy
Open shift 4 infra deep dive
What is AWS | AWS Certified Solutions Architect | AWS Tutorial | AWS Training...
Azure devops
Introduction to Azure monitor
20명 규모의 팀에서 Vault 사용하기
Getting Started on Amazon EKS
OpenStack Architecture
浸透するサーバーレス 実際に見るユースケースと実装パターン
AWS VS AZURE VS GCP.pptx
Docker introduction
Introduction to docker
AWS 기반의 마이크로 서비스 아키텍쳐 구현 방안 :: 김필중 :: AWS Summit Seoul 20
AWS Transit Gateway를 통한 Multi-VPC 아키텍처 패턴 - 강동환 솔루션즈 아키텍트, AWS :: AWS Summit ...
Introduction to Google Cloud Platform (GCP) | Google Cloud Tutorial for Begin...
Ad

Similar to Kubernetes Security with Calico and Open Policy Agent (20)

PDF
Securing Kubernetes Workloads
PDF
Secure your K8s cluster from multi-layers
PPTX
Kubernetes Internals
PDF
Tame the Mesh An intro to cross-platform tracing and troubleshooting.pdf
PPTX
Cloudify workshop at CCCEU 2014
PDF
CloudStack Tooling Ecosystem – Kiran Chavala, ShapeBlue
PDF
Head in the clouds
PPTX
Power of Azure Devops
PDF
Evolution of security strategies in K8s environments- All day devops
PPTX
BSidesDFW2022-PurpleTeam_Cloud_Identity.pptx
PPTX
What's New in Docker - February 2017
PDF
Kubernetes basics and hands on exercise
PDF
2016 07 - CloudBridge Python library (XSEDE16)
PDF
(ATS6-PLAT04) Query service
PPTX
Security hardening enhancements for Kubernetes
PDF
Implementing-SaaS-on-Kubernetes-Michael-Knapp-Andrew-Gao-Capital-One.pdf
PPTX
Centralizing Kubernetes and Container Operations
PDF
Anthos Security: modernize your security posture for cloud native applications
PDF
Kubernetes One-Click Deployment: Hands-on Workshop (Mainz)
Securing Kubernetes Workloads
Secure your K8s cluster from multi-layers
Kubernetes Internals
Tame the Mesh An intro to cross-platform tracing and troubleshooting.pdf
Cloudify workshop at CCCEU 2014
CloudStack Tooling Ecosystem – Kiran Chavala, ShapeBlue
Head in the clouds
Power of Azure Devops
Evolution of security strategies in K8s environments- All day devops
BSidesDFW2022-PurpleTeam_Cloud_Identity.pptx
What's New in Docker - February 2017
Kubernetes basics and hands on exercise
2016 07 - CloudBridge Python library (XSEDE16)
(ATS6-PLAT04) Query service
Security hardening enhancements for Kubernetes
Implementing-SaaS-on-Kubernetes-Michael-Knapp-Andrew-Gao-Capital-One.pdf
Centralizing Kubernetes and Container Operations
Anthos Security: modernize your security posture for cloud native applications
Kubernetes One-Click Deployment: Hands-on Workshop (Mainz)
Ad

More from CloudOps2005 (20)

PDF
Defense in Depth: Securing your new Kubernetes cluster from the challenges th...
PPTX
Human No, Machine Yes: Welcome to the CDF with Incremental Confidence
PDF
The Salmon Algorithm Spawning with Kubernetes
PDF
Own your Destiny in the Cloud - Ian Rae - Cloud Native Day Montreal 2019
PDF
Plateformes et infrastructure infonuagique natif de ville de Montréall
PPTX
Using Rook to Manage Kubernetes Storage with Ceph
PDF
Kafka on Kubernetes
PDF
Kubernetes: Crossing the Chasm
PPTX
Distributed Logging with Kubernetes
PDF
Advanced Deployment Strategies with Kubernetes and Istio
PDF
GitOps with ArgoCD
PPTX
Kubernetes Services are sooo Yesterday!
PPTX
Amazon EKS: the good, the bad, and the ugly
PDF
Kubernetes, Terraform, Vault, and Consul
PDF
SIG Multicluster and the Path to Federation
PDF
To Russia with Love: Deploying Kubernetes in Exotic Locations On Prem
PDF
Operator SDK for K8s using Go
PPTX
How to Handle your Kubernetes Upgrades
PDF
Kubernetes and Cloud Native Meetup - March, 2019
PDF
Prometheus and Thanos
Defense in Depth: Securing your new Kubernetes cluster from the challenges th...
Human No, Machine Yes: Welcome to the CDF with Incremental Confidence
The Salmon Algorithm Spawning with Kubernetes
Own your Destiny in the Cloud - Ian Rae - Cloud Native Day Montreal 2019
Plateformes et infrastructure infonuagique natif de ville de Montréall
Using Rook to Manage Kubernetes Storage with Ceph
Kafka on Kubernetes
Kubernetes: Crossing the Chasm
Distributed Logging with Kubernetes
Advanced Deployment Strategies with Kubernetes and Istio
GitOps with ArgoCD
Kubernetes Services are sooo Yesterday!
Amazon EKS: the good, the bad, and the ugly
Kubernetes, Terraform, Vault, and Consul
SIG Multicluster and the Path to Federation
To Russia with Love: Deploying Kubernetes in Exotic Locations On Prem
Operator SDK for K8s using Go
How to Handle your Kubernetes Upgrades
Kubernetes and Cloud Native Meetup - March, 2019
Prometheus and Thanos

Recently uploaded (20)

PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Accuracy of neural networks in brain wave diagnosis of schizophrenia
PPTX
A Presentation on Artificial Intelligence
PDF
Empathic Computing: Creating Shared Understanding
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
Spectroscopy.pptx food analysis technology
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
Big Data Technologies - Introduction.pptx
PPTX
Machine Learning_overview_presentation.pptx
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Electronic commerce courselecture one. Pdf
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Reach Out and Touch Someone: Haptics and Empathic Computing
Accuracy of neural networks in brain wave diagnosis of schizophrenia
A Presentation on Artificial Intelligence
Empathic Computing: Creating Shared Understanding
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Building Integrated photovoltaic BIPV_UPV.pdf
“AI and Expert System Decision Support & Business Intelligence Systems”
MIND Revenue Release Quarter 2 2025 Press Release
Spectroscopy.pptx food analysis technology
Encapsulation_ Review paper, used for researhc scholars
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Per capita expenditure prediction using model stacking based on satellite ima...
Big Data Technologies - Introduction.pptx
Machine Learning_overview_presentation.pptx
Assigned Numbers - 2025 - Bluetooth® Document
Programs and apps: productivity, graphics, security and other tools
Electronic commerce courselecture one. Pdf
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton

Kubernetes Security with Calico and Open Policy Agent

  • 2. Network policy • All Pods are non-isolated by default • Flat network. All pods can talk to other pods • Accept traffic from anyone • Multi stage/zone project this could expose security risks • 3 tier webapp. • Front end could technically talk directly to DB tier
  • 3. Azure Kubernetes Network Policies • Provides micro-segmentation for containers – like NSGs for VMs • Label-based selection of Pods • Policy resource yaml file specifies Ingress and Egress policies • Policies defined for a label • Works in conjunction with Azure CNI • Supports Linux hosts • Supported in aks-engine • Set networkPolicy setting to azure in cluster definition file • Supported on AKS in Preview Azure Policy Manager Azure Policy Manager
  • 4. Network policy • Pod Selector • PolicyTypes • Ingress, egress Ingress • namespaceSelector • podSelector • ipBlock apiVersion: networking.k8s.io/v1 kind: NetworkPolicy metadata: name: test-network-policy namespace: default spec: podSelector: matchLabels: role: db policyTypes: - Ingress - Egress ingress: - from: - ipBlock: cidr: 172.17.0.0/16 except: - 172.17.1.0/24 - namespaceSelector: matchLabels: project: myproject - podSelector: matchLabels: role: frontend ports: - protocol: TCP port: 6379 egress: - to: - ipBlock: cidr: 10.0.0.0/24 ports: - protocol: TCP port: 5978
  • 5. Network policy • Recommend to create default policies that apply to all pods • Default deny all ingress traffic • Default deny all egress traffic. • Allow Specific Traffic (Ingress & Egress)
  • 6. Calico Global Network Policy apiVersion: projectcalico.org/v3 kind: GlobalNetworkPolicy metadata: name: allow-tcp-6379 spec: selector: role == 'database' types: - Ingress - Egress ingress: - action: Allow protocol: TCP source: selector: role == 'frontend' destination: ports: - 6379 egress: - action: Allow
  • 7. Calico Global Network Set apiVersion: projectcalico.org/v3 kind: GlobalNetworkSet metadata: name: a-name-for-the-set labels: role: external-database spec: nets: - 198.51.100.0/28 - 203.0.113.0/24
  • 8. <- Single Rule where two conditions must be met <- two conditions either/or must be met
  • 9. When to use Azure NSG vs. Kubernetes Network policy • Azure Network Security Groups • Use it to filter North-South traffic, that is, traffic entering and leaving your cluster subnet • Kubernetes Network Policies • Use it to filter East-West traffic, that is, traffic between pods in your cluster
  • 10. Network Policy Demo • Fruit Categorization App • Web Frontend • ML Backend for image recognition • Signal R as a managed websocket service between FE/BE • Default allow • Create a policy (deny all by default) • Open a policy to communicate between FE/BE services
  • 13. Dynamic Admission Control • Validating Webhook o Allows you to intercept and validate requests o Can be run in parallel, as they don’t mutate objects o Example use case: restricting resource creation • Mutating Webhook o Executes the mutation by sending requests to webhook server o Matching webhooks are called in serial o Example use case: injecting side cars o Policy Enforcement o Admission Control is policy based on Kubernetes objects. o Network Policy and PodSecurity Policy focus on data plane policy o RBAC is policy enforced on the user
  • 16. Open Policy Agent Image: openpolicyagent.org • CNCF Hosted Sandbox Project • General purpose policy engine • Can be used across the stack • Declarative policy language (Rego)
  • 17. Service refers to: • Kubernetes API • Custom API • SSH Daemon • Terraform • Authorization APi Output can be any JSON value: ”true ”request annotated” “ “annotations": { costCenter: 8000 } Input can be any JSON value: "kind": "Service", "metadata": { "annotations": { department: dev } Service OPA Policy (Rego) Data (JSON) Request Enforcement Policy Query Policy Decision Diagram rewritten from: www.openpolicyagent.org
  • 18. Example Rego Policy • Rego is a policy language and not a programing language, so don’t think about sockets, methods, binary trees, etc. • Think about two things: Logic and Data • Rego logic is all queries. A query finds values for variables that make boolean conditions true. • You write logic to search and combine JSON/YAML data from different sources. deny[{ "id": "conditional-annotation", "resource": {"kind": kind, "namespace": namespace, "name": name}, "resolution": {"patches": p, "message" : "conditional annotation"}, }] { matches[[kind, namespace, name, matched_object]] matched_object.metadata.annotations[”Mr-T"] p = [{"op": "add", "path": "/metadata/annotations/cost-center", "value": ”A-Team"}] }
  • 19. Who manages all this policy? Ice Kube Acid Burn The Governor Platform Operator Developer OPA Policy Creates And Maintains Deploys Apps Audits Platform
  • 20. Kubernetes Policy Controller • Kubernetes Policy Controller • Moving to OPA org, as a standard Kubernetes Policy Controller • Authorization module makes it possible to implement a blacklist in front of RBAC • Provides auditing features • Deployment consist of three containers: OPA, kube-mgmt., and Controller • Examples: • Whitelist / blacklist registries. • Not allow conflicting hosts for ingresses. • Label objects based on a user from a department. • Block kubectl exec <pod>
  • 21. The Good, The Bad, and Gotchas • Good • OPA approach allows you to decouple policy from your applications • General purpose, so can be used outside of Kubernetes context. • Bad • There can be a learning curve to Rego. • Can cause latency, but’s negligible for most apps. (more of a consideration) • Gotchas • Mutating objects need to be handled with care. They can cause unexpected behavior to what the end-user expects.
  • 22. Takeaways • Focus on security is a must in any Kubernetes deployment. • Help educate Security Teams on how to extend Kubernetes to integrate custom policies. • Treat the Kubernetes cluster as immutable, just like you do with applications. • Multiple ways to accomplish policy • Build all your own logic and utilize dynamic admission control • Utilize Open Policy Agent to simplify deployment and logic for rule sets.