bwrap 1.0.0.pre.beta1 → 1.0.0.pre.beta2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: db6e7253c0a896975954c0d649c68321958ade750f891f353ba30b9ea58880cb
4
- data.tar.gz: 90f384499e8727660b9810711e0237ce604f8ef219ed415c210db16bcd764804
3
+ metadata.gz: 807b5065d9a5615be9910e52bf7beed12faf271a6aa533de71fe925d759d68c3
4
+ data.tar.gz: a3ed8130aac69442f2175b9035aa34392b462fcc3934e3e7a69081b2b936b8f7
5
5
  SHA512:
6
- metadata.gz: 03e6873b068e52bc0c9fbbc072f9fc1a411696ca3c09aabcee05c8e660e5a210030c13fab84348aee720e7bd431600a0b18c3be124dfcb955ac95c250d83aeec
7
- data.tar.gz: 4183575c47d740dd74c88995add7b87366299e75b4a8edaa89c20d422cd73cbd957b411e5bd51b9c9eabcd3881d8af1ba85922ce806b2387d75a0f30d8abd377
6
+ metadata.gz: 66131023be01339b797c21615ce32b5aa639fd0599590724f9262f8393d2cc9226c1bfa87bfad37dba751bac15d6b6fc9efa3babd168cc2f40973f8a5729f9cd
7
+ data.tar.gz: fcf5fdd36a7728e84502e33efb86d43ce08d44732f0c070ecdaa54b5bbc15a35749238fd79084b688baedd605b98252c59fdaee61ef4434ea967deb00f10a577
checksums.yaml.gz.sig CHANGED
Binary file
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # Changes
2
2
 
3
+ ## 1.0.0-beta2 (02.02.2022)
4
+
5
+ * Added nscd feature
6
+ * Added gem_env_paths to ruby feature
7
+ * If Config#root is set, set working directory to /
8
+ * Execution#execvalue: Allow setting log: true
9
+ * Execution#execvalue: pass all kwargs as kwargs to execute()
10
+ * Output::Log: Don’t die if log file can’t be written to
11
+
3
12
  ## 1.0.0-beta1 (12.12.2021)
4
13
 
5
14
  * optimist gem is now optional dependency
@@ -8,6 +8,9 @@ require_relative "mime"
8
8
  class Bwrap::Args::Bind
9
9
  # TODO: documentation
10
10
  #
11
+ # TODO: It may be that this should be renamed to “Binary” or ”Executable”, as this
12
+ # handles all binaries, not just libraries.
13
+ #
11
14
  # @api private
12
15
  class Library
13
16
  include Bwrap::Execution::Path
@@ -28,6 +31,47 @@ class Bwrap::Args::Bind
28
31
 
29
32
  attr_writer :executable_path
30
33
 
34
+ # Ruby feature implementation specific class.
35
+ #
36
+ # @api private
37
+ class RubyBinds
38
+ # Instance of {Bwrap::Config}.
39
+ attr_writer :config
40
+
41
+ def initialize args
42
+ @args = args
43
+ end
44
+
45
+ def ruby_binds_for_features
46
+ return unless @config and @config.features.ruby.enabled?
47
+
48
+ @mounts = []
49
+
50
+ # Mount some common Ruby executables.
51
+
52
+ # This is most often /usr/bin.
53
+ bindir = Pathname.new RbConfig::CONFIG["bindir"]
54
+
55
+ path = bindir / "ruby"
56
+ if File.exist? path
57
+ @mounts << "--ro-bind" << path.to_s << path.to_s
58
+ end
59
+
60
+ gem_binds bindir
61
+
62
+ @args += @mounts
63
+ end
64
+
65
+ private def gem_binds bindir
66
+ return unless @config.features.ruby.gem_env_paths?
67
+
68
+ path = bindir / "gem"
69
+ return unless File.exist? path
70
+
71
+ @mounts << "--ro-bind" << path.to_s << path.to_s
72
+ end
73
+ end
74
+
31
75
  def initialize args
32
76
  @args = args
33
77
  end
@@ -92,6 +136,17 @@ class Bwrap::Args::Bind
92
136
  @args.append library_mounts
93
137
  end
94
138
 
