Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: updates the exec cmd to start user application #1643

Merged
merged 5 commits into from
Mar 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions pkg/hooks/launch.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,9 +474,15 @@ func (h *Hook) processDockerEnv(appCmd, appContainer, appNetwork string, buildDe

// It runs the application using the given command
func (h *Hook) runApp(appCmd string, isUnitTestIntegration bool) error {
// Create a new command with your appCmd
cmd := exec.Command("sh", "-c", appCmd)

// Create a new command with your appCmd'
username := os.Getenv("SUDO_USER")
var cmd *exec.Cmd
if username != "" {
// Run the command as the user who invoked sudo to preserve the user environment variables and PATH
cmd = exec.Command("sudo", "-E", "-u", os.Getenv("SUDO_USER"), "env", "PATH="+os.Getenv("PATH"), "sh", "-c", appCmd)
} else {
cmd = exec.Command("sh", "-c", appCmd)
}
cmd.SysProcAttr = &syscall.SysProcAttr{
Setpgid: true,
}
Expand All @@ -487,7 +493,6 @@ func (h *Hook) runApp(appCmd string, isUnitTestIntegration bool) error {
h.userAppCmd = cmd

// Run the app as the user who invoked sudo
username := os.Getenv("SUDO_USER")
if username != "" {
uidCmd := exec.Command("id", "-u", username)
gidCmd := exec.Command("id", "-g", username)
Expand Down
Loading