Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

don't remove representative peers in any-namespace #352

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions pkg/netpol/connlist/connlist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -940,4 +940,17 @@ var goodPathTests = []struct {
exposureAnalysis: true,
outputFormats: ExposureValidFormats,
},
{
// following test resources : contains two pods in different namespaces, and two policies, one for each namespace
// first policy captures: hello-world/workload-a and exposes it on Ingress to all pods in backend namespace
// second policy captures: backend/backend-app and denies all egress from it
// so as result hello-world/workload-a is actually exposed to all backend pods except for backend-app
// @TODO: following exposure line in output :
// `hello-world/workload-a[Deployment] <= backend/[all pods] : TCP 8050`
// should be replaced with :
// `hello-world/workload-a[Deployment] <= backend/[all pods except backend/backend-app] : TCP 8050`
adisos marked this conversation as resolved.
Show resolved Hide resolved
testDirName: "test_exposure_to_namespace_except_specific_pod",
exposureAnalysis: true,
outputFormats: ExposureValidFormats,
},
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
digraph {
subgraph "cluster_backend" {
color="black"
fontcolor="black"
"all pods_in_backend" [label="all pods" color="red2" fontcolor="red2"]
"backend/backend-app[Deployment]" [label="backend-app[Deployment]" color="blue" fontcolor="blue"]
label="backend"
}
subgraph "cluster_hello_world" {
color="black"
fontcolor="black"
"hello-world/workload-a[Deployment]" [label="workload-a[Deployment]" color="blue" fontcolor="blue"]
label="hello-world"
}
"0.0.0.0-255.255.255.255" [label="0.0.0.0-255.255.255.255" color="red2" fontcolor="red2"]
"entire-cluster" [label="entire-cluster" color="red2" fontcolor="red2" shape=diamond]
"0.0.0.0-255.255.255.255" -> "backend/backend-app[Deployment]" [label="All Connections" color="gold2" fontcolor="darkgreen"]
"all pods_in_backend" -> "hello-world/workload-a[Deployment]" [label="TCP 8050" color="gold2" fontcolor="darkgreen" weight=1]
"entire-cluster" -> "backend/backend-app[Deployment]" [label="All Connections" color="gold2" fontcolor="darkgreen" weight=1]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
0.0.0.0-255.255.255.255 => backend/backend-app[Deployment] : All Connections

Exposure Analysis Result:

Ingress Exposure:
backend/backend-app[Deployment] <= 0.0.0.0-255.255.255.255 : All Connections
backend/backend-app[Deployment] <= entire-cluster : All Connections
hello-world/workload-a[Deployment] <= backend/[all pods] : TCP 8050

Workloads not protected by network policies:
backend/backend-app[Deployment] is not protected on Ingress
40 changes: 40 additions & 0 deletions tests/test_exposure_to_namespace_except_specific_pod/backend.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: backend-app
namespace: backend
spec:
selector:
matchLabels:
app: backend-app
template:
metadata:
labels:
app: backend-app
spec:
containers:
- name: server
image: backend-app
ports:
- containerPort: 9090
readinessProbe:
initialDelaySeconds: 10
httpGet:
path: "/_healthz"
port: 9090
livenessProbe:
initialDelaySeconds: 10
httpGet:
path: "/_healthz"
port: 9090
env:
- name: PORT
value: "9090"
resources:
requests:
cpu: 100m
memory: 64Mi
limits:
cpu: 200m
memory: 128Mi
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# this policy denies any egress from backend/backend-app
# however hello_world_netpol.yaml allows ingress to hello-world/workload-a from all pods in backend
# so the result we should see is that hello-world/workload-a is exposed on Ingress to backend/[all pods except backend-app]

kind: NetworkPolicy
apiVersion: networking.k8s.io/v1
metadata:
name: deny-egress-from-backend-app
namespace: backend
spec:
podSelector:
matchLabels:
app: backend-app
policyTypes:
- Egress
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
kind: NetworkPolicy
apiVersion: networking.k8s.io/v1
metadata:
name: allow-ingress-to-backend-ns
namespace: hello-world
spec:
podSelector:
matchLabels:
app: a-app
policyTypes:
- Ingress
- Egress
ingress:
- from:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: backend
ports:
- port: 8050
protocol: TCP
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
apiVersion: v1
kind: Namespace
metadata:
name: hello-world
spec: {}
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: workload-a
namespace: hello-world
labels:
app: a-app
spec:
selector:
matchLabels:
app: a-app
template:
metadata:
labels:
app: a-app
spec:
containers:
- name: hello-world
image: quay.io/shfa/hello-world:latest
ports:
- containerPort: 8000 # containerport1
- containerPort: 8050 # containerport2
- containerPort: 8090 # containerport3
---