Skip to content

Commit 32687c6

Browse files
committed
feat(sandbox): add landlock for sandboxing
1 parent af13bb6 commit 32687c6

5 files changed

Lines changed: 579 additions & 3 deletions

File tree

Cargo.lock

Lines changed: 35 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ diesel_migrations = { version = "2.3.1", features = ["sqlite"] }
3434
documented = "0.9.2"
3535
fast-glob = "1.0.0"
3636
image = { version = "0.25.9", default-features = false, features = ["png"] }
37+
landlock = "0.4.4"
3738
libsqlite3-sys = { version = ">=0.30.1,<0.36.0", features = [ "bundled" ]}
3839
miette = { version = "7.6.0", features = ["fancy"] }
3940
nix = { version = "0.30.1", features = ["ioctl", "term", "user"] }

crates/soar-core/src/error.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,48 @@ pub enum SoarError {
135135
#[error(transparent)]
136136
#[diagnostic(code(soar::regex), help("Check your regex pattern syntax"))]
137137
RegexError(#[from] regex::Error),
138+
139+
#[error("Landlock is not supported on this system")]
140+
#[diagnostic(
141+
code(soar::sandbox::not_supported),
142+
help("Landlock requires Linux kernel 5.13+. Hooks will run without sandboxing.")
143+
)]
144+
SandboxNotSupported,
145+
146+
#[error("Failed to create Landlock ruleset: {0}")]
147+
#[diagnostic(
148+
code(soar::sandbox::ruleset),
149+
help("This may indicate a kernel or permission issue")
150+
)]
151+
SandboxRulesetCreation(String),
152+
153+
#[error("Failed to add sandbox rule for path '{path}': {reason}")]
154+
#[diagnostic(
155+
code(soar::sandbox::path_rule),
156+
help("Check if the path exists and is accessible")
157+
)]
158+
SandboxPathRule { path: String, reason: String },
159+
160+
#[error("Failed to add sandbox network rule for port {port}: {reason}")]
161+
#[diagnostic(
162+
code(soar::sandbox::network_rule),
163+
help("Network restrictions require Landlock V4+ (kernel 6.7+)")
164+
)]
165+
SandboxNetworkRule { port: u16, reason: String },
166+
167+
#[error("Failed to enforce Landlock sandbox: {0}")]
168+
#[diagnostic(
169+
code(soar::sandbox::enforcement),
170+
help("This may indicate a kernel or permission issue")
171+
)]
172+
SandboxEnforcement(String),
173+
174+
#[error("Sandboxed command execution failed: {0}")]
175+
#[diagnostic(
176+
code(soar::sandbox::execution),
177+
help("Check the command and sandbox configuration")
178+
)]
179+
SandboxExecution(String),
138180
}
139181

140182
impl SoarError {

crates/soar-core/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ pub mod constants;
44
pub mod database;
55
pub mod error;
66
pub mod package;
7+
pub mod sandbox;
78
pub mod utils;
89

910
pub type SoarResult<T> = std::result::Result<T, SoarError>;

0 commit comments

Comments
 (0)