SlideShare a Scribd company logo
1 of 28
共享 x 安全 = NetworkPolicy ?
施嘉峻 (ccshih)
iiiccshih@gmail.com
Presented at iThome Kubernetes Day, Sep 20, 2017
About Me
@ ccshih
# Kubernetes
# OpenShift
+ Red Hat Certificate of Expertise in
Platform-as-a-Service (OpenShift Admin)
2
Agenda
• Share x Security @ k8s 1.7 (p. 4)
• Network Policies (p. 6)
• Use cases
• How to
• Limitations
• Adoption Advices (p. 18)
• Looking Forward (p. 22)
• Takeaway (p. 25)
3
3 cases
1 advice
2 promising tech
Share x Security @ k8s 1.7
Network
Policies
(Beta from 1.6)
RBAC
Namespace
(GA from 1.7)
Virtual cluster
Multiple teams or projects
Scope of control
Role-Based Access Control
Attach permissions to roles
Bind roles to users
Control pods incoming connection
Based on Labels
Project A Project B
Namespace Namespace
Pod Pod
Admin
Role
User
Role
?
4
*Also matters: Resource Quota, Pod Security Policies
允入
Use Labels to Organize Objects
5
tier=frontend
(key-value pairs)
tier=backend
tier=database
env=dev
env=qa
env=staging
env=prod
release=stable
release=canary
Pod
Labels …
env=prod
tier=frontend
release=stable
env=prod
Namespace
First Scenario
6
Pod
Pod Pod
Pod Pod
Pod
tier=frontend tier=backend tier=database
Namespace b
PodPod
PodPod
Namespace a
Without Network Policy (k8s default)
7
Pod
Pod Pod
Pod Pod
Pod
tier=frontend tier=backend tier=database
Namespace b
PodPod
PodPod
Namespace a
Pod accepts any connection from any namespace
Network Policy Use Case (1)
8
Pod
Pod Pod
Pod Pod
Pod
tier=frontend tier=backend tier=database
Namespace b
PodPod
PodPod
Namespace a
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: allow-backend-access-database
namespace: b
spec:
podSelector:
matchLabels:
tier: database
ingress:
- from:
- podSelector:
matchLabels:
tier: backend
ports:
- protocol: TCP
port: 3306
Network Policy Example (1)
9
This policy applies to …
Allows connection from …
to this port
Pod
Pod Pod
Pod Pod
Pod
tier=frontend tier=backend tier=database
Namespace b
PodPod
PodPod
Namespace a
Policy:
Network Policy Rules
• If no policy applied to a pod
• Allow connection from any source
• If any policy applied to a pod
• Whitelist: Deny all incoming connections, unless source satisfies at least one
policies
10
PodPod
Pod
PodPod
Pod
No Policy
applied
Policy:
Network Policy Use Case (2)
11
Pod
Pod Pod
Pod
Pod
tier=frontend tier=backend tier=database
PodPod
PodPod
release=canary
release=stable
Namespace b
Network Policy Example (2)
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: allow-canary-backend-access-database
namespace: b
spec:
podSelector:
matchLabels:
tier: database
release: stable
ingress:
- from:
- podSelector:
matchLabels:
tier: backend
ports:
- protocol: TCP
port: 3306
12
This policy applies to …
Allows connection from …
to this port
Pod
Pod Pod
Pod
Pod
tier=frontend tier=backend tier=database
PodPod
PodPod
release=canary
release=stable
Namespace b
(AND)
in the same selector
Network Policy Non-Use Case
13
Pod
Pod Pod
Pod
Pod
tier=frontend tier=backend tier=database
PodPod
PodPod
Namespace
b-plus
Namespace
b
Network Policy Non-Example
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
namespace: b
…
…
ingress:
- from:
- podSelector:
matchLabels:
tier: backend
- namespaceSelector:
matchLabels:
name: b-plus
ports:
- protocol: TCP
port: 3306
14
Allows connection from …(OR)
Pod
Pod Pod
Pod
Pod
tier=frontend tier=backend tier=database
PodPod
PodPod
Namespace
b-plus
Namespace
b
Need (AND),
but NOT supported yet*
* https://github.com/kubernetes/kubernetes/issues/50451
in different selector
Network Policy Limitation in K8s 1.7
• A selector can not match both Namespace labels and Pod labels
• No Egress Policy
• What if your pods are compromised?
• Prerequisite: Need support of Container Network Providers
15
Pod
(Ingress) (Egress)
Network Providers who Support Network Policy
16
Calico cilium ROMANA WeaveNet
&
Note:
• Not standard k8s Network Policy
• Run with calicoctl, instead of kubectl
• Calico also supports Egress policy (not
shown here)
Calico’s Policy Definition
17
Pod
Pod Pod
Pod
Pod
tier=frontend tier=backend tier=database
PodPod
PodPod
Namespace
b-plus
Namespace
bapiVersion: v1
kind: policy
metadata:
name: allow-b-plus-backend-access-b-database
spec:
selector: >
calico/k8s_ns == 'b' &&
tier == 'database'
ingress:
- action: allow
source:
selector: >
calico/k8s_ns == 'b-plus' &&
tier == 'backend'
protocol: tcp
destination:
ports: [3306]
# calicoctl apply -f <FILENAME>
Adoption Advices
18
Adoption Advices
• (skipped) Use special labels for network policy
• Rethink IP-based packet filter
19
Dynamic Nature of K8s
20
Source: https://www.slideshare.net/gmccance/cern-data-centre-evolution
K8s is primarily
designed for
(Static)
(Dynamic)
(change IP)
Rethink IP-based packet filter
• Pod up/down triggers firewall rule adjustment
• Translate application-level policy to network-level policy
• Given that Firewall can recognize pod IP
21
IP
Source Labels
Destination
Labels
IP IP
IP
IP
IP IP
IP
IP-based
Firewall rules
Application-level
Policy
change
frequently
Looking Forward
22
Looking forward (1)
• Cilium
• Not use IP to define filter
• Flexible and Efficient
23
IP
Source Labels
Destination
Labels
IP IP
IP
IP
IP IP
IP
eBPF
(Packet Filter)
Application-level
Policy
change
frequently
(Require Linux Kernel 4.8 ↑)
id
id
Looking forward (2)
24
• Istio
• Each service pod equips with a sidecar container (envoy), which enforces policy
Source: https://github.com/istio/auth
Takeaway
25
Takeaway
• By default, pod can talk to each other at network level
• Network Policy
• whitelists pod incoming connection
• needs container network provider’s support
• can not apply to some cross-namespace scenario
• Adoption
• security needs as agile as containers
• Looking forward
• Flavored policy enforcement
26
Contact
• iiiccshih@gmail.com
27
References
• Network Policy
• Official document
• Recipes by ahmetb
• Calico
• Getting started with k8s
28

More Related Content

What's hot

Introduction to kubernetes
Introduction to kubernetesIntroduction to kubernetes
Introduction to kubernetesRishabh Indoria
 
Terraform and Weave GitOps: Build a Fully Automated Application Stack
Terraform and Weave GitOps: Build a Fully Automated Application StackTerraform and Weave GitOps: Build a Fully Automated Application Stack
Terraform and Weave GitOps: Build a Fully Automated Application StackWeaveworks
 
Open stack architecture overview-meetup-6-6_2013
Open stack architecture overview-meetup-6-6_2013Open stack architecture overview-meetup-6-6_2013
Open stack architecture overview-meetup-6-6_2013Mirantis
 
Introduction to kubernetes
Introduction to kubernetesIntroduction to kubernetes
Introduction to kubernetesGabriel Carro
 
Kubernetes - introduction
Kubernetes - introductionKubernetes - introduction
Kubernetes - introductionSparkbit
 
Room 1 - 5 - Thủy Đặng - Load balancing k8s services on baremetal with Cilium...
Room 1 - 5 - Thủy Đặng - Load balancing k8s services on baremetal with Cilium...Room 1 - 5 - Thủy Đặng - Load balancing k8s services on baremetal with Cilium...
Room 1 - 5 - Thủy Đặng - Load balancing k8s services on baremetal with Cilium...Vietnam Open Infrastructure User Group
 
