CNP: User stories + Samples
NOTE: This powerpoint is meant to be viewed in accordance with the following google doc for completeness
User Stories:
The following is a list of the main user stories CNP is being designed to cover.
All Diagram sources can be found here
Global Assumptions
Use cases for Cluster Network Policy
Solutions considered
Notes on current vendor Cluster network policies
A: “Non-explicit priority”
B: “Priority Ordering”
A: “Non-explicit priority”
B: “Priority Ordering”
Contd .. from prior slide
Contd from prior slide
User Story Samples
Notes for non-explicit Priority based samples
Notes for Priority based samples
1a. Isolate Pods carrying sensitive data from Namespace named “sensitive-ns” from all other Namespaces.
1a
foo-ns-1
foo-ns-2
bar-ns-1
kube-system
sensitive-ns
foo-pod
foo-pod
foo-pod
bar-pod
bar-pod
sensitive
kube-dns
svc-pub
Non-overridable DENY
Dropped traffic
1a: Non-explicit Priority (Empower, Deny, Allow)
apiVersion: netpol.networking.k8s.io/v1alpha1�kind: ClusterNetworkPolicy�metadata:� name: strict-deny�spec:� appliedTo: // applies to Pods carrying sensitive data in namespace “Sensitive-ns”� namespaceSelector: matchLabels: kubernetes.io/metadata.name: sensitive-ns podSelector: matchLabels: type: sensitive� ingress:� - from: - namespaceSelector: {} action: Deny egress:� - to: - namespaceSelector: {} action: Deny
|
|
1a: Explicit Priority Ordering
// Deny for Sensitive namespace, must be highest priority in cluster to �// ensure sensitive ns is adequately isolated�apiVersion: netpol.networking.k8s.io/v1alpha1�kind: ClusterNetworkPolicy�metadata:� name: strict-deny�spec:� priority: 100� appliedTo:� // applies to sensitive-ns� namespaceSelector:� matchLabels:� kubernetes.io/metadata.name: sensitive-ns� ingress:� // Rules to strictly deny traffic from all other Namespaces� - from:� - namespaceSelector: {}� action: Deny egress: - to: - namespaceSelector: {} action: Deny
|
|
2a. Allow traffic to/from kube-dns Pods from kube-system Namespace and allow system monitoring namespace.
2a
Allowed traffic
Allowed traffic
foo-ns-1
foo-ns-2
bar-ns-1
kube-system
foo-pod
foo-pod
foo-pod
bar-pod
bar-pod
kube-dns
svc-pub
Monitoring-ns
2a: Non-explicit Priority (Empower, Deny, Allow)
// make sure all pods kube-system and the Monitoring ns can talk to all �// other namespaces // there should be no Deny policy for this traffic apiVersion: netpol.networking.k8s.io/v1alpha1�kind: ClusterNetworkPolicy�metadata:� name: allow-system�spec:� appliedTo: // applies to all Namespaces� namespaceSelector: {}� ingress:� - action: Allow from: // allow from system namespaces - namespaceSelector: matchExpressions: - {Key: kubernetes.io/metadata.name, Operator: In, Values: [“kube-system”, “monitoring-ns”]}
|
|
// allow from kube-dns pods - namespaceSelector: matchLabels: kubernetes.io/metadata.name: kube-system podSelector: matchLabels: app: kube-dns egress:� - action: Allow to: // allow to system namespaces - namespaceSelector: matchLabels: kubernetes.io/metadata.name: monitoring-ns // allow to kube-dns pods - namespaceSelector: matchLabels: kubernetes.io/metadata.name: kube-system podSelector: matchLabels: app: kube-dns |
|
2a: Non-explicit Priority (Empower, Deny, Allow)
apiVersion: netpol.networking.k8s.io/v1alpha1�kind: ClusterNetworkPolicy�metadata:� name: allow-to-all�spec:� appliedTo: // applies to system namespaces� namespaceSelector: matchLabels: kubernetes.io/metadata.name: monitoring-ns� ingress:� - action: Allow from: // allow from all namespaces - namespaceSelector: {} egress:� - action: Allow to: // allow to all namespaces - namespaceSelector: {}
|
|
|
|
2a: Explicit Priority ordering
// make sure all pods kube-system and the Monitoring ns can talk to all �// other namespaces // must be highest priority to ensure traffic is always allowed�apiVersion: netpol.networking.k8s.io/v1alpha1�kind: ClusterNetworkPolicy�metadata:� name: allow-system�spec:� priority: 100� appliedTo:� // applies to all Namespaces� namespaceSelector: {}� ingress:� // Allow from kube-dns pods and monitoring pods� - from:� - namespaceSelector:� matchLabels:� kubernetes.io/metadata.name: kube-system� podSelector:� matchLabels: app: kube-dns� action: allow
|
|
- namespaceSelector: matchExpressions: - {Key: kubernetes.io/metadata.name, Operator: In, Values: [“kube-system”, “monitoring-ns”]} egress:� // Allow to kube-dns pods and monitoring pods� - to:� - namespaceSelector:� matchLabels:� kubernetes.io/metadata.name: kube-system� podSelector:� matchLabels: app:kube-dns� action: allow - namespaceSelector: matchExpressions: - {Key: kubernetes.io/metadata.name, Operator: In, Values: [“kube-system”, “monitoring-ns”]} |
|
3a. Strictly deny inter-tenant traffic but strictly allow traffic from system Namespace monitoring and kube-dns Pods
Please see additional Document for YAML Samples
4a. Strictly deny inter-tenant traffic but delegate public Service (backed by Pods labeled “app: svc-pub” from Namespace “bar-ns-1”)
4a
Tenant Bar Namespace
foo-ns-1
foo-ns-2
bar-ns-1
foo-pod
foo-pod
foo-pod
bar-pod
bar-pod
svc-pub
Tenant Foo Namespaces
Tenant Bar Namespaces
overridable DENY
Non-overridable DENY
“Delegate”: Exceptions to Deny. Tenants discretion to allow/deny traffic
Allowed traffic
“Delegate”: Exceptions to Deny. Tenants discretion to allow/deny traffic
Allowed traffic
Dropped traffic
4a
foo-ns-1
foo-ns-2
bar-ns-1
foo-pod
foo-pod
foo-pod
bar-pod
bar-pod
svc-pub
overridable DENY
Non-overridable DENY
“Delegate”: Exceptions to Deny. Tenants discretion to allow/deny traffic
Allowed traffic
“Delegate”: Exceptions to Deny. Tenants discretion to allow/deny traffic
Allowed traffic
Dropped traffic
4a: Non-explicit Priority (Empower, Deny, Allow)
apiVersion: netpol.networking.k8s.io/v1alpha1�kind: ClusterNetworkPolicy�metadata:� name: delegate-svc-pub�spec: appliedTo: // applies to all tenant Namespaces� namespaceSelector: matchExpressions: - {Key: tenant, Operator: Exists} ingress:� - action: Empower from: // skip from public svc - namespaceSelector: matchLabels: kubernetes.io/metadata.name: bar podSelector: matchLabels: app: svc-pub
|
|
// skip intra-tenant - namespaces: scope: SameLabels labels: [“tenant”] - action: Deny from: // drop from all other namespaces. This can be replaced by using NotSameLabels Namespaces scope. - namespaceSelector: {} egress:� - action: Empower to: // skip to public svc - namespaceSelector: matchLabels: kubernetes.io/metadata.name: bar podSelector: matchLabels: app: svc-pub // skip intra-tenant - namespaces: scope: SameLabels labels: [“tenant”] - action: Deny to: // drop to all other namespaces. This can be replaced by using NotSameLabels Namespaces scope. - namespaceSelector: {} |
|
4a: Non-explicit Priority (Empower, Deny, Allow) cont
apiVersion: netpol.networking.k8s.io/v1alpha1�kind: ClusterNetworkPolicy�metadata:� name: allow-svc-pub�spec:� appliedTo: // applies to svc-pub Pods� namespaceSelector: matchLabels: kubernetes.io/metadata.name: bar podSelector: matchLabels: app: svc-pub� ingress:� - action: Empower from: // allow from all namespaces - namespaceSelector: {} egress:� - action: Empower to: // allow to all namespaces - namespaceSelector: {}
|
|
4a: Explicit Priority ordering
apiVersion: netpol.networking.k8s.io/v1alpha1�kind: ClusterNetworkPolicy�metadata:� name: inter-tenant-deny�spec:� appliedTo:� namespaceSelector: matchLabels: type: tenant� priority: 10 Ingress: // Rules listed in order of priority // Explicitly skip/ delegate traffic from pub-svc - from: namespaceSelector: matchLabels: tenant: bar podSelector: matchLabels: app: svc-pub action: Pass
|
|
// Deny traffic from other tenant namespaces (tenant label not same) // traffic from same-tenant falls through delegated to netpol - from: namespaces: scope: NotSameLabels labels: [“tenant”] action: Deny Egress: - to: namespaceSelector: matchLabels: tenant: bar podSelector: matchLabels: app: svc-pub action: Pass |
|
4a: Explicit Priority ordering cont.
apiVersion: netpol.networking.k8s.io/v1alpha1�kind: ClusterNetworkPolicy�metadata:� name: allow-svc-pub�spec:� appliedTo: // applies to svc-pub Pods� namespaceSelector: matchLabels: tenant: bar podSelector: matchLabels: app: svc-pub� priority: 10 ingress:� - from: // allow from all namespaces namespaceSelector: {} action: pass egress:� - to: // allow to all namespaces namespaceSelector: {} action: pass
|
|
|
|
5a. What happens when delegated intra-ns traffic is not handled by Namespace owner. Default deny or allow?
5a
Tenant Bar Namespace
foo-ns-1
foo-ns-2
bar-ns-1
foo-pod
foo-pod
foo-pod
bar-pod
bar-pod
svc-pub
Tenant Foo Namespaces
Tenant Bar Namespace
overridable DENY
“Delegate”: Exceptions to Deny. Tenants discretion to allow/deny traffic
“Delegate”: Exceptions to Deny. Tenants discretion to allow/deny traffic
Dropped traffic
5a: Non-explicit Priority (Empower, Deny, Allow)
apiVersion: netpol.networking.k8s.io/v1alpha1�kind: ClusterNetworkPolicy�metadata:� name: delegate-intra-tenant�spec:� appliedTo: // applies to all tenant Namespaces� namespaceSelector: matchExpressions: - {Key: tenant, Operator: Exists}� ingress:� - action: Empower from: // skip intra-tenant - namespaces: scope: SameLabels labels: [“tenant”] - action: Deny from: // drop from all other namespaces. This can be replaced by using NotSameLabels Namespaces scope. - namespaceSelector: {}
|
|
egress:� - action: Empower to: // skip intra-tenant - namespaces: scope: SameLabels labels: [“tenant”] - action: Deny to: // drop to all other namespaces. This can be replaced by using NotSameLabels Namespaces scope. - namespaceSelector: {} |
|
5a: Non-explicit Priority (Empower, Deny, Allow) cont.
apiVersion: netpol.networking.k8s.io/v1alpha1�kind: ClusterDefaultNetworkPolicy�metadata:� name: default-deny�spec:� appliedTo: // applies to all tenant Namespaces� namespaceSelector: matchExpressions: - {Key: tenant, Operator: Exists}� ingress: egress: |
|
|
|
5a: Explicit Priority ordering
apiVersion: netpol.networking.k8s.io/v1alpha1�kind: ClusterNetworkPolicy�metadata:� name: inter-tenant-deny�spec:� appliedTo:� namespaceSelector: matchLabels: type: tenant� priority: 10 Ingress: // Deny traffic from other tenant namespaces (tenant label not same) // traffic from same-tenant falls through delegated to netpol - from: namespaces: scope: NotSameLabels labels: tenant action: Deny Egress: - to: namespaces: scope: NotSameLabels labels: tenant action: Deny |
|
5a: Explicit Priority ordering cont.
apiVersion: netpol.networking.k8s.io/v1alpha1�kind: ClusterNetworkPolicy�metadata:� name: default-overridable-by-tenant �spec:� appliedTo:� namespaceSelector: matchLabels: type: tenant // Default policy hence priority 0 priority: 0 Ingress: - from: namespaces: scope: SameLabels labels: tenant action: Deny Egress: - to: namespaces: scope: SameLabels labels: tenant action: Deny |
|
5b. Default deny rules to for the cluster when no CNP or K8s NP rules apply
5b: Non-explicit priority (Empower, Deny, Allow)
apiVersion: netpol.networking.k8s.io/v1alpha1�kind: ClusterDefaultNetworkPolicy�metadata:� name: default-cluster-policy�spec:� appliedTo: // applies to all tenant Namespaces� namespaceSelector: matchLabels: type: tenant� ingress: egress: |
|
5b: Explicit Priority ordering
apiVersion: netpol.networking.k8s.io/v1alpha1�kind: ClusterNetworkPolicy�metadata:� name: default-overridable-by-tenant �spec:� appliedTo:� namespaceSelector: matchLabels: type: tenant // Default policy hence priority 0 priority: 0 Ingress: - from: namespaces: scope: SameLabels labels: tenant action: Deny Egress: - to: namespaces: scope: SameLabels labels: tenant action: Deny |
|
7. Extensibility: Consider a future IPBlock selector, loggingPolicy
7: Extensibility: IPBlock selector in future
apiVersion: netpol.networking.k8s.io/v1alpha1�kind: ClusterNetworkPolicy�metadata:� name: cnp-with-ipblock�spec:� appliedTo: // applies to all tenant Namespaces� namespaceSelector: matchLabels: type: tenant� egress:� - action: Empower // Rules to skip public Svc from strict deny rules to: - podSelector: matchLabels: app: pub-svc - ipBlock: cidr: 10.0.10.0/24 - ipBlock: cidr: 10.0.50.0/24 |
|
// Rules to strictly deny traffic to all other Namespaces - action: Deny to: - namespaceSelector: {} - ipBlock: cidr: 10.0.0.0/16 - action: Allow to: - ipBlock: cidr: 10.0.10.0/24 |
|
8. Deny inter-tenant and sensitive-ns traffic but strictly allow traffic to coreDNS Pods and system monitoring namespace AND delegate traffic to public service to developers.
8a
Tenant Bar Namespace
foo-ns-1
foo-ns-2
bar-ns-1
foo-pod
foo-pod
foo-pod
bar-pod
bar-pod
svc-pub
Tenant Foo Namespaces
Tenant Bar Namespaces
kube-system
sensitive-ns
sensitive
kube-dns
Monitoring-ns
overridable DENY
Non-overridable DENY
“Delegate”: Exceptions to Deny. Tenants discretion to allow/deny traffic
Allowed traffic
“Delegate”: Exceptions to Deny. Tenants discretion to allow/deny traffic
Allowed traffic
Dropped traffic
Please see additional Document for YAML Samples
Additional Notes
Notes on alternate simplified model
Precedence model
6: Cluster external: All or none
apiVersion: netpol.networking.k8s.io/v1alpha1�kind: ClusterNetworkPolicy�metadata:� name: deny-all�spec:� appliedTo: // applies to all tenant Namespaces� namespaceSelector: matchLabels: type: tenant� ingress: action: Deny egress: action: Deny |
|
apiVersion: netpol.networking.k8s.io/v1alpha1�kind: ClusterNetworkPolicy�metadata:� name: allow-all�spec:� appliedTo: // applies to all tenant Namespaces� namespaceSelector: matchLabels: type: tenant� ingress: action: Allow egress: action: Allow |
|
6. Cluster external: All or nothing for external traffic