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 committed Apr 3, 2024
1 parent bbeb84d commit 3426fbd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
19 changes: 18 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,21 @@ 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
}
}
// Now launch package management process
cmd := exec.Command("apt-get")
return cmd.Run()
}
return nil
}
2 changes: 2 additions & 0 deletions script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
echo "Hello, world!"

0 comments on commit 3426fbd

Please sign in to comment.