fix: Remove violation mode

This commit is contained in:
Abhisek Datta
2026-01-08 20:27:05 +05:30
parent cb081348fa
commit 774d21fc32
7 changed files with 5 additions and 80 deletions
-2
View File
@@ -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)")
}
-3
View File
@@ -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"`
+2 -6
View File
@@ -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:
+1 -61
View File
@@ -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)
+2 -4
View File
@@ -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.
-2
View File
@@ -6,8 +6,6 @@ package_managers:
- yarn
- bun
violation_mode: block
filesystem:
allow_read:
- ${CWD}/**
-2
View File
@@ -6,8 +6,6 @@ package_managers:
- poetry
- uv
violation_mode: block
filesystem:
allow_read:
- ${CWD}/**