programs: sandbox: omit media dirs by default, and implement --sane-sandbox-autodetect for programs which are liable to load data from paths
This commit is contained in:
@@ -63,7 +63,9 @@ in
|
|||||||
});
|
});
|
||||||
|
|
||||||
sandbox.method = "bwrap";
|
sandbox.method = "bwrap";
|
||||||
# sandbox.method = "firejail"; #< fails on moby
|
sandbox.extraConfig = [
|
||||||
|
"--sane-sandbox-autodetect"
|
||||||
|
];
|
||||||
|
|
||||||
persist.byStore.plaintext = [ ".local/state/mpv/watch_later" ];
|
persist.byStore.plaintext = [ ".local/state/mpv/watch_later" ];
|
||||||
fs.".config/mpv/input.conf".symlink.text = let
|
fs.".config/mpv/input.conf".symlink.text = let
|
||||||
|
@@ -40,24 +40,12 @@ let
|
|||||||
let
|
let
|
||||||
makeSandboxed = pkgs.callPackage ./make-sandboxed.nix { sane-sandboxed = config.sane.sandboxHelper; };
|
makeSandboxed = pkgs.callPackage ./make-sandboxed.nix { sane-sandboxed = config.sane.sandboxHelper; };
|
||||||
vpn = lib.findSingle (v: v.default) null null (builtins.attrValues config.sane.vpn);
|
vpn = lib.findSingle (v: v.default) null null (builtins.attrValues config.sane.vpn);
|
||||||
# TODO: restrict access to these media paths a bit more.
|
|
||||||
# maybe mount them user=nobody and restrict based on group?
|
|
||||||
mediaHomePaths = [
|
|
||||||
"Books"
|
|
||||||
"Music"
|
|
||||||
"Pictures"
|
|
||||||
"Videos"
|
|
||||||
"tmp"
|
|
||||||
];
|
|
||||||
mediaRootPaths = [
|
|
||||||
"/mnt/servo-media"
|
|
||||||
];
|
|
||||||
in
|
in
|
||||||
makeSandboxed {
|
makeSandboxed {
|
||||||
inherit pkgName package;
|
inherit pkgName package;
|
||||||
inherit (sandbox) binMap method extraConfig;
|
inherit (sandbox) binMap method extraConfig;
|
||||||
vpn = if net == "vpn" then vpn else null;
|
vpn = if net == "vpn" then vpn else null;
|
||||||
allowedHomePaths = builtins.attrNames fs ++ builtins.attrNames persist.byPath ++ mediaHomePaths;
|
allowedHomePaths = builtins.attrNames fs ++ builtins.attrNames persist.byPath;
|
||||||
allowedRootPaths = [
|
allowedRootPaths = [
|
||||||
"/nix/store"
|
"/nix/store"
|
||||||
"/bin/sh"
|
"/bin/sh"
|
||||||
@@ -72,7 +60,7 @@ let
|
|||||||
"/run/user" #< particularly /run/user/$id/wayland-1, pulse, etc.
|
"/run/user" #< particularly /run/user/$id/wayland-1, pulse, etc.
|
||||||
"/run/secrets/home"
|
"/run/secrets/home"
|
||||||
# "/dev/dri" #< fix non-fatal "libEGL warning: wayland-egl: could not open /dev/dri/renderD128" (geary)
|
# "/dev/dri" #< fix non-fatal "libEGL warning: wayland-egl: could not open /dev/dri/renderD128" (geary)
|
||||||
] ++ mediaRootPaths ++ sandbox.extraPaths;
|
] ++ sandbox.extraPaths;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
pkgSpec = with lib; types.submodule ({ config, name, ... }: {
|
pkgSpec = with lib; types.submodule ({ config, name, ... }: {
|
||||||
|
@@ -3,6 +3,7 @@
|
|||||||
test -n "$SANE_SANDBOX_DEBUG" && set -x
|
test -n "$SANE_SANDBOX_DEBUG" && set -x
|
||||||
|
|
||||||
cliArgs=()
|
cliArgs=()
|
||||||
|
autodetect=
|
||||||
profilesNamed=()
|
profilesNamed=()
|
||||||
rootPaths=()
|
rootPaths=()
|
||||||
homePaths=()
|
homePaths=()
|
||||||
@@ -67,21 +68,28 @@ parseArgs() {
|
|||||||
method="$1"
|
method="$1"
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
|
(--sane-sandbox-autodetect)
|
||||||
|
# autodetect: crawl the CLI program's args & bind any which look like paths into the sandbox.
|
||||||
|
# this is handy for e.g. media players or document viewers.
|
||||||
|
# it's best combined with some two-tiered thing.
|
||||||
|
# e.g. first drop to the broadest path set of interest (Music,Videos,tmp, ...), then drop via autodetect.
|
||||||
|
autodetect=1
|
||||||
|
;;
|
||||||
(--sane-sandbox-dns)
|
(--sane-sandbox-dns)
|
||||||
# N.B.: these named temporary variables ensure that `set -x` causes $1 to be printed
|
# N.B.: these named temporary variables ensure that `set -x` causes $1 to be printed
|
||||||
_dns="$1"
|
_dns="$1"
|
||||||
dns+=("$_dns")
|
|
||||||
shift
|
shift
|
||||||
|
dns+=("$_dns")
|
||||||
;;
|
;;
|
||||||
(--sane-sandbox-firejail-arg)
|
(--sane-sandbox-firejail-arg)
|
||||||
_fjFlag="$1"
|
_fjFlag="$1"
|
||||||
firejailFlags+=("$_fjFlag")
|
|
||||||
shift
|
shift
|
||||||
|
firejailFlags+=("$_fjFlag")
|
||||||
;;
|
;;
|
||||||
(--sane-sandbox-bwrap-arg)
|
(--sane-sandbox-bwrap-arg)
|
||||||
_bwrapFlag="$1"
|
_bwrapFlag="$1"
|
||||||
bwrapFlags+=("$_bwrapFlag")
|
|
||||||
shift
|
shift
|
||||||
|
bwrapFlags+=("$_bwrapFlag")
|
||||||
;;
|
;;
|
||||||
(--sane-sandbox-net)
|
(--sane-sandbox-net)
|
||||||
net="$1"
|
net="$1"
|
||||||
@@ -89,13 +97,13 @@ parseArgs() {
|
|||||||
;;
|
;;
|
||||||
(--sane-sandbox-home-path)
|
(--sane-sandbox-home-path)
|
||||||
_path="$1"
|
_path="$1"
|
||||||
homePaths+=("$_path")
|
|
||||||
shift
|
shift
|
||||||
|
homePaths+=("$_path")
|
||||||
;;
|
;;
|
||||||
(--sane-sandbox-path)
|
(--sane-sandbox-path)
|
||||||
_path="$1"
|
_path="$1"
|
||||||
rootPaths+=("$_path")
|
|
||||||
shift
|
shift
|
||||||
|
rootPaths+=("$_path")
|
||||||
;;
|
;;
|
||||||
(--sane-sandbox-profile)
|
(--sane-sandbox-profile)
|
||||||
tryLoadProfileByName "$1"
|
tryLoadProfileByName "$1"
|
||||||
@@ -175,7 +183,7 @@ bwrapIngestProfile() {
|
|||||||
# WIP
|
# WIP
|
||||||
|
|
||||||
bwrapExec() {
|
bwrapExec() {
|
||||||
PATH="$PATH:@bubblewrap@/bin" exec bwrap --dev /dev --proc /proc "${bwrapFlags[@]}" -- "${cliArgs[@]}"
|
PATH="$PATH:@bubblewrap@/bin" exec bwrap --dev /dev --proc /proc --tmpfs /tmp "${bwrapFlags[@]}" -- "${cliArgs[@]}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -197,6 +205,17 @@ for _path in "${homePaths[@]}"; do
|
|||||||
"$method"IngestHomePath "$_path"
|
"$method"IngestHomePath "$_path"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
if [ -n "$autodetect" ]; then
|
||||||
|
_pwd=$(pwd)
|
||||||
|
for _arg in "${cliArgs[@]}"; do
|
||||||
|
if [[ "$_arg" == "/*" ]]; then
|
||||||
|
test -e "$_arg" && "$method"IngestRootPath "$_arg"
|
||||||
|
elif test -e "$_pwd/$_arg"; then
|
||||||
|
"$method"IngestRootPath "$_pwd/$_arg"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
if [ -n "$net" ]; then
|
if [ -n "$net" ]; then
|
||||||
"$method"IngestNet "$net"
|
"$method"IngestNet "$net"
|
||||||
fi
|
fi
|
||||||
|
Reference in New Issue
Block a user