Skip to content

Commit 6a7b880

Browse files
Use explicit verbs in tiered policy passthrough (tigera#3887)
1 parent 643f8d4 commit 6a7b880

File tree

1 file changed

+28
-13
lines changed

1 file changed

+28
-13
lines changed

pkg/render/apiserver.go

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,27 @@ const (
7878
L7AdmissionControllerPortName = "l7admctrl"
7979
)
8080

81-
var TigeraAPIServerEntityRule = v3.EntityRule{
82-
Services: &v3.ServiceMatch{
83-
Namespace: QueryserverNamespace,
84-
Name: QueryserverServiceName,
85-
},
86-
}
81+
var (
82+
TigeraAPIServerEntityRule = v3.EntityRule{
83+
Services: &v3.ServiceMatch{
84+
Namespace: QueryserverNamespace,
85+
Name: QueryserverServiceName,
86+
},
87+
}
88+
89+
// allVerbs is a list of all verbs that are supported by the API server, used
90+
// for tiered policy passthrough.
91+
allVerbs = []string{
92+
"get",
93+
"list",
94+
"watch",
95+
"create",
96+
"update",
97+
"patch",
98+
"delete",
99+
"deletecollection",
100+
}
101+
)
87102

88103
// The following functions are helpers for determining resource names based on
89104
// the configured product variant.
@@ -1006,9 +1021,9 @@ func getContainerPort(cfg *APIServerConfiguration, containerName ContainerName)
10061021
//
10071022
// Both Calico and Calico Enterprise, different namespaces.
10081023
func (c *apiServerComponent) apiServerService() *corev1.Service {
1009-
var apiServerTargetPort = getContainerPort(c.cfg, APIServerContainerName)
1010-
var queryServerTargetPort = getContainerPort(c.cfg, TigeraAPIServerQueryServerContainerName)
1011-
var l7AdmissionControllerTargetPort = getContainerPort(c.cfg, L7AdmissionControllerContainerName)
1024+
apiServerTargetPort := getContainerPort(c.cfg, APIServerContainerName)
1025+
queryServerTargetPort := getContainerPort(c.cfg, TigeraAPIServerQueryServerContainerName)
1026+
l7AdmissionControllerTargetPort := getContainerPort(c.cfg, L7AdmissionControllerContainerName)
10121027

10131028
s := &corev1.Service{
10141029
TypeMeta: metav1.TypeMeta{Kind: "Service", APIVersion: "v1"},
@@ -2085,13 +2100,13 @@ func (c *apiServerComponent) calicoPolicyPassthruClusterRole() *rbacv1.ClusterRo
20852100
Name: "calico-tiered-policy-passthrough",
20862101
},
20872102
// If tiered policy is enabled we allow all authenticated users to access the main tier resource, instead
2088-
// restricting access using the tier.xxx resource type. Kubernetes NetworkPolicy and the
2089-
// StagedKubernetesNetworkPolicy are handled using normal (non-tiered) RBAC.
2103+
// restricting access using the tier.xxx resource type. Kubernetes NetworkPolicy and
2104+
// StagedKubernetesNetworkPolicy objects are handled using normal (non-tiered) RBAC.
20902105
Rules: []rbacv1.PolicyRule{
20912106
{
20922107
APIGroups: []string{"projectcalico.org"},
20932108
Resources: []string{"networkpolicies", "globalnetworkpolicies"},
2094-
Verbs: []string{"*"},
2109+
Verbs: allVerbs,
20952110
},
20962111
},
20972112
}
@@ -2136,7 +2151,7 @@ func (c *apiServerComponent) tieredPolicyPassthruClusterRole() *rbacv1.ClusterRo
21362151
{
21372152
APIGroups: []string{"projectcalico.org"},
21382153
Resources: []string{"stagednetworkpolicies", "stagedglobalnetworkpolicies"},
2139-
Verbs: []string{"*"},
2154+
Verbs: allVerbs,
21402155
},
21412156
},
21422157
}

0 commit comments

Comments
 (0)