miniswen 1.3.4 → 1.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/miniswen/environment.rb +2 -0
- data/lib/miniswen/jail.rb +19 -10
- data/lib/miniswen/local.rb +0 -2
- data/lib/miniswen/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: bb0210425289d60629f23be4579598a50bd5e901da6ba2c8198ba3d9cb5760a0
|
|
4
|
+
data.tar.gz: e9377f196e3342d3cc3b67cd1ff5be7af22937be9a49647872a90a9a5ff888d1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8fbdd1b68f84eab112e32de6a8eed4d85872424cae07ae3166aa334bb924e2c00b73654d59386b22e58b4ad4125fb0405dbff3b82484495c9927e650173f1af4
|
|
7
|
+
data.tar.gz: 5f6e01261b89cc6fc048f3ea960a89eef3ce5e43b9d2d16e2758b2c8899731e3eb849a1b7bd996224b30f21c216ad7abf1baf540b3ae9036c6278531669a1d6b
|
data/lib/miniswen/environment.rb
CHANGED
data/lib/miniswen/jail.rb
CHANGED
|
@@ -1,27 +1,22 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require "shellwords"
|
|
4
|
+
|
|
3
5
|
require "miniswen/local"
|
|
4
6
|
|
|
5
7
|
module Miniswen
|
|
6
8
|
# Runs every command in its own namespaces: none of the harness's environment,
|
|
7
9
|
# no network, read-only system, none of its files.
|
|
8
10
|
class Jail < Local
|
|
9
|
-
SETUP = <<~SH
|
|
10
|
-
set -eu
|
|
11
|
-
ip link set lo up
|
|
12
|
-
for dir in /usr /etc /opt; do mount -o bind,ro "$dir" "$dir"; done
|
|
13
|
-
for dir in /tmp /run /root; do mkdir -p "/var/lib/miniswen$dir" && mount --bind "/var/lib/miniswen$dir" "$dir"; done
|
|
14
|
-
echo ready
|
|
15
|
-
exec sleep infinity
|
|
16
|
-
SH
|
|
17
|
-
|
|
18
11
|
def initialize(workdir: Dir.pwd)
|
|
19
12
|
@workdir = workdir
|
|
20
13
|
end
|
|
21
14
|
|
|
22
15
|
def start
|
|
23
16
|
_, @stdout, @stderr, @holder = Open3.popen3(
|
|
24
|
-
|
|
17
|
+
ENV.to_h.slice(*container_variables),
|
|
18
|
+
"unshare", "--net", "--mount", "--pid", "--fork", "--kill-child", "--mount-proc", "sh", "-c", setup,
|
|
19
|
+
pgroup: true, unsetenv_others: true
|
|
25
20
|
)
|
|
26
21
|
return self if @stdout.gets == "ready\n"
|
|
27
22
|
|
|
@@ -34,6 +29,20 @@ module Miniswen
|
|
|
34
29
|
|
|
35
30
|
private
|
|
36
31
|
|
|
32
|
+
def setup = <<~SH
|
|
33
|
+
set -eu
|
|
34
|
+
# Bring loopback up
|
|
35
|
+
ip link set lo up
|
|
36
|
+
# Make the workdir its own mount
|
|
37
|
+
mount --bind #{Shellwords.escape(@workdir)} #{Shellwords.escape(@workdir)}
|
|
38
|
+
# Make private temp dirs their own mounts
|
|
39
|
+
for dir in /tmp /run /root; do mkdir -p "/var/lib/miniswen$dir" && mount --bind "/var/lib/miniswen$dir" "$dir"; done
|
|
40
|
+
# Make everything without its own mount read-only
|
|
41
|
+
mount -o remount,bind,ro /
|
|
42
|
+
echo ready
|
|
43
|
+
exec sleep infinity
|
|
44
|
+
SH
|
|
45
|
+
|
|
37
46
|
def spawn_arguments(command, env)
|
|
38
47
|
[ ENV.to_h.merge(env.to_h).slice(*container_variables),
|
|
39
48
|
"nsenter", "--target", @holder.pid.to_s, "--net", "--mount", "--pid=/proc/#{@holder.pid}/ns/pid_for_children", "--wd=#{@workdir}",
|
data/lib/miniswen/local.rb
CHANGED
data/lib/miniswen/version.rb
CHANGED