implement transparent sandboxing#1783
Conversation
67f281d to
3e66c51
Compare
|
If this works on macOS, I'll be damned :) |
|
No, this currently only works on Linux and on supported kernels. The sandboxing is "best-effort" and disabled if not supported. Landlock support is pretty good and getting better. Mac has My goal was to start simple and add upon the implementation once we see it work. For example syscall filtering with Seccomp would be really nice. We could also add other implementations like Bubblewrap (user namespaces), but I prefer these lightweight implementations. I haven't fully thought this through, but I think the filesystem sandboxing could also be used to make the environment more pure, by only allowing access to the shell Nix closure, which would ensure no other packages are accidentally used within the scripts. |
1211fbf to
6927ad3
Compare
|
Maybe a more feasible apprach would be to run sandboxing at That would be tricky for loading things like editor config, etc. |
|
That could also work, but my goal was to enable transparent sandboxing. One main advantage of devenv is that development is not within a container, meaning everything else on the host system stays available. |
|
I like that really! Containers come with heavy problems in CI which turns quickly into nested containers which make things hard etc. So a less container approach is really nice |
|
@LorenzBischof do you have some findings to share on this PR? |
|
This definitely needs more work and was just an experiment. I wont have any time to develop or think about this until next year. |
This comment was marked as outdated.
This comment was marked as outdated.
|
perhaps something similar to the PoC could be achieved by simply integrating use landlock::{
Access, AccessFs, Ruleset, RulesetAttr, RulesetCreatedAttr, ABI,
};
// let allowed_dirs = get_sandbox_config_dirs()
let allowed_dirs = vec![
"/tmp",
"/home/user/safe_dir",
];
// Create a Landlock ruleset
let abi = ABI::V2; // Use the latest ABI your kernel supports
let status = Ruleset::default()
.handle_access(AccessFs::from_all(abi))?
.create()?
.add_rules(
allowed_dirs.iter().map(|dir| {
landlock::path_beneath_rules(
dir,
AccessFs::from_read(abi) | AccessFs::from_write(abi),
)
})
)?
.restrict_self()?;Pros:
It seems direnv integration might be tricky (LLM-generated summary below): Supervisor process using Linux Key Points
Requirements
Trade-offs Pros: Truly dynamic, fine-grained control, seamless UX Why not Landlock? Restrictions can only increase, never decrease - incompatible with dynamic add/remove requirement. |
|
Inspired by https://github.com/landlock-lsm/island?target=https://github.com I created another POC https://github.com/LorenzBischof/peninsula?target=https://github.com which should support direnv. |
fa2232b to
79a6336
Compare
44f755d to
744138c
Compare
cb8bfb4 to
1e9048c
Compare
The idea is to transparently sandbox all processes, packages, tasks and scripts to the current directory, without the user having to develop inside a container.
This is currently just an idea. I still have to figure out if it is feasible.