Skip to content

Commit 882c812

Browse files
authored
migrate libbeat seccomp integ test to go (#49501)
1 parent 9dd7c3c commit 882c812

File tree

2 files changed

+82
-44
lines changed

2 files changed

+82
-44
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
// Licensed to Elasticsearch B.V. under one or more contributor
2+
// license agreements. See the NOTICE file distributed with
3+
// this work for additional information regarding copyright
4+
// ownership. Elasticsearch B.V. licenses this file to you under
5+
// the Apache License, Version 2.0 (the "License"); you may
6+
// not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
//go:build integration
19+
20+
package integration
21+
22+
import (
23+
"fmt"
24+
"os"
25+
"runtime"
26+
"strings"
27+
"testing"
28+
"time"
29+
)
30+
31+
// isSeccompSupported returns true if the current system supports seccomp:
32+
// Linux kernel >= 3.17 on i386, amd64, or arm64.
33+
func isSeccompSupported() bool {
34+
if runtime.GOOS != "linux" {
35+
return false
36+
}
37+
38+
switch runtime.GOARCH {
39+
case "386", "amd64", "arm64":
40+
default:
41+
return false
42+
}
43+
44+
data, err := os.ReadFile("/proc/sys/kernel/osrelease")
45+
if err != nil {
46+
return false
47+
}
48+
49+
release := strings.TrimSpace(string(data))
50+
var major, minor int
51+
if _, err := fmt.Sscanf(release, "%d.%d", &major, &minor); err != nil {
52+
return false
53+
}
54+
55+
return major > 3 || (major == 3 && minor >= 17)
56+
}
57+
58+
var SeccompCfg = `
59+
mockbeat:
60+
name:
61+
queue.mem:
62+
events: 4096
63+
flush.min_events: 8
64+
flush.timeout: 0.1s
65+
output.console:
66+
code.json:
67+
pretty: false
68+
logging:
69+
level: debug
70+
`
71+
72+
func TestSeccompInstalled(t *testing.T) {
73+
if !isSeccompSupported() {
74+
t.Skip("Requires Linux 3.17 or greater and i386/amd64/arm64 architecture")
75+
}
76+
77+
mockbeat := NewBeat(t, "mockbeat", "../../libbeat.test")
78+
mockbeat.WriteConfigFile(SeccompCfg)
79+
mockbeat.Start("-N")
80+
mockbeat.WaitLogsContains("Syscall filter successfully installed", 60*time.Second)
81+
mockbeat.Stop()
82+
}

libbeat/tests/system/test_seccomp.py

Lines changed: 0 additions & 44 deletions
This file was deleted.

0 commit comments

Comments
 (0)