Skip to content

Commit d85696e

Browse files
Merge pull request #2167 from joelanford/fix/explicit-catsrc-secctx
Explicitly set `readOnlyRootFilesystem: false` on created registry pods.
2 parents c376e28 + 4be967a commit d85696e

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

pkg/controller/registry/reconciler/reconciler.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ package reconciler
44
import (
55
"strings"
66

7+
v1 "k8s.io/api/core/v1"
8+
"k8s.io/apimachinery/pkg/api/resource"
9+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
10+
711
"github.com/operator-framework/api/pkg/operators/v1alpha1"
812
controllerclient "github.com/operator-framework/operator-lifecycle-manager/pkg/lib/controller-runtime/client"
913
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorclient"
1014
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorlister"
11-
v1 "k8s.io/api/core/v1"
12-
"k8s.io/apimachinery/pkg/api/resource"
13-
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1415
)
1516

1617
type nowFunc func() metav1.Time
@@ -102,6 +103,8 @@ func Pod(source *v1alpha1.CatalogSource, name string, image string, saName strin
102103
pullPolicy = v1.PullAlways
103104
}
104105

106+
readOnlyRootFilesystem := false
107+
105108
pod := &v1.Pod{
106109
ObjectMeta: metav1.ObjectMeta{
107110
GenerateName: source.GetName() + "-",
@@ -143,6 +146,9 @@ func Pod(source *v1alpha1.CatalogSource, name string, image string, saName strin
143146
v1.ResourceMemory: resource.MustParse("50Mi"),
144147
},
145148
},
149+
SecurityContext: &v1.SecurityContext{
150+
ReadOnlyRootFilesystem: &readOnlyRootFilesystem,
151+
},
146152
ImagePullPolicy: pullPolicy,
147153
TerminationMessagePolicy: v1.TerminationMessageFallbackToLogsOnError,
148154
},

pkg/controller/registry/reconciler/reconciler_test.go

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package reconciler
22

33
import (
4-
"github.com/operator-framework/api/pkg/operators/v1alpha1"
4+
"testing"
5+
6+
"github.com/stretchr/testify/require"
57
corev1 "k8s.io/api/core/v1"
68
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
79

8-
"testing"
10+
"github.com/operator-framework/api/pkg/operators/v1alpha1"
911
)
1012

1113
func TestPodNodeSelector(t *testing.T) {
@@ -74,3 +76,21 @@ func TestPullPolicy(t *testing.T) {
7476
}
7577
}
7678
}
79+
80+
func TestPodContainerSecurityContext(t *testing.T) {
81+
expectedReadOnlyRootFilesystem := false
82+
expectedContainerSecCtx := &corev1.SecurityContext{
83+
ReadOnlyRootFilesystem: &expectedReadOnlyRootFilesystem,
84+
}
85+
86+
catsrc := &v1alpha1.CatalogSource{
87+
ObjectMeta: metav1.ObjectMeta{
88+
Name: "test",
89+
Namespace: "testns",
90+
},
91+
}
92+
93+
gotPod := Pod(catsrc, "hello", "busybox", "", map[string]string{}, map[string]string{}, int32(0), int32(0))
94+
gotContainerSecCtx := gotPod.Spec.Containers[0].SecurityContext
95+
require.Equal(t, expectedContainerSecCtx, gotContainerSecCtx)
96+
}

0 commit comments

Comments
 (0)