Skip to content

Commit ef69b58

Browse files
fix: rootless k8s integration tests (#5290)
* fix: remove redundant setcap on agentbeat * fix: add required capabilities for rootless agent * fix: increase agent resources to prevent OOM restarts
1 parent ddde355 commit ef69b58

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

dev-tools/packaging/templates/docker/Dockerfile.elastic-agent.tmpl

+1-2
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ RUN true && \
5656
true
5757

5858
# Keep this after any chown command, chown resets any applied capabilities
59-
RUN setcap =p {{ $beatHome }}/data/elastic-agent-{{ commit_short }}/elastic-agent
60-
RUN setcap cap_net_raw,cap_setuid+p {{ $beatHome }}/data/elastic-agent-{{ commit_short }}/components/agentbeat && \
59+
RUN setcap =p {{ $beatHome }}/data/elastic-agent-{{ commit_short }}/elastic-agent && \
6160
{{- if .linux_capabilities }}
6261
# Since the beat is stored at the other end of a symlink we must follow the symlink first
6362
# For security reasons setcap does not support symlinks. This is smart in the general case

testing/integration/kubernetes_agent_standalone_test.go

+9-4
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
batchv1 "k8s.io/api/batch/v1"
3131
corev1 "k8s.io/api/core/v1"
3232
rbacv1 "k8s.io/api/rbac/v1"
33+
"k8s.io/apimachinery/pkg/api/resource"
3334
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3435
"k8s.io/apimachinery/pkg/runtime"
3536
"k8s.io/apimachinery/pkg/runtime/serializer"
@@ -122,18 +123,18 @@ func TestKubernetesAgentStandalone(t *testing.T) {
122123
int64Ptr(1000), // elastic-agent uid
123124
nil,
124125
[]corev1.Capability{"ALL"},
125-
[]corev1.Capability{"CHOWN", "SETPCAP"},
126+
[]corev1.Capability{"CHOWN", "SETPCAP", "DAC_READ_SEARCH", "SYS_PTRACE"},
126127
true,
127-
"https://github.com/elastic/elastic-agent/issues/5275",
128+
"",
128129
},
129130
{
130131
"drop ALL add CHOWN, SETPCAP capabilities - rootless agent random uid:gid",
131132
int64Ptr(500),
132133
int64Ptr(500),
133134
[]corev1.Capability{"ALL"},
134-
[]corev1.Capability{"CHOWN", "SETPCAP", "DAC_READ_SEARCH"},
135+
[]corev1.Capability{"CHOWN", "SETPCAP", "DAC_READ_SEARCH", "SYS_PTRACE"},
135136
true,
136-
"https://github.com/elastic/elastic-agent/issues/5275",
137+
"",
137138
},
138139
}
139140

@@ -160,6 +161,10 @@ func TestKubernetesAgentStandalone(t *testing.T) {
160161
// as the image is already loaded by the kubernetes provisioner
161162
container.ImagePullPolicy = "Never"
162163

164+
container.Resources.Limits = corev1.ResourceList{
165+
corev1.ResourceMemory: resource.MustParse("800Mi"),
166+
}
167+
163168
if tc.capabilitiesDrop != nil || tc.capabilitiesAdd != nil || tc.runUser != nil || tc.runGroup != nil {
164169
// set security context
165170
container.SecurityContext = &corev1.SecurityContext{

0 commit comments

Comments
 (0)