Skip to content

Commit bf9b057

Browse files
authored
remove namespace admin auth check (#279)
Signed-off-by: YuChen <[email protected]>
1 parent 2d0692f commit bf9b057

File tree

1 file changed

+13
-48
lines changed

1 file changed

+13
-48
lines changed

controllers/namespacescope_controller.go

Lines changed: 13 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -938,34 +938,6 @@ func (r *NamespaceScopeReconciler) checkGetNSAuth(ctx context.Context) bool {
938938
return sar.Status.Allowed
939939
}
940940

941-
// Check if operator has namespace admin permission
942-
func (r *NamespaceScopeReconciler) checkNamespaceAdminAuth(ctx context.Context, namespace string) bool {
943-
verbs := []string{"create", "delete", "get", "list", "patch", "update", "watch", "deletecollection"}
944-
for _, verb := range verbs {
945-
sar := &authorizationv1.SelfSubjectAccessReview{
946-
Spec: authorizationv1.SelfSubjectAccessReviewSpec{
947-
ResourceAttributes: &authorizationv1.ResourceAttributes{
948-
Namespace: namespace,
949-
Verb: verb,
950-
Group: "*",
951-
Resource: "*",
952-
},
953-
},
954-
}
955-
if err := r.Create(ctx, sar); err != nil {
956-
klog.Errorf("Failed to check operator namespace permission: %v", err)
957-
return false
958-
}
959-
960-
klog.V(2).Infof("Namespace admin permission in namespace %s, Allowed: %t, Denied: %t, Reason: %s", namespace, sar.Status.Allowed, sar.Status.Denied, sar.Status.Reason)
961-
962-
if !sar.Status.Allowed {
963-
return false
964-
}
965-
}
966-
return true
967-
}
968-
969941
func rulesFilter(orgRule []rbacv1.PolicyRule) []rbacv1.PolicyRule {
970942
verbMap := make(map[string]struct{})
971943
verbs := []string{"create", "delete", "get", "list", "patch", "update", "watch", "deletecollection"}
@@ -1006,30 +978,23 @@ func (r *NamespaceScopeReconciler) getValidatedNamespaces(ctx context.Context, i
1006978
validatedNs = append(validatedNs, nsMem)
1007979
continue
1008980
}
1009-
// Check if operator has target namespace admin permission
1010-
if r.checkNamespaceAdminAuth(ctx, nsMem) {
1011-
// Check if operator has permission to get namespace resource
1012-
if r.checkGetNSAuth(ctx) {
1013-
ns := &corev1.Namespace{}
1014-
key := types.NamespacedName{Name: nsMem}
1015-
if err := r.Client.Get(ctx, key, ns); err != nil {
1016-
if errors.IsNotFound(err) {
1017-
klog.Infof("Namespace %s does not exist and will be ignored", nsMem)
1018-
continue
1019-
}
1020-
return nil, err
1021-
}
1022-
if ns.Status.Phase == corev1.NamespaceTerminating {
1023-
klog.Infof("Namespace %s is terminating. Ignore this namespace", nsMem)
981+
// Check if operator has permission to get namespace resource
982+
if r.checkGetNSAuth(ctx) {
983+
ns := &corev1.Namespace{}
984+
key := types.NamespacedName{Name: nsMem}
985+
if err := r.Client.Get(ctx, key, ns); err != nil {
986+
if errors.IsNotFound(err) {
987+
klog.Infof("Namespace %s does not exist and will be ignored", nsMem)
1024988
continue
1025989
}
990+
return nil, err
991+
}
992+
if ns.Status.Phase == corev1.NamespaceTerminating {
993+
klog.Infof("Namespace %s is terminating. Ignore this namespace", nsMem)
994+
continue
1026995
}
1027-
validatedNs = append(validatedNs, nsMem)
1028-
} else {
1029-
klog.Infof("ibm-namespace-scope-operator doesn't have admin permission in namespace %s", nsMem)
1030-
klog.Infof("NOTE: Please refer to https://ibm.biz/cs_namespace_operator to authorize ibm-namespace-scope-operator permissions to namespace %s", nsMem)
1031-
r.Recorder.Eventf(instance, corev1.EventTypeWarning, "Forbidden", "ibm-namespace-scope-operator doesn't have admin permission in namespace %s. NOTE: Refer to https://ibm.biz/cs_namespace_operator to authorize ibm-namespace-scope-operator permissions to namespace %s", nsMem, nsMem)
1032996
}
997+
validatedNs = append(validatedNs, nsMem)
1033998
}
1034999
return validatedNs, nil
10351000
}

0 commit comments

Comments
 (0)