139
+ # Some features, like {Bwrap::Config::Features::Nscd}, requires some binds
140
+ # in order to operate properly.
141
+ def binds_for_features
142
+ # NOTE: Still nothing here, as I think this is better for library binds than anything else.
143
+ # The nscd bind is better in another, more generic, place.
144
+ #
145
+ # Keeping this method because I think this really makes sense for structure, in future.
146
+
147
+ ruby_binds_for_features
148
+ end
149
+
95
150
  # Used by {#libs_command_requires}.
96
151
  private def resolve_executable_name command
97
152
  if command.is_a? String
@@ -121,5 +176,13 @@ class Bwrap::Args::Bind
121
176
 
122
177
  which executable_name, env_path_var: env_path
123
178
  end
179
+
180
+ private def ruby_binds_for_features
181
+ return unless @config.features.ruby.enabled?
182
+
183
+ binds = RubyBinds.new @args
184
+ binds.config = @config
185
+ binds.ruby_binds_for_features
186
+ end
124
187
  end
125
188
  end
@@ -79,6 +79,8 @@ class Bwrap::Args::Bind
79
79
 
80
80
  library_bind = construct_library_bind
81
81
 
82
+ binds_for_features
83
+ library_bind.binds_for_features
82
84
  library_bind.extra_executables_mounts
83
85
 
84
86
  return unless @config.full_system_mounts
@@ -95,7 +97,7 @@ class Bwrap::Args::Bind
95
97
  binds << "--ro-bind" << source_path.to_s << destination_path.to_s
96
98
  end
97
99
 
98
- @args.append binds
100
+ @args.append binds unless binds.empty?
99
101
  end
100
102
 
101
103
  # Performs cleanup operations after execution.
@@ -131,4 +133,9 @@ class Bwrap::Args::Bind
131
133
 
132
134
  library_bind
133
135
  end
136
+
137
+ # Binds feature specific common directories.
138
+ private def binds_for_features
139
+ # Nya.
140
+ end
134
141
  end
@@ -1,15 +1,23 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "bwrap/execution"
3
4
  require "bwrap/output"
4
5
  require_relative "args"
5
6
 
6
7
  # Environment variable calculation for bwrap.
7
8
  class Bwrap::Args::Environment < Hash
9
+ include Bwrap::Execution
8
10
  include Bwrap::Output
9
11
 
10
12
  # Instance of {Config}.
11
13
  attr_writer :config
12
14
 
15
+ def initialize
16
+ super
17
+
18
+ self["PATH"] ||= []
19
+ end
20
+
13
21
  # Returns used environment variables wrapped as bwrap arguments.
14
22
  def environment_variables
15
23
  if debug?
@@ -31,11 +39,11 @@ class Bwrap::Args::Environment < Hash
31
39
  # @return [Array] All environment paths added via {Config#add_env_path} and other parsing logic
32
40
  def env_paths
33
41
  if @config.env_paths.respond_to? :each
34
- self["PATH"] ||= []
35
-
36
42
  self["PATH"] |= @config.env_paths
37
43
  end
38
44
 
45
+ features_env_paths
46
+
39
47
  self["PATH"]
40
48
  end
41
49
 
@@ -43,8 +51,6 @@ class Bwrap::Args::Environment < Hash
43
51
  #
44
52
  # @param elements [String, Array] Path(s) to be added added to PATH environment variable
45
53
  def add_to_path elements
46
- self["PATH"] ||= []
47
-
48
54
  if elements.respond_to? :each
49
55
  self["PATH"] += elements
50
56
  else
@@ -52,4 +58,25 @@ class Bwrap::Args::Environment < Hash
52
58
  self["PATH"] << elements
53
59
  end
54
60
  end
61
+
62
+ # Feature specific environment path handling.
63
+ private def features_env_paths
64
+ ruby_env_paths
65
+ end
66
+
67
+ # Ruby feature specific environment path handling.
68
+ private def ruby_env_paths
69
+ return unless @config.features.ruby.enabled?
70
+ return unless @config.features.ruby.gem_env_paths?
71
+
72
+ unless command_available? "gem"
73
+ warn "gem is not installed in the system, so can’t add its bindirs to PATH."
74
+ return
75
+ end
76
+
77
+ gempath = execvalue %w{ gem environment gempath }
78
+ gempath.split(":").each do |path|
79
+ self["PATH"] << "#{path}/bin"
80
+ end
81
+ end
55
82
  end
