Skip to content

Commit 2d47938

Browse files
committed
Update CatalogSource Pod security context
Signed-off-by: perdasilva <[email protected]>
1 parent c610a3e commit 2d47938

File tree

4 files changed

+55
-3
lines changed

4 files changed

+55
-3
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ FROM quay.io/fedora/fedora:34-x86_64 as builder
22
LABEL stage=builder
33
WORKDIR /build
44

5-
# install dependencies and go 1.16
5+
# install dependencies and go 1.17
66

77
# copy just enough of the git repo to parse HEAD, used to record version in OLM binaries
88
RUN dnf update -y && dnf install -y bash make git mercurial jq wget && dnf upgrade -y

pkg/controller/registry/reconciler/reconciler.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,13 @@ func Pod(source *operatorsv1alpha1.CatalogSource, name string, image string, saN
113113
pullPolicy = corev1.PullAlways
114114
}
115115

116+
// Security context
116117
readOnlyRootFilesystem := false
118+
allowPrivilegeEscalation := false
119+
runAsNonRoot := true
120+
121+
// See: https://github.com/operator-framework/operator-registry/blob/master/Dockerfile#L27
122+
runAsUser := int64(1001)
117123

118124
pod := &corev1.Pod{
119125
ObjectMeta: metav1.ObjectMeta{
@@ -167,12 +173,23 @@ func Pod(source *operatorsv1alpha1.CatalogSource, name string, image string, saN
167173
},
168174
},
169175
SecurityContext: &corev1.SecurityContext{
170-
ReadOnlyRootFilesystem: &readOnlyRootFilesystem,
176+
ReadOnlyRootFilesystem: &readOnlyRootFilesystem,
177+
AllowPrivilegeEscalation: &allowPrivilegeEscalation,
178+
Capabilities: &corev1.Capabilities{
179+
Drop: []corev1.Capability{"ALL"},
180+
},
171181
},
172182
ImagePullPolicy: pullPolicy,
173183
TerminationMessagePolicy: corev1.TerminationMessageFallbackToLogsOnError,
174184
},
175185
},
186+
SecurityContext: &corev1.PodSecurityContext{
187+
RunAsNonRoot: &runAsNonRoot,
188+
RunAsUser: &runAsUser,
189+
SeccompProfile: &corev1.SeccompProfile{
190+
Type: corev1.SeccompProfileTypeRuntimeDefault,
191+
},
192+
},
176193
NodeSelector: map[string]string{
177194
"kubernetes.io/os": "linux",
178195
},

pkg/controller/registry/reconciler/reconciler_test.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,23 @@ func TestPullPolicy(t *testing.T) {
7979

8080
func TestPodContainerSecurityContext(t *testing.T) {
8181
expectedReadOnlyRootFilesystem := false
82+
expectedAllowPrivilegeEscalation := false
83+
expectedRunAsNonRoot := true
84+
expectedRunAsUser := int64(1001)
85+
8286
expectedContainerSecCtx := &corev1.SecurityContext{
83-
ReadOnlyRootFilesystem: &expectedReadOnlyRootFilesystem,
87+
ReadOnlyRootFilesystem: &expectedReadOnlyRootFilesystem,
88+
AllowPrivilegeEscalation: &expectedAllowPrivilegeEscalation,
89+
Capabilities: &corev1.Capabilities{
90+
Drop: []corev1.Capability{"ALL"},
91+
},
92+
}
93+
expectedPodSecCtx := &corev1.PodSecurityContext{
94+
RunAsNonRoot: &expectedRunAsNonRoot,
95+
RunAsUser: &expectedRunAsUser,
96+
SeccompProfile: &corev1.SeccompProfile{
97+
Type: corev1.SeccompProfileTypeRuntimeDefault,
98+
},
8499
}
85100

86101
catsrc := &v1alpha1.CatalogSource{
@@ -92,7 +107,9 @@ func TestPodContainerSecurityContext(t *testing.T) {
92107

93108
gotPod := Pod(catsrc, "hello", "busybox", "", map[string]string{}, map[string]string{}, int32(0), int32(0))
94109
gotContainerSecCtx := gotPod.Spec.Containers[0].SecurityContext
110+
gotPodSecCtx := gotPod.Spec.SecurityContext
95111
require.Equal(t, expectedContainerSecCtx, gotContainerSecCtx)
112+
require.Equal(t, expectedPodSecCtx, gotPodSecCtx)
96113
}
97114

98115
func TestPodSchedulingOverrides(t *testing.T) {

test/e2e/collect-ci-artifacts.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,25 @@ echo "Using the ${TEST_ARTIFACTS_DIR} output directory"
1414
mkdir -p "${TEST_ARTIFACTS_DIR}"
1515

1616
commands=()
17+
commands+=("describe catalogsources")
18+
commands+=("describe subscriptions")
19+
commands+=("describe operatorgroups")
20+
commands+=("describe clusterserviceversions")
21+
commands+=("describe installplans")
22+
commands+=("describe pods")
23+
commands+=("describe service")
24+
commands+=("describe configmap")
1725
commands+=("get catalogsources -o yaml")
1826
commands+=("get subscriptions -o yaml")
1927
commands+=("get operatorgroups -o yaml")
2028
commands+=("get clusterserviceversions -o yaml")
2129
commands+=("get installplans -o yaml")
30+
commands+=("get pods -o yaml")
31+
commands+=("get all -o yaml")
32+
commands+=("get service -o yaml")
33+
commands+=("get configmap -o yaml")
2234
commands+=("get pods -o wide")
35+
commands+=("get all -o wide")
2336
commands+=("get events --sort-by .lastTimestamp")
2437

2538
echo "Storing the test artifact output in the ${TEST_ARTIFACTS_DIR} directory"
@@ -28,3 +41,8 @@ for command in "${commands[@]}"; do
2841
COMMAND_OUTPUT_FILE=${TEST_ARTIFACTS_DIR}/${command// /_}
2942
${KUBECTL} -n ${TEST_NAMESPACE} ${command} >> "${COMMAND_OUTPUT_FILE}"
3043
done
44+
45+
for pod in $(${KUBECTL} -n ${TEST_NAMESPACE} get --no-headers pods | awk '{ print $1 }'); do
46+
echo "Collecting logs for pod: ${pod}"
47+
${KUBECTL} -n ${TEST_NAMESPACE} logs ${pod} >> "${TEST_ARTIFACTS_DIR}/${pod}.log"
48+
done

0 commit comments

Comments
 (0)