@@ -1396,7 +1396,151 @@ var _ = Describe("Starting CatalogSource e2e tests", func() {
1396
1396
})
1397
1397
})
1398
1398
})
1399
+ When ("The namespace is labled as Pod Security Admission policy enforce:restricted" , func () {
1400
+ BeforeEach (func () {
1401
+ var err error
1402
+ testNS := & corev1.Namespace {}
1403
+ Eventually (func () error {
1404
+ testNS , err = c .KubernetesInterface ().CoreV1 ().Namespaces ().Get (context .TODO (), ns .GetName (), metav1.GetOptions {})
1405
+ if err != nil {
1406
+ return err
1407
+ }
1408
+ return nil
1409
+ }).Should (BeNil ())
1410
+
1411
+ testNS .ObjectMeta .Labels = map [string ]string {
1412
+ "pod-security.kubernetes.io/enforce" : "restricted" ,
1413
+ "pod-security.kubernetes.io/enforce-version" : "latest" ,
1414
+ }
1415
+
1416
+ Eventually (func () error {
1417
+ _ , err := c .KubernetesInterface ().CoreV1 ().Namespaces ().Update (context .TODO (), testNS , metav1.UpdateOptions {})
1418
+ if err != nil {
1419
+ return err
1420
+ }
1421
+ return nil
1422
+ }).Should (BeNil ())
1423
+ })
1424
+ When ("A CatalogSource built with opm v1.21.0 (<v1.23.2)is created without spec.GrpcPodConfig.SecurityContextConfig set to legacy" , func () {
1425
+ var sourceName string
1426
+ BeforeEach (func () {
1427
+ // In OPC, any namespace created that is not prefixed with openshift- is overriden to be PSA restricted.
1428
+ // This test namespace needs to prefixed with openshift- so that the baseline enforcement is not overriden,
1429
+ // and it passes in OCP.
1430
+ // Change it only after https://github.com/operator-framework/operator-lifecycle-manager/issues/2859 is closed.
1431
+ sourceName = genName ("openshift-" )
1432
+ source := & v1alpha1.CatalogSource {
1433
+ TypeMeta : metav1.TypeMeta {
1434
+ Kind : v1alpha1 .CatalogSourceKind ,
1435
+ APIVersion : v1alpha1 .CatalogSourceCRDAPIVersion ,
1436
+ },
1437
+ ObjectMeta : metav1.ObjectMeta {
1438
+ Name : sourceName ,
1439
+ Namespace : ns .GetName (),
1440
+ Labels : map [string ]string {"olm.catalogSource" : sourceName },
1441
+ },
1442
+ Spec : v1alpha1.CatalogSourceSpec {
1443
+ SourceType : v1alpha1 .SourceTypeGrpc ,
1444
+ Image : "quay.io/olmtest/old-opm-catsrc:v1.21.0" ,
1445
+ },
1446
+ }
1447
+
1448
+ Eventually (func () error {
1449
+ _ , err := crc .OperatorsV1alpha1 ().CatalogSources (source .GetNamespace ()).Create (context .Background (), source , metav1.CreateOptions {})
1450
+ return err
1451
+ }).Should (Succeed ())
1452
+ })
1453
+ It ("The registry pod fails to become come up because of lack of permission" , func () {
1454
+ Eventually (func () (bool , error ) {
1455
+ podList , err := c .KubernetesInterface ().CoreV1 ().Pods (ns .GetName ()).List (context .TODO (), metav1.ListOptions {})
1456
+ if err != nil {
1457
+ return false , err
1458
+ }
1459
+ for _ , pod := range podList .Items {
1460
+ if pod .ObjectMeta .OwnerReferences != nil && pod .ObjectMeta .OwnerReferences [0 ].Name == sourceName {
1461
+ if pod .Status .ContainerStatuses != nil && pod .Status .ContainerStatuses [0 ].State .Terminated != nil {
1462
+ return true , nil
1463
+ }
1464
+ }
1465
+ }
1466
+ return false , nil
1467
+ }).Should (BeTrue ())
1468
+ })
1469
+ })
1470
+ })
1471
+ When ("The namespace is labled as Pod Security Admission policy enforce:baseline" , func () {
1472
+ BeforeEach (func () {
1473
+ var err error
1474
+ testNS := & corev1.Namespace {}
1475
+ Eventually (func () error {
1476
+ testNS , err = c .KubernetesInterface ().CoreV1 ().Namespaces ().Get (context .TODO (), ns .GetName (), metav1.GetOptions {})
1477
+ if err != nil {
1478
+ return err
1479
+ }
1480
+ return nil
1481
+ }).Should (BeNil ())
1482
+
1483
+ testNS .ObjectMeta .Labels = map [string ]string {
1484
+ "pod-security.kubernetes.io/enforce" : "baseline" ,
1485
+ "pod-security.kubernetes.io/enforce-version" : "latest" ,
1486
+ }
1399
1487
1488
+ Eventually (func () error {
1489
+ _ , err := c .KubernetesInterface ().CoreV1 ().Namespaces ().Update (context .TODO (), testNS , metav1.UpdateOptions {})
1490
+ if err != nil {
1491
+ return err
1492
+ }
1493
+ return nil
1494
+ }).Should (BeNil ())
1495
+ })
1496
+ When ("A CatalogSource built with opm v1.21.0 (<v1.23.2)is created with spec.GrpcPodConfig.SecurityContextConfig set to legacy" , func () {
1497
+ var sourceName string
1498
+ BeforeEach (func () {
1499
+ sourceName = genName ("catalog-" )
1500
+ source := & v1alpha1.CatalogSource {
1501
+ TypeMeta : metav1.TypeMeta {
1502
+ Kind : v1alpha1 .CatalogSourceKind ,
1503
+ APIVersion : v1alpha1 .CatalogSourceCRDAPIVersion ,
1504
+ },
1505
+ ObjectMeta : metav1.ObjectMeta {
1506
+ Name : sourceName ,
1507
+ Namespace : ns .GetName (),
1508
+ Labels : map [string ]string {"olm.catalogSource" : sourceName },
1509
+ },
1510
+ Spec : v1alpha1.CatalogSourceSpec {
1511
+ GrpcPodConfig : & v1alpha1.GrpcPodConfig {
1512
+ SecurityContextConfig : operatorsv1alpha1 .Legacy ,
1513
+ },
1514
+ SourceType : v1alpha1 .SourceTypeGrpc ,
1515
+ Image : "quay.io/olmtest/old-opm-catsrc:v1.21.0" ,
1516
+ },
1517
+ }
1518
+
1519
+ Eventually (func () error {
1520
+ _ , err := crc .OperatorsV1alpha1 ().CatalogSources (source .GetNamespace ()).Create (context .Background (), source , metav1.CreateOptions {})
1521
+ return err
1522
+ }).Should (Succeed ())
1523
+ })
1524
+ It ("The registry pod comes up successfully" , func () {
1525
+ Eventually (func () (bool , error ) {
1526
+ podList , err := c .KubernetesInterface ().CoreV1 ().Pods (ns .GetName ()).List (context .TODO (), metav1.ListOptions {})
1527
+ if err != nil {
1528
+ return false , err
1529
+ }
1530
+ for _ , pod := range podList .Items {
1531
+ if pod .ObjectMeta .OwnerReferences != nil && pod .ObjectMeta .OwnerReferences [0 ].Name == sourceName {
1532
+ if pod .Status .ContainerStatuses != nil {
1533
+ if * pod .Status .ContainerStatuses [0 ].Started == true {
1534
+ return true , nil
1535
+ }
1536
+ }
1537
+ }
1538
+ }
1539
+ return false , nil
1540
+ }).Should (BeTrue ())
1541
+ })
1542
+ })
1543
+ })
1400
1544
})
1401
1545
1402
1546
func getOperatorDeployment (c operatorclient.ClientInterface , namespace string , operatorLabels labels.Set ) (* appsv1.Deployment , error ) {
0 commit comments