@@ -29,6 +29,22 @@ class Bwrap::Args::Features < Hash
29
29
  end
30
30
  end
31
31
 
32
+ # Implementation for nscd feature set.
33
+ #
34
+ # @api private
35
+ class NscdBinds
36
+ # Custom binds needed by the feature.
37
+ def custom_binds
38
+ mounts = []
39
+
40
+ # TODO: Probably some path checking is needed here. Or somewhere.
41
+ # TODO: Since on many systems /var/run is symlinked to /run, that probably should be handled.
42
+ mounts << "--ro-bind" << "/var/run/nscd" << "/var/run/nscd"
43
+
44
+ mounts
45
+ end
46
+ end
47
+
32
48
  # Implementation for Ruby feature set.
33
49
  #
34
50
  # @api private
@@ -79,6 +95,7 @@ class Bwrap::Args::Features < Hash
79
95
  # - ruby
80
96
  def feature_binds
81
97
  bash_binds
98
+ nscd_binds
82
99
  ruby_binds
83
100
  end
84
101
 
@@ -90,6 +107,14 @@ class Bwrap::Args::Features < Hash
90
107
  @args.append binds.bash_mounts
91
108
  end
92
109
 
110
+ private def nscd_binds
111
+ return unless @config.features.nscd.enabled?
112
+
113
+ binds = NscdBinds.new
114
+
115
+ @args.append binds.custom_binds
116
+ end
117
+
93
118
  # @note This does not allow development headers needed for compilation for now.
94
119
  # I’ll look at it after I have an use for it.
95
120
  private def ruby_binds
@@ -25,7 +25,7 @@ class Bwrap::Args::MachineId
25
25
  # Returning [] means that execute() will ignore this fully.
26
26
  # Nil would be converted to empty string, causing spawn() to pass it as argument, causing
27
27
  # bwrap to misbehave.
28
- return unless @config.machine_id
28
+ return unless @config&.machine_id
29
29
 
30
30
  machine_id = @config.machine_id
31
31
 
@@ -52,10 +52,10 @@ class Bwrap::Args::MachineId
52
52
  debug "Using random machine id as /etc/machine-id"
53
53
 
54
54
  @machine_id_file = Tempfile.new "bwrap-random_machine_id-", @config.tmpdir
55
- @machine_id_file.write SecureRandom.uuid.delete("-", "")
55
+ @machine_id_file.write SecureRandom.uuid.tr("-", "")
56
56
  @machine_id_file.flush
57
57
 
