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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d3124b6837dc7ec83d7abb8ec1a49da77b96767a0ab0e564d99b1cc639d6bf4f
4
- data.tar.gz: b16c938ec5c39af746923c5814583e22ff576d357332c579ef8f7c0d9bdc73b1
3
+ metadata.gz: bb0210425289d60629f23be4579598a50bd5e901da6ba2c8198ba3d9cb5760a0
4
+ data.tar.gz: e9377f196e3342d3cc3b67cd1ff5be7af22937be9a49647872a90a9a5ff888d1
5
5
  SHA512:
6
- metadata.gz: 3084347bf1ccf8c6fbcab21af5b1699ee00b30d27dc5f8dfe7610c684bf27709b47e82658ec5a4e00234ce235c27a180f532f1f520ec8613e20f6e02634c96a7
7
- data.tar.gz: d7a7873f8af98236c23d32809b2361409b0f0d27a310979b93bb705feafab0d26dfac3764c4378ade8de2e56943b54f6746e258e8a675861ec93709dada0542a
6
+ metadata.gz: 8fbdd1b68f84eab112e32de6a8eed4d85872424cae07ae3166aa334bb924e2c00b73654d59386b22e58b4ad4125fb0405dbff3b82484495c9927e650173f1af4
7
+ data.tar.gz: 5f6e01261b89cc6fc048f3ea960a89eef3ce5e43b9d2d16e2758b2c8899731e3eb849a1b7bd996224b30f21c216ad7abf1baf540b3ae9036c6278531669a1d6b
@@ -10,5 +10,7 @@ module Miniswen
10
10
 
11
11
  # Execute a shell command
12
12
  def exec(cmd, timeout: nil, env: nil) = raise NotImplementedError
13
+
14
+ def stop = nil
13
15
  end
14
16
  end
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
- "unshare", "--net", "--mount", "--pid", "--fork", "--kill-child", "--mount-proc", "sh", "-c", SETUP, pgroup: true
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}",
@@ -27,8 +27,6 @@ module Miniswen
27
27
  end
28
28
  end
29
29
 
30
- def stop = nil
31
-
32
30
  private
33
31
 
34
32
  def spawn_arguments(command, env) = [ env || {}, "sh", "-c", command ]
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Miniswen
4
- VERSION = "1.3.4"
4
+ VERSION = "1.3.5"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: miniswen
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.4
4
+ version: 1.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Svyatoslav Kryukov