Skip to content

Commit

Permalink
Switch to a new user such that username is not equal to _apt
Browse files Browse the repository at this point in the history
Signed-off-by: GLVS Kiriti <glvskiriti2003369@gmail.com>
  • Loading branch information
GLVSKiriti authored and poiana committed Apr 3, 2024
1 parent f3b30db commit 2953f26
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion events/syscall/launch_package_management_process_in_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ limitations under the License.
package syscall

import (
"os"
"os/exec"

"github.com/falcosecurity/event-generator/events"
)

Expand All @@ -26,7 +29,22 @@ var _ = events.Register(
func LaunchPackageManagementProcessInContainer(h events.Helper) error {
// Make sure it runs in container and user.name != _apt
if h.InContainer() {
return runAsUser(h, "root", "apt-get")
if os.Getenv("USER") == "_apt" {
// Create a new user
username := "user-created-by-event-generator"
err := exec.Command("adduser", username).Run()
if err != nil {
return err
}
err = exec.Command("su", username).Run()
if err != nil {
return err
}
defer exec.Command("userdel", "-r", username).Run() // Remove the created user at end
}
// Now launch package management process
cmd := exec.Command("apt-get")
return cmd.Run()
}
return nil
}

0 comments on commit 2953f26

Please sign in to comment.