58
- %W{ --ro-bind-data #{machine_id_file.fileno} /etc/machine-id }
58
+ %W{ --ro-bind-data #{@machine_id_file.fileno} /etc/machine-id }
59
59
  end
60
60
 
61
61
  # Uses `10000000000000000000000000000000` as machine id.
@@ -80,6 +80,8 @@ class Bwrap::Args::MachineId
80
80
  end
81
81
 
82
82
  # Uses file inside sandbox directory as machine id.
83
+ #
84
+ # TODO: I kind of want to deprecate this one. It may make sense, but eh... Let’s see.
83
85
  private def machine_id_inside_sandbox_dir sandbox_directory
84
86
  machine_id_file = "#{sandbox_directory}/machine-id"
85
87
 
@@ -10,6 +10,7 @@ module Bwrap::Args::Mount
10
10
 
11
11
  debug "Binding #{@config.root} as /"
12
12
  @args.append %W{ --bind #{@config.root} / }
13
+ @args.append %w{ --chdir / }
13
14
  end
14
15
 
15
16
  # Arguments for mounting devtmpfs to /dev.
data/lib/bwrap/bwrap.rb CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  #require "deep-cover" if ENV["DEEP_COVER"]
4
4
 
5
+ require_relative "bwrap_module"
5
6
  require "bwrap/version"
6
7
  require "bwrap/args/construct"
7
8
  require "bwrap/config"
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ # ruby-bwrap provides easy-to-use interface to run complex programs in sandboxes created with
4
+ # {https://github.com/containers/bubblewrap bubblewrap}.
5
+ #
6
+ # To run a program inside bubblewrap, a wrapper executable can be created. For example:
7
+ #
8
+ # require "bwrap"
9
+ #
10
+ # config = Bwrap::Config.new
11
+ # config.user = "dummy_user"
12
+ # config.full_system_mounts = true
13
+ # config.binaries_from = %w{
14
+ # /bin
15
+ # /usr/bin
16
+ # }
17
+ #
18
+ # bwrap = Bwrap::Bwrap.new config
19
+ # bwrap.parse_command_line_arguments
20
+ # bwrap.run "/bin/true"
21
+ #
22
+ # There also are few generic utilities, {Bwrap::Output} for handling output of scripts and
23
+ # {Bwrap::Execution} to run executables.
24
+ module Bwrap
25
+ # Empty module.
26
+ end
@@ -3,41 +3,72 @@
3
3
  class Bwrap::Config
4
4
  # Methods to enable or disable feature sets to control various aspects of sandboxing.
5
5
  class Features
6
- # Defines Bash feature set.
7
- class Bash
6
+ # @abstract
7
+ #
8
+ # Base of all features.
9
+ class Base
10
+ # @param features [Bwrap::Config::Features] Instance of features object in {Config}
11
+ def initialize features
12
+ @features = features
13
+ end
14
+
15
+ # Checks if the feature has been enabled.
16
+ #
17
+ # @return [Boolean] whether feature is enabled
8
18
  def enabled?
9
19
  @enabled
10
20
  end
11
21
 
22
+ # Enable the feature.
12
23
  def enable
13
24
  @enabled = true
14
25
  end
15
26
 
16
- # Disable Bash feature set.
27
+ # Disable the feature.
17
28
  def disable
18
29
  @enabled = false
19
30
  end
20
31
  end
21
32
 
33
+ # Defines Bash feature set.
34
+ class Bash < Base
35
+ # Nya.
36
+ end
37
+
38
+ # Defines Nscd feature set.
39
+ #
40
+ # nscd is short of name service cache daemon. It may make sense to
41
+ # have this class under another name, but I don’t know how nscd specific
42
+ # this feature can be, so this name it is for now.
43
+ class Nscd < Base
44
+ # Nya.
45
+ end
46
+
22
47
  # Defines Ruby feature set.
23
- class Ruby
48
+ #
49
+ # Implies {Nscd} feature.
50
+ class Ruby < Base
24
51
  # Extra libraries to be loaded from `RbConfig::CONFIG["rubyarchdir"]`.
25
52
  #
26
53
  # @note This is only required to be called if extra dependencies are necessary.
27
54
  # For example, psych.so requires libyaml.so.
28
55
  #
29
- # @note There is stdlib= method also. Yardoc is broken.
30
- #
31
56
  # @return [Array] list of needed libraries.
57
+ #
58
+ # @overload stdlib
59
+ # @overload stdlib=(libs)
32
60
  attr_reader :stdlib
33
61
 
34
- def initialize
62
+ def initialize features
63
+ super features
64
+
65
+ @gem_env_paths = true
35
66
  @stdlib = []
36
67
  end
37
68
 
38
- # @see enabled=
39
- def enabled?
40
- @enabled
69
+ # @return true if bindirs from “gem environment” should be added to sandbox.
70
+ def gem_env_paths?
71
+ @gem_env_paths
41
72
  end
42
73
 
43
74
  # Enable Ruby feature set.
@@ -46,13 +77,12 @@ class Bwrap::Config
46
77
  #
47
78
  # @note This does not allow development headers needed for compilation for now.
48
79
  # I’ll look at it after I have an use for it.
80
+ #
81
+ # @note Also enables {Nscd} feature.
49
82
  def enable
50
- @enabled = true
51
- end
83
+ super
52
84
 
53
- # Disable Ruby feature set.
54
- def disable
55
- @enabled = false
85
+ @features.nscd.enable
56
86
  end
57
87
 
58
88
  # @see #stdlib
@@ -70,12 +100,17 @@ class Bwrap::Config
70
100
 
71
101
  # @return [Bash] Instance of feature class for Bash
72
102
  def bash
73
- @bash ||= Bash.new
103
+ @bash ||= Bash.new self
104
+ end
105
+
106
+ # @return [Nscd] Instance of feature class for nscd
107
+ def nscd
108
+ @nscd ||= Nscd.new self
74
109
  end
75
110
 
76
111
  # @return [Ruby] Instance of feature class for Ruby
77
112
  def ruby
78
- @ruby ||= Ruby.new
113
+ @ruby ||= Ruby.new self
79
114
  end
80
115
  end
81
116
  end
data/lib/bwrap/config.rb CHANGED
@@ -18,8 +18,45 @@ require_relative "config/features"
18
18
  #
19
19
  # @todo Add some documentation about syntax where necessary, like for #binaries_from.
20
20
  class Bwrap::Config
21
+ # Array of audio schemes usable inside chroot.
22
+ #
23
+ # Currently supports:
24
+ # - :pulseaudio
25
+ #
26
+ attr_accessor :audio
27
+
28
+ # Set to `true` if command given to {Bwrap::Bwrap#run} is expected to
29
+ # be inside sandbox, and not bound from host.
30
+ #
31
+ # @return [Boolean] `true` if executed command is inside sandbox
32
+ attr_accessor :command_inside_root
33
+
34
+ attr_accessor :extra_executables
35
+
36
+ # TODO: IIRC this doesn’t match the reality any more. So write correct documentation.
37
+ #
38
+ # Causes libraries required by the executable given to {Bwrap#run} to be
39
+ # mounted inside sandbox.
40
+ #
41
+ # Often it is enough to use this flag instead of binding all system libraries
42
+ # using {#libdir_mounts=}
43
+ #
44
+ # @return [Boolean] true if Linux library loaders are mounted inside chroot
45
+ attr_accessor :full_system_mounts
46
+
21
47
  attr_accessor :hostname
22
48
 
49
+ # Set to true if basic system directories, like /usr/lib and /usr/lib64,
50
+ # should be bound inside chroot.
51
+ #
52
+ # /usr/bin can be mounted using {Config#binaries_from=}.
53
+ #
54
+ # Often it is enough to use {#full_system_mounts=} instead of binding all
55
+ # system libraries using this flag.
56
+ #
57
+ # @return [Boolean] true if libdirs are mounted to the chroot
58
+ attr_accessor :libdir_mounts
59
+
23
60
  # What should be used as /etc/machine_id file.
24
61
  #
25
62
  # If not specified, no /etc/machine_id handling is done.
@@ -34,6 +71,9 @@ class Bwrap::Config
34
71
  # Given file as bound as /etc/machine_id.
35
72
  attr_accessor :machine_id
36
73
 
74
+ # @return [Boolean] true if network should be shared from host.
75
+ attr_accessor :share_net
76
+
37
77
  # Name of the user inside chroot.
38
78
  #
39
79
  # This is optional and defaults to no user.
@@ -45,46 +85,23 @@ class Bwrap::Config
45
85
  # @return [Boolean] Whether Xorg specific binds are used.
46
86
  attr_accessor :xorg_application
47
87
 
48
- # Array of audio schemes usable inside chroot.
49
- #
50
- # Currently supports:
51
- # - :pulseaudio
52
- #
53
- attr_accessor :audio
54
-
55
- # @return [Boolean] true if network should be shared from host.
56
- attr_accessor :share_net
57
-
58
- # Causes libraries required by the executable given to {Bwrap#run} to be
59
- # mounted inside sandbox.
60
- #
61
- # Often it is enough to use this flag instead of binding all system libraries
62
- # using {#libdir_mounts=}
88
+ # Array of directories to be bind mounted in sandbox.
63
89
  #
64
- # @return [Boolean] true if Linux library loaders are mounted inside chroot
65
- attr_accessor :full_system_mounts
66
-
67
- # Set to true if basic system directories, like /usr/lib and /usr/lib64,
68
- # should be bound inside chroot.
90
+ # Given paths are also added to PATH environment variable inside sandbox.
69
91
  #
70
- # /usr/bin can be mounted using {Config#binaries_from=}.
92
+ # @hint At least on SUSE, many executables are symlinks to /etc/alternatives/*,
93
+ # which in turn symlinks to versioned executable under the same bindir.
94
+ # To use these executables, /etc/alternatives should also be bound:
71
95
  #
72
- # Often it is enough to use {#full_system_mounts=} instead of binding all
73
- # system libraries using this flag.
96
+ # config.ro_binds["/etc/alternatives"] = "/etc/alternatives"
74
97
  #
75
- # @return [Boolean] true if libdirs are mounted to the chroot
76
- attr_accessor :libdir_mounts
98
+ # @return [Array] Paths to directories where binaries are looked from.
99
+ attr_reader :binaries_from
77
100
 
78
- # Set to `true` if command given to {Bwrap::Bwrap#run} is expected to
79
- # be inside sandbox, and not bound from host.
101
+ # Paths to be added to sandbox instance’s PATH environment variable.
80
102
  #
81
- # @return [Boolean] `true` if executed command is inside sandbox
82
- attr_accessor :command_inside_root
83
-
84
- attr_accessor :extra_executables
85
-
86
- # Array of directories to be bind mounted and used to construct PATH environment variable.
87
- attr_reader :binaries_from
103
+ # @see #add_env_path
104
+ attr_reader :env_paths
88
105
 
89
106
  # TODO: Document this.
90
107
  # TODO: I wonder if this should just be removed. I don’t know, this is a bit ...
@@ -116,16 +133,12 @@ class Bwrap::Config
116
133
  # @param dir Path to temporary directory
117
134
  attr_reader :tmpdir
118
135
 
119
- # Paths to be added to sandbox instance’s PATH environment variable.
120
- #
121
- # @see #add_env_path
122
- attr_reader :env_paths
123
-
124
136
  def initialize
125
- @binaries_from = []
126
- @tmpdir = Dir.tmpdir
127
137
  @audio = []
138
+ @binaries_from = []
128
139
  @env_paths = []
140
+ @ro_binds = {}
141
+ @tmpdir = Dir.tmpdir
129
142
  end
130
143
 
131
144
  def binaries_from= array
@@ -91,14 +91,14 @@ module Bwrap::Execution
91
91
  # execute commands.
92
92
  #
93
93
  # @see .do_execute .do_execute for documentation of argument syntax
94
- private def execute *args
94
+ private def execute *args, **kwargs
95
95
  # Mangle proper location to error message.
96
- if args.last.is_a? Hash
97
- args.last[:log_callback] = 3
96
+ if kwargs.is_a? Hash
97
+ kwargs[:log_callback] = 3
98
98
  else
99
- args << { log_callback: 3 }
99
+ kwargs = { log_callback: 3 }
100
100
  end
101
- Bwrap::Execution.do_execute(*args)
101
+ Bwrap::Execution.do_execute(*args, **kwargs)
102
102
  end
103
103
 
104
104
  # Same as ::execute, but uses log: false to avoid unnecessary output when we’re just getting a
@@ -106,7 +106,7 @@ module Bwrap::Execution
106
106
  #
107
107
  # Defaults to fail: false, since when one just wants to get the value, there is not that much
108
108
  # need to unconditionally die if getting bad exit code.
109
- private def execvalue *args, fail: false, rootcmd: nil, env: {}
109
+ private def execvalue *args, fail: false, log: false, **kwargs
110
110
  # This logging handling is a bit of duplication from execute(), but to be extra safe, it is duplicated.
111
111
  # The debug message contents will always be evaluated, so can just do it like this.
112
112
  log_command = args[0].respond_to?(:join) && args[0].join(" ") || args[0]
@@ -121,7 +121,7 @@ module Bwrap::Execution
121
121
  return
122
122
  end
123
123
  trace "Execvaluing “#{log_command}” at #{caller_locations(1, 1)[0]}"
124
- execute(*args, fail: fail, log: false, rootcmd: rootcmd, env: env)
124
+ execute(*args, fail: fail, log: log, **kwargs)
125
125
  end
126
126
 
127
127
  private def exec_success?
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative "bwrap_module"
4
+
3
5
  # Declare Execution module here so Bwrap::Execution module is
4
6
  # already declared for Execution module classes, to avoid
5
7
  # a circular dependency.
@@ -1,8 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # force_encoding modifies string, so can’t freeze strings.
4
-
5
3
  # Logging methods.
4
+ #
5
+ # @note One should require "bwrap/output" instead of this file directly, even
6
+ # if using only methods from this class.
7
+ #
8
+ # This is because Bwrap::Output module would be missing, or there could be
9
+ # a circular dependency, which is always bad, even if Ruby would break it for you.
6
10
  class Bwrap::Output::Log
7
11
  @@log_file = nil
8
12
 
@@ -29,6 +33,10 @@ class Bwrap::Output::Log
29
33
 
30
34
  # Starts logging to given file.
31
35
  def self.log_to_file log_path
36
+ unless File.writable? log_path
37
+ warn "Given log file #{log_path} is not writable by current user."
38
+ return
39
+ end
32
40
  log_file = File.open log_path, "w"
33
41
 
34
42
  # In default mode, log messages disappears as Ruby’s own buffer gets full.
@@ -3,6 +3,7 @@
3
3
  # Have variables like $CHILD_STATUS which is alias of $?.
4
4
  require "English"
5
5
 
6
+ require "bwrap/bwrap_module"
6
7
  require "bwrap/execution/labels"
7
8
 
8
9
  require_relative "levels"
data/lib/bwrap/output.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative "bwrap_module"
4
+
3
5
  # Declare Output module here so Bwrap::Output module is
4
6
  # already declared for Output module classes, to avoid
5
7
  # a circular dependency.
data/lib/bwrap/version.rb CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Bwrap
4
4
  # Current version of bwrap.
5
- VERSION = "1.0.0-beta1"
5
+ VERSION = "1.0.0-beta2"
6
6
  end
7
7
 
8
8
  require "deep-cover" if ENV["DEEP_COVER"]
data/lib/bwrap.rb CHANGED
@@ -1,28 +1,3 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "bwrap/bwrap"
4
-
5
- # ruby-bwrap provides easy-to-use interface to run complex programs in sandboxes created with
6
- # {https://github.com/containers/bubblewrap bubblewrap}.
7
- #
8
- # To run a program inside bubblewrap, a wrapper executable can be created. For example:
9
- #
10
- # require "bwrap"
11
- #
12
- # config = Bwrap::Config.new
13
- # config.user = "dummy_user"
14
- # config.full_system_mounts = true
15
- # config.binaries_from = %w{
16
- # /bin
17
- # /usr/bin
18
- # }
19
- #
20
- # bwrap = Bwrap::Bwrap.new config
21
- # bwrap.parse_command_line_arguments
22
- # bwrap.run "/bin/true"
23
- #
24
- # There also are few generic utilities, {Bwrap::Output} for handling output of scripts and
25
- # {Bwrap::Execution} to run executables.
26
- module Bwrap
27
- # Empty module.
28
- end
3
+ require "bwrap/bwrap"
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bwrap
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.pre.beta1
4
+ version: 1.0.0.pre.beta2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samu Voutilainen
@@ -34,7 +34,7 @@ cert_chain:
34
34
  X4ioQwEn1/9tHs19VO1CLF58451HgEo1BXd7eWLmV1V5cqw0YWok1ly4L/Su/Phf
35
35
  MRxVMHiVAqY=
36
36
  -----END CERTIFICATE-----
37
- date: 2021-12-12 00:00:00.000000000 Z
37
+ date: 2022-02-02 00:00:00.000000000 Z
38
38
  dependencies:
39
39
  - !ruby/object:Gem::Dependency
40
40
  name: bundler
@@ -129,6 +129,7 @@ files:
129
129
  - lib/bwrap/args/machine_id.rb
130
130
  - lib/bwrap/args/mount.rb
131
131
  - lib/bwrap/bwrap.rb
132
+ - lib/bwrap/bwrap_module.rb
132
133
  - lib/bwrap/config.rb
133
134
  - lib/bwrap/config/features.rb
134
135
  - lib/bwrap/execution.rb
metadata.gz.sig CHANGED
Binary file