forked from openshift/operator-framework-operator-controller
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patholmv1_ce.go
More file actions
3420 lines (3115 loc) · 157 KB
/
olmv1_ce.go
File metadata and controls
3420 lines (3115 loc) · 157 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package specs
import (
"context"
"fmt"
"os"
"os/exec"
"path/filepath"
"strings"
"time"
g "github.com/onsi/ginkgo/v2"
o "github.com/onsi/gomega"
"k8s.io/apimachinery/pkg/util/wait"
e2e "k8s.io/kubernetes/test/e2e/framework"
exutil "github.com/openshift/operator-framework-operator-controller/openshift/tests-extension/test/qe/util"
"github.com/openshift/operator-framework-operator-controller/openshift/tests-extension/test/qe/util/architecture"
olmv1util "github.com/openshift/operator-framework-operator-controller/openshift/tests-extension/test/qe/util/olmv1util"
)
var _ = g.Describe("[sig-olmv1][Jira:OLM] clusterextension", g.Label("NonHyperShiftHOST"), func() {
defer g.GinkgoRecover()
var (
oc = exutil.NewCLIWithoutNamespace("default")
)
g.BeforeEach(func() {
exutil.SkipMicroshift(oc)
exutil.SkipNoOLMv1Core(oc)
})
g.It("PolarionID:83069-[OTP]olmv1 static networkpolicy.", g.Label("original-name:[sig-olmv1][Jira:OLM] clusterextension PolarionID:83069-olmv1 static networkpolicy."), g.Label("ReleaseGate"), func() {
policies := []olmv1util.NpExpecter{
{
Name: "catalogd-controller-manager",
Namespace: "openshift-catalogd",
ExpectIngress: []olmv1util.IngressRule{
{
Ports: []olmv1util.Port{
{Port: 7443, Protocol: "TCP"},
{Port: 8443, Protocol: "TCP"},
{Port: 9443, Protocol: "TCP"},
},
Selectors: nil,
},
},
ExpectEgress: []olmv1util.EgressRule{
{
Ports: []olmv1util.Port{{}}, // empty rule
Selectors: nil,
},
},
ExpectSelector: map[string]string{"control-plane": "catalogd-controller-manager"},
ExpectPolicyTypes: []string{"Ingress", "Egress"},
},
{
Name: "catalogd-default-deny-all-traffic",
Namespace: "openshift-catalogd",
ExpectIngress: nil,
ExpectEgress: nil,
ExpectSelector: map[string]string{},
ExpectPolicyTypes: []string{"Ingress", "Egress"},
},
{
Name: "allow-egress-to-api-server",
Namespace: "openshift-cluster-olm-operator",
ExpectIngress: nil,
ExpectEgress: []olmv1util.EgressRule{
{
Ports: []olmv1util.Port{{Port: 6443, Protocol: "TCP"}},
Selectors: nil,
},
},
ExpectSelector: map[string]string{"name": "cluster-olm-operator"},
ExpectPolicyTypes: []string{"Egress"},
},
{
Name: "allow-egress-to-openshift-dns",
Namespace: "openshift-cluster-olm-operator",
ExpectIngress: nil,
ExpectEgress: []olmv1util.EgressRule{
{
Ports: []olmv1util.Port{
{Port: "dns-tcp", Protocol: "TCP"},
{Port: "dns", Protocol: "UDP"},
},
Selectors: []olmv1util.Selector{
{NamespaceLabels: map[string]string{"kubernetes.io/metadata.name": "openshift-dns"}},
},
},
},
ExpectSelector: map[string]string{"name": "cluster-olm-operator"},
ExpectPolicyTypes: []string{"Egress"},
},
{
Name: "allow-metrics-traffic",
Namespace: "openshift-cluster-olm-operator",
ExpectIngress: []olmv1util.IngressRule{
{
Ports: []olmv1util.Port{{Port: 8443, Protocol: "TCP"}},
Selectors: []olmv1util.Selector{
{NamespaceLabels: map[string]string{"name": "openshift-monitoring"}},
},
},
},
ExpectEgress: nil,
ExpectSelector: map[string]string{"name": "cluster-olm-operator"},
ExpectPolicyTypes: []string{"Ingress"},
},
{
Name: "default-deny-all",
Namespace: "openshift-cluster-olm-operator",
ExpectIngress: nil,
ExpectEgress: nil,
ExpectSelector: map[string]string{},
ExpectPolicyTypes: []string{"Ingress", "Egress"},
},
{
Name: "operator-controller-controller-manager",
Namespace: "openshift-operator-controller",
ExpectIngress: []olmv1util.IngressRule{
{
Ports: []olmv1util.Port{{Port: 8443, Protocol: "TCP"}},
Selectors: nil,
},
},
ExpectEgress: []olmv1util.EgressRule{
{
Ports: []olmv1util.Port{{}}, // empty rule
Selectors: nil,
},
},
ExpectSelector: map[string]string{"control-plane": "operator-controller-controller-manager"},
ExpectPolicyTypes: []string{"Ingress", "Egress"},
},
{
Name: "operator-controller-default-deny-all-traffic",
Namespace: "openshift-operator-controller",
ExpectIngress: nil,
ExpectEgress: nil,
ExpectSelector: map[string]string{},
ExpectPolicyTypes: []string{"Ingress", "Egress"},
},
}
for _, policy := range policies {
g.By(fmt.Sprintf("Checking NP %s in %s", policy.Name, policy.Namespace))
specs, err := oc.AsAdmin().WithoutNamespace().
Run("get").Args("networkpolicy", policy.Name, "-n", policy.Namespace, "-o=jsonpath={.spec}").Output()
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(specs).NotTo(o.BeEmpty())
e2e.Logf("specs: %v", specs)
olmv1util.VerifySelector(specs, policy.ExpectSelector, policy.Name)
olmv1util.VerifyPolicyTypes(specs, policy.ExpectPolicyTypes, policy.Name)
olmv1util.VerifyIngress(specs, policy.ExpectIngress, policy.Name)
olmv1util.VerifyEgress(specs, policy.ExpectEgress, policy.Name)
}
})
g.It("PolarionID:68936-[OTP]cluster extension can not be installed with insufficient permission sa for operand", g.Label("original-name:[sig-olmv1][Jira:OLM] clusterextension PolarionID:68936-[Skipped:Disconnected]cluster extension can not be installed with insufficient permission sa for operand"), func() {
e2e.Logf("Testing ClusterExtension installation failure when ServiceAccount lacks sufficient permissions for operand resources. Originally case 75492, using 68936 for faster execution.")
exutil.SkipForSNOCluster(oc)
olmv1util.ValidateAccessEnvironment(oc)
var (
caseID = "68936"
ns = "ns-" + caseID
sa = caseID
labelValue = caseID
baseDir = exutil.FixturePath("testdata", "olm")
clustercatalogTemplate = filepath.Join(baseDir, "clustercatalog-withlabel.yaml")
clusterextensionTemplate = filepath.Join(baseDir, "clusterextension-withselectorlabel.yaml")
// Select template based on Boxcutter runtime feature gate
saClusterRoleBindingOperandTemplate string
)
// Use Boxcutter template if BoxcutterRuntime is enabled, otherwise use Helm template
// Note: Both templates have the same content for this test (both lack finalizers permissions)
if olmv1util.IsFeaturegateEnabled(oc, "NewOLMBoxCutterRuntime") {
saClusterRoleBindingOperandTemplate = filepath.Join(baseDir, "sa-nginx-insufficient-operand-clusterrole-boxcutter.yaml")
} else {
saClusterRoleBindingOperandTemplate = filepath.Join(baseDir, "sa-nginx-insufficient-operand-clusterrole.yaml")
}
saCrb := olmv1util.SaCLusterRolebindingDescription{
Name: sa,
Namespace: ns,
RBACObjects: []olmv1util.ChildResource{
{Kind: "RoleBinding", Ns: ns, Names: []string{fmt.Sprintf("%s-installer-role-binding", sa)}},
{Kind: "Role", Ns: ns, Names: []string{fmt.Sprintf("%s-installer-role", sa)}},
{Kind: "ClusterRoleBinding", Ns: "", Names: []string{fmt.Sprintf("%s-installer-rbac-clusterrole-binding", sa),
fmt.Sprintf("%s-installer-clusterrole-binding", sa)}},
{Kind: "ClusterRole", Ns: "", Names: []string{fmt.Sprintf("%s-installer-rbac-clusterrole", sa),
fmt.Sprintf("%s-installer-clusterrole", sa)}},
{Kind: "ServiceAccount", Ns: ns, Names: []string{sa}},
},
Kinds: "okv68936s",
Template: saClusterRoleBindingOperandTemplate,
}
clustercatalog := olmv1util.ClusterCatalogDescription{
Name: "clustercatalog-68936",
Imageref: "quay.io/olmqe/nginx-ok-index:vokv68936",
LabelValue: labelValue,
Template: clustercatalogTemplate,
}
ceInsufficient := olmv1util.ClusterExtensionDescription{
Name: "insufficient-68936",
PackageName: "nginx-ok-v68936",
Channel: "alpha",
Version: ">=0.0.1",
InstallNamespace: ns,
SaName: sa,
LabelValue: labelValue,
Template: clusterextensionTemplate,
}
g.By("Create namespace")
defer func() {
_ = oc.WithoutNamespace().AsAdmin().Run("delete").Args("ns", ns, "--ignore-not-found", "--force").Execute()
}()
err := oc.WithoutNamespace().AsAdmin().Run("create").Args("ns", ns).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(olmv1util.Appearance(oc, exutil.Appear, "ns", ns)).To(o.BeTrue())
g.By("Create SA for clusterextension")
defer saCrb.Delete(oc)
saCrb.Create(oc)
g.By("Create clustercatalog")
defer clustercatalog.Delete(oc)
clustercatalog.Create(oc)
g.By("check Insufficient sa from operand")
defer ceInsufficient.Delete(oc)
_ = ceInsufficient.CreateWithoutCheck(oc)
if olmv1util.IsFeaturegateEnabled(oc, "NewOLMPreflightPermissionChecks") {
// Env2 (Helm, preflight) or Env3 (Boxcutter, preflight): Both return same preflight error
ceInsufficient.CheckClusterExtensionCondition(oc, "Progressing", "message", "pre-authorization failed", 10, 60, 0)
} else {
// Env1 (Helm, no preflight) or Env4 (Boxcutter, no preflight)
// Error checking order differs between runtimes:
// - Helm (Env1): checks blockOwnerDeletion first, then privilege escalation
// - Boxcutter (Env4): checks privilege escalation first, then blockOwnerDeletion
if olmv1util.IsFeaturegateEnabled(oc, "NewOLMBoxCutterRuntime") {
// Env4: Boxcutter encounters privilege escalation error before blockOwnerDeletion check
ceInsufficient.CheckClusterExtensionCondition(oc, "Progressing", "message", "is attempting to grant RBAC permissions not currently held", 10, 60, 0)
} else {
// Env1: Helm encounters blockOwnerDeletion error
ceInsufficient.CheckClusterExtensionCondition(oc, "Progressing", "message", "cannot set blockOwnerDeletion", 10, 60, 0)
}
}
})
g.It("PolarionID:68937-[OTP]cluster extension can not be installed with insufficient permission sa for operand rbac object", g.Label("original-name:[sig-olmv1][Jira:OLM] clusterextension PolarionID:68937-[Skipped:Disconnected]cluster extension can not be installed with insufficient permission sa for operand rbac object"), func() {
e2e.Logf("Testing ClusterExtension installation failure when ServiceAccount lacks sufficient permissions for operand RBAC objects. Originally case 75492, using 68937 for faster execution.")
exutil.SkipForSNOCluster(oc)
olmv1util.ValidateAccessEnvironment(oc)
var (
caseID = "68937"
ns = "ns-" + caseID
sa = caseID
labelValue = caseID
baseDir = exutil.FixturePath("testdata", "olm")
clustercatalogTemplate = filepath.Join(baseDir, "clustercatalog-withlabel.yaml")
clusterextensionTemplate = filepath.Join(baseDir, "clusterextension-withselectorlabel.yaml")
// Select template based on Boxcutter runtime feature gate
saClusterRoleBindingOperandTemplate string
)
// Use Boxcutter template if BoxcutterRuntime is enabled, otherwise use Helm template
if olmv1util.IsFeaturegateEnabled(oc, "NewOLMBoxCutterRuntime") {
saClusterRoleBindingOperandTemplate = filepath.Join(baseDir, "sa-nginx-insufficient-operand-rbac-boxcutter.yaml")
} else {
saClusterRoleBindingOperandTemplate = filepath.Join(baseDir, "sa-nginx-insufficient-operand-rbac.yaml")
}
saCrb := olmv1util.SaCLusterRolebindingDescription{
Name: sa,
Namespace: ns,
RBACObjects: []olmv1util.ChildResource{
{Kind: "RoleBinding", Ns: ns, Names: []string{fmt.Sprintf("%s-installer-role-binding", sa)}},
{Kind: "Role", Ns: ns, Names: []string{fmt.Sprintf("%s-installer-role", sa)}},
{Kind: "ClusterRoleBinding", Ns: "", Names: []string{fmt.Sprintf("%s-installer-rbac-clusterrole-binding", sa),
fmt.Sprintf("%s-installer-clusterrole-binding", sa)}},
{Kind: "ClusterRole", Ns: "", Names: []string{fmt.Sprintf("%s-installer-rbac-clusterrole", sa),
fmt.Sprintf("%s-installer-clusterrole", sa)}},
{Kind: "ServiceAccount", Ns: ns, Names: []string{sa}},
},
Kinds: "okv68937s",
Template: saClusterRoleBindingOperandTemplate,
}
clustercatalog := olmv1util.ClusterCatalogDescription{
Name: "clustercatalog-68937",
Imageref: "quay.io/olmqe/nginx-ok-index:vokv68937",
LabelValue: labelValue,
Template: clustercatalogTemplate,
}
ceInsufficient := olmv1util.ClusterExtensionDescription{
Name: "insufficient-68937",
PackageName: "nginx-ok-v68937",
Channel: "alpha",
Version: ">=0.0.1",
InstallNamespace: ns,
SaName: sa,
LabelValue: labelValue,
Template: clusterextensionTemplate,
}
g.By("Create namespace")
defer func() {
_ = oc.WithoutNamespace().AsAdmin().Run("delete").Args("ns", ns, "--ignore-not-found", "--force").Execute()
}()
err := oc.WithoutNamespace().AsAdmin().Run("create").Args("ns", ns).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(olmv1util.Appearance(oc, exutil.Appear, "ns", ns)).To(o.BeTrue())
g.By("Create SA for clusterextension")
defer saCrb.Delete(oc)
saCrb.Create(oc)
g.By("Create clustercatalog")
defer clustercatalog.Delete(oc)
clustercatalog.Create(oc)
g.By("check Insufficient sa from operand rbac")
defer ceInsufficient.Delete(oc)
_ = ceInsufficient.CreateWithoutCheck(oc)
if olmv1util.IsFeaturegateEnabled(oc, "NewOLMPreflightPermissionChecks") {
// Env2 (Helm, preflight) or Env3 (Boxcutter, preflight): Both return same preflight error
ceInsufficient.CheckClusterExtensionCondition(oc, "Progressing", "message", "pre-authorization failed", 10, 60, 0)
} else {
// Env1 (Helm, no preflight) or Env4 (Boxcutter, no preflight): Both return K8s API RBAC error
// The specific error message is the same for both runtimes when encountering the same permission issue
ceInsufficient.CheckClusterExtensionCondition(oc, "Progressing", "message", "permissions not currently held", 10, 60, 0)
}
})
g.It("PolarionID:70723-[OTP][Skipped:Disconnected]olmv1 downgrade version", func() {
olmv1util.ValidateAccessEnvironment(oc)
var (
caseID = "70723"
labelValue = caseID
ns = "ns-70723"
sa = "sa70723"
baseDir = exutil.FixturePath("testdata", "olm")
clustercatalogTemplate = filepath.Join(baseDir, "clustercatalog-withlabel.yaml")
clusterextensionTemplate = filepath.Join(baseDir, "clusterextension-withselectorlabel.yaml")
saClusterRoleBindingTemplate = filepath.Join(baseDir, "sa-admin.yaml")
saCrb = olmv1util.SaCLusterRolebindingDescription{
Name: sa,
Namespace: ns,
Template: saClusterRoleBindingTemplate,
}
clustercatalog = olmv1util.ClusterCatalogDescription{
Name: "clustercatalog-70723",
Imageref: "quay.io/openshifttest/nginxolm-operator-index:nginxolm70723",
LabelValue: labelValue,
Template: clustercatalogTemplate,
}
clusterextension = olmv1util.ClusterExtensionDescription{
Name: "clusterextension-70723",
InstallNamespace: ns,
PackageName: "nginx70723",
Channel: "candidate-v2",
Version: "2.2.1",
SaName: sa,
LabelValue: labelValue,
Template: clusterextensionTemplate,
}
)
g.By("Create namespace")
defer func() {
_ = oc.WithoutNamespace().AsAdmin().Run("delete").Args("ns", ns, "--ignore-not-found", "--force").Execute()
}()
err := oc.WithoutNamespace().AsAdmin().Run("create").Args("ns", ns).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(olmv1util.Appearance(oc, exutil.Appear, "ns", ns)).To(o.BeTrue())
g.By("Create SA for clusterextension")
defer saCrb.Delete(oc)
saCrb.Create(oc)
g.By("Create clustercatalog")
defer clustercatalog.Delete(oc)
clustercatalog.Create(oc)
g.By("Install version 2.2.1")
defer clusterextension.Delete(oc)
clusterextension.Create(oc)
o.Expect(clusterextension.InstalledBundle).To(o.ContainSubstring("2.2.1"))
g.By("Attempt to downgrade to version 2.0.0 with CatalogProvided policy and expect failure")
clusterextension.Patch(oc, `{"spec":{"source":{"catalog":{"version": "2.0.0"}}}}`)
clusterextension.CheckClusterExtensionCondition(oc, "Progressing", "message", "error upgrading", 3, 150, 0)
g.By("Change UpgradeConstraintPolicy to SelfCertified and allow downgrade")
clusterextension.Patch(oc, `{"spec":{"source":{"catalog":{"upgradeConstraintPolicy": "SelfCertified"}}}}`)
clusterextension.WaitClusterExtensionVersion(oc, "2.0.0")
})
g.It("PolarionID:75492-[OTP][Level0]cluster extension can not be installed with wrong sa or insufficient permission sa", g.Label("original-name:[sig-olmv1][Jira:OLM] clusterextension PolarionID:75492-[Skipped:Disconnected]cluster extension can not be installed with wrong sa or insufficient permission sa"), func() {
exutil.SkipForSNOCluster(oc)
olmv1util.ValidateAccessEnvironment(oc)
var (
caseID = "75492"
ns = "ns-" + caseID
sa = "sa" + caseID
labelValue = caseID
catalogName = "clustercatalog-" + caseID
ceInsufficientName = "ce-insufficient-" + caseID
ceWrongSaName = "ce-wrongsa-" + caseID
baseDir = exutil.FixturePath("testdata", "olm")
clustercatalogTemplate = filepath.Join(baseDir, "clustercatalog-withlabel.yaml")
clusterextensionTemplate = filepath.Join(baseDir, "clusterextension-withselectorlabel.yaml")
// Select template based on Boxcutter runtime feature gate
saClusterRoleBindingTemplate string
)
// Use Boxcutter template if BoxcutterRuntime is enabled, otherwise use Helm template
// Note: Both templates have the same content for this test (both lack finalizers permissions)
if olmv1util.IsFeaturegateEnabled(oc, "NewOLMBoxCutterRuntime") {
saClusterRoleBindingTemplate = filepath.Join(baseDir, "sa-nginx-insufficient-bundle-boxcutter.yaml")
} else {
saClusterRoleBindingTemplate = filepath.Join(baseDir, "sa-nginx-insufficient-bundle.yaml")
}
saCrb := olmv1util.SaCLusterRolebindingDescription{
Name: sa,
Namespace: ns,
RBACObjects: []olmv1util.ChildResource{
{Kind: "RoleBinding", Ns: ns, Names: []string{fmt.Sprintf("%s-installer-role-binding", sa)}},
{Kind: "Role", Ns: ns, Names: []string{fmt.Sprintf("%s-installer-role", sa)}},
{Kind: "ClusterRoleBinding", Ns: "", Names: []string{fmt.Sprintf("%s-installer-rbac-clusterrole-binding", sa),
fmt.Sprintf("%s-installer-clusterrole-binding", sa)}},
{Kind: "ClusterRole", Ns: "", Names: []string{fmt.Sprintf("%s-installer-rbac-clusterrole", sa),
fmt.Sprintf("%s-installer-clusterrole", sa)}},
{Kind: "ServiceAccount", Ns: ns, Names: []string{sa}},
},
Kinds: "okv3277775492s",
Template: saClusterRoleBindingTemplate,
}
clustercatalog := olmv1util.ClusterCatalogDescription{
Name: catalogName,
Imageref: "quay.io/olmqe/nginx-ok-index:vokv3283",
LabelValue: labelValue,
Template: clustercatalogTemplate,
}
ce75492Insufficient := olmv1util.ClusterExtensionDescription{
Name: ceInsufficientName,
PackageName: "nginx-ok-v3277775492",
Channel: "alpha",
Version: ">=0.0.1",
InstallNamespace: ns,
SaName: sa,
LabelValue: labelValue,
Template: clusterextensionTemplate,
}
ce75492WrongSa := olmv1util.ClusterExtensionDescription{
Name: ceWrongSaName,
PackageName: "nginx-ok-v3277775492",
Channel: "alpha",
Version: ">=0.0.1",
InstallNamespace: ns,
SaName: sa + "1",
LabelValue: labelValue,
Template: clusterextensionTemplate,
}
g.By("Create namespace")
defer func() {
_ = oc.WithoutNamespace().AsAdmin().Run("delete").Args("ns", ns, "--ignore-not-found", "--force").Execute()
}()
err := oc.WithoutNamespace().AsAdmin().Run("create").Args("ns", ns).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(olmv1util.Appearance(oc, exutil.Appear, "ns", ns)).To(o.BeTrue())
g.By("Create SA for clusterextension")
defer saCrb.Delete(oc)
saCrb.Create(oc)
g.By("Create clustercatalog")
defer clustercatalog.Delete(oc)
clustercatalog.Create(oc)
g.By("check Insufficient sa from bundle")
defer ce75492Insufficient.Delete(oc)
_ = ce75492Insufficient.CreateWithoutCheck(oc)
if olmv1util.IsFeaturegateEnabled(oc, "NewOLMPreflightPermissionChecks") {
// Env2 (Helm, preflight) or Env3 (Boxcutter, preflight): Both return same preflight error
ce75492Insufficient.CheckClusterExtensionCondition(oc, "Progressing", "message", "pre-authorization failed", 10, 60, 0)
} else {
// Env1 (Helm, no preflight) or Env4 (Boxcutter, no preflight)
// Error checking order differs between runtimes:
// - Helm (Env1): may encounter CRD creation errors first
// - Boxcutter (Env4): encounters privilege escalation errors first
if olmv1util.IsFeaturegateEnabled(oc, "NewOLMBoxCutterRuntime") {
// Env4: Boxcutter encounters privilege escalation error (missing namespace permissions)
ce75492Insufficient.CheckClusterExtensionCondition(oc, "Progressing", "message", "is attempting to grant RBAC permissions not currently held", 10, 60, 0)
} else {
// Env1: Helm may encounter CRD-related errors
ce75492Insufficient.CheckClusterExtensionCondition(oc, "Progressing", "message", "could not get information about the resource CustomResourceDefinition", 10, 60, 0)
}
}
g.By("check wrong sa")
defer ce75492WrongSa.Delete(oc)
_ = ce75492WrongSa.CreateWithoutCheck(oc)
// All environments now validate ServiceAccount existence at the start of the reconciliation
// pipeline (after finalizer handling, before revision state retrieval). This provides:
// - Consistent error messages across all feature gate combinations
// - Fail-fast behavior (no wasted reconciliation cycles)
// - User-facing error format: "operation cannot proceed due to the following validation error(s):
// service account \"xxx\" not found in namespace \"yyy\""
//
// The validation uses ServiceAccountValidator which performs a direct CoreV1 API Get call.
ce75492WrongSa.CheckClusterExtensionCondition(oc, "Progressing", "message", "not found", 10, 60, 0)
})
g.It("PolarionID:75493-[OTP][Level0]cluster extension can be installed with enough permission sa", g.Label("original-name:[sig-olmv1][Jira:OLM] clusterextension PolarionID:75493-[Skipped:Disconnected]cluster extension can be installed with enough permission sa"), func() {
exutil.SkipForSNOCluster(oc)
olmv1util.ValidateAccessEnvironment(oc)
var (
caseID = "75493"
ns = "ns-" + caseID
sa = "sa" + caseID
labelValue = caseID
catalogName = "clustercatalog-" + caseID
ceSufficientName = "ce-sufficient" + caseID
baseDir = exutil.FixturePath("testdata", "olm")
clustercatalogTemplate = filepath.Join(baseDir, "clustercatalog-withlabel.yaml")
clusterextensionTemplate = filepath.Join(baseDir, "clusterextension-withselectorlabel.yaml")
// Select template based on runtime: Boxcutter needs clusterobjectsets/finalizers, Helm needs clusterextensions/finalizers
saTemplate string
)
if olmv1util.IsFeaturegateEnabled(oc, "NewOLMBoxCutterRuntime") {
saTemplate = filepath.Join(baseDir, "sa-nginx-limited-boxcutter.yaml")
} else {
saTemplate = filepath.Join(baseDir, "sa-nginx-limited.yaml")
}
var (
saCrb = olmv1util.SaCLusterRolebindingDescription{
Name: sa,
Namespace: ns,
RBACObjects: []olmv1util.ChildResource{
{Kind: "RoleBinding", Ns: ns, Names: []string{fmt.Sprintf("%s-installer-role-binding", sa)}},
{Kind: "Role", Ns: ns, Names: []string{fmt.Sprintf("%s-installer-role", sa)}},
{Kind: "ClusterRoleBinding", Ns: "", Names: []string{fmt.Sprintf("%s-installer-rbac-clusterrole-binding", sa),
fmt.Sprintf("%s-installer-clusterrole-binding", sa)}},
{Kind: "ClusterRole", Ns: "", Names: []string{fmt.Sprintf("%s-installer-rbac-clusterrole", sa),
fmt.Sprintf("%s-installer-clusterrole", sa)}},
{Kind: "ServiceAccount", Ns: ns, Names: []string{sa}},
},
Kinds: "okv3277775493s",
Template: saTemplate,
}
clustercatalog = olmv1util.ClusterCatalogDescription{
Name: catalogName,
Imageref: "quay.io/olmqe/nginx-ok-index:vokv3283",
LabelValue: labelValue,
Template: clustercatalogTemplate,
}
ce75493 = olmv1util.ClusterExtensionDescription{
Name: ceSufficientName,
PackageName: "nginx-ok-v3277775493",
Channel: "alpha",
Version: ">=0.0.1",
InstallNamespace: ns,
SaName: sa,
LabelValue: labelValue,
Template: clusterextensionTemplate,
}
)
g.By("Create namespace")
defer func() {
_ = oc.WithoutNamespace().AsAdmin().Run("delete").Args("ns", ns, "--ignore-not-found", "--force").Execute()
}()
err := oc.WithoutNamespace().AsAdmin().Run("create").Args("ns", ns).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(olmv1util.Appearance(oc, exutil.Appear, "ns", ns)).To(o.BeTrue())
g.By("Create SA for clusterextension")
defer saCrb.Delete(oc)
saCrb.Create(oc)
g.By("Create clustercatalog")
defer clustercatalog.Delete(oc)
clustercatalog.Create(oc)
g.By("check if ce is installed with limited permission")
defer ce75493.Delete(oc)
ce75493.Create(oc)
o.Expect(olmv1util.Appearance(oc, exutil.Appear, "customresourcedefinitions.apiextensions.k8s.io", "okv3277775493s.cache.example.com")).To(o.BeTrue())
o.Expect(olmv1util.Appearance(oc, exutil.Appear, "services", "nginx-ok-v3283-75493-controller-manager-metrics-service", "-n", ns)).To(o.BeTrue())
ce75493.Delete(oc)
o.Expect(olmv1util.Appearance(oc, exutil.Disappear, "customresourcedefinitions.apiextensions.k8s.io", "okv3277775493s.cache.example.com")).To(o.BeTrue())
o.Expect(olmv1util.Appearance(oc, exutil.Disappear, "services", "nginx-ok-v3283-75493-controller-manager-metrics-service", "-n", ns)).To(o.BeTrue())
})
g.It("PolarionID:81538-[OTP]preflight check on permission on allns mode", g.Label("original-name:[sig-olmv1][Jira:OLM] clusterextension PolarionID:81538-[Skipped:Disconnected]preflight check on permission on allns mode"), func() {
if !olmv1util.IsFeaturegateEnabled(oc, "NewOLMPreflightPermissionChecks") {
g.Skip("NewOLMPreflightPermissionChecks feature gate is disabled. This test requires preflight permission validation to be enabled.")
}
exutil.SkipForSNOCluster(oc)
olmv1util.ValidateAccessEnvironment(oc)
var (
caseID = "81538"
ns = "ns-" + caseID
sa = "sa" + caseID
labelValue = caseID
catalogName = "clustercatalog-" + caseID
ceName = "ce-" + caseID
clusterroleName = ceName + "-clusterrole"
roleName = ceName + "-role" + "-" + ns
baseDir = exutil.FixturePath("testdata", "olm")
clustercatalogTemplate = filepath.Join(baseDir, "clustercatalog-withlabel.yaml")
clusterextensionTemplate = filepath.Join(baseDir, "clusterextension-withselectorlabel.yaml")
saTemplate = filepath.Join(baseDir, "sa.yaml")
bindingTemplate = filepath.Join(baseDir, "binding-prefligth.yaml")
clusterroleTemplate = filepath.Join(baseDir, "prefligth-clusterrole.yaml")
clustercatalog = olmv1util.ClusterCatalogDescription{
Name: catalogName,
Imageref: "quay.io/olmqe/nginx-ok-index:vokv81538",
LabelValue: labelValue,
Template: clustercatalogTemplate,
}
ce = olmv1util.ClusterExtensionDescription{
Name: ceName,
PackageName: "nginx-ok-v81538",
Channel: "alpha",
Version: ">=0.0.1",
InstallNamespace: ns,
SaName: sa,
LabelValue: labelValue,
Template: clusterextensionTemplate,
}
)
g.By("Create namespace")
defer func() {
_ = oc.WithoutNamespace().AsAdmin().Run("delete").Args("ns", ns, "--ignore-not-found", "--force").Execute()
}()
err := oc.WithoutNamespace().AsAdmin().Run("create").Args("ns", ns).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(olmv1util.Appearance(oc, exutil.Appear, "ns", ns)).To(o.BeTrue())
g.By("Create clustercatalog")
defer clustercatalog.Delete(oc)
clustercatalog.Create(oc)
g.By("create sa")
paremeters := []string{"-n", "default", "--ignore-unknown-parameters=true", "-f", saTemplate, "-p",
"NAME=" + sa, "NAMESPACE=" + ns}
configFileSa, errApplySa := olmv1util.ApplyNamepsaceResourceFromTemplate(oc, ns, paremeters...)
o.Expect(errApplySa).NotTo(o.HaveOccurred())
defer func() { _ = oc.AsAdmin().WithoutNamespace().Run("delete").Args("-f", configFileSa).Execute() }()
g.By("create clusterrole with wrong rule")
paremeters = []string{"-n", "default", "--ignore-unknown-parameters=true", "-f", clusterroleTemplate, "-p",
"NAME=" + clusterroleName}
configFileCLusterroe, errApplyCLusterrole := olmv1util.ApplyClusterResourceFromTemplate(oc, paremeters...)
o.Expect(errApplyCLusterrole).NotTo(o.HaveOccurred())
defer func() { _ = oc.AsAdmin().WithoutNamespace().Run("delete").Args("-f", configFileCLusterroe).Execute() }()
g.By("create binding")
paremeters = []string{"-n", "default", "--ignore-unknown-parameters=true", "-f", bindingTemplate, "-p",
"SANAME=" + sa, "NAMESPACE=" + ns, "ROLENAME=" + roleName, "CLUSTERROLESANAME=" + clusterroleName}
configFileBinding, errApplyBinding := olmv1util.ApplyClusterResourceFromTemplate(oc, paremeters...)
o.Expect(errApplyBinding).NotTo(o.HaveOccurred())
defer func() { _ = oc.AsAdmin().WithoutNamespace().Run("delete").Args("-f", configFileBinding).Execute() }()
g.By("check missing rule")
defer ce.Delete(oc)
_ = ce.CreateWithoutCheck(oc)
ce.CheckClusterExtensionCondition(oc, "Progressing", "message",
`Namespace:"" Verbs:[get] NonResourceURLs:[/metrics]`, 3, 150, 0)
ce.CheckClusterExtensionCondition(oc, "Progressing", "message",
`Namespace:"ns-81538" APIGroups:[] Resources:[services] ResourceNames:[nginx-ok-v81538-controller-manager-metrics-service] Verbs:[delete,get,patch,update]`, 3, 150, 0)
// Check finalizers permission based on Boxcutter runtime feature gate
if olmv1util.IsFeaturegateEnabled(oc, "NewOLMBoxCutterRuntime") {
// Env3: Boxcutter with preflight - expects clusterobjectsets/finalizers
// Note: In Boxcutter, the ResourceName is the ClusterObjectSet name (ce-81538-1 for first revision)
ce.CheckClusterExtensionCondition(oc, "Progressing", "message",
`Namespace:"" APIGroups:[olm.operatorframework.io] Resources:[clusterobjectsets/finalizers] ResourceNames:[ce-81538-1] Verbs:[update]`, 3, 150, 0)
} else {
// Env2: Helm with preflight - expects clusterextensions/finalizers
ce.CheckClusterExtensionCondition(oc, "Progressing", "message",
`Namespace:"" APIGroups:[olm.operatorframework.io] Resources:[clusterextensions/finalizers] ResourceNames:[ce-81538] Verbs:[update]`, 3, 150, 0)
}
g.By("generate rbac per missing rule and delete ce")
jsonpath := fmt.Sprintf(`jsonpath={.status.conditions[?(@.type=="%s")].%s}`, "Progressing", "message")
output, errGet := olmv1util.GetNoEmpty(oc, "clusterextension", ce.Name, "-o", jsonpath)
o.Expect(errGet).NotTo(o.HaveOccurred())
e2e.Logf("====%v====", output)
start := "permissions to manage cluster extension:"
end1 := "authorization evaluation error:"
end2 := "for resolved bundle"
filtered := olmv1util.FilterPermissions(output, start, end1, end2)
e2e.Logf("===============================================================================")
e2e.Logf("%v", filtered)
e2e.Logf("===============================================================================")
rabcDir := e2e.TestContext.OutputDir
clusterroleFile := filepath.Join(rabcDir, fmt.Sprintf("%s.yaml", clusterroleName))
roleFile := filepath.Join(rabcDir, fmt.Sprintf("%s.yaml", roleName))
errGen := olmv1util.GenerateRBACFromMissingRules(filtered, ceName, rabcDir)
o.Expect(errGen).NotTo(o.HaveOccurred())
g.By("create clusterrole")
err = oc.AsAdmin().WithoutNamespace().Run("apply").Args("-f", clusterroleFile).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
g.By("create role")
defer func() { _ = oc.AsAdmin().WithoutNamespace().Run("delete").Args("-f", roleFile).Execute() }()
err = oc.AsAdmin().WithoutNamespace().Run("apply").Args("-f", roleFile).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
g.By("check ce again afrer applying correct rules")
ce.CheckClusterExtensionCondition(oc, "Progressing", "reason", "Succeeded", 10, 600, 0)
})
g.It("PolarionID:81664-[OTP]preflight check on permission on own ns mode", g.Label("original-name:[sig-olmv1][Jira:OLM] clusterextension PolarionID:81664-[Skipped:Disconnected]preflight check on permission on own ns mode"), func() {
if !olmv1util.IsFeaturegateEnabled(oc, "NewOLMPreflightPermissionChecks") ||
!olmv1util.IsFeaturegateEnabled(oc, "NewOLMOwnSingleNamespace") {
g.Skip("Required feature gates are disabled: NewOLMPreflightPermissionChecks and NewOLMOwnSingleNamespace must both be enabled for this test.")
}
exutil.SkipForSNOCluster(oc)
olmv1util.ValidateAccessEnvironment(oc)
var (
caseID = "81664"
ns = "ns-" + caseID
sa = "sa" + caseID
labelValue = caseID
catalogName = "clustercatalog-" + caseID
ceName = "ce-" + caseID
clusterroleName = ceName + "-clusterrole"
roleName = ceName + "-role" + "-" + ns
baseDir = exutil.FixturePath("testdata", "olm")
clustercatalogTemplate = filepath.Join(baseDir, "clustercatalog-withlabel.yaml")
clusterextensionTemplate = filepath.Join(baseDir, "clusterextension-withselectorlabel-OwnSingle.yaml")
saTemplate = filepath.Join(baseDir, "sa.yaml")
bindingTemplate = filepath.Join(baseDir, "binding-prefligth.yaml")
clustercatalog = olmv1util.ClusterCatalogDescription{
Name: catalogName,
Imageref: "quay.io/olmqe/nginx-ok-index:vokv81664",
LabelValue: labelValue,
Template: clustercatalogTemplate,
}
ce = olmv1util.ClusterExtensionDescription{
Name: ceName,
PackageName: "nginx-ok-v81664",
Channel: "alpha",
Version: ">=0.0.1",
InstallNamespace: ns,
WatchNamespace: ns,
SaName: sa,
LabelValue: labelValue,
Template: clusterextensionTemplate,
}
)
g.By("Create namespace")
defer func() {
_ = oc.WithoutNamespace().AsAdmin().Run("delete").Args("ns", ns, "--ignore-not-found", "--force").Execute()
}()
err := oc.WithoutNamespace().AsAdmin().Run("create").Args("ns", ns).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(olmv1util.Appearance(oc, exutil.Appear, "ns", ns)).To(o.BeTrue())
g.By("Create clustercatalog")
defer clustercatalog.Delete(oc)
clustercatalog.Create(oc)
g.By("create sa")
paremeters := []string{"-n", "default", "--ignore-unknown-parameters=true", "-f", saTemplate, "-p",
"NAME=" + sa, "NAMESPACE=" + ns}
configFileSa, errApplySa := olmv1util.ApplyNamepsaceResourceFromTemplate(oc, ns, paremeters...)
o.Expect(errApplySa).NotTo(o.HaveOccurred())
defer func() { _ = oc.AsAdmin().WithoutNamespace().Run("delete").Args("-f", configFileSa).Execute() }()
g.By("check missing rule")
defer ce.Delete(oc)
_ = ce.CreateWithoutCheck(oc)
ce.CheckClusterExtensionCondition(oc, "Progressing", "message",
`Namespace:"" Verbs:[get] NonResourceURLs:[/metrics]`, 3, 150, 0)
ce.CheckClusterExtensionCondition(oc, "Progressing", "message",
`Namespace:"ns-81664" APIGroups:[] Resources:[services] ResourceNames:[nginx-ok-v81664-controller-manager-metrics-service] Verbs:[delete,get,patch,update]`, 3, 150, 0)
// Check finalizers permission based on Boxcutter runtime feature gate
if olmv1util.IsFeaturegateEnabled(oc, "NewOLMBoxCutterRuntime") {
// Env3: Boxcutter with preflight - expects clusterobjectsets/finalizers
// Note: In Boxcutter, the ResourceName is the ClusterObjectSet name (ce-81664-1 for first revision)
ce.CheckClusterExtensionCondition(oc, "Progressing", "message",
`Namespace:"" APIGroups:[olm.operatorframework.io] Resources:[clusterobjectsets/finalizers] ResourceNames:[ce-81664-1] Verbs:[update]`, 3, 150, 0)
} else {
// Env2: Helm with preflight - expects clusterextensions/finalizers
ce.CheckClusterExtensionCondition(oc, "Progressing", "message",
`Namespace:"" APIGroups:[olm.operatorframework.io] Resources:[clusterextensions/finalizers] ResourceNames:[ce-81664] Verbs:[update]`, 3, 150, 0)
}
g.By("generate rbac per missing rule and delete ce")
jsonpath := fmt.Sprintf(`jsonpath={.status.conditions[?(@.type=="%s")].%s}`, "Progressing", "message")
output, errGet := olmv1util.GetNoEmpty(oc, "clusterextension", ce.Name, "-o", jsonpath)
o.Expect(errGet).NotTo(o.HaveOccurred())
ce.Delete(oc)
e2e.Logf("====%v====", output)
start := "permissions to manage cluster extension:"
end1 := "authorization evaluation error:"
end2 := "for resolved bundle"
filtered := olmv1util.FilterPermissions(output, start, end1, end2)
e2e.Logf("===============================================================================")
e2e.Logf("%v", filtered)
e2e.Logf("===============================================================================")
rabcDir := e2e.TestContext.OutputDir
clusterroleFile := filepath.Join(rabcDir, fmt.Sprintf("%s.yaml", clusterroleName))
roleFile := filepath.Join(rabcDir, fmt.Sprintf("%s.yaml", roleName))
errGen := olmv1util.GenerateRBACFromMissingRules(filtered, ceName, rabcDir)
o.Expect(errGen).NotTo(o.HaveOccurred())
g.By("create clusterrole")
defer func() { _ = oc.AsAdmin().WithoutNamespace().Run("delete").Args("-f", clusterroleFile).Execute() }()
err = oc.AsAdmin().WithoutNamespace().Run("apply").Args("-f", clusterroleFile).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
g.By("create role")
defer func() { _ = oc.AsAdmin().WithoutNamespace().Run("delete").Args("-f", roleFile).Execute() }()
err = oc.AsAdmin().WithoutNamespace().Run("apply").Args("-f", roleFile).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
g.By("create binding")
paremeters = []string{"-n", "default", "--ignore-unknown-parameters=true", "-f", bindingTemplate, "-p",
"SANAME=" + sa, "NAMESPACE=" + ns, "ROLENAME=" + roleName, "CLUSTERROLESANAME=" + clusterroleName}
configFileBinding, errApplyBinding := olmv1util.ApplyClusterResourceFromTemplate(oc, paremeters...)
o.Expect(errApplyBinding).NotTo(o.HaveOccurred())
defer func() { _ = oc.AsAdmin().WithoutNamespace().Run("delete").Args("-f", configFileBinding).Execute() }()
g.By("check ce again afrer applying correct rules")
ce.Create(oc)
})
g.It("PolarionID:81696-[OTP]preflight check on permission on single ns mode", g.Label("original-name:[sig-olmv1][Jira:OLM] clusterextension PolarionID:81696-[Skipped:Disconnected]preflight check on permission on single ns mode"), func() {
if !olmv1util.IsFeaturegateEnabled(oc, "NewOLMPreflightPermissionChecks") ||
!olmv1util.IsFeaturegateEnabled(oc, "NewOLMOwnSingleNamespace") {
g.Skip("Required feature gates are disabled: NewOLMPreflightPermissionChecks and NewOLMOwnSingleNamespace must both be enabled for this test.")
}
exutil.SkipForSNOCluster(oc)
olmv1util.ValidateAccessEnvironment(oc)
var (
caseID = "81696"
ns = "ns-" + caseID
nsWatch = "ns-" + caseID + "-watch"
sa = "sa" + caseID
labelValue = caseID
catalogName = "clustercatalog-" + caseID
ceName = "ce-" + caseID
clusterroleName = ceName + "-clusterrole"
roleNsName = ceName + "-role" + "-" + ns
roleNsWatchName = ceName + "-role" + "-" + nsWatch
baseDir = exutil.FixturePath("testdata", "olm")
clustercatalogTemplate = filepath.Join(baseDir, "clustercatalog-withlabel.yaml")
clusterextensionTemplate = filepath.Join(baseDir, "clusterextension-withselectorlabel-OwnSingle.yaml")
saTemplate = filepath.Join(baseDir, "sa.yaml")
bindingTemplate = filepath.Join(baseDir, "binding-prefligth_multirole.yaml")
clustercatalog = olmv1util.ClusterCatalogDescription{
Name: catalogName,
Imageref: "quay.io/olmqe/nginx-ok-index:vokv81696",
LabelValue: labelValue,
Template: clustercatalogTemplate,
}
ce = olmv1util.ClusterExtensionDescription{
Name: ceName,
PackageName: "nginx-ok-v81696",
Channel: "alpha",
Version: ">=0.0.1",
InstallNamespace: ns,
WatchNamespace: nsWatch,
SaName: sa,
LabelValue: labelValue,
Template: clusterextensionTemplate,
}
)
g.By("Create namespace")
defer func() {
_ = oc.WithoutNamespace().AsAdmin().Run("delete").Args("ns", ns, "--ignore-not-found", "--force").Execute()
}()
err := oc.WithoutNamespace().AsAdmin().Run("create").Args("ns", ns).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(olmv1util.Appearance(oc, exutil.Appear, "ns", ns)).To(o.BeTrue())
g.By("Create watch namespace")
defer func() {
_ = oc.WithoutNamespace().AsAdmin().Run("delete").Args("ns", nsWatch, "--ignore-not-found", "--force").Execute()
}()
err = oc.WithoutNamespace().AsAdmin().Run("create").Args("ns", nsWatch).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(olmv1util.Appearance(oc, exutil.Appear, "ns", nsWatch)).To(o.BeTrue())
g.By("Create clustercatalog")
defer clustercatalog.Delete(oc)
clustercatalog.Create(oc)
g.By("create sa")
paremeters := []string{"-n", "default", "--ignore-unknown-parameters=true", "-f", saTemplate, "-p",
"NAME=" + sa, "NAMESPACE=" + ns}
configFileSa, errApplySa := olmv1util.ApplyNamepsaceResourceFromTemplate(oc, ns, paremeters...)
o.Expect(errApplySa).NotTo(o.HaveOccurred())
defer func() { _ = oc.AsAdmin().WithoutNamespace().Run("delete").Args("-f", configFileSa).Execute() }()
g.By("check missing rule")
defer ce.Delete(oc)
_ = ce.CreateWithoutCheck(oc)
ce.CheckClusterExtensionCondition(oc, "Progressing", "message",
`Namespace:"" Verbs:[get] NonResourceURLs:[/metrics]`, 3, 150, 0)
ce.CheckClusterExtensionCondition(oc, "Progressing", "message",
`Namespace:"ns-81696" APIGroups:[] Resources:[services] ResourceNames:[nginx-ok-v81696-controller-manager-metrics-service] Verbs:[delete,get,patch,update]`, 3, 150, 0)
// Check finalizers permission based on Boxcutter runtime feature gate
if olmv1util.IsFeaturegateEnabled(oc, "NewOLMBoxCutterRuntime") {
// Env3: Boxcutter with preflight - expects clusterobjectsets/finalizers
// Note: In Boxcutter, the ResourceName is the ClusterObjectSet name (ce-81696-1 for first revision)
ce.CheckClusterExtensionCondition(oc, "Progressing", "message",
`Namespace:"" APIGroups:[olm.operatorframework.io] Resources:[clusterobjectsets/finalizers] ResourceNames:[ce-81696-1] Verbs:[update]`, 3, 150, 0)
} else {
// Env2: Helm with preflight - expects clusterextensions/finalizers
ce.CheckClusterExtensionCondition(oc, "Progressing", "message",
`Namespace:"" APIGroups:[olm.operatorframework.io] Resources:[clusterextensions/finalizers] ResourceNames:[ce-81696] Verbs:[update]`, 3, 150, 0)
}
g.By("generate rbac per missing rule and delete ce")
jsonpath := fmt.Sprintf(`jsonpath={.status.conditions[?(@.type=="%s")].%s}`, "Progressing", "message")
output, errGet := olmv1util.GetNoEmpty(oc, "clusterextension", ce.Name, "-o", jsonpath)
o.Expect(errGet).NotTo(o.HaveOccurred())
ce.Delete(oc)
e2e.Logf("====%v====", output)
start := "permissions to manage cluster extension:"
end1 := "authorization evaluation error:"
end2 := "for resolved bundle"
filtered := olmv1util.FilterPermissions(output, start, end1, end2)
e2e.Logf("===============================================================================")
e2e.Logf("%v", filtered)
e2e.Logf("===============================================================================")
rbacDir := e2e.TestContext.OutputDir
clusterroleFile := filepath.Join(rbacDir, fmt.Sprintf("%s.yaml", clusterroleName))
roleNsFile := filepath.Join(rbacDir, fmt.Sprintf("%s.yaml", roleNsName))
roleNsWatchFile := filepath.Join(rbacDir, fmt.Sprintf("%s.yaml", roleNsWatchName))
errGen := olmv1util.GenerateRBACFromMissingRules(filtered, ceName, rbacDir)
o.Expect(errGen).NotTo(o.HaveOccurred())
g.By("create clusterrole")
defer func() { _ = oc.AsAdmin().WithoutNamespace().Run("delete").Args("-f", clusterroleFile).Execute() }()
err = oc.AsAdmin().WithoutNamespace().Run("apply").Args("-f", clusterroleFile).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
g.By("create role for ns")
defer func() { _ = oc.AsAdmin().WithoutNamespace().Run("delete").Args("-f", roleNsFile).Execute() }()
err = oc.AsAdmin().WithoutNamespace().Run("apply").Args("-f", roleNsFile).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
g.By("create role for ns watch")
// Check if the watch namespace role file exists before trying to apply it
// The file may not exist if no permissions are needed for the watch namespace
if _, err := os.Stat(roleNsWatchFile); err == nil {
defer func() { _ = oc.AsAdmin().WithoutNamespace().Run("delete").Args("-f", roleNsWatchFile).Execute() }()
err = oc.AsAdmin().WithoutNamespace().Run("apply").Args("-f", roleNsWatchFile).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
} else {
e2e.Logf("Watch namespace role file %s does not exist, skipping creation", roleNsWatchFile)
}
g.By("create binding")
paremeters = []string{"-n", "default", "--ignore-unknown-parameters=true", "-f", bindingTemplate, "-p",
"SANAME=" + sa, "NAMESPACE=" + ns, "ROLENAME=" + roleNsName, "CLUSTERROLESANAME=" + clusterroleName,
"WATCHNAMESPACE=" + nsWatch, "WATCHROLENAME=" + roleNsWatchName}
configFileBinding, errApplyBinding := olmv1util.ApplyClusterResourceFromTemplate(oc, paremeters...)
o.Expect(errApplyBinding).NotTo(o.HaveOccurred())
defer func() { _ = oc.AsAdmin().WithoutNamespace().Run("delete").Args("-f", configFileBinding).Execute() }()
g.By("check ce again afrer applying correct rules")
ce.Create(oc)
})
g.It("PolarionID:87224-[Skipped:Disconnected]Upgrade version support [Serial]", func() {
var (
caseID = "87224"
ns = "ns-" + caseID
sa = "sa" + caseID
ceName = "ce-" + caseID
labelValue = caseID
baseDir = exutil.FixturePath("testdata", "olm")
clustercatalogTemplate = filepath.Join(baseDir, "clustercatalog-withlabel.yaml")
clusterextensionTemplate = filepath.Join(baseDir, "clusterextension-withselectorlabel-WithoutChannel.yaml")
saClusterRoleBindingTemplate = filepath.Join(baseDir, "sa-admin.yaml")