Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -540,10 +540,10 @@ func (r *ReconcilePolicyRecommendation) createDefaultPolicyRecommendationScope(c
prs.Name = "default"
prs.Spec.NamespaceSpec = &v3.PolicyRecommendationScopeNamespaceSpec{
RecStatus: "Disabled",
Selector: "!(projectcalico.org/name starts with 'tigera-') && !(projectcalico.org/name starts with 'calico-') && !(projectcalico.org/name starts with 'kube-')",
Selector: "!(kubernetes.io/metadata.name starts with 'tigera-') && !(kubernetes.io/metadata.name starts with 'calico-') && !(kubernetes.io/metadata.name starts with 'kube-')",
}
if r.opts.DetectedProvider.IsOpenShift() {
prs.Spec.NamespaceSpec.Selector += " && !(projectcalico.org/name starts with 'openshift-')"
prs.Spec.NamespaceSpec.Selector += " && !(kubernetes.io/metadata.name starts with 'openshift-')"
}

if err := r.client.Create(ctx, prs); err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ var _ = Describe("PolicyRecommendation controller tests", func() {

// Verify the values of the created PolicyRecommendationScope object.
Expect(prs.Spec.NamespaceSpec.RecStatus).To(Equal(v3.PolicyRecommendationDisabled))
Expect(prs.Spec.NamespaceSpec.Selector).To(Equal("!(projectcalico.org/name starts with 'tigera-') && !(projectcalico.org/name starts with 'calico-') && !(projectcalico.org/name starts with 'kube-')"))
Expect(prs.Spec.NamespaceSpec.Selector).To(Equal("!(kubernetes.io/metadata.name starts with 'tigera-') && !(kubernetes.io/metadata.name starts with 'calico-') && !(kubernetes.io/metadata.name starts with 'kube-')"))
})

It("should create default PolicyRecommendationScope for openshift", func() {
Expand Down Expand Up @@ -584,7 +584,7 @@ var _ = Describe("PolicyRecommendation controller tests", func() {

// Verify the values of the created PolicyRecommendationScope object.
Expect(prs.Spec.NamespaceSpec.RecStatus).To(Equal(v3.PolicyRecommendationDisabled))
Expect(prs.Spec.NamespaceSpec.Selector).To(Equal("!(projectcalico.org/name starts with 'tigera-') && !(projectcalico.org/name starts with 'calico-') && !(projectcalico.org/name starts with 'kube-') && !(projectcalico.org/name starts with 'openshift-')"))
Expect(prs.Spec.NamespaceSpec.Selector).To(Equal("!(kubernetes.io/metadata.name starts with 'tigera-') && !(kubernetes.io/metadata.name starts with 'calico-') && !(kubernetes.io/metadata.name starts with 'kube-') && !(kubernetes.io/metadata.name starts with 'openshift-')"))
})
})
})
12 changes: 6 additions & 6 deletions pkg/render/common/networkpolicy/networkpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func AppendDNSEgressRules(egressRules []v3.Rule, openShift bool) []v3.Rule {
Action: v3.Allow,
Protocol: &UDPProtocol,
Destination: v3.EntityRule{
NamespaceSelector: "projectcalico.org/name == 'openshift-dns'",
NamespaceSelector: "kubernetes.io/metadata.name == 'openshift-dns'",
Selector: "dns.operator.openshift.io/daemonset-dns == 'default'",
Ports: Ports(5353),
},
Expand All @@ -58,7 +58,7 @@ func AppendDNSEgressRules(egressRules []v3.Rule, openShift bool) []v3.Rule {
Action: v3.Allow,
Protocol: &TCPProtocol,
Destination: v3.EntityRule{
NamespaceSelector: "projectcalico.org/name == 'openshift-dns'",
NamespaceSelector: "kubernetes.io/metadata.name == 'openshift-dns'",
Selector: "dns.operator.openshift.io/daemonset-dns == 'default'",
Ports: Ports(5353),
},
Expand All @@ -69,7 +69,7 @@ func AppendDNSEgressRules(egressRules []v3.Rule, openShift bool) []v3.Rule {
Action: v3.Allow,
Protocol: &UDPProtocol,
Destination: v3.EntityRule{
NamespaceSelector: "projectcalico.org/name == 'kube-system'",
NamespaceSelector: "kubernetes.io/metadata.name == 'kube-system'",
// In most Kubernetes distros the label is for kube-dns, but in Canonical it is for coredns.
Selector: "k8s-app in { 'kube-dns', 'coredns' }",
Ports: Ports(53),
Expand All @@ -83,7 +83,7 @@ func AppendDNSEgressRules(egressRules []v3.Rule, openShift bool) []v3.Rule {
// CreateEntityRule creates an entity rule that matches traffic using label selectors based on namespace, deployment name, and port.
func CreateEntityRule(namespace string, deploymentName string, ports ...uint16) v3.EntityRule {
return v3.EntityRule{
NamespaceSelector: fmt.Sprintf("projectcalico.org/name == '%s'", namespace),
NamespaceSelector: fmt.Sprintf("kubernetes.io/metadata.name == '%s'", namespace),
Selector: fmt.Sprintf("k8s-app == '%s'", deploymentName),
Ports: Ports(ports...),
}
Expand All @@ -93,7 +93,7 @@ func CreateEntityRule(namespace string, deploymentName string, ports ...uint16)
func CreateSourceEntityRule(namespace string, deploymentName string) v3.EntityRule {
return v3.EntityRule{
Selector: fmt.Sprintf("k8s-app == '%s'", deploymentName),
NamespaceSelector: fmt.Sprintf("projectcalico.org/name == '%s'", namespace),
NamespaceSelector: fmt.Sprintf("kubernetes.io/metadata.name == '%s'", namespace),
}
}

Expand Down Expand Up @@ -320,7 +320,7 @@ func DeprecatedAllowTigeraNetworkPolicyObject(name, namespace string) client.Obj
const PrometheusSelector = "k8s-app == 'tigera-prometheus'"

var PrometheusEntityRule = v3.EntityRule{
NamespaceSelector: "projectcalico.org/name == 'tigera-prometheus'",
NamespaceSelector: "kubernetes.io/metadata.name == 'tigera-prometheus'",
Selector: PrometheusSelector,
Ports: Ports(9095),
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/render/common/selector/label.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
const (
OpenShiftDNSDaemonsetLabel = "dns.operator.openshift.io/daemonset-dns"
K8sNameLabel = "app.kubernetes.io/name"
CalicoNameLabel = "projectcalico.org/name"
CalicoNameLabel = "kubernetes.io/metadata.name"
)

func PodLabelSelector(name string) *metav1.LabelSelector {
Expand Down
2 changes: 1 addition & 1 deletion pkg/render/intrusion_detection.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const (

// Register secret/certs that need Server and Client Key usage
var (
intrusionDetectionNamespaceSelector = fmt.Sprintf("projectcalico.org/name == '%s'", IntrusionDetectionNamespace)
intrusionDetectionNamespaceSelector = fmt.Sprintf("kubernetes.io/metadata.name == '%s'", IntrusionDetectionNamespace)
IntrusionDetectionSourceEntityRule = v3.EntityRule{
NamespaceSelector: intrusionDetectionNamespaceSelector,
Selector: fmt.Sprintf("k8s-app == '%s'", IntrusionDetectionControllerName),
Expand Down
4 changes: 2 additions & 2 deletions pkg/render/intrusion_detection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ var _ = Describe("Intrusion Detection rendering tests", func() {
Action: v3.Allow,
Protocol: &networkpolicy.UDPProtocol,
Destination: v3.EntityRule{
NamespaceSelector: "projectcalico.org/name == 'kube-system'",
NamespaceSelector: "kubernetes.io/metadata.name == 'kube-system'",
Selector: "k8s-app in { 'kube-dns', 'coredns' }",
Ports: networkpolicy.Ports(53),
},
Expand All @@ -759,7 +759,7 @@ var _ = Describe("Intrusion Detection rendering tests", func() {
Action: v3.Allow,
Protocol: &networkpolicy.TCPProtocol,
Destination: v3.EntityRule{
NamespaceSelector: fmt.Sprintf("projectcalico.org/name == '%s'", tenantANamespace),
NamespaceSelector: fmt.Sprintf("kubernetes.io/metadata.name == '%s'", tenantANamespace),
Selector: "k8s-app == 'calico-manager'",
Ports: networkpolicy.Ports(9443),
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/render/logcollector/fluentbit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1387,7 +1387,7 @@ var _ = Describe("Tigera Secure Fluent Bit rendering tests", func() {
Protocol: &networkpolicy.TCPProtocol,
Source: v3.EntityRule{
Selector: fmt.Sprintf("k8s-app == '%s'", render.ManagerDeploymentName),
NamespaceSelector: fmt.Sprintf("projectcalico.org/name == '%s'", render.ManagerNamespace),
NamespaceSelector: fmt.Sprintf("kubernetes.io/metadata.name == '%s'", render.ManagerNamespace),
},
Destination: v3.EntityRule{
Ports: networkpolicy.Ports(logcollector.FluentBitInputPort),
Expand Down
6 changes: 3 additions & 3 deletions pkg/render/logcollector/networkpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func (c *fluentBitComponent) calicoSystemPolicy() *v3.NetworkPolicy {
Protocol: &networkpolicy.TCPProtocol,
Source: v3.EntityRule{},
Destination: v3.EntityRule{
NamespaceSelector: fmt.Sprintf("projectcalico.org/name == '%s'", render.GuardianNamespace),
NamespaceSelector: fmt.Sprintf("kubernetes.io/metadata.name == '%s'", render.GuardianNamespace),
Selector: networkpolicy.KubernetesAppSelector(render.GuardianServiceName),
NotPorts: networkpolicy.Ports(8080),
},
Expand All @@ -161,7 +161,7 @@ func (c *fluentBitComponent) calicoSystemPolicy() *v3.NetworkPolicy {
Protocol: &networkpolicy.TCPProtocol,
Source: v3.EntityRule{},
Destination: v3.EntityRule{
NamespaceSelector: fmt.Sprintf("projectcalico.org/name == '%s'", render.ElasticsearchNamespace),
NamespaceSelector: fmt.Sprintf("kubernetes.io/metadata.name == '%s'", render.ElasticsearchNamespace),
Selector: networkpolicy.KubernetesAppSelector("tigera-secure-es-gateway"),
NotPorts: networkpolicy.Ports(5554),
},
Expand All @@ -171,7 +171,7 @@ func (c *fluentBitComponent) calicoSystemPolicy() *v3.NetworkPolicy {
Protocol: &networkpolicy.TCPProtocol,
Source: v3.EntityRule{},
Destination: v3.EntityRule{
NamespaceSelector: fmt.Sprintf("projectcalico.org/name == '%s'", render.ElasticsearchNamespace),
NamespaceSelector: fmt.Sprintf("kubernetes.io/metadata.name == '%s'", render.ElasticsearchNamespace),
Selector: networkpolicy.KubernetesAppSelector("tigera-linseed"),
NotPorts: networkpolicy.Ports(8444),
},
Expand Down
4 changes: 2 additions & 2 deletions pkg/render/logstorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,14 @@ const (
var (
ElasticsearchSelector = fmt.Sprintf("elasticsearch.k8s.elastic.co/cluster-name == '%s'", ElasticsearchName)
ElasticsearchEntityRule = v3.EntityRule{
NamespaceSelector: fmt.Sprintf("projectcalico.org/name == '%s'", ElasticsearchNamespace),
NamespaceSelector: fmt.Sprintf("kubernetes.io/metadata.name == '%s'", ElasticsearchNamespace),
Selector: ElasticsearchSelector,
Ports: []numorstring.Port{{MinPort: ElasticsearchDefaultPort, MaxPort: ElasticsearchDefaultPort}},
}
)

var InternalElasticsearchEntityRule = v3.EntityRule{
NamespaceSelector: fmt.Sprintf("projectcalico.org/name == '%s'", ElasticsearchNamespace),
NamespaceSelector: fmt.Sprintf("kubernetes.io/metadata.name == '%s'", ElasticsearchNamespace),
Selector: ElasticsearchSelector,
Ports: []numorstring.Port{{MinPort: ElasticsearchInternalPort, MaxPort: ElasticsearchInternalPort}},
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/render/logstorage/esgateway/esgateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ func (e *esGateway) cloudAccessNetworkPolicy() *v3.NetworkPolicy {
Action: v3.Allow,
Protocol: &networkpolicy.TCPProtocol,
Source: v3.EntityRule{
NamespaceSelector: "projectcalico.org/name == 'monitoring'",
NamespaceSelector: "kubernetes.io/metadata.name == 'monitoring'",
Selector: "app == 'prometheus'",
},
// Allow prometheus to scrape the metrics endpoint, which is enabled only on
Expand Down
2 changes: 1 addition & 1 deletion pkg/render/logstorage/linseed/linseed.go
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,7 @@ func (l *linseed) cloudAccessNetworkPolicy() *v3.NetworkPolicy {
Action: v3.Allow,
Protocol: &networkpolicy.TCPProtocol,
Source: v3.EntityRule{
NamespaceSelector: "projectcalico.org/name == 'monitoring'",
NamespaceSelector: "kubernetes.io/metadata.name == 'monitoring'",
Selector: "app == 'prometheus'",
},
Destination: v3.EntityRule{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"action": "Allow",
"protocol": "UDP",
"destination": {
"namespaceSelector": "projectcalico.org/name == 'kube-system'",
"namespaceSelector": "kubernetes.io/metadata.name == 'kube-system'",
"selector": "k8s-app in { 'kube-dns', 'coredns' }",
"ports": [
53
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"action": "Allow",
"protocol": "UDP",
"destination": {
"namespaceSelector": "projectcalico.org/name == 'openshift-dns'",
"namespaceSelector": "kubernetes.io/metadata.name == 'openshift-dns'",
"selector": "dns.operator.openshift.io/daemonset-dns == 'default'",
"ports": [
5353
Expand All @@ -71,7 +71,7 @@
"action": "Allow",
"protocol": "TCP",
"destination": {
"namespaceSelector": "projectcalico.org/name == 'openshift-dns'",
"namespaceSelector": "kubernetes.io/metadata.name == 'openshift-dns'",
"selector": "dns.operator.openshift.io/daemonset-dns == 'default'",
"ports": [
5353
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 @@ -29,7 +29,7 @@
"action": "Allow",
"protocol": "UDP",
"destination": {
"namespaceSelector": "projectcalico.org/name == 'kube-system'",
"namespaceSelector": "kubernetes.io/metadata.name == 'kube-system'",
"selector": "k8s-app in { 'kube-dns', 'coredns' }",
"ports": [
53
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"action": "Allow",
"protocol": "UDP",
"destination": {
"namespaceSelector": "projectcalico.org/name == 'openshift-dns'",
"namespaceSelector": "kubernetes.io/metadata.name == 'openshift-dns'",
"selector": "dns.operator.openshift.io/daemonset-dns == 'default'",
"ports": [
5353
Expand All @@ -40,7 +40,7 @@
"action": "Allow",
"protocol": "TCP",
"destination": {
"namespaceSelector": "projectcalico.org/name == 'openshift-dns'",
"namespaceSelector": "kubernetes.io/metadata.name == 'openshift-dns'",
"selector": "dns.operator.openshift.io/daemonset-dns == 'default'",
"ports": [
5353
Expand Down
8 changes: 4 additions & 4 deletions pkg/render/testutils/expected_policies/apiserver.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"action": "Allow",
"protocol": "UDP",
"destination": {
"namespaceSelector": "projectcalico.org/name == 'kube-system'",
"namespaceSelector": "kubernetes.io/metadata.name == 'kube-system'",
"selector": "k8s-app in { 'kube-dns', 'coredns' }",
"ports": [
53
Expand All @@ -75,7 +75,7 @@
"action": "Allow",
"protocol": "TCP",
"destination": {
"namespaceSelector": "projectcalico.org/name == 'tigera-prometheus'",
"namespaceSelector": "kubernetes.io/metadata.name == 'tigera-prometheus'",
"selector": "k8s-app == 'tigera-prometheus'",
"ports": [
9095
Expand All @@ -87,7 +87,7 @@
"protocol": "TCP",
"destination": {
"selector": "k8s-app == 'tigera-dex'",
"namespaceSelector": "projectcalico.org/name == 'tigera-dex'",
"namespaceSelector": "kubernetes.io/metadata.name == 'tigera-dex'",
"ports" : [
5556
]
Expand All @@ -97,7 +97,7 @@
"action": "Allow",
"protocol": "TCP",
"destination": {
"namespaceSelector": "projectcalico.org/name == 'tigera-elasticsearch'",
"namespaceSelector": "kubernetes.io/metadata.name == 'tigera-elasticsearch'",
"selector": "k8s-app == 'tigera-linseed'",
"ports": [
8444
Expand Down
10 changes: 5 additions & 5 deletions pkg/render/testutils/expected_policies/apiserver_ocp.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"action": "Allow",
"protocol": "UDP",
"destination": {
"namespaceSelector": "projectcalico.org/name == 'openshift-dns'",
"namespaceSelector": "kubernetes.io/metadata.name == 'openshift-dns'",
"selector": "dns.operator.openshift.io/daemonset-dns == 'default'",
"ports": [
5353
Expand All @@ -65,7 +65,7 @@
"action": "Allow",
"protocol": "TCP",
"destination": {
"namespaceSelector": "projectcalico.org/name == 'openshift-dns'",
"namespaceSelector": "kubernetes.io/metadata.name == 'openshift-dns'",
"selector": "dns.operator.openshift.io/daemonset-dns == 'default'",
"ports": [
5353
Expand All @@ -86,7 +86,7 @@
"action": "Allow",
"protocol": "TCP",
"destination": {
"namespaceSelector": "projectcalico.org/name == 'tigera-prometheus'",
"namespaceSelector": "kubernetes.io/metadata.name == 'tigera-prometheus'",
"selector": "k8s-app == 'tigera-prometheus'",
"ports": [
9095
Expand All @@ -98,7 +98,7 @@
"protocol": "TCP",
"destination": {
"selector": "k8s-app == 'tigera-dex'",
"namespaceSelector": "projectcalico.org/name == 'tigera-dex'",
"namespaceSelector": "kubernetes.io/metadata.name == 'tigera-dex'",
"ports" : [
5556
]
Expand All @@ -108,7 +108,7 @@
"action": "Allow",
"protocol": "TCP",
"destination": {
"namespaceSelector": "projectcalico.org/name == 'tigera-elasticsearch'",
"namespaceSelector": "kubernetes.io/metadata.name == 'tigera-elasticsearch'",
"selector": "k8s-app == 'tigera-linseed'",
"ports": [
8444
Expand Down
4 changes: 2 additions & 2 deletions pkg/render/testutils/expected_policies/dashboards.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"action": "Allow",
"protocol": "UDP",
"destination": {
"namespaceSelector": "projectcalico.org/name == 'kube-system'",
"namespaceSelector": "kubernetes.io/metadata.name == 'kube-system'",
"selector": "k8s-app in { 'kube-dns', 'coredns' }",
"ports": [
53
Expand All @@ -28,7 +28,7 @@
"action": "Allow",
"protocol": "TCP",
"destination": {
"namespaceSelector": "projectcalico.org/name == 'tigera-kibana'",
"namespaceSelector": "kubernetes.io/metadata.name == 'tigera-kibana'",
"selector": "k8s-app == 'tigera-secure'",
"ports": [
5601
Expand Down
6 changes: 3 additions & 3 deletions pkg/render/testutils/expected_policies/dashboards_ocp.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"action": "Allow",
"protocol": "UDP",
"destination": {
"namespaceSelector": "projectcalico.org/name == 'openshift-dns'",
"namespaceSelector": "kubernetes.io/metadata.name == 'openshift-dns'",
"selector": "dns.operator.openshift.io/daemonset-dns == 'default'",
"ports": [
5353
Expand All @@ -28,7 +28,7 @@
"action": "Allow",
"protocol": "TCP",
"destination": {
"namespaceSelector": "projectcalico.org/name == 'openshift-dns'",
"namespaceSelector": "kubernetes.io/metadata.name == 'openshift-dns'",
"selector": "dns.operator.openshift.io/daemonset-dns == 'default'",
"ports": [
5353
Expand All @@ -39,7 +39,7 @@
"action": "Allow",
"protocol": "TCP",
"destination": {
"namespaceSelector": "projectcalico.org/name == 'tigera-kibana'",
"namespaceSelector": "kubernetes.io/metadata.name == 'tigera-kibana'",
"selector": "k8s-app == 'tigera-secure'",
"ports": [
5601
Expand Down
Loading
Loading