Skip to content

Commit 22189e1

Browse files
[release-1.8] Added security context to source receive adapter pod (#962)
* added security context to source receive adapter pod * fixed tests Co-authored-by: gabriel <[email protected]>
1 parent 90cd1f9 commit 22189e1

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

pkg/reconciler/source/resources/receive_adapter.go

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"knative.dev/eventing-rabbitmq/pkg/apis/sources/v1alpha1"
2929
eventingduckv1 "knative.dev/eventing/pkg/apis/duck/v1"
3030
"knative.dev/pkg/kmeta"
31+
"knative.dev/pkg/ptr"
3132
)
3233

3334
type ReceiveAdapterArgs struct {
@@ -168,17 +169,23 @@ func MakeReceiveAdapter(args *ReceiveAdapterArgs) *v1.Deployment {
168169
},
169170
Spec: corev1.PodSpec{
170171
ServiceAccountName: args.Source.Spec.ServiceAccountName,
171-
Containers: []corev1.Container{
172-
{
173-
Name: "receive-adapter",
174-
Image: args.Image,
175-
ImagePullPolicy: "IfNotPresent",
176-
Env: env,
177-
// This resource requests and limits comes from performance testing 1500msgs/s with a parallelism of 1000
178-
// more info in this issue: https://github.com/knative-sandbox/eventing-rabbitmq/issues/703
179-
Resources: args.ResourceRequirements,
172+
Containers: []corev1.Container{{
173+
Name: "receive-adapter",
174+
Image: args.Image,
175+
ImagePullPolicy: "IfNotPresent",
176+
Env: env,
177+
// This resource requests and limits comes from performance testing 1500msgs/s with a parallelism of 1000
178+
// more info in this issue: https://github.com/knative-sandbox/eventing-rabbitmq/issues/703
179+
Resources: args.ResourceRequirements,
180+
SecurityContext: &corev1.SecurityContext{
181+
AllowPrivilegeEscalation: ptr.Bool(false),
182+
ReadOnlyRootFilesystem: ptr.Bool(true),
183+
RunAsNonRoot: ptr.Bool(true),
184+
Capabilities: &corev1.Capabilities{
185+
Drop: []corev1.Capability{"all"},
186+
},
180187
},
181-
},
188+
}},
182189
},
183190
},
184191
},

pkg/reconciler/source/resources/receive_adapter_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2727
v1alpha12 "knative.dev/eventing-rabbitmq/pkg/apis/sources/v1alpha1"
2828
eventingduckv1 "knative.dev/eventing/pkg/apis/duck/v1"
29+
"knative.dev/pkg/ptr"
2930
)
3031

3132
const (
@@ -153,6 +154,14 @@ func TestMakeReceiveAdapter(t *testing.T) {
153154
corev1.ResourceCPU: resource.MustParse("4000m"),
154155
corev1.ResourceMemory: resource.MustParse("600Mi")},
155156
},
157+
SecurityContext: &corev1.SecurityContext{
158+
AllowPrivilegeEscalation: ptr.Bool(false),
159+
ReadOnlyRootFilesystem: ptr.Bool(true),
160+
RunAsNonRoot: ptr.Bool(true),
161+
Capabilities: &corev1.Capabilities{
162+
Drop: []corev1.Capability{"all"},
163+
},
164+
},
156165
VolumeMounts: []corev1.VolumeMount{
157166
{
158167
MountPath: "/etc/ssl/certs/",

0 commit comments

Comments
 (0)