@@ -27,8 +27,10 @@ import (
27
27
"k8s.io/client-go/tools/cache"
28
28
e2e "k8s.io/kubernetes/test/e2e/framework"
29
29
admissionapi "k8s.io/pod-security-admission/api"
30
+ "k8s.io/utils/ptr"
30
31
31
32
routev1 "github.com/openshift/api/route/v1"
33
+ v2 "github.com/openshift/api/security/v1"
32
34
routeclientset "github.com/openshift/client-go/route/clientset/versioned"
33
35
v1 "github.com/openshift/client-go/route/clientset/versioned/typed/route/v1"
34
36
exutil "github.com/openshift/origin/test/extended/util"
@@ -78,6 +80,24 @@ var _ = g.Describe("[sig-network][Feature:Router][apigroup:route.openshift.io]",
78
80
Name : "system:router" ,
79
81
},
80
82
}, metav1.CreateOptions {})
83
+ // The router typically runs with allowPrivilegeEscalation enabled; however, all service accounts are assigned
84
+ // to restricted-v2 scc by default, which disallows privilege escalation. The restricted policy permits
85
+ // privilege escalation.
86
+ _ , err = oc .AdminKubeClient ().RbacV1 ().RoleBindings (ns ).Create (context .Background (), & rbacv1.RoleBinding {
87
+ ObjectMeta : metav1.ObjectMeta {
88
+ Name : "router-restricted" ,
89
+ },
90
+ Subjects : []rbacv1.Subject {
91
+ {
92
+ Kind : "ServiceAccount" ,
93
+ Name : "default" ,
94
+ },
95
+ },
96
+ RoleRef : rbacv1.RoleRef {
97
+ Kind : "ClusterRole" ,
98
+ Name : "system:openshift:scc:restricted" ,
99
+ },
100
+ }, metav1.CreateOptions {})
81
101
o .Expect (err ).NotTo (o .HaveOccurred ())
82
102
})
83
103
@@ -546,17 +566,54 @@ func scaledRouter(name, image string, args []string) *appsv1.ReplicaSet {
546
566
Template : corev1.PodTemplateSpec {
547
567
ObjectMeta : metav1.ObjectMeta {
548
568
Labels : map [string ]string {"app" : name },
569
+ Annotations : map [string ]string {
570
+ // The restricted-v2 scc preempts restricted, so we must pin to restricted.
571
+ v2 .RequiredSCCAnnotation : "restricted" ,
572
+ },
549
573
},
550
574
Spec : corev1.PodSpec {
551
575
TerminationGracePeriodSeconds : & one ,
552
576
Containers : []corev1.Container {
553
577
{
554
578
Env : []corev1.EnvVar {
555
- {Name : "NAME" , ValueFrom : & corev1.EnvVarSource {FieldRef : & corev1.ObjectFieldSelector {FieldPath : "metadata.name" }}},
579
+ {
580
+ Name : "NAME" , ValueFrom : & corev1.EnvVarSource {
581
+ FieldRef : & corev1.ObjectFieldSelector {
582
+ FieldPath : "metadata.name" ,
583
+ },
584
+ },
585
+ },
586
+ {
587
+ Name : "POD_NAMESPACE" ,
588
+ ValueFrom : & corev1.EnvVarSource {
589
+ FieldRef : & corev1.ObjectFieldSelector {
590
+ FieldPath : "metadata.namespace" ,
591
+ },
592
+ },
593
+ },
556
594
},
557
595
Name : "router" ,
558
596
Image : image ,
559
- Args : args ,
597
+ Args : append (args , "--stats-port=1936" , "--metrics-type=haproxy" ),
598
+ Ports : []corev1.ContainerPort {
599
+ {
600
+ ContainerPort : 1936 ,
601
+ Name : "stats" ,
602
+ Protocol : corev1 .ProtocolTCP ,
603
+ },
604
+ },
605
+ ReadinessProbe : & corev1.Probe {
606
+ ProbeHandler : corev1.ProbeHandler {
607
+ HTTPGet : & corev1.HTTPGetAction {
608
+ Path : "/healthz/ready" ,
609
+ Port : intstr .FromInt32 (1936 ),
610
+ },
611
+ },
612
+ },
613
+ SecurityContext : & corev1.SecurityContext {
614
+ // Default is true, but explicitly specified here for clarity.
615
+ AllowPrivilegeEscalation : ptr.To [bool ](true ),
616
+ },
560
617
},
561
618
},
562
619
},
0 commit comments