Add reset combinator
This commit is contained in:
parent
7720833ef4
commit
98a6bd032c
4 changed files with 53 additions and 0 deletions
|
|
@ -51,6 +51,7 @@ let
|
||||||
readonly-runtime-args = ./combinators/readonly-runtime-args.nix;
|
readonly-runtime-args = ./combinators/readonly-runtime-args.nix;
|
||||||
readwrite = ./combinators/readwrite.nix;
|
readwrite = ./combinators/readwrite.nix;
|
||||||
readwrite-runtime-args = ./combinators/readwrite-runtime-args.nix;
|
readwrite-runtime-args = ./combinators/readwrite-runtime-args.nix;
|
||||||
|
reset = ./combinators/reset.nix;
|
||||||
ro-bind = ./combinators/ro-bind.nix;
|
ro-bind = ./combinators/ro-bind.nix;
|
||||||
runtime-deep-ro-bind = ./combinators/runtime-deep-ro-bind.nix;
|
runtime-deep-ro-bind = ./combinators/runtime-deep-ro-bind.nix;
|
||||||
rw-bind = ./combinators/rw-bind.nix;
|
rw-bind = ./combinators/rw-bind.nix;
|
||||||
|
|
|
||||||
28
lib/combinators/reset.nix
Normal file
28
lib/combinators/reset.nix
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
_: {
|
||||||
|
sig = "Permission";
|
||||||
|
doc = ''
|
||||||
|
Resets the jail state back to the initial empty state.
|
||||||
|
|
||||||
|
All permissions before this one (including ones set in
|
||||||
|
[`basePermissions`](advanced-configuration.md#basepermissions)) are
|
||||||
|
removed.
|
||||||
|
|
||||||
|
This is useful if you have some permissions set in
|
||||||
|
[`basePermissions`](advanced-configuration.md#basepermissions) that you
|
||||||
|
want for most of your jails, but want to remove them in a one-off jail.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
```nix
|
||||||
|
jail "some-package" some-package (combinators: with combinators; [
|
||||||
|
# First, use reset to remove the base combinators:
|
||||||
|
reset
|
||||||
|
|
||||||
|
# Then, re-apply the base combinators you want:
|
||||||
|
base
|
||||||
|
bind-nix-store-runtime-closure
|
||||||
|
fake-passwd
|
||||||
|
])
|
||||||
|
```
|
||||||
|
'';
|
||||||
|
impl = state: state.initialState;
|
||||||
|
}
|
||||||
|
|
@ -45,6 +45,7 @@ let
|
||||||
additionalRuntimeClosures = [ ]; # See bind-nix-store-runtime-closure
|
additionalRuntimeClosures = [ ]; # See bind-nix-store-runtime-closure
|
||||||
dbusPermissions = [ ]; # See dbus combinator
|
dbusPermissions = [ ]; # See dbus combinator
|
||||||
seccompPermissions = [ ]; # See add-seccomp combinator
|
seccompPermissions = [ ]; # See add-seccomp combinator
|
||||||
|
inherit initialState; # See reset combinator
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
lib.pipe initialState (
|
lib.pipe initialState (
|
||||||
|
|
|
||||||
|
|
@ -213,6 +213,29 @@ spec = parallel $ inTestM $ do
|
||||||
])
|
])
|
||||||
|]
|
|]
|
||||||
|
|
||||||
|
describe "reset" $ do
|
||||||
|
it "clears all set permissions - including ones set in base permissions" $ do
|
||||||
|
[i|
|
||||||
|
let
|
||||||
|
jail' = jail-nix.extend {
|
||||||
|
inherit pkgs;
|
||||||
|
basePermissions = c: [
|
||||||
|
c.base
|
||||||
|
(c.readonly "/nix/store")
|
||||||
|
(c.write-text "/test-from-base-permissions" "")
|
||||||
|
];
|
||||||
|
};
|
||||||
|
in
|
||||||
|
jail' "test" (sh "echo /test-from-*") (c: [
|
||||||
|
(c.write-text "/test-from-pre-reset-jail-permissions" "")
|
||||||
|
c.reset
|
||||||
|
c.base
|
||||||
|
(c.readonly "/nix/store")
|
||||||
|
(c.write-text "/test-from-post-reset-jail-permissions" "")
|
||||||
|
])
|
||||||
|
|]
|
||||||
|
`shouldOutput` "/test-from-post-reset-jail-permissions\n"
|
||||||
|
|
||||||
describe "set-argv" $ do
|
describe "set-argv" $ do
|
||||||
it "overrides argv passed to the jailed program" $ do
|
it "overrides argv passed to the jailed program" $ do
|
||||||
[i|
|
[i|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue