mirror of
https://github.com/safedep/pmg.git
synced 2026-08-03 07:24:09 +02:00
fix: Merge conflicts
This commit is contained in:
@@ -25,6 +25,7 @@ require (
|
|||||||
go.yaml.in/yaml/v3 v3.0.4
|
go.yaml.in/yaml/v3 v3.0.4
|
||||||
golang.org/x/term v0.34.0
|
golang.org/x/term v0.34.0
|
||||||
google.golang.org/grpc v1.72.0
|
google.golang.org/grpc v1.72.0
|
||||||
|
gopkg.in/yaml.v3 v3.0.1
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
|||||||
@@ -270,8 +270,17 @@ func (f *proxyFlow) executeWithProxyForNonInteractiveTTY(
|
|||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
result, err := executor.ApplySandbox(ctx, cmd, f.pm.Name())
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to apply sandbox: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
defer result.Close()
|
||||||
|
|
||||||
// Only run the command if the sandbox didn't already execute it
|
// Only run the command if the sandbox didn't already execute it
|
||||||
if result.ShouldRun() {
|
if result.ShouldRun() {
|
||||||
|
log.Debugf("Running command with args: %s: %v", cmd.Path, cmd.Args[1:])
|
||||||
|
|
||||||
err = cmd.Run()
|
err = cmd.Run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if exitErr, ok := err.(*exec.ExitError); ok {
|
if exitErr, ok := err.(*exec.ExitError); ok {
|
||||||
@@ -302,7 +311,27 @@ func (f *proxyFlow) executeWithProxy(
|
|||||||
return ui.GetConfirmationOnMalwareWithReader(malwarePackages, interaction.Reader())
|
return ui.GetConfirmationOnMalwareWithReader(malwarePackages, interaction.Reader())
|
||||||
}
|
}
|
||||||
|
|
||||||
sessionConfig := pty.NewSessionConfig(parsedCmd.Command.Exe, parsedCmd.Command.Args, env)
|
cmd := exec.CommandContext(ctx, parsedCmd.Command.Exe, parsedCmd.Command.Args...)
|
||||||
|
result, err := executor.ApplySandbox(ctx, cmd, f.pm.Name())
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to apply sandbox: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !result.ShouldRun() {
|
||||||
|
return fmt.Errorf("sandbox executed command cannot be used with PTY session. Please use non-interactive TTY mode instead.")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extract the command executable and arguments from the sandboxed command
|
||||||
|
// for use to create the PTY session.
|
||||||
|
cmdExe := cmd.Path
|
||||||
|
cmdArgs := cmd.Args[1:]
|
||||||
|
|
||||||
|
log.Debugf("Running command with args: %s: %v", cmdExe, cmdArgs)
|
||||||
|
|
||||||
|
// Create the PTY session with the sandbox command
|
||||||
|
// This is not compatible with sandbox that executes the command directly within the sandbox
|
||||||
|
// because internally we use ptyx.Spawn() to create the process with PTY support.
|
||||||
|
sessionConfig := pty.NewSessionConfig(cmdExe, cmdArgs, env)
|
||||||
|
|
||||||
sess, err := pty.NewSession(ctx, sessionConfig)
|
sess, err := pty.NewSession(ctx, sessionConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -399,6 +428,7 @@ func (f *proxyFlow) executeWithProxy(
|
|||||||
|
|
||||||
os.Exit(exitErr.Code)
|
os.Exit(exitErr.Code)
|
||||||
}
|
}
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,15 +34,15 @@ func WithSandbox(sb sandbox.Sandbox) applySandboxOpt {
|
|||||||
func ApplySandbox(ctx context.Context, cmd *exec.Cmd, pmName string, opts ...applySandboxOpt) (*sandbox.ExecutionResult, error) {
|
func ApplySandbox(ctx context.Context, cmd *exec.Cmd, pmName string, opts ...applySandboxOpt) (*sandbox.ExecutionResult, error) {
|
||||||
cfg := config.Get()
|
cfg := config.Get()
|
||||||
|
|
||||||
|
if !cfg.Config.Sandbox.Enabled {
|
||||||
|
return sandbox.NewExecutionResult(), nil
|
||||||
|
}
|
||||||
|
|
||||||
applyConfig := &applySandboxConfig{}
|
applyConfig := &applySandboxConfig{}
|
||||||
for _, opt := range opts {
|
for _, opt := range opts {
|
||||||
opt(applyConfig)
|
opt(applyConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !cfg.Config.Sandbox.Enabled {
|
|
||||||
return sandbox.NewExecutionResult(), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
registry, err := sandbox.NewProfileRegistry()
|
registry, err := sandbox.NewProfileRegistry()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to create profile registry: %w", err)
|
return nil, fmt.Errorf("failed to create profile registry: %w", err)
|
||||||
|
|||||||
Reference in New Issue
Block a user