Skip to content

Commit b3ec2cd

Browse files
committed
Default to legacy PSA settings
Problem: OLM recently introduced a few changes to default to running its workloads in a restricted mode. As a part of these changes, catalogSources built with earlier versions of OPM will not run as expected unless the catalogSource yaml is configured to run in a legacy version. Unfortunately, these legacy catalogs cannot be ran in restricted namespaces, which includes the `olm` namespace which is used to define global catalogSources. Solution: Provide users ample time to convert to the new restricted fromat by defaulting to legacy restrictions and reclassify the `olm` namespace as a baseline privilege namespace. Signed-off-by: Alexander Greene <[email protected]>
1 parent c3340a3 commit b3ec2cd

File tree

3 files changed

+47
-16
lines changed

3 files changed

+47
-16
lines changed

pkg/controller/registry/reconciler/reconciler.go

+1-5
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,7 @@ func Pod(source *operatorsv1alpha1.CatalogSource, name string, image string, saN
195195
},
196196
}
197197

198-
if source.Spec.GrpcPodConfig != nil {
199-
if source.Spec.GrpcPodConfig.SecurityContextConfig == operatorsv1alpha1.Restricted {
200-
addSecurityContext(pod, runAsUser)
201-
}
202-
} else {
198+
if source.Spec.GrpcPodConfig != nil && source.Spec.GrpcPodConfig.SecurityContextConfig == operatorsv1alpha1.Restricted {
203199
addSecurityContext(pod, runAsUser)
204200
}
205201

pkg/controller/registry/reconciler/reconciler_test.go

+42-10
Original file line numberDiff line numberDiff line change
@@ -88,25 +88,57 @@ func TestPodContainerSecurityContext(t *testing.T) {
8888
expectedContainerSecurityContext *corev1.SecurityContext
8989
}{
9090
{
91-
title: "NoSpecDefined/PodContainsSecurityConfigForPSARestricted",
91+
title: "NoSpecDefined/PodContainsSecurityConfigForPSALegacy",
9292
inputCatsrc: &v1alpha1.CatalogSource{
9393
ObjectMeta: metav1.ObjectMeta{
9494
Name: "test",
9595
Namespace: "testns",
9696
},
9797
},
98-
expectedContainerSecurityContext: &corev1.SecurityContext{
99-
ReadOnlyRootFilesystem: pointer.Bool(false),
100-
AllowPrivilegeEscalation: pointer.Bool(false),
101-
Capabilities: &corev1.Capabilities{
102-
Drop: []corev1.Capability{"ALL"},
98+
expectedContainerSecurityContext: nil,
99+
expectedSecurityContext: nil,
100+
},
101+
{
102+
title: "SpecDefined/NoGRPCPodConfig/PodContainsSecurityConfigForPSALegacy",
103+
inputCatsrc: &v1alpha1.CatalogSource{
104+
ObjectMeta: metav1.ObjectMeta{
105+
Name: "test",
106+
Namespace: "testns",
103107
},
108+
Spec: v1alpha1.CatalogSourceSpec{},
104109
},
105-
expectedSecurityContext: &corev1.PodSecurityContext{
106-
SeccompProfile: &corev1.SeccompProfile{Type: corev1.SeccompProfileTypeRuntimeDefault},
107-
RunAsUser: pointer.Int64(workloadUserID),
108-
RunAsNonRoot: pointer.Bool(true),
110+
expectedContainerSecurityContext: nil,
111+
expectedSecurityContext: nil,
112+
},
113+
{
114+
title: "SpecDefined/GRPCPodConfigDefined/PodContainsSecurityConfigForPSALegacy",
115+
inputCatsrc: &v1alpha1.CatalogSource{
116+
ObjectMeta: metav1.ObjectMeta{
117+
Name: "test",
118+
Namespace: "testns",
119+
},
120+
Spec: v1alpha1.CatalogSourceSpec{
121+
GrpcPodConfig: &v1alpha1.GrpcPodConfig{},
122+
},
123+
},
124+
expectedContainerSecurityContext: nil,
125+
expectedSecurityContext: nil,
126+
},
127+
{
128+
title: "SpecDefined/SecurityContextConfig:Legacy/PodContainsSecurityConfigForPSALegacy",
129+
inputCatsrc: &v1alpha1.CatalogSource{
130+
ObjectMeta: metav1.ObjectMeta{
131+
Name: "test",
132+
Namespace: "testns",
133+
},
134+
Spec: v1alpha1.CatalogSourceSpec{
135+
GrpcPodConfig: &v1alpha1.GrpcPodConfig{
136+
SecurityContextConfig: v1alpha1.Legacy,
137+
},
138+
},
109139
},
140+
expectedContainerSecurityContext: nil,
141+
expectedSecurityContext: nil,
110142
},
111143
{
112144
title: "SpecDefined/SecurityContextConfig:Restricted/PodContainsSecurityConfigForPSARestricted",

test/e2e/catalog_e2e_test.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -1425,7 +1425,7 @@ var _ = Describe("Starting CatalogSource e2e tests", func() {
14251425
return nil
14261426
}).Should(BeNil())
14271427
})
1428-
When("A CatalogSource built with opm v1.21.0 (<v1.23.2)is created without spec.GrpcPodConfig.SecurityContextConfig set to legacy", func() {
1428+
When("A CatalogSource built with opm v1.21.0 (<v1.23.2)is created with spec.GrpcPodConfig.SecurityContextConfig set to restricted", func() {
14291429
var sourceName string
14301430
BeforeEach(func() {
14311431
sourceName = genName("catalog-")
@@ -1442,6 +1442,9 @@ var _ = Describe("Starting CatalogSource e2e tests", func() {
14421442
Spec: v1alpha1.CatalogSourceSpec{
14431443
SourceType: v1alpha1.SourceTypeGrpc,
14441444
Image: "quay.io/olmtest/old-opm-catsrc:v1.21.0",
1445+
GrpcPodConfig: &v1alpha1.GrpcPodConfig{
1446+
SecurityContextConfig: operatorsv1alpha1.Restricted,
1447+
},
14451448
},
14461449
}
14471450

0 commit comments

Comments
 (0)