-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix symlink handling with Linux sandbox
This fixes an issue where dangling symbolic links would cause errors while locking down the sandbox since the `mount` syscall is not able to resolve the link. To ensure symlinks are mapped correctly, the Linux sandbox now maps every exception to its canonicalized path, granting access to the symlink's **TARGET**. Then if necessary the symlink pointing to this file is created to ensure access through the exception's original path.
- Loading branch information
Showing
6 changed files
with
144 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use std::fs; | ||
|
||
use birdcage::{Birdcage, Exception, Sandbox}; | ||
|
||
fn main() { | ||
const FILE_CONTENT: &str = "expected content"; | ||
|
||
// Setup our test tree. | ||
let tempdir = tempfile::tempdir().unwrap().into_path(); | ||
let tempfile = tempdir.join("target-file"); | ||
fs::write(&tempfile, FILE_CONTENT.as_bytes()).unwrap(); | ||
|
||
// Setup sandbox, allowing write to dir, but only read for the file. | ||
let mut birdcage = Birdcage::new(); | ||
birdcage.add_exception(Exception::WriteAndRead(tempdir.clone())).unwrap(); | ||
birdcage.add_exception(Exception::Read(tempfile.clone())).unwrap(); | ||
birdcage.lock().unwrap(); | ||
|
||
// Write access to directory works. | ||
fs::create_dir(tempdir.join("boop")).unwrap(); | ||
|
||
// Read access to file works. | ||
let content = fs::read_to_string(&tempfile).unwrap(); | ||
assert_eq!(content, FILE_CONTENT); | ||
|
||
// Write access to file is denied. | ||
let result = fs::write(&tempfile, "no"); | ||
assert!(result.is_err()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use std::fs; | ||
use std::os::unix::fs as unixfs; | ||
|
||
use birdcage::{Birdcage, Exception, Sandbox}; | ||
|
||
fn main() { | ||
const FILE_CONTENT: &str = "expected content"; | ||
|
||
// Setup our test tree. | ||
|
||
let root = tempfile::tempdir().unwrap().into_path(); | ||
|
||
let lib = root.join("usr").join("lib"); | ||
fs::create_dir_all(&lib).unwrap(); | ||
let file = lib.join("os-release"); | ||
|
||
let etc = root.join("etc"); | ||
fs::create_dir(&etc).unwrap(); | ||
fs::write(&file, FILE_CONTENT.as_bytes()).unwrap(); | ||
let symlink = etc.join("os-release"); | ||
unixfs::symlink("../usr/lib/os-release", &symlink).unwrap(); | ||
|
||
// Setup sandbox, ensuring sandbox can be created. | ||
let mut birdcage = Birdcage::new(); | ||
birdcage.add_exception(Exception::Read(etc.clone())).unwrap(); | ||
birdcage.add_exception(Exception::Read(symlink.clone())).unwrap(); | ||
birdcage.lock().unwrap(); | ||
|
||
// Ensure we can read from the symlink. | ||
let content = fs::read_to_string(symlink).unwrap(); | ||
assert_eq!(content, FILE_CONTENT); | ||
} |