mirror of
https://github.com/safedep/pmg.git
synced 2026-08-03 07:24:09 +02:00
fix: Remove violation mode
This commit is contained in:
@@ -23,8 +23,6 @@ func ApplyCobraFlags(cmd *cobra.Command) {
|
|||||||
globalConfig.Config.ExperimentalProxyMode, "Use experimental proxy-based interception (EXPERIMENTAL)")
|
globalConfig.Config.ExperimentalProxyMode, "Use experimental proxy-based interception (EXPERIMENTAL)")
|
||||||
cmd.PersistentFlags().BoolVar(&globalConfig.Config.Sandbox.Enabled, "sandbox",
|
cmd.PersistentFlags().BoolVar(&globalConfig.Config.Sandbox.Enabled, "sandbox",
|
||||||
globalConfig.Config.Sandbox.Enabled, "Enable sandbox mode to isolate package manager processes (EXPERIMENTAL)")
|
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",
|
cmd.PersistentFlags().StringVar(&globalConfig.SandboxProfileOverride, "sandbox-profile",
|
||||||
globalConfig.SandboxProfileOverride, "Override sandbox policy profile (built-in name or path to custom YAML)")
|
globalConfig.SandboxProfileOverride, "Override sandbox policy profile (built-in name or path to custom YAML)")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,9 +70,6 @@ type SandboxConfig struct {
|
|||||||
// Enabled enables sandbox mode (opt-in by default for backward compatibility).
|
// Enabled enables sandbox mode (opt-in by default for backward compatibility).
|
||||||
Enabled bool `mapstructure:"enabled"`
|
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.
|
// Policies maps package manager names to their sandbox policy references.
|
||||||
// Key is package manager name (e.g., "npm", "pip"), value is policy reference.
|
// Key is package manager name (e.g., "npm", "pip"), value is policy reference.
|
||||||
Policies map[string]SandboxPolicyRef `mapstructure:"policies"`
|
Policies map[string]SandboxPolicyRef `mapstructure:"policies"`
|
||||||
|
|||||||
@@ -52,6 +52,8 @@ trusted_packages:
|
|||||||
# filesystem, network, and process execution access. This provides defense-in-depth
|
# filesystem, network, and process execution access. This provides defense-in-depth
|
||||||
# protection against malicious install scripts and supply chain attacks.
|
# protection against malicious install scripts and supply chain attacks.
|
||||||
#
|
#
|
||||||
|
# Policy violations will block execution (this is the only supported behavior).
|
||||||
|
#
|
||||||
# Currently supported platforms:
|
# Currently supported platforms:
|
||||||
# - macOS (using Seatbelt sandbox-exec)
|
# - macOS (using Seatbelt sandbox-exec)
|
||||||
# - Linux (coming soon: Bubblewrap or seccomp-bpf)
|
# - Linux (coming soon: Bubblewrap or seccomp-bpf)
|
||||||
@@ -60,12 +62,6 @@ sandbox:
|
|||||||
# Enable sandbox mode (opt-in, default: false for backward compatibility)
|
# Enable sandbox mode (opt-in, default: false for backward compatibility)
|
||||||
enabled: false
|
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
|
# Per-package-manager sandbox policies
|
||||||
# Each package manager can have its own policy to account for unique security characteristics
|
# Each package manager can have its own policy to account for unique security characteristics
|
||||||
policies:
|
policies:
|
||||||
|
|||||||
+1
-61
@@ -7,11 +7,11 @@ import (
|
|||||||
|
|
||||||
// SandboxPolicy represents a parsed and validated sandbox policy that defines
|
// SandboxPolicy represents a parsed and validated sandbox policy that defines
|
||||||
// filesystem, network, and process execution restrictions for package managers.
|
// filesystem, network, and process execution restrictions for package managers.
|
||||||
|
// Policy violations will block execution.
|
||||||
type SandboxPolicy struct {
|
type SandboxPolicy struct {
|
||||||
Name string `yaml:"name" json:"name"`
|
Name string `yaml:"name" json:"name"`
|
||||||
Description string `yaml:"description" json:"description"`
|
Description string `yaml:"description" json:"description"`
|
||||||
PackageManagers []string `yaml:"package_managers" json:"package_managers"`
|
PackageManagers []string `yaml:"package_managers" json:"package_managers"`
|
||||||
ViolationMode string `yaml:"violation_mode" json:"violation_mode"`
|
|
||||||
Filesystem FilesystemPolicy `yaml:"filesystem" json:"filesystem"`
|
Filesystem FilesystemPolicy `yaml:"filesystem" json:"filesystem"`
|
||||||
Network NetworkPolicy `yaml:"network" json:"network"`
|
Network NetworkPolicy `yaml:"network" json:"network"`
|
||||||
Process ProcessPolicy `yaml:"process" json:"process"`
|
Process ProcessPolicy `yaml:"process" json:"process"`
|
||||||
@@ -40,46 +40,6 @@ type ProcessPolicy struct {
|
|||||||
DenyExec []string `yaml:"deny_exec" json:"deny_exec"`
|
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.
|
// Validate validates the sandbox policy for correctness.
|
||||||
// Returns an error if the policy is invalid.
|
// Returns an error if the policy is invalid.
|
||||||
func (p *SandboxPolicy) Validate() error {
|
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")
|
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 ||
|
hasRules := len(p.Filesystem.AllowRead) > 0 ||
|
||||||
len(p.Filesystem.AllowWrite) > 0 ||
|
len(p.Filesystem.AllowWrite) > 0 ||
|
||||||
len(p.Filesystem.DenyRead) > 0 ||
|
len(p.Filesystem.DenyRead) > 0 ||
|
||||||
@@ -113,20 +67,6 @@ func (p *SandboxPolicy) Validate() error {
|
|||||||
return nil
|
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.
|
// AppliesToPackageManager returns true if this policy applies to the given package manager.
|
||||||
func (p *SandboxPolicy) AppliesToPackageManager(pm string) bool {
|
func (p *SandboxPolicy) AppliesToPackageManager(pm string) bool {
|
||||||
pmLower := strings.ToLower(pm)
|
pmLower := strings.ToLower(pm)
|
||||||
|
|||||||
@@ -39,8 +39,6 @@ See the [Policy Schema Documentation](../policy.go) for details on the YAML stru
|
|||||||
- `${CWD}`: Current working directory
|
- `${CWD}`: Current working directory
|
||||||
- `${TMPDIR}`: Temporary directory
|
- `${TMPDIR}`: Temporary directory
|
||||||
|
|
||||||
### Violation Modes
|
## Policy Enforcement
|
||||||
|
|
||||||
- `block`: Block execution on policy violation (recommended)
|
All policy violations will block execution. This provides defense-in-depth protection against malicious install scripts and supply chain attacks.
|
||||||
- `warn`: Log warning but allow execution
|
|
||||||
- `allow`: Allow all operations (disables sandbox)
|
|
||||||
|
|||||||
@@ -6,8 +6,6 @@ package_managers:
|
|||||||
- yarn
|
- yarn
|
||||||
- bun
|
- bun
|
||||||
|
|
||||||
violation_mode: block
|
|
||||||
|
|
||||||
filesystem:
|
filesystem:
|
||||||
allow_read:
|
allow_read:
|
||||||
- ${CWD}/**
|
- ${CWD}/**
|
||||||
|
|||||||
@@ -6,8 +6,6 @@ package_managers:
|
|||||||
- poetry
|
- poetry
|
||||||
- uv
|
- uv
|
||||||
|
|
||||||
violation_mode: block
|
|
||||||
|
|
||||||
filesystem:
|
filesystem:
|
||||||
allow_read:
|
allow_read:
|
||||||
- ${CWD}/**
|
- ${CWD}/**
|
||||||
|
|||||||
Reference in New Issue
Block a user