Skip to content

Commit

Permalink
Merge branch 'main' into Fix-keploy#1640
Browse files Browse the repository at this point in the history
  • Loading branch information
Tushar-kalsi committed Mar 4, 2024
2 parents 717978d + c389dbf commit 4c58341
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
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
6 changes: 6 additions & 0 deletions pkg/hooks/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ type Hook struct {
mutex sync.RWMutex
userAppCmd *exec.Cmd
userAppShutdownInitiated bool
isHooksLoaded bool
mainRoutineId int

// ebpf objects and events
Expand Down Expand Up @@ -583,6 +584,9 @@ func deleteFileIfExists(filename string, logger *zap.Logger) error {
}

func (h *Hook) Stop(forceStop bool) {
if !h.isHooksLoaded || h.socket == nil {
return
}

if !forceStop && !h.IsUserAppTerminateInitiated() {
h.logger.Info("Received signal to exit keploy program..")
Expand Down Expand Up @@ -976,6 +980,8 @@ func (h *Hook) LoadHooks(appCmd, appContainer string, pid uint32, ctx context.Co
h.SendAppPid(pid)
}

// hooks are loaded so inform the state
h.isHooksLoaded = true
return nil
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/proxy/integrations/postgresParser/postgres_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ func (p *PostgresParser) ProcessOutgoing(requestBuffer []byte, clientConn, destC
case models.MODE_RECORD:
err := encodePostgresOutgoing(requestBuffer, clientConn, destConn, p.hooks, p.logger, ctx)
if err != nil {
p.logger.Error("failed to encode the outgoing postgres call", zap.Error(err))
p.logger.Debug("failed to encode the outgoing postgres call", zap.Error(err))
}
case models.MODE_TEST:
logger := p.logger.With(zap.Any("Client IP Address", clientConn.RemoteAddr().String()), zap.Any("Client ConnectionID", util.GetNextID()), zap.Any("Destination ConnectionID", util.GetNextID()))
err := decodePostgresOutgoing(requestBuffer, clientConn, destConn, p.hooks, logger, ctx)
if err != nil {
logger.Error("failed to decode the outgoing postgres call", zap.Error(err))
if err != nil && !p.hooks.IsUserAppTerminateInitiated() {
logger.Debug("failed to decode the outgoing postgres call", zap.Error(err))
}
default:
p.logger.Info("Invalid mode detected while intercepting outgoing http call", zap.Any("mode", models.GetMode()))
Expand Down Expand Up @@ -506,7 +506,7 @@ func decodePostgresOutgoing(requestBuffer []byte, clientConn, destConn net.Conn,
logger.Debug("EOF error received from client. Closing connection in postgres !!")
return err
}
logger.Error("failed to read the request message in proxy for postgres dependency", zap.Error(err))
logger.Debug("failed to read the request message in proxy for postgres dependency", zap.Error(err))
return err
}
}
Expand Down
2 changes: 0 additions & 2 deletions pkg/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,6 @@ func SetupCA(logger *zap.Logger, pid uint32, lang string) error {
return err
}

fmt.Println("set the certificate path in environment", os.Getenv("NODE_EXTRA_CA_CERTS"))

// for python
err = os.Setenv("REQUESTS_CA_BUNDLE", tempCertPath)
if err != nil {
Expand Down

0 comments on commit 4c58341

Please sign in to comment.