@@ -1047,184 +1047,6 @@ func TestLabellingUpdates(t *testing.T) {
10471047 },
10481048 shouldBeAllowed : true ,
10491049 },
1050- {
1051- testID : "user-can-remove-removable-label-from-unpriv-ns" ,
1052- targetNamespace : "my-customer-ns" ,
1053- username : "test@user" ,
1054- userGroups : []string {"system:authenticated" , "system:authenticated:oauth" },
1055- operation : admissionv1 .Update ,
1056- oldObject : createOldObject ("my-customer-ns" , "user-can-remove-removable-label-from-unpriv-ns" , map [string ]string {
1057- "openshift.io/cluster-monitoring" : "true" ,
1058- }),
1059- labels : map [string ]string {},
1060- shouldBeAllowed : true ,
1061- },
1062- {
1063- testID : "user-cant-alter-removable-label-key-unpriv-ns" ,
1064- targetNamespace : "my-customer-ns" ,
1065- username : "test@user" ,
1066- userGroups : []string {"system:authenticated" , "system:authenticated:oauth" },
1067- operation : admissionv1 .Update ,
1068- oldObject : createOldObject ("my-customer-ns" , "user-can-remove-removable-label-from-unpriv-ns" , map [string ]string {
1069- "openshift.io/cluster-monitoring" : "true" ,
1070- }),
1071- labels : map [string ]string {"openshift.io/cluster-monitoring" : "false" },
1072- shouldBeAllowed : false ,
1073- },
1074- {
1075- testID : "user-cant-add-removable-label-on-unpriv-ns" ,
1076- targetNamespace : "my-customer-ns" ,
1077- username : "test@user" ,
1078- userGroups : []string {"system:authenticated" , "system:authenticated:oauth" },
1079- operation : admissionv1 .Update ,
1080- oldObject : createOldObject ("my-customer-ns" , "user-can-remove-removable-label-from-unpriv-ns" , map [string ]string {}),
1081- labels : map [string ]string {"openshift.io/cluster-monitoring" : "true" },
1082- shouldBeAllowed : false ,
1083- },
1084- {
1085- testID : "cluster-admin-can-add-removable-label-on-unpriv-ns" ,
1086- targetNamespace : "my-customer-ns" ,
1087- username : "test@user" ,
1088- userGroups : []string {"cluster-admins" , "system:authenticated" , "system:authenticated:oauth" },
1089- operation : admissionv1 .Update ,
1090- oldObject : createOldObject ("my-customer-ns" , "user-can-remove-removable-label-from-unpriv-ns" , map [string ]string {}),
1091- labels : map [string ]string {"openshift.io/cluster-monitoring" : "true" },
1092- shouldBeAllowed : true ,
1093- },
1094- {
1095- testID : "backplane-cluster-admin-can-add-removable-label-on-unpriv-ns" ,
1096- targetNamespace : "my-customer-ns" ,
1097- username : "backplane-cluster-admin" ,
1098- userGroups : []string {"system:authenticated" , "system:authenticated:oauth" },
1099- operation : admissionv1 .Update ,
1100- oldObject : createOldObject ("my-customer-ns" , "user-can-remove-removable-label-from-unpriv-ns" , map [string ]string {}),
1101- labels : map [string ]string {"openshift.io/cluster-monitoring" : "true" },
1102- shouldBeAllowed : true ,
1103- },
1104- {
1105- testID : "backplane-cluster-admin-can-add-removable-label-on-priv-ns" ,
1106- targetNamespace : "openshift-kube-apiserver" ,
1107- username : "backplane-cluster-admin" ,
1108- userGroups : []string {"system:authenticated" , "system:authenticated:oauth" },
1109- operation : admissionv1 .Update ,
1110- oldObject : createOldObject ("my-customer-ns" , "user-can-remove-removable-label-from-unpriv-ns" , map [string ]string {}),
1111- labels : map [string ]string {"openshift.io/cluster-monitoring" : "true" },
1112- shouldBeAllowed : true ,
1113- },
1114- {
1115- testID : "backplane-cluster-admin-can-remove-removable-label-on-priv-ns" ,
1116- targetNamespace : "openshift-kube-apiserver" ,
1117- username : "backplane-cluster-admin" ,
1118- userGroups : []string {"system:authenticated" , "system:authenticated:oauth" },
1119- operation : admissionv1 .Update ,
1120- oldObject : createOldObject ("my-customer-ns" , "user-can-remove-removable-label-from-unpriv-ns" , map [string ]string {
1121- "openshift.io/cluster-monitoring" : "true" ,
1122- }),
1123- labels : map [string ]string {},
1124- shouldBeAllowed : true ,
1125- },
1126- // https://issues.redhat.com/browse/SREP-1770 - test explicit exception for nvidia-gpu-operator
1127- {
1128- testID : "nvidia-gpu-operator-can-add-label-to-unprotected-ns" ,
1129- targetNamespace : "nvidia-gpu-operator" ,
1130- username : "system:serviceaccount:nvidia-gpu-operator:gpu-operator" ,
1131- userGroups : []string {"system:authenticated" , "system:authenticated:oauth" },
1132- operation : admissionv1 .Update ,
1133- oldObject : createOldObject ("nvidia-gpu-operator" , "nvidia-gpu-operato-can-add-label-to-unprotected-ns" , map [string ]string {}),
1134- labels : map [string ]string {"openshift.io/cluster-monitoring" : "true" },
1135- shouldBeAllowed : true ,
1136- },
1137- {
1138- testID : "nvidia-gpu-operator-can-remove-label-from-unprotected-ns" ,
1139- targetNamespace : "nvidia-gpu-operator" ,
1140- username : "system:serviceaccount:nvidia-gpu-operator:gpu-operator" ,
1141- userGroups : []string {"system:authenticated" , "system:authenticated:oauth" },
1142- operation : admissionv1 .Update ,
1143- oldObject : createOldObject ("nvidia-gpu-operator" , "nvidia-gpu-operato-can-remove-label-from-unprotected-ns" , map [string ]string {
1144- "openshift.io/cluster-monitoring" : "true" ,
1145- }),
1146- labels : map [string ]string {},
1147- shouldBeAllowed : true ,
1148- },
1149- {
1150- testID : "nvidia-gpu-operator-cannot-remove-label-from-protected-ns" ,
1151- targetNamespace : "nvidia-gpu-operator" ,
1152- username : "system:serviceaccount:nvidia-gpu-operator:gpu-operator" ,
1153- userGroups : []string {"system:authenticated" , "system:authenticated:oauth" },
1154- operation : admissionv1 .Update ,
1155- oldObject : createOldObject ("openshift-kube-apiserver" , "nvidia-gpu-operato-cannot-remove-label-from-protected-ns" , map [string ]string {
1156- "openshift.io/cluster-monitoring" : "true" ,
1157- }),
1158- labels : map [string ]string {},
1159- shouldBeAllowed : false ,
1160- },
1161- // https://issues.redhat.com/browse/SREP-2070 - test explicit exception for multiclusterhub-operator
1162- {
1163- testID : "multiclusterhub-operator-can-add-label-to-unprotected-ns" ,
1164- targetNamespace : "open-cluster-management" ,
1165- username : "system:serviceaccount:open-cluster-management:multiclusterhub-operator" ,
1166- userGroups : []string {"system:authenticated" , "system:authenticated:oauth" },
1167- operation : admissionv1 .Update ,
1168- oldObject : createOldObject ("open-cluster-management" , "multiclusterhub-operator-can-add-label-to-unprotected-ns" , map [string ]string {}),
1169- labels : map [string ]string {"openshift.io/cluster-monitoring" : "true" },
1170- shouldBeAllowed : true ,
1171- },
1172- {
1173- testID : "multiclusterhub-operator-can-remove-label-from-unprotected-ns" ,
1174- targetNamespace : "open-cluster-management" ,
1175- username : "system:serviceaccount:open-cluster-management:multiclusterhub-operator" ,
1176- userGroups : []string {"system:authenticated" , "system:authenticated:oauth" },
1177- operation : admissionv1 .Update ,
1178- oldObject : createOldObject ("open-cluster-management" , "multiclusterhub-operator-can-remove-label-from-unprotected-ns" , map [string ]string {
1179- "openshift.io/cluster-monitoring" : "true" ,
1180- }),
1181- labels : map [string ]string {},
1182- shouldBeAllowed : true ,
1183- },
1184- {
1185- testID : "multiclusterhub-operator-can-modify-label-on-unprotected-ns" ,
1186- targetNamespace : "open-cluster-management" ,
1187- username : "system:serviceaccount:open-cluster-management:multiclusterhub-operator" ,
1188- userGroups : []string {"system:authenticated" , "system:authenticated:oauth" },
1189- operation : admissionv1 .Update ,
1190- oldObject : createOldObject ("open-cluster-management" , "multiclusterhub-operator-can-modify-label-on-unprotected-ns" , map [string ]string {
1191- "openshift.io/cluster-monitoring" : "false" ,
1192- }),
1193- labels : map [string ]string {"openshift.io/cluster-monitoring" : "true" },
1194- shouldBeAllowed : true ,
1195- },
1196- {
1197- testID : "multiclusterhub-operator-different-namespace-can-add-label" ,
1198- targetNamespace : "some-other-namespace" ,
1199- username : "system:serviceaccount:different-namespace:multiclusterhub-operator" ,
1200- userGroups : []string {"system:authenticated" , "system:authenticated:oauth" },
1201- operation : admissionv1 .Update ,
1202- oldObject : createOldObject ("some-other-namespace" , "multiclusterhub-operator-different-namespace-can-add-label" , map [string ]string {}),
1203- labels : map [string ]string {"openshift.io/cluster-monitoring" : "true" },
1204- shouldBeAllowed : true ,
1205- },
1206- {
1207- testID : "multiclusterhub-operator-cannot-access-protected-ns" ,
1208- targetNamespace : "openshift-kube-apiserver" ,
1209- username : "system:serviceaccount:open-cluster-management:multiclusterhub-operator" ,
1210- userGroups : []string {"system:authenticated" , "system:authenticated:oauth" },
1211- operation : admissionv1 .Update ,
1212- oldObject : createOldObject ("openshift-kube-apiserver" , "multiclusterhub-operator-cannot-access-protected-ns" , map [string ]string {
1213- "openshift.io/cluster-monitoring" : "true" ,
1214- }),
1215- labels : map [string ]string {},
1216- shouldBeAllowed : false ,
1217- },
1218- {
1219- testID : "non-excepted-operator-cannot-add-label" ,
1220- targetNamespace : "some-namespace" ,
1221- username : "system:serviceaccount:some-namespace:some-other-operator" ,
1222- userGroups : []string {"system:authenticated" , "system:authenticated:oauth" },
1223- operation : admissionv1 .Update ,
1224- oldObject : createOldObject ("some-namespace" , "non-excepted-operator-cannot-add-label" , map [string ]string {}),
1225- labels : map [string ]string {"openshift.io/cluster-monitoring" : "true" },
1226- shouldBeAllowed : false ,
1227- },
12281050 }
12291051 runNamespaceTests (t , tests )
12301052}
0 commit comments