diff --git a/config/cobra.go b/config/cobra.go index 1e0b18f..7f4113b 100644 --- a/config/cobra.go +++ b/config/cobra.go @@ -23,8 +23,6 @@ func ApplyCobraFlags(cmd *cobra.Command) { globalConfig.Config.ExperimentalProxyMode, "Use experimental proxy-based interception (EXPERIMENTAL)") cmd.PersistentFlags().BoolVar(&globalConfig.Config.Sandbox.Enabled, "sandbox", globalConfig.Config.Sandbox.Enabled, "Enable sandbox mode to isolate package manager processes (EXPERIMENTAL)") - cmd.PersistentFlags().StringVar(&globalConfig.Config.Sandbox.ViolationMode, "sandbox-violation-mode", - globalConfig.Config.Sandbox.ViolationMode, "How to handle sandbox policy violations: block, warn, or allow") cmd.PersistentFlags().StringVar(&globalConfig.SandboxProfileOverride, "sandbox-profile", globalConfig.SandboxProfileOverride, "Override sandbox policy profile (built-in name or path to custom YAML)") } diff --git a/config/config.go b/config/config.go index 70292e8..e88b83b 100644 --- a/config/config.go +++ b/config/config.go @@ -70,9 +70,6 @@ type SandboxConfig struct { // Enabled enables sandbox mode (opt-in by default for backward compatibility). Enabled bool `mapstructure:"enabled"` - // ViolationMode defines how policy violations are handled (block, warn, or allow). - ViolationMode string `mapstructure:"violation_mode"` - // Policies maps package manager names to their sandbox policy references. // Key is package manager name (e.g., "npm", "pip"), value is policy reference. Policies map[string]SandboxPolicyRef `mapstructure:"policies"` diff --git a/config/config.template.yml b/config/config.template.yml index 0728086..b552e23 100644 --- a/config/config.template.yml +++ b/config/config.template.yml @@ -52,6 +52,8 @@ trusted_packages: # filesystem, network, and process execution access. This provides defense-in-depth # protection against malicious install scripts and supply chain attacks. # +# Policy violations will block execution (this is the only supported behavior). +# # Currently supported platforms: # - macOS (using Seatbelt sandbox-exec) # - Linux (coming soon: Bubblewrap or seccomp-bpf) @@ -60,12 +62,6 @@ sandbox: # Enable sandbox mode (opt-in, default: false for backward compatibility) enabled: false - # How to handle policy violations: block | warn | allow - # - block: Prevent execution on policy violation (recommended) - # - warn: Log warning but allow execution - # - allow: Allow all operations (disables sandbox) - violation_mode: block - # Per-package-manager sandbox policies # Each package manager can have its own policy to account for unique security characteristics policies: diff --git a/sandbox/policy.go b/sandbox/policy.go index ee7aae3..3ad0f65 100644 --- a/sandbox/policy.go +++ b/sandbox/policy.go @@ -7,11 +7,11 @@ import ( // SandboxPolicy represents a parsed and validated sandbox policy that defines // filesystem, network, and process execution restrictions for package managers. +// Policy violations will block execution. type SandboxPolicy struct { Name string `yaml:"name" json:"name"` Description string `yaml:"description" json:"description"` PackageManagers []string `yaml:"package_managers" json:"package_managers"` - ViolationMode string `yaml:"violation_mode" json:"violation_mode"` Filesystem FilesystemPolicy `yaml:"filesystem" json:"filesystem"` Network NetworkPolicy `yaml:"network" json:"network"` Process ProcessPolicy `yaml:"process" json:"process"` @@ -40,46 +40,6 @@ type ProcessPolicy struct { DenyExec []string `yaml:"deny_exec" json:"deny_exec"` } -// ViolationMode represents how sandbox policy violations are handled. -type ViolationMode int - -const ( - // ViolationModeBlock blocks execution when a policy violation is detected (default). - ViolationModeBlock ViolationMode = iota - // ViolationModeWarn logs a warning but allows execution to continue. - ViolationModeWarn - // ViolationModeAllow allows all operations (effectively disables the sandbox). - ViolationModeAllow -) - -// String returns the string representation of the violation mode. -func (v ViolationMode) String() string { - switch v { - case ViolationModeBlock: - return "block" - case ViolationModeWarn: - return "warn" - case ViolationModeAllow: - return "allow" - default: - return "unknown" - } -} - -// ParseViolationMode parses a violation mode string into a ViolationMode value. -func ParseViolationMode(s string) (ViolationMode, error) { - switch strings.ToLower(s) { - case "block": - return ViolationModeBlock, nil - case "warn": - return ViolationModeWarn, nil - case "allow": - return ViolationModeAllow, nil - default: - return ViolationModeBlock, fmt.Errorf("invalid violation mode: %s (must be block, warn, or allow)", s) - } -} - // Validate validates the sandbox policy for correctness. // Returns an error if the policy is invalid. func (p *SandboxPolicy) Validate() error { @@ -91,12 +51,6 @@ func (p *SandboxPolicy) Validate() error { return fmt.Errorf("policy must specify at least one package manager") } - if p.ViolationMode != "" { - if _, err := ParseViolationMode(p.ViolationMode); err != nil { - return fmt.Errorf("invalid violation mode: %w", err) - } - } - hasRules := len(p.Filesystem.AllowRead) > 0 || len(p.Filesystem.AllowWrite) > 0 || len(p.Filesystem.DenyRead) > 0 || @@ -113,20 +67,6 @@ func (p *SandboxPolicy) Validate() error { return nil } -// GetViolationMode returns the parsed violation mode for the policy. -func (p *SandboxPolicy) GetViolationMode() ViolationMode { - if p.ViolationMode == "" { - return ViolationModeBlock - } - - mode, err := ParseViolationMode(p.ViolationMode) - if err != nil { - return ViolationModeBlock - } - - return mode -} - // AppliesToPackageManager returns true if this policy applies to the given package manager. func (p *SandboxPolicy) AppliesToPackageManager(pm string) bool { pmLower := strings.ToLower(pm) diff --git a/sandbox/profiles/README.md b/sandbox/profiles/README.md index 622a678..f35ffe8 100644 --- a/sandbox/profiles/README.md +++ b/sandbox/profiles/README.md @@ -39,8 +39,6 @@ See the [Policy Schema Documentation](../policy.go) for details on the YAML stru - `${CWD}`: Current working directory - `${TMPDIR}`: Temporary directory -### Violation Modes +## Policy Enforcement -- `block`: Block execution on policy violation (recommended) -- `warn`: Log warning but allow execution -- `allow`: Allow all operations (disables sandbox) +All policy violations will block execution. This provides defense-in-depth protection against malicious install scripts and supply chain attacks. diff --git a/sandbox/profiles/npm-restrictive.yml b/sandbox/profiles/npm-restrictive.yml index 26f19ba..c95579b 100644 --- a/sandbox/profiles/npm-restrictive.yml +++ b/sandbox/profiles/npm-restrictive.yml @@ -6,8 +6,6 @@ package_managers: - yarn - bun -violation_mode: block - filesystem: allow_read: - ${CWD}/** diff --git a/sandbox/profiles/pypi-restrictive.yml b/sandbox/profiles/pypi-restrictive.yml index 52355f3..d18fd7a 100644 --- a/sandbox/profiles/pypi-restrictive.yml +++ b/sandbox/profiles/pypi-restrictive.yml @@ -6,8 +6,6 @@ package_managers: - poetry - uv -violation_mode: block - filesystem: allow_read: - ${CWD}/**