Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 7 additions & 2 deletions pkg/render/common/networkpolicy/k8snetworkpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,13 @@ func K8sDNSEgressRules(openShift bool) []netv1.NetworkPolicyEgressRule {
To: []netv1.NetworkPolicyPeer{
{
PodSelector: &metav1.LabelSelector{
MatchLabels: map[string]string{
"k8s-app": "kube-dns",
MatchExpressions: []metav1.LabelSelectorRequirement{
{
Key: "k8s-app",
Operator: metav1.LabelSelectorOpIn,
// In most Kubernetes distros the label is for kube-dns, but in Canonical it is for codedns.
Values: []string{"kube-dns", "coredns"},
},
},
},
NamespaceSelector: &metav1.LabelSelector{
Expand Down
34 changes: 24 additions & 10 deletions pkg/render/common/networkpolicy/networkpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ func AppendDNSEgressRules(egressRules []v3.Rule, openShift bool) []v3.Rule {
Protocol: &UDPProtocol,
Destination: v3.EntityRule{
NamespaceSelector: "projectcalico.org/name == 'kube-system'",
Selector: "k8s-app == 'kube-dns'",
Ports: Ports(53),
// In most Kubernetes distros the label is for kube-dns, but in Canonical it is for codedns.
Selector: "k8s-app == 'kube-dns' || k8s-app == 'coredns'",
Ports: Ports(53),
},
})
}
Expand Down Expand Up @@ -138,16 +139,29 @@ func AppendServiceSelectorDNSEgressRules(egressRules []v3.Rule, openShift bool)
},
}...)
} else {
egressRules = append(egressRules, v3.Rule{
Action: v3.Allow,
Protocol: &UDPProtocol,
Destination: v3.EntityRule{
Services: &v3.ServiceMatch{
Namespace: "kube-system",
Name: "kube-dns",
// In most Kubernetes distros, the DNS service is kube-dns, but in Canonical it is coredns.
egressRules = append(egressRules, []v3.Rule{
{
Action: v3.Allow,
Protocol: &UDPProtocol,
Destination: v3.EntityRule{
Services: &v3.ServiceMatch{
Namespace: "kube-system",
Name: "kube-dns",
},
},
},
})
{
Action: v3.Allow,
Protocol: &UDPProtocol,
Destination: v3.EntityRule{
Services: &v3.ServiceMatch{
Namespace: "kube-system",
Name: "coredns",
},
},
},
}...)
}

return egressRules
Expand Down
2 changes: 1 addition & 1 deletion pkg/render/intrusion_detection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ var _ = Describe("Intrusion Detection rendering tests", func() {
Protocol: &networkpolicy.UDPProtocol,
Destination: v3.EntityRule{
NamespaceSelector: "projectcalico.org/name == 'kube-system'",
Selector: "k8s-app == 'kube-dns'",
Selector: "k8s-app == 'kube-dns' || k8s-app == 'coredns'",
Ports: networkpolicy.Ports(53),
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"protocol": "UDP",
"destination": {
"namespaceSelector": "projectcalico.org/name == 'kube-system'",
"selector": "k8s-app == 'kube-dns'",
"selector": "k8s-app == 'kube-dns' || k8s-app == 'coredns'",
"ports": [
53
]
Expand Down
2 changes: 1 addition & 1 deletion pkg/render/testutils/expected_policies/alertmanager.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"protocol": "UDP",
"destination": {
"namespaceSelector": "projectcalico.org/name == 'kube-system'",
"selector": "k8s-app == 'kube-dns'",
"selector": "k8s-app == 'kube-dns' || k8s-app == 'coredns'",
"ports": [
53
]
Expand Down
2 changes: 1 addition & 1 deletion pkg/render/testutils/expected_policies/apiserver.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"protocol": "UDP",
"destination": {
"namespaceSelector": "projectcalico.org/name == 'kube-system'",
"selector": "k8s-app == 'kube-dns'",
"selector": "k8s-app == 'kube-dns' || k8s-app == 'coredns'",
"ports": [
53
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"protocol": "UDP",
"destination": {
"namespaceSelector": "projectcalico.org/name == 'kube-system'",
"selector": "k8s-app == 'kube-dns'",
"selector": "k8s-app == 'kube-dns' || k8s-app == 'coredns'",
"ports": [
53
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"protocol": "UDP",
"destination": {
"namespaceSelector": "projectcalico.org/name == 'kube-system'",
"selector": "k8s-app == 'kube-dns'",
"selector": "k8s-app == 'kube-dns' || k8s-app == 'coredns'",
"ports": [
53
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"protocol": "UDP",
"destination": {
"namespaceSelector": "projectcalico.org/name == 'kube-system'",
"selector": "k8s-app == 'kube-dns'",
"selector": "k8s-app == 'kube-dns' || k8s-app == 'coredns'",
"ports": [
53
]
Expand Down
2 changes: 1 addition & 1 deletion pkg/render/testutils/expected_policies/dashboards.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"protocol": "UDP",
"destination": {
"namespaceSelector": "projectcalico.org/name == 'kube-system'",
"selector": "k8s-app == 'kube-dns'",
"selector": "k8s-app == 'kube-dns' || k8s-app == 'coredns'",
"ports": [
53
]
Expand Down
2 changes: 1 addition & 1 deletion pkg/render/testutils/expected_policies/dex.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
"protocol": "UDP",
"destination": {
"namespaceSelector": "projectcalico.org/name == 'kube-system'",
"selector": "k8s-app == 'kube-dns'",
"selector": "k8s-app == 'kube-dns' || k8s-app == 'coredns'",
"ports": [
53
]
Expand Down
2 changes: 1 addition & 1 deletion pkg/render/testutils/expected_policies/dns.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"destination": {}
}
],
"selector": "k8s-app == 'kube-dns'",
"selector": "k8s-app == 'kube-dns' || k8s-app == 'coredns'",
"types": [
"Ingress",
"Egress"
Expand Down
10 changes: 10 additions & 0 deletions pkg/render/testutils/expected_policies/dpi_managed.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@
}
}
},
{
"action": "Allow",
"protocol": "UDP",
"destination": {
"services": {
"namespace": "kube-system",
"name": "coredns"
}
}
},
{
"action": "Allow",
"protocol": "TCP",
Expand Down
10 changes: 10 additions & 0 deletions pkg/render/testutils/expected_policies/dpi_unmanaged.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@
}
}
},
{
"action": "Allow",
"protocol": "UDP",
"destination": {
"services": {
"namespace": "kube-system",
"name": "coredns"
}
}
},
{
"action": "Allow",
"protocol": "TCP",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"protocol": "UDP",
"destination": {
"namespaceSelector": "projectcalico.org/name == 'kube-system'",
"selector": "k8s-app == 'kube-dns'",
"selector": "k8s-app == 'kube-dns' || k8s-app == 'coredns'",
"ports": [
53
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
"protocol": "UDP",
"destination": {
"namespaceSelector": "projectcalico.org/name == 'kube-system'",
"selector": "k8s-app == 'kube-dns'",
"selector": "k8s-app == 'kube-dns' || k8s-app == 'coredns'",
"ports": [
53
]
Expand Down
2 changes: 1 addition & 1 deletion pkg/render/testutils/expected_policies/es-gateway.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
"protocol": "UDP",
"destination": {
"namespaceSelector": "projectcalico.org/name == 'kube-system'",
"selector": "k8s-app == 'kube-dns'",
"selector": "k8s-app == 'kube-dns' || k8s-app == 'coredns'",
"ports": [
53
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"protocol": "UDP",
"destination": {
"namespaceSelector": "projectcalico.org/name == 'kube-system'",
"selector": "k8s-app == 'kube-dns'",
"selector": "k8s-app == 'kube-dns' || k8s-app == 'coredns'",
"ports": [
53
]
Expand Down
2 changes: 1 addition & 1 deletion pkg/render/testutils/expected_policies/es-metrics.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"protocol": "UDP",
"destination": {
"namespaceSelector": "projectcalico.org/name == 'kube-system'",
"selector": "k8s-app == 'kube-dns'",
"selector": "k8s-app == 'kube-dns' || k8s-app == 'coredns'",
"ports": [
53
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"protocol": "UDP",
"destination": {
"namespaceSelector": "projectcalico.org/name == 'kube-system'",
"selector": "k8s-app == 'kube-dns'",
"selector": "k8s-app == 'kube-dns' || k8s-app == 'coredns'",
"ports": [
53
]
Expand Down
2 changes: 1 addition & 1 deletion pkg/render/testutils/expected_policies/guardian.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
"protocol": "UDP",
"destination": {
"namespaceSelector": "projectcalico.org/name == 'kube-system'",
"selector": "k8s-app == 'kube-dns'",
"selector": "k8s-app == 'kube-dns' || k8s-app == 'coredns'",
"ports": [
53
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"protocol": "UDP",
"destination": {
"namespaceSelector": "projectcalico.org/name == 'kube-system'",
"selector": "k8s-app == 'kube-dns'",
"selector": "k8s-app == 'kube-dns' || k8s-app == 'coredns'",
"ports": [
53
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"protocol": "UDP",
"destination": {
"namespaceSelector": "projectcalico.org/name == 'kube-system'",
"selector": "k8s-app == 'kube-dns'",
"selector": "k8s-app == 'kube-dns' || k8s-app == 'coredns'",
"ports": [
53
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"protocol": "UDP",
"destination": {
"namespaceSelector": "projectcalico.org/name == 'kube-system'",
"selector": "k8s-app == 'kube-dns'",
"selector": "k8s-app == 'kube-dns' || k8s-app == 'coredns'",
"ports": [
53
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"protocol": "UDP",
"destination": {
"namespaceSelector": "projectcalico.org/name == 'kube-system'",
"selector": "k8s-app == 'kube-dns'",
"selector": "k8s-app == 'kube-dns' || k8s-app == 'coredns'",
"ports": [
53
]
Expand Down
2 changes: 1 addition & 1 deletion pkg/render/testutils/expected_policies/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
"protocol": "UDP",
"destination": {
"namespaceSelector": "projectcalico.org/name == 'kube-system'",
"selector": "k8s-app == 'kube-dns'",
"selector": "k8s-app == 'kube-dns' || k8s-app == 'coredns'",
"ports": [
53
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"protocol": "UDP",
"destination": {
"namespaceSelector": "projectcalico.org/name == 'kube-system'",
"selector": "k8s-app == 'kube-dns'",
"selector": "k8s-app == 'kube-dns' || k8s-app == 'coredns'",
"ports": [
53
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"protocol": "UDP",
"destination": {
"namespaceSelector": "projectcalico.org/name == 'kube-system'",
"selector": "k8s-app == 'kube-dns'",
"selector": "k8s-app == 'kube-dns' || k8s-app == 'coredns'",
"ports": [
53
]
Expand Down
2 changes: 1 addition & 1 deletion pkg/render/testutils/expected_policies/linseed.json
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@
"protocol": "UDP",
"destination": {
"namespaceSelector": "projectcalico.org/name == 'kube-system'",
"selector": "k8s-app == 'kube-dns'",
"selector": "k8s-app == 'kube-dns' || k8s-app == 'coredns'",
"ports": [
53
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
"protocol": "UDP",
"destination": {
"namespaceSelector": "projectcalico.org/name == 'kube-system'",
"selector": "k8s-app == 'kube-dns'",
"selector": "k8s-app == 'kube-dns' || k8s-app == 'coredns'",
"ports": [
53
]
Expand Down
2 changes: 1 addition & 1 deletion pkg/render/testutils/expected_policies/manager.json
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
"protocol": "UDP",
"destination": {
"namespaceSelector": "projectcalico.org/name == 'kube-system'",
"selector": "k8s-app == 'kube-dns'",
"selector": "k8s-app == 'kube-dns' || k8s-app == 'coredns'",
"ports": [
53
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"protocol": "UDP",
"destination": {
"namespaceSelector": "projectcalico.org/name == 'kube-system'",
"selector": "k8s-app == 'kube-dns'",
"selector": "k8s-app == 'kube-dns' || k8s-app == 'coredns'",
"ports": [
53
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"protocol": "UDP",
"destination": {
"namespaceSelector": "projectcalico.org/name == 'kube-system'",
"selector": "k8s-app == 'kube-dns'",
"selector": "k8s-app == 'kube-dns' || k8s-app == 'coredns'",
"ports": [
53
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"protocol": "UDP",
"destination": {
"namespaceSelector": "projectcalico.org/name == 'kube-system'",
"selector": "k8s-app == 'kube-dns'",
"selector": "k8s-app == 'kube-dns' || k8s-app == 'coredns'",
"ports": [
53
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"protocol": "UDP",
"destination": {
"namespaceSelector": "projectcalico.org/name == 'kube-system'",
"selector": "k8s-app == 'kube-dns'",
"selector": "k8s-app == 'kube-dns' || k8s-app == 'coredns'",
"ports": [
53
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"protocol": "UDP",
"destination": {
"namespaceSelector": "projectcalico.org/name == 'kube-system'",
"selector": "k8s-app == 'kube-dns'",
"selector": "k8s-app == 'kube-dns' || k8s-app == 'coredns'",
"ports": [
53
]
Expand Down
2 changes: 1 addition & 1 deletion pkg/render/testutils/expected_policies/prometheus.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"protocol": "UDP",
"destination": {
"namespaceSelector": "projectcalico.org/name == 'kube-system'",
"selector": "k8s-app == 'kube-dns'",
"selector": "k8s-app == 'kube-dns' || k8s-app == 'coredns'",
"ports": [
53
]
Expand Down
Loading
Loading