Let's talk about Failures with Kubernetes - Hamburg Meetup
Let's talk about Failures with Kubernetes - Hamburg MeetupLet's talk about Failures with Kubernetes - Hamburg Meetup
Let's talk about Failures with Kubernetes - Hamburg MeetupHenning Jacobs
 
Kubernetes Concepts And Architecture Powerpoint Presentation Slides
Kubernetes Concepts And Architecture Powerpoint Presentation SlidesKubernetes Concepts And Architecture Powerpoint Presentation Slides
Kubernetes Concepts And Architecture Powerpoint Presentation SlidesSlideTeam
 
Room 1 - 4 - Phạm Tường Chiến & Trần Văn Thắng - Deliver managed Kubernetes C...
Room 1 - 4 - Phạm Tường Chiến & Trần Văn Thắng - Deliver managed Kubernetes C...Room 1 - 4 - Phạm Tường Chiến & Trần Văn Thắng - Deliver managed Kubernetes C...
Room 1 - 4 - Phạm Tường Chiến & Trần Văn Thắng - Deliver managed Kubernetes C...Vietnam Open Infrastructure User Group
 
An overview of the Kubernetes architecture
An overview of the Kubernetes architectureAn overview of the Kubernetes architecture
An overview of the Kubernetes architectureIgor Sfiligoi
 
Kubernetes Workshop
Kubernetes WorkshopKubernetes Workshop
Kubernetes Workshoploodse
 
Room 1 - 3 - Lê Anh Tuấn - Build a High Performance Identification at GHTK wi...
Room 1 - 3 - Lê Anh Tuấn - Build a High Performance Identification at GHTK wi...Room 1 - 3 - Lê Anh Tuấn - Build a High Performance Identification at GHTK wi...
Room 1 - 3 - Lê Anh Tuấn - Build a High Performance Identification at GHTK wi...Vietnam Open Infrastructure User Group
 
Room 3 - 1 - Nguyễn Xuân Trường Lâm - Zero touch on-premise storage infrastru...
Room 3 - 1 - Nguyễn Xuân Trường Lâm - Zero touch on-premise storage infrastru...Room 3 - 1 - Nguyễn Xuân Trường Lâm - Zero touch on-premise storage infrastru...
Room 3 - 1 - Nguyễn Xuân Trường Lâm - Zero touch on-premise storage infrastru...Vietnam Open Infrastructure User Group
 
Cluster-as-code. The Many Ways towards Kubernetes
Cluster-as-code. The Many Ways towards KubernetesCluster-as-code. The Many Ways towards Kubernetes
Cluster-as-code. The Many Ways towards KubernetesQAware GmbH
 
Kubernetes internals (Kubernetes 해부하기)
Kubernetes internals (Kubernetes 해부하기)Kubernetes internals (Kubernetes 해부하기)
Kubernetes internals (Kubernetes 해부하기)DongHyeon Kim
 
Kubernetes Networking
Kubernetes NetworkingKubernetes Networking
Kubernetes NetworkingCJ Cullen
 
Understanding kube proxy in ipvs mode
Understanding kube proxy in ipvs modeUnderstanding kube proxy in ipvs mode
Understanding kube proxy in ipvs modeVictor Morales
 
P4, EPBF, and Linux TC Offload
P4, EPBF, and Linux TC OffloadP4, EPBF, and Linux TC Offload
P4, EPBF, and Linux TC OffloadOpen-NFP
 

What's hot (20)

Introduction to kubernetes
Introduction to kubernetesIntroduction to kubernetes
Introduction to kubernetes
 
Terraform and Weave GitOps: Build a Fully Automated Application Stack
Terraform and Weave GitOps: Build a Fully Automated Application StackTerraform and Weave GitOps: Build a Fully Automated Application Stack
Terraform and Weave GitOps: Build a Fully Automated Application Stack
 
Open stack architecture overview-meetup-6-6_2013
Open stack architecture overview-meetup-6-6_2013Open stack architecture overview-meetup-6-6_2013
Open stack architecture overview-meetup-6-6_2013
 
Introduction to kubernetes
Introduction to kubernetesIntroduction to kubernetes
Introduction to kubernetes
 
