From 8d452ecbf8dfbf59bc0235abfa565d1a03898e3c Mon Sep 17 00:00:00 2001 From: Leonardo Di Giovanna Date: Thu, 21 Nov 2024 17:45:45 +0100 Subject: [PATCH] feat(decl/proc-chain): add user and capabilities support Add the capability to specify the user and the linux capabilities a process in the process chain can be run with. Capabilities can only be specified for the leaf process. Omitting capabilities is equivalent to specify 'all=iep'. Each process in the chain runs with real user/group ID equals to 0 (root). Specifying a user sets the effective and the saved set-user/group-ID to the corresponding user/group IDs. If a user specified in the chain doesn't exist, it is created before running the test and deleted after test execution. The securebit SECBBIT_NOROOT is enabled before creating any child process: this is done in order to prevent the kernel from ignoring the specified capabilities when the real user ID is zero (see 'Capabilities and execution of programs by root' in capabilities(7)). Users who wish to run the before and after script or creating a 'process' test resource must take into account to provide at least CAP_SETPCAP in its permitted and effective set. Signed-off-by: Leonardo Di Giovanna --- pkg/process/process.go | 282 +++++++++++++++++++++++++++++---- pkg/test/runner/host/host.go | 25 ++- pkg/test/script/shell/shell.go | 9 +- 3 files changed, 280 insertions(+), 36 deletions(-) diff --git a/pkg/process/process.go b/pkg/process/process.go index f03c933c..a74e1e37 100644 --- a/pkg/process/process.go +++ b/pkg/process/process.go @@ -19,14 +19,18 @@ import ( "context" "errors" "fmt" + "io" "os" "os/exec" + "os/user" "path/filepath" "regexp" + "strconv" "github.com/go-logr/logr" "golang.org/x/sys/unix" + "github.com/falcosecurity/event-generator/pkg/capability" "github.com/falcosecurity/event-generator/pkg/random" ) @@ -38,10 +42,18 @@ type Process struct { // simExePath is the "simulated" executable path. This sets the executable path accessible through // `readlink -f /proc/