Kubernetes - introduction
Kubernetes - introductionKubernetes - introduction
Kubernetes - introduction
 
Room 1 - 5 - Thủy Đặng - Load balancing k8s services on baremetal with Cilium...
Room 1 - 5 - Thủy Đặng - Load balancing k8s services on baremetal with Cilium...Room 1 - 5 - Thủy Đặng - Load balancing k8s services on baremetal with Cilium...
Room 1 - 5 - Thủy Đặng - Load balancing k8s services on baremetal with Cilium...
 
Let's talk about Failures with Kubernetes - Hamburg Meetup
Let's talk about Failures with Kubernetes - Hamburg MeetupLet's talk about Failures with Kubernetes - Hamburg Meetup
Let's talk about Failures with Kubernetes - Hamburg Meetup
 
Kubernetes Concepts And Architecture Powerpoint Presentation Slides
Kubernetes Concepts And Architecture Powerpoint Presentation SlidesKubernetes Concepts And Architecture Powerpoint Presentation Slides
Kubernetes Concepts And Architecture Powerpoint Presentation Slides
 
Room 1 - 4 - Phạm Tường Chiến & Trần Văn Thắng - Deliver managed Kubernetes C...
Room 1 - 4 - Phạm Tường Chiến & Trần Văn Thắng - Deliver managed Kubernetes C...Room 1 - 4 - Phạm Tường Chiến & Trần Văn Thắng - Deliver managed Kubernetes C...
Room 1 - 4 - Phạm Tường Chiến & Trần Văn Thắng - Deliver managed Kubernetes C...
 
An overview of the Kubernetes architecture
An overview of the Kubernetes architectureAn overview of the Kubernetes architecture
An overview of the Kubernetes architecture
 
Kubernetes Workshop
Kubernetes WorkshopKubernetes Workshop
Kubernetes Workshop
 
Room 1 - 3 - Lê Anh Tuấn - Build a High Performance Identification at GHTK wi...
Room 1 - 3 - Lê Anh Tuấn - Build a High Performance Identification at GHTK wi...Room 1 - 3 - Lê Anh Tuấn - Build a High Performance Identification at GHTK wi...
Room 1 - 3 - Lê Anh Tuấn - Build a High Performance Identification at GHTK wi...
 
Room 3 - 1 - Nguyễn Xuân Trường Lâm - Zero touch on-premise storage infrastru...
Room 3 - 1 - Nguyễn Xuân Trường Lâm - Zero touch on-premise storage infrastru...Room 3 - 1 - Nguyễn Xuân Trường Lâm - Zero touch on-premise storage infrastru...
Room 3 - 1 - Nguyễn Xuân Trường Lâm - Zero touch on-premise storage infrastru...
 
Kubernetes Basics
Kubernetes BasicsKubernetes Basics
Kubernetes Basics
 
Kubernetes networking & Security
Kubernetes networking & SecurityKubernetes networking & Security
Kubernetes networking & Security
 
Cluster-as-code. The Many Ways towards Kubernetes
Cluster-as-code. The Many Ways towards KubernetesCluster-as-code. The Many Ways towards Kubernetes
Cluster-as-code. The Many Ways towards Kubernetes
 
Kubernetes internals (Kubernetes 해부하기)
Kubernetes internals (Kubernetes 해부하기)Kubernetes internals (Kubernetes 해부하기)
Kubernetes internals (Kubernetes 해부하기)
 
Kubernetes Networking
Kubernetes NetworkingKubernetes Networking
Kubernetes Networking
 
Understanding kube proxy in ipvs mode
Understanding kube proxy in ipvs modeUnderstanding kube proxy in ipvs mode
Understanding kube proxy in ipvs mode
 
P4, EPBF, and Linux TC Offload
P4, EPBF, and Linux TC OffloadP4, EPBF, and Linux TC Offload
P4, EPBF, and Linux TC Offload
 

Similar to Network policy @ k8s day

Kubernetes Security with Calico and Open Policy Agent
Kubernetes Security with Calico and Open Policy AgentKubernetes Security with Calico and Open Policy Agent
Kubernetes Security with Calico and Open Policy AgentCloudOps2005
 
Kubernetes One-Click Deployment: Hands-on Workshop (Mainz)
Kubernetes One-Click Deployment: Hands-on Workshop (Mainz)Kubernetes One-Click Deployment: Hands-on Workshop (Mainz)
Kubernetes One-Click Deployment: Hands-on Workshop (Mainz)QAware GmbH
 
stackconf 2021 | Embracing change: Policy-as-code for Kubernetes with OPA and...
stackconf 2021 | Embracing change: Policy-as-code for Kubernetes with OPA and...stackconf 2021 | Embracing change: Policy-as-code for Kubernetes with OPA and...
stackconf 2021 | Embracing change: Policy-as-code for Kubernetes with OPA and...NETWAYS
 
Kerberos, Token and Hadoop
Kerberos, Token and HadoopKerberos, Token and Hadoop
Kerberos, Token and HadoopKai Zheng
 
Big Data Security with Hadoop
Big Data Security with HadoopBig Data Security with Hadoop
Big Data Security with HadoopCloudera, Inc.
 
PRO TALK - Kubernetes Security Workshop.pdf
PRO TALK - Kubernetes Security Workshop.pdfPRO TALK - Kubernetes Security Workshop.pdf
PRO TALK - Kubernetes Security Workshop.pdfAvinashDesireddy
 
Kubernetes Security Workshop
Kubernetes Security WorkshopKubernetes Security Workshop
Kubernetes Security WorkshopMirantis
 
How we can do Multi-Tenancy on Kubernetes
How we can do Multi-Tenancy on KubernetesHow we can do Multi-Tenancy on Kubernetes
How we can do Multi-Tenancy on KubernetesOpsta
 
Opa gatekeeper
Opa gatekeeperOpa gatekeeper
Opa gatekeeperRita Zhang
 
Evolution of security strategies in K8s environments- All day devops
Evolution of security strategies in K8s environments- All day devops Evolution of security strategies in K8s environments- All day devops
Evolution of security strategies in K8s environments- All day devops Jose Manuel Ortega Candel
 
Scientific Computing @ Fred Hutch
Scientific Computing @ Fred HutchScientific Computing @ Fred Hutch
Scientific Computing @ Fred HutchDirk Petersen
 
Building a Kubernetes cluster for a large organisation 101
Building a Kubernetes cluster for a large organisation 101Building a Kubernetes cluster for a large organisation 101
Building a Kubernetes cluster for a large organisation 101Ed Schouten
 
[Call for code] IBM 블록체인을 활용하여 투명하게 구호기금 관리하기 - Hyperledger Fabric v1.1 by 맹개발
[Call for code] IBM 블록체인을 활용하여 투명하게 구호기금 관리하기 - Hyperledger Fabric v1.1 by 맹개발 [Call for code] IBM 블록체인을 활용하여 투명하게 구호기금 관리하기 - Hyperledger Fabric v1.1 by 맹개발
[Call for code] IBM 블록체인을 활용하여 투명하게 구호기금 관리하기 - Hyperledger Fabric v1.1 by 맹개발 Yunho Maeng
 
Kubernetes at (Organizational) Scale
Kubernetes at (Organizational) ScaleKubernetes at (Organizational) Scale
Kubernetes at (Organizational) ScaleJeff Zellner
 
JDO 2019: What you should be aware of before setting up kubernetes on premise...
JDO 2019: What you should be aware of before setting up kubernetes on premise...JDO 2019: What you should be aware of before setting up kubernetes on premise...
JDO 2019: What you should be aware of before setting up kubernetes on premise...PROIDEA
 
Building a dev pipeline using GitHub Actions, Node.js, and AWS ECS Fargate
Building a dev pipeline using GitHub Actions, Node.js, and AWS ECS FargateBuilding a dev pipeline using GitHub Actions, Node.js, and AWS ECS Fargate
Building a dev pipeline using GitHub Actions, Node.js, and AWS ECS Fargatedatree
 
"Enabling Googley microservices with gRPC" VoxxedDays Minsk edition
"Enabling Googley microservices with gRPC" VoxxedDays Minsk edition"Enabling Googley microservices with gRPC" VoxxedDays Minsk edition
"Enabling Googley microservices with gRPC" VoxxedDays Minsk editionAlex Borysov
 
"Enabling Googley microservices with gRPC" Riga DevDays 2018 edition
"Enabling Googley microservices with gRPC" Riga DevDays 2018 edition"Enabling Googley microservices with gRPC" Riga DevDays 2018 edition
"Enabling Googley microservices with gRPC" Riga DevDays 2018 editionAlex Borysov
 
Operating PostgreSQL at Scale with Kubernetes
Operating PostgreSQL at Scale with KubernetesOperating PostgreSQL at Scale with Kubernetes
Operating PostgreSQL at Scale with KubernetesJonathan Katz
 

Similar to Network policy @ k8s day (20)

Kubernetes Security with Calico and Open Policy Agent
Kubernetes Security with Calico and Open Policy AgentKubernetes Security with Calico and Open Policy Agent
Kubernetes Security with Calico and Open Policy Agent
 
Kubernetes One-Click Deployment: Hands-on Workshop (Mainz)
Kubernetes One-Click Deployment: Hands-on Workshop (Mainz)Kubernetes One-Click Deployment: Hands-on Workshop (Mainz)
Kubernetes One-Click Deployment: Hands-on Workshop (Mainz)
 
stackconf 2021 | Embracing change: Policy-as-code for Kubernetes with OPA and...
stackconf 2021 | Embracing change: Policy-as-code for Kubernetes with OPA and...stackconf 2021 | Embracing change: Policy-as-code for Kubernetes with OPA and...
stackconf 2021 | Embracing change: Policy-as-code for Kubernetes with OPA and...
 
Kerberos, Token and Hadoop
Kerberos, Token and HadoopKerberos, Token and Hadoop
Kerberos, Token and Hadoop
 
Big Data Security with Hadoop
Big Data Security with HadoopBig Data Security with Hadoop
Big Data Security with Hadoop
 
PRO TALK - Kubernetes Security Workshop.pdf
PRO TALK - Kubernetes Security Workshop.pdfPRO TALK - Kubernetes Security Workshop.pdf
PRO TALK - Kubernetes Security Workshop.pdf
 
Kubernetes Security Workshop
Kubernetes Security WorkshopKubernetes Security Workshop
Kubernetes Security Workshop
 
How we can do Multi-Tenancy on Kubernetes
How we can do Multi-Tenancy on KubernetesHow we can do Multi-Tenancy on Kubernetes
How we can do Multi-Tenancy on Kubernetes
 
Intro to kubernetes
Intro to kubernetesIntro to kubernetes
Intro to kubernetes
 
Opa gatekeeper
Opa gatekeeperOpa gatekeeper
Opa gatekeeper
 
Evolution of security strategies in K8s environments- All day devops
Evolution of security strategies in K8s environments- All day devops Evolution of security strategies in K8s environments- All day devops
Evolution of security strategies in K8s environments- All day devops
 
Scientific Computing @ Fred Hutch
Scientific Computing @ Fred HutchScientific Computing @ Fred Hutch
Scientific Computing @ Fred Hutch
 
Building a Kubernetes cluster for a large organisation 101
Building a Kubernetes cluster for a large organisation 101Building a Kubernetes cluster for a large organisation 101
Building a Kubernetes cluster for a large organisation 101
 
[Call for code] IBM 블록체인을 활용하여 투명하게 구호기금 관리하기 - Hyperledger Fabric v1.1 by 맹개발
[Call for code] IBM 블록체인을 활용하여 투명하게 구호기금 관리하기 - Hyperledger Fabric v1.1 by 맹개발 [Call for code] IBM 블록체인을 활용하여 투명하게 구호기금 관리하기 - Hyperledger Fabric v1.1 by 맹개발
[Call for code] IBM 블록체인을 활용하여 투명하게 구호기금 관리하기 - Hyperledger Fabric v1.1 by 맹개발
 
Kubernetes at (Organizational) Scale
Kubernetes at (Organizational) ScaleKubernetes at (Organizational) Scale
Kubernetes at (Organizational) Scale
 
JDO 2019: What you should be aware of before setting up kubernetes on premise...
JDO 2019: What you should be aware of before setting up kubernetes on premise...JDO 2019: What you should be aware of before setting up kubernetes on premise...
JDO 2019: What you should be aware of before setting up kubernetes on premise...
 
Building a dev pipeline using GitHub Actions, Node.js, and AWS ECS Fargate
Building a dev pipeline using GitHub Actions, Node.js, and AWS ECS FargateBuilding a dev pipeline using GitHub Actions, Node.js, and AWS ECS Fargate
Building a dev pipeline using GitHub Actions, Node.js, and AWS ECS Fargate
 
"Enabling Googley microservices with gRPC" VoxxedDays Minsk edition
"Enabling Googley microservices with gRPC" VoxxedDays Minsk edition"Enabling Googley microservices with gRPC" VoxxedDays Minsk edition
"Enabling Googley microservices with gRPC" VoxxedDays Minsk edition
 
"Enabling Googley microservices with gRPC" Riga DevDays 2018 edition
"Enabling Googley microservices with gRPC" Riga DevDays 2018 edition"Enabling Googley microservices with gRPC" Riga DevDays 2018 edition
"Enabling Googley microservices with gRPC" Riga DevDays 2018 edition
 
Operating PostgreSQL at Scale with Kubernetes
Operating PostgreSQL at Scale with KubernetesOperating PostgreSQL at Scale with Kubernetes
Operating PostgreSQL at Scale with Kubernetes
 

Recently uploaded

🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 

Recently uploaded (20)

🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 

Network policy @ k8s day

  • 1. 共享 x 安全 = NetworkPolicy ? 施嘉峻 (ccshih) iiiccshih@gmail.com Presented at iThome Kubernetes Day, Sep 20, 2017
  • 2. About Me @ ccshih # Kubernetes # OpenShift + Red Hat Certificate of Expertise in Platform-as-a-Service (OpenShift Admin) 2
  • 3. Agenda • Share x Security @ k8s 1.7 (p. 4) • Network Policies (p. 6) • Use cases • How to • Limitations • Adoption Advices (p. 18) • Looking Forward (p. 22) • Takeaway (p. 25) 3 3 cases 1 advice 2 promising tech
  • 4. Share x Security @ k8s 1.7 Network Policies (Beta from 1.6) RBAC Namespace (GA from 1.7) Virtual cluster Multiple teams or projects Scope of control Role-Based Access Control Attach permissions to roles Bind roles to users Control pods incoming connection Based on Labels Project A Project B Namespace Namespace Pod Pod Admin Role User Role ? 4 *Also matters: Resource Quota, Pod Security Policies 允入
  • 5. Use Labels to Organize Objects 5 tier=frontend (key-value pairs) tier=backend tier=database env=dev env=qa env=staging env=prod release=stable release=canary Pod Labels … env=prod tier=frontend release=stable env=prod Namespace
  • 6. First Scenario 6 Pod Pod Pod Pod Pod Pod tier=frontend tier=backend tier=database Namespace b PodPod PodPod Namespace a
  • 7. Without Network Policy (k8s default) 7 Pod Pod Pod Pod Pod Pod tier=frontend tier=backend tier=database Namespace b PodPod PodPod Namespace a Pod accepts any connection from any namespace
  • 8. Network Policy Use Case (1) 8 Pod Pod Pod Pod Pod Pod tier=frontend tier=backend tier=database Namespace b PodPod PodPod Namespace a
  • 9. apiVersion: networking.k8s.io/v1 kind: NetworkPolicy metadata: name: allow-backend-access-database namespace: b spec: podSelector: matchLabels: tier: database ingress: - from: - podSelector: matchLabels: tier: backend ports: - protocol: TCP port: 3306 Network Policy Example (1) 9 This policy applies to … Allows connection from … to this port Pod Pod Pod Pod Pod Pod tier=frontend tier=backend tier=database Namespace b PodPod PodPod Namespace a
  • 10. Policy: Network Policy Rules • If no policy applied to a pod • Allow connection from any source • If any policy applied to a pod • Whitelist: Deny all incoming connections, unless source satisfies at least one policies 10 PodPod Pod PodPod Pod No Policy applied Policy:
  • 11. Network Policy Use Case (2) 11 Pod Pod Pod Pod Pod tier=frontend tier=backend tier=database PodPod PodPod release=canary release=stable Namespace b
  • 12. Network Policy Example (2) apiVersion: networking.k8s.io/v1 kind: NetworkPolicy metadata: name: allow-canary-backend-access-database namespace: b spec: podSelector: matchLabels: tier: database release: stable ingress: - from: - podSelector: matchLabels: tier: backend ports: - protocol: TCP port: 3306 12 This policy applies to … Allows connection from … to this port Pod Pod Pod Pod Pod tier=frontend tier=backend tier=database PodPod PodPod release=canary release=stable Namespace b (AND) in the same selector
  • 13. Network Policy Non-Use Case 13 Pod Pod Pod Pod Pod tier=frontend tier=backend tier=database PodPod PodPod Namespace b-plus Namespace b
  • 14. Network Policy Non-Example apiVersion: networking.k8s.io/v1 kind: NetworkPolicy metadata: namespace: b … … ingress: - from: - podSelector: matchLabels: tier: backend - namespaceSelector: matchLabels: name: b-plus ports: - protocol: TCP port: 3306 14 Allows connection from …(OR) Pod Pod Pod Pod Pod tier=frontend tier=backend tier=database PodPod PodPod Namespace b-plus Namespace b Need (AND), but NOT supported yet* * https://github.com/kubernetes/kubernetes/issues/50451 in different selector
  • 15. Network Policy Limitation in K8s 1.7 • A selector can not match both Namespace labels and Pod labels • No Egress Policy • What if your pods are compromised? • Prerequisite: Need support of Container Network Providers 15 Pod (Ingress) (Egress)
  • 16. Network Providers who Support Network Policy 16 Calico cilium ROMANA WeaveNet &
  • 17. Note: • Not standard k8s Network Policy • Run with calicoctl, instead of kubectl • Calico also supports Egress policy (not shown here) Calico’s Policy Definition 17 Pod Pod Pod Pod Pod tier=frontend tier=backend tier=database PodPod PodPod Namespace b-plus Namespace bapiVersion: v1 kind: policy metadata: name: allow-b-plus-backend-access-b-database spec: selector: > calico/k8s_ns == 'b' && tier == 'database' ingress: - action: allow source: selector: > calico/k8s_ns == 'b-plus' && tier == 'backend' protocol: tcp destination: ports: [3306] # calicoctl apply -f <FILENAME>
  • 19. Adoption Advices • (skipped) Use special labels for network policy • Rethink IP-based packet filter 19
  • 20. Dynamic Nature of K8s 20 Source: https://www.slideshare.net/gmccance/cern-data-centre-evolution K8s is primarily designed for (Static) (Dynamic) (change IP)
  • 21. Rethink IP-based packet filter • Pod up/down triggers firewall rule adjustment • Translate application-level policy to network-level policy • Given that Firewall can recognize pod IP 21 IP Source Labels Destination Labels IP IP IP IP IP IP IP IP-based Firewall rules Application-level Policy change frequently
  • 23. Looking forward (1) • Cilium • Not use IP to define filter • Flexible and Efficient 23 IP Source Labels Destination Labels IP IP IP IP IP IP IP eBPF (Packet Filter) Application-level Policy change frequently (Require Linux Kernel 4.8 ↑) id id
  • 24. Looking forward (2) 24 • Istio • Each service pod equips with a sidecar container (envoy), which enforces policy Source: https://github.com/istio/auth
  • 26. Takeaway • By default, pod can talk to each other at network level • Network Policy • whitelists pod incoming connection • needs container network provider’s support • can not apply to some cross-namespace scenario • Adoption • security needs as agile as containers • Looking forward • Flavored policy enforcement 26
  • 28. References • Network Policy • Official document • Recipes by ahmetb • Calico • Getting started with k8s 28

Editor's Notes

  1. 檔入口
  2. 檔入口
  3. 檔入口
  4. 乖乖, Cattle, 抓交替, 消耗品, 動態, 變化的 IP