microsandbox-rb 0.17.4 → 0.18.0
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/CHANGELOG.md +378 -1
- data/Cargo.lock +747 -1134
- data/DESIGN.md +52 -36
- data/README.md +27 -20
- data/SECURITY.md +22 -6
- data/docs/configuration.md +153 -17
- data/docs/errors.md +8 -2
- data/docs/execution.md +17 -0
- data/docs/filesystem.md +2 -1
- data/docs/images.md +74 -2
- data/docs/lifecycle.md +130 -6
- data/docs/observability.md +9 -7
- data/docs/releasing.md +1 -1
- data/docs/runtime.md +126 -43
- data/docs/surface.md +55 -14
- data/ext/microsandbox/Cargo.toml +22 -20
- data/ext/microsandbox/extconf.rb +9 -8
- data/ext/microsandbox/src/backend.rs +21 -15
- data/ext/microsandbox/src/error.rs +59 -1
- data/ext/microsandbox/src/host_path.rs +37 -28
- data/ext/microsandbox/src/lib.rs +314 -42
- data/ext/microsandbox/src/runtime.rs +5 -5
- data/ext/microsandbox/src/sandbox.rs +508 -241
- data/ext/microsandbox/src/snapshot.rs +63 -20
- data/ext/microsandbox/src/storage.rs +44 -0
- data/lib/microsandbox/errors.rb +63 -0
- data/lib/microsandbox/exec_handle.rb +2 -1
- data/lib/microsandbox/runtime_info.rb +65 -0
- data/lib/microsandbox/sandbox.rb +544 -158
- data/lib/microsandbox/snapshot.rb +101 -28
- data/lib/microsandbox/storage.rb +205 -0
- data/lib/microsandbox/version.rb +5 -4
- data/lib/microsandbox.rb +259 -60
- data/rust-toolchain.toml +1 -1
- data/sig/microsandbox.rbs +113 -7
- metadata +5 -2
data/lib/microsandbox.rb
CHANGED
|
@@ -20,6 +20,7 @@ end
|
|
|
20
20
|
|
|
21
21
|
require_relative "microsandbox/errors"
|
|
22
22
|
require_relative "microsandbox/backend_info"
|
|
23
|
+
require_relative "microsandbox/runtime_info"
|
|
23
24
|
require_relative "microsandbox/exec_output"
|
|
24
25
|
require_relative "microsandbox/exec_handle"
|
|
25
26
|
require_relative "microsandbox/fs"
|
|
@@ -37,6 +38,7 @@ require_relative "microsandbox/agent"
|
|
|
37
38
|
require_relative "microsandbox/ssh"
|
|
38
39
|
require_relative "microsandbox/modification"
|
|
39
40
|
require_relative "microsandbox/sandbox"
|
|
41
|
+
require_relative "microsandbox/storage"
|
|
40
42
|
|
|
41
43
|
# Microsandbox — lightweight microVM sandboxes for Ruby.
|
|
42
44
|
#
|
|
@@ -71,104 +73,167 @@ module Microsandbox
|
|
|
71
73
|
RUNTIME_VERSION
|
|
72
74
|
end
|
|
73
75
|
|
|
74
|
-
#
|
|
75
|
-
#
|
|
76
|
+
# Install the runtime this SDK was built for — `msb` + `libkrunfw` of
|
|
77
|
+
# upstream {RUNTIME_VERSION} — into the runtime home (`MSB_HOME`, default
|
|
78
|
+
# `~/.microsandbox`).
|
|
76
79
|
#
|
|
77
80
|
# This gem is SDK-only: nothing is provisioned at build/install time. The
|
|
78
81
|
# runtime comes from the companion `microsandbox-rb-binaries` gem when it is
|
|
79
|
-
# installed (see {ensure_runtime!}); otherwise it is fetched into
|
|
80
|
-
#
|
|
81
|
-
#
|
|
82
|
-
#
|
|
83
|
-
#
|
|
82
|
+
# installed (see {ensure_runtime!}); otherwise it is fetched into the home
|
|
83
|
+
# on first use. Call this explicitly to provision ahead of time (e.g. while
|
|
84
|
+
# baking a container image) so the first {Sandbox.create} doesn't pay the
|
|
85
|
+
# download.
|
|
86
|
+
#
|
|
87
|
+
# Version-aware and idempotent. It checks the home itself — the exact two
|
|
88
|
+
# files the resolver expects there — whatever `MSB_PATH` or a configured
|
|
89
|
+
# path would select instead:
|
|
90
|
+
#
|
|
91
|
+
# - both present and `msb` is exactly {RUNTIME_VERSION}: nothing to do (no
|
|
92
|
+
# download), unless +force+;
|
|
93
|
+
# - absent: download and install;
|
|
94
|
+
# - present but another version (a pre-0.7 `msb` carries none): replace both;
|
|
95
|
+
# - only one of the two present: raise — the installer never repairs a
|
|
96
|
+
# partial home; the message names the files to delete.
|
|
97
|
+
#
|
|
98
|
+
# @param force [Boolean] reinstall even when the home is already current
|
|
84
99
|
# @return [nil]
|
|
85
|
-
|
|
86
|
-
|
|
100
|
+
# @raise [RuntimeIncompleteError] when the home holds only half of the pair
|
|
101
|
+
def install(force: false)
|
|
102
|
+
RUNTIME_SETUP_LOCK.synchronize do
|
|
103
|
+
msb, lib = Native.runtime_home_pair
|
|
104
|
+
case home_runtime_state(msb, lib)
|
|
105
|
+
when :partial then raise RuntimeIncompleteError, partial_home_message(msb, lib)
|
|
106
|
+
when :absent then Native.install_runtime({})
|
|
107
|
+
when :stale then Native.install_runtime({"force" => true})
|
|
108
|
+
when :current then Native.install_runtime({"force" => true}) if force
|
|
109
|
+
end
|
|
110
|
+
end
|
|
87
111
|
nil
|
|
88
112
|
end
|
|
89
113
|
|
|
90
|
-
# Customizable install via
|
|
114
|
+
# Customizable install via upstream's installer. Like {install} but with
|
|
91
115
|
# control over where and what to install — mirrors the Node `Setup` builder.
|
|
116
|
+
# Presence-only: a complete pair already in the target home is kept unless
|
|
117
|
+
# +force+, whatever its version.
|
|
92
118
|
#
|
|
93
119
|
# @param base_dir [String, nil] install root (default `~/.microsandbox`)
|
|
94
|
-
# @param version [String, nil]
|
|
120
|
+
# @param version [String, nil] the runtime release to download. Runtime
|
|
121
|
+
# v0.7 launches only an `msb` of exactly {RUNTIME_VERSION}: any other
|
|
122
|
+
# version is refused at every local sandbox start, so this warns.
|
|
95
123
|
# @param force [Boolean] re-download even if binaries already exist — the way
|
|
96
|
-
# to repair a corrupt
|
|
124
|
+
# to repair a corrupt `~/.microsandbox`
|
|
97
125
|
# @param skip_verify [Boolean] skip the post-install verification step
|
|
98
126
|
# @return [nil]
|
|
99
127
|
def setup(base_dir: nil, version: nil, force: false, skip_verify: false)
|
|
100
128
|
opts = {}
|
|
101
129
|
opts["base_dir"] = base_dir.to_s if base_dir
|
|
102
|
-
|
|
130
|
+
if version
|
|
131
|
+
opts["version"] = version.to_s
|
|
132
|
+
unless version.to_s.delete_prefix("v") == sdk_runtime_version
|
|
133
|
+
warn "[microsandbox] setup(version: #{version.to_s.inspect}): this SDK launches only runtime " \
|
|
134
|
+
"#{sdk_runtime_version}; a #{version.to_s.delete_prefix("v")} runtime will be refused " \
|
|
135
|
+
"at every local sandbox start"
|
|
136
|
+
end
|
|
137
|
+
end
|
|
103
138
|
opts["force"] = true if force
|
|
104
139
|
opts["skip_verify"] = true if skip_verify
|
|
105
140
|
RUNTIME_SETUP_LOCK.synchronize { Native.setup(opts) }
|
|
106
141
|
nil
|
|
107
142
|
end
|
|
108
143
|
|
|
109
|
-
#
|
|
144
|
+
# Whether a complete `msb` + `libkrunfw` pair resolves from any source the
|
|
145
|
+
# local backend would use (`MSB_PATH`, the binaries gem, configured paths,
|
|
146
|
+
# the runtime home). Presence only: says nothing about the version — see
|
|
147
|
+
# {runtime_info} and {RuntimeInfo#matches_sdk?}.
|
|
148
|
+
# @return [Boolean]
|
|
110
149
|
def installed?
|
|
111
150
|
Native.installed?
|
|
112
151
|
end
|
|
113
152
|
|
|
114
|
-
#
|
|
115
|
-
#
|
|
116
|
-
#
|
|
117
|
-
#
|
|
153
|
+
# The runtime pair local sandboxes would launch with, and where it came
|
|
154
|
+
# from. Reads files and the environment only (nothing is downloaded,
|
|
155
|
+
# created or run); independent of the selected backend.
|
|
156
|
+
# @return [RuntimeInfo]
|
|
157
|
+
# @raise [RuntimeNotInstalledError] when no pair resolves from any source
|
|
158
|
+
# @raise [RuntimeIncompleteError] when the selected source is partial or
|
|
159
|
+
# unpaired (e.g. `MSB_PATH` with no `libkrunfw` beside it)
|
|
160
|
+
def runtime_info
|
|
161
|
+
data = Native.runtime_info
|
|
162
|
+
RuntimeInfo.new(data.merge("origin" => classify_runtime_origin(data)))
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
# Make sure local sandboxes can start: the runtime pair resolves and its
|
|
166
|
+
# `msb` is exactly the version this SDK was built for (runtime v0.7 refuses
|
|
167
|
+
# every other one at launch). Called automatically by {Sandbox.create},
|
|
168
|
+
# {Sandbox.start} and the other calls that boot a microVM, so a freshly
|
|
169
|
+
# installed gem gets a working runtime without a manual {install} step.
|
|
118
170
|
#
|
|
119
|
-
# Runs at most once per process
|
|
120
|
-
# gem supplies the runtime (it was activated at load time and its `msb` is
|
|
121
|
-
# what the resolver now returns from {runtime_path}), nothing is downloaded
|
|
122
|
-
# or touched in `~/.microsandbox` — the bundled binaries are already the
|
|
123
|
-
# matching version. Opt out of the download by setting
|
|
124
|
-
# `MICROSANDBOX_NO_AUTO_INSTALL` (e.g. air-gapped hosts that provision the
|
|
125
|
-
# runtime out of band); the runtime is then left untouched and a missing or
|
|
126
|
-
# stale one surfaces at the operation itself.
|
|
171
|
+
# Runs at most once per process (successful outcomes are memoized):
|
|
127
172
|
#
|
|
128
|
-
#
|
|
129
|
-
#
|
|
130
|
-
# `
|
|
131
|
-
#
|
|
132
|
-
#
|
|
133
|
-
#
|
|
134
|
-
#
|
|
135
|
-
#
|
|
136
|
-
#
|
|
137
|
-
#
|
|
138
|
-
#
|
|
173
|
+
# - cloud backend, or the binaries gem's runtime is the one selected:
|
|
174
|
+
# nothing to do;
|
|
175
|
+
# - `MICROSANDBOX_NO_AUTO_INSTALL` set: never downloads or writes. A
|
|
176
|
+
# mismatched runtime is reported with a warning; a missing or partial one
|
|
177
|
+
# is left for the operation itself to raise;
|
|
178
|
+
# - nothing resolves: warn, then {install} into the runtime home;
|
|
179
|
+
# - the runtime home's own `msb` is another version: warn, then
|
|
180
|
+
# `install(force: true)` replaces the pair;
|
|
181
|
+
# - another source (`MSB_PATH`, configured paths) is another version:
|
|
182
|
+
# never touched — warn that every local start will be refused;
|
|
183
|
+
# - a partial pair: raise with the files to delete or the variable to set.
|
|
184
|
+
#
|
|
185
|
+
# The local backend reads its runtime configuration (`MSB_HOME`,
|
|
186
|
+
# `MSB_PATH`, `MSB_LIBKRUNFW_PATH`, the config file) once, when it is
|
|
187
|
+
# first used; if it has changed since, this raises {InvalidConfigError}
|
|
188
|
+
# before checking or installing anything.
|
|
139
189
|
# @return [nil]
|
|
190
|
+
# @raise [RuntimeIncompleteError] for a partial runtime (unless opted out)
|
|
191
|
+
# @raise [InvalidConfigError] when the runtime configuration changed after
|
|
192
|
+
# the local backend was created
|
|
140
193
|
def ensure_runtime!
|
|
141
194
|
return if @runtime_ready
|
|
142
195
|
RUNTIME_SETUP_LOCK.synchronize do
|
|
143
196
|
# Re-check under the lock: another thread may have finished meanwhile.
|
|
144
197
|
return if @runtime_ready
|
|
145
|
-
# A cloud backend has no local msb/libkrunfw runtime to provision
|
|
146
|
-
# presence check and the first-use download entirely. Resolving the kind
|
|
147
|
-
# uses the same lazy env/profile/config ladder every operation already
|
|
148
|
-
# consults, so this adds no work for local hosts (the common case).
|
|
198
|
+
# A cloud backend has no local msb/libkrunfw runtime to provision.
|
|
149
199
|
return if default_backend_kind == :cloud
|
|
150
|
-
# The
|
|
151
|
-
#
|
|
152
|
-
#
|
|
153
|
-
#
|
|
200
|
+
# The local backend captured its runtime configuration when it was
|
|
201
|
+
# built (this builds it if nothing has yet). Refuse when the current
|
|
202
|
+
# configuration has moved away from it — before anything is installed
|
|
203
|
+
# or memoized. Everything below then reads that captured
|
|
204
|
+
# configuration only (`Native.backend_*`): the runtime it selects, its
|
|
205
|
+
# home pair and the install target, so a change to the environment
|
|
206
|
+
# while bootstrap runs cannot redirect the decision or the write.
|
|
207
|
+
Native.verify_backend_runtime_config
|
|
208
|
+
home_msb, = Native.backend_runtime_home_pair
|
|
209
|
+
# The binaries gem won the resolver: its vendored pair is exactly the
|
|
210
|
+
# version this gem was built for, so there is nothing to check.
|
|
154
211
|
if bundled_runtime_active?
|
|
155
212
|
@runtime_ready = true
|
|
156
213
|
return
|
|
157
214
|
end
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
# the process); the operation resolves `msb` itself and surfaces any problem.
|
|
215
|
+
info = bootstrap_runtime_info
|
|
216
|
+
return if @runtime_ready # opted out with an incomplete runtime
|
|
161
217
|
if auto_install_disabled?
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
unless installed?
|
|
218
|
+
# Opted out: the caller manages the runtime out of band. Never write;
|
|
219
|
+
# a missing runtime surfaces at the operation itself.
|
|
220
|
+
warn_runtime_mismatch(info) if info && !info.matches_sdk?
|
|
221
|
+
elsif info.nil?
|
|
167
222
|
warn "[microsandbox] runtime (msb + libkrunfw) not found; " \
|
|
168
|
-
"downloading
|
|
169
|
-
"or install the microsandbox-rb-binaries gem
|
|
223
|
+
"downloading runtime #{sdk_runtime_version} to #{File.dirname(home_msb, 2)} " \
|
|
224
|
+
"(set MICROSANDBOX_NO_AUTO_INSTALL to skip, or install the microsandbox-rb-binaries gem " \
|
|
225
|
+
"to ship it with your bundle)..."
|
|
226
|
+
bootstrap_install(home_msb)
|
|
227
|
+
elsif !info.matches_sdk?
|
|
228
|
+
if replaceable_home_runtime?(info, home_msb)
|
|
229
|
+
warn "[microsandbox] runtime #{describe_runtime_version(info)} in #{File.dirname(info.msb_path, 2)} " \
|
|
230
|
+
"is not the #{sdk_runtime_version} this SDK launches; replacing it " \
|
|
231
|
+
"(set MICROSANDBOX_NO_AUTO_INSTALL to keep it)..."
|
|
232
|
+
bootstrap_install(home_msb, force: true)
|
|
233
|
+
else
|
|
234
|
+
warn_runtime_mismatch(info)
|
|
235
|
+
end
|
|
170
236
|
end
|
|
171
|
-
install
|
|
172
237
|
@runtime_ready = true
|
|
173
238
|
end
|
|
174
239
|
nil
|
|
@@ -202,12 +267,19 @@ module Microsandbox
|
|
|
202
267
|
# Override the `libkrunfw` shared-library path (SDK tier of the resolver,
|
|
203
268
|
# below the `MSB_LIBKRUNFW_PATH` environment variable). Process-level and
|
|
204
269
|
# set-once: a second call is silently ignored, and the env var still wins.
|
|
205
|
-
# Mirrors {runtime_path=} for libkrunfw.
|
|
270
|
+
# Mirrors {runtime_path=} for libkrunfw. The companion
|
|
271
|
+
# `microsandbox-rb-binaries` gem claims this slot too (unless `MSB_PATH` is
|
|
272
|
+
# set when `microsandbox` is required), which makes this a no-op.
|
|
206
273
|
# @param path [String]
|
|
207
274
|
# @return [void]
|
|
208
275
|
# @raise [ArgumentError] for nil or an empty path (the slot cannot be cleared)
|
|
209
276
|
def libkrunfw_path=(path)
|
|
210
277
|
require_runtime_path!(:libkrunfw_path=, path)
|
|
278
|
+
if @bundled_libkrunfw_claimed && path.to_s != @bundled_libkrunfw_path
|
|
279
|
+
warn "[microsandbox] libkrunfw_path= ignored: the microsandbox-rb-binaries gem already " \
|
|
280
|
+
"claimed the set-once SDK slot (#{@bundled_libkrunfw_path}); set MSB_PATH (and " \
|
|
281
|
+
"MSB_LIBKRUNFW_PATH) to override it"
|
|
282
|
+
end
|
|
211
283
|
Native.set_runtime_libkrunfw_path(path.to_s)
|
|
212
284
|
end
|
|
213
285
|
|
|
@@ -366,6 +438,8 @@ module Microsandbox
|
|
|
366
438
|
# @return [String, nil] the activated msb path
|
|
367
439
|
def activate_bundled_runtime!
|
|
368
440
|
@bundled_msb_path = nil
|
|
441
|
+
@bundled_libkrunfw_path = nil
|
|
442
|
+
@bundled_libkrunfw_claimed = false
|
|
369
443
|
begin
|
|
370
444
|
# Pin the lockstep version when RubyGems (not Bundler) picks the gem, so
|
|
371
445
|
# a newer/older companion left around doesn't get activated over the
|
|
@@ -411,6 +485,16 @@ module Microsandbox
|
|
|
411
485
|
end
|
|
412
486
|
Native.set_runtime_msb_path(msb)
|
|
413
487
|
@bundled_msb_path = msb
|
|
488
|
+
@bundled_libkrunfw_path = Binaries.libkrunfw_path
|
|
489
|
+
# Pair the library explicitly too (msb first: a library slot with no
|
|
490
|
+
# msb slot would pair a home msb with this library). Not when `MSB_PATH`
|
|
491
|
+
# is set: the resolver takes the library slot over the one next to an
|
|
492
|
+
# `MSB_PATH` runtime, which would pair that runtime with this library.
|
|
493
|
+
unless ENV.key?("MSB_PATH")
|
|
494
|
+
Native.set_runtime_libkrunfw_path(@bundled_libkrunfw_path)
|
|
495
|
+
@bundled_libkrunfw_claimed = true
|
|
496
|
+
end
|
|
497
|
+
msb
|
|
414
498
|
rescue StandardError, ScriptError => e
|
|
415
499
|
# ScriptError too: a corrupt or newer-syntax binaries.rb raises
|
|
416
500
|
# SyntaxError (not a StandardError) out of `require`, and the optional
|
|
@@ -442,14 +526,129 @@ module Microsandbox
|
|
|
442
526
|
raise ArgumentError, "#{setter} needs a non-empty path (the slot is set-once and cannot be cleared)"
|
|
443
527
|
end
|
|
444
528
|
|
|
445
|
-
# Whether the binaries gem's
|
|
446
|
-
# it was activated
|
|
529
|
+
# Whether the binaries gem's pair is what the resolver actually returns —
|
|
530
|
+
# it was activated, nothing higher in the ladder (`MSB_PATH`) overrides it,
|
|
531
|
+
# and the library paired with its msb is its own.
|
|
447
532
|
def bundled_runtime_active?
|
|
448
533
|
return false unless @bundled_msb_path
|
|
449
|
-
|
|
534
|
+
info = backend_runtime_info
|
|
535
|
+
info.origin == :sdk_package && same_path?(info.libkrunfw_path, @bundled_libkrunfw_path)
|
|
450
536
|
rescue Microsandbox::Error
|
|
451
537
|
false
|
|
452
538
|
end
|
|
539
|
+
|
|
540
|
+
# Runtime v0.7.14 layers `MSB_PATH` and the SDK path slots into the
|
|
541
|
+
# configuration before it resolves, so it reports both as `configuration`.
|
|
542
|
+
# Tell them apart by the resolved msb, in the precedence the layering uses
|
|
543
|
+
# (the environment wins over the slot). Every other origin is passed
|
|
544
|
+
# through untouched — `home` above all, which the forced reinstall keys on.
|
|
545
|
+
def classify_runtime_origin(data)
|
|
546
|
+
origin = data["origin"]
|
|
547
|
+
return origin unless origin == "configuration"
|
|
548
|
+
msb = data["msb_path"]
|
|
549
|
+
# `key?`, not non-empty: the core reads an empty MSB_PATH as set.
|
|
550
|
+
return "environment" if ENV.key?("MSB_PATH") && same_path?(msb, ENV["MSB_PATH"])
|
|
551
|
+
return "sdk_package" if @bundled_msb_path && same_path?(msb, @bundled_msb_path)
|
|
552
|
+
origin
|
|
553
|
+
end
|
|
554
|
+
|
|
555
|
+
# Whether two runtime paths name the same file: equal once expanded (the
|
|
556
|
+
# core makes a relative MSB_PATH absolute against the working directory),
|
|
557
|
+
# or with the same real path.
|
|
558
|
+
def same_path?(a, b)
|
|
559
|
+
return false if a.nil? || b.nil? || a.to_s.empty? || b.to_s.empty?
|
|
560
|
+
return true if File.expand_path(a) == File.expand_path(b)
|
|
561
|
+
File.realpath(a) == File.realpath(b)
|
|
562
|
+
rescue SystemCallError
|
|
563
|
+
false
|
|
564
|
+
end
|
|
565
|
+
|
|
566
|
+
# "0.7.14", the runtime version this SDK launches.
|
|
567
|
+
def sdk_runtime_version = RUNTIME_VERSION.delete_prefix("v")
|
|
568
|
+
|
|
569
|
+
# The state of the runtime home itself — the exact two files the resolver
|
|
570
|
+
# expects there (no glob: an unrelated `libkrunfw.backup` is not the
|
|
571
|
+
# library) — whatever a higher-priority source would select instead.
|
|
572
|
+
def home_runtime_state(msb, lib)
|
|
573
|
+
has_msb = File.file?(msb)
|
|
574
|
+
has_lib = File.file?(lib)
|
|
575
|
+
return :absent unless has_msb || has_lib
|
|
576
|
+
return :partial unless has_msb && has_lib
|
|
577
|
+
(home_msb_version(msb) == sdk_runtime_version) ? :current : :stale
|
|
578
|
+
end
|
|
579
|
+
|
|
580
|
+
# An unreadable home msb counts as stale: the installer replaces it.
|
|
581
|
+
def home_msb_version(msb)
|
|
582
|
+
Native.msb_version(msb)
|
|
583
|
+
rescue Microsandbox::Error
|
|
584
|
+
nil
|
|
585
|
+
end
|
|
586
|
+
|
|
587
|
+
def partial_home_message(msb, lib)
|
|
588
|
+
present, missing = [msb, lib].partition { |path| File.file?(path) }
|
|
589
|
+
"partial runtime installation in #{File.dirname(msb, 2)}: found #{present.join(", ")} " \
|
|
590
|
+
"but not #{missing.join(", ")}. The installer never repairs a partial home; " \
|
|
591
|
+
"delete #{msb} and #{lib} (whichever exist) and retry"
|
|
592
|
+
end
|
|
593
|
+
|
|
594
|
+
# {runtime_info} of the local backend's captured configuration — the pair
|
|
595
|
+
# `create` launches — for ensure_runtime!.
|
|
596
|
+
def backend_runtime_info
|
|
597
|
+
data = Native.backend_runtime_info
|
|
598
|
+
RuntimeInfo.new(data.merge("origin" => classify_runtime_origin(data)))
|
|
599
|
+
end
|
|
600
|
+
|
|
601
|
+
# ensure_runtime!'s install: into the captured configuration's home
|
|
602
|
+
# (`home_msb` is the pair the decision was made for), never one read
|
|
603
|
+
# afresh. {install} stays backend-independent.
|
|
604
|
+
def bootstrap_install(home_msb, force: false)
|
|
605
|
+
Native.install_backend_runtime(home_msb, force ? {"force" => true} : {})
|
|
606
|
+
end
|
|
607
|
+
|
|
608
|
+
# backend_runtime_info for ensure_runtime!: nil when nothing resolves. A
|
|
609
|
+
# partial runtime raises with directions — unless opted out, when the
|
|
610
|
+
# operation is left to raise it (and the process is marked ready).
|
|
611
|
+
def bootstrap_runtime_info
|
|
612
|
+
backend_runtime_info
|
|
613
|
+
rescue RuntimeNotInstalledError
|
|
614
|
+
nil
|
|
615
|
+
rescue RuntimeIncompleteError => e
|
|
616
|
+
if auto_install_disabled?
|
|
617
|
+
@runtime_ready = true
|
|
618
|
+
return nil
|
|
619
|
+
end
|
|
620
|
+
# The error comes from the first source the resolver consulted: the
|
|
621
|
+
# environment when it is set, otherwise (no configured paths) the home.
|
|
622
|
+
hint = runtime_env_hint || begin
|
|
623
|
+
msb, lib = Native.backend_runtime_home_pair
|
|
624
|
+
partial_home_message(msb, lib) if home_runtime_state(msb, lib) == :partial
|
|
625
|
+
end
|
|
626
|
+
raise unless hint
|
|
627
|
+
raise RuntimeIncompleteError, "#{e.message} — #{hint}"
|
|
628
|
+
end
|
|
629
|
+
|
|
630
|
+
def runtime_env_hint
|
|
631
|
+
return nil unless ENV.key?("MSB_PATH") || ENV.key?("MSB_LIBKRUNFW_PATH")
|
|
632
|
+
"MSB_PATH needs libkrunfw beside it (in its directory or ../lib) or MSB_LIBKRUNFW_PATH " \
|
|
633
|
+
"naming it; MSB_LIBKRUNFW_PATH alone is not enough"
|
|
634
|
+
end
|
|
635
|
+
|
|
636
|
+
# The forced reinstall replaces files in the user's home, so only when the
|
|
637
|
+
# resolved pair provably IS the home pair.
|
|
638
|
+
def replaceable_home_runtime?(info, home_msb)
|
|
639
|
+
info.origin == :home && same_path?(info.msb_path, home_msb)
|
|
640
|
+
end
|
|
641
|
+
|
|
642
|
+
def describe_runtime_version(info)
|
|
643
|
+
info.version || "with no embedded version (pre-0.7 msb or a wrapper script)"
|
|
644
|
+
end
|
|
645
|
+
|
|
646
|
+
# The one mismatch warning (4c / 7): a runtime this SDK did not install
|
|
647
|
+
# and will not touch.
|
|
648
|
+
def warn_runtime_mismatch(info)
|
|
649
|
+
warn "[microsandbox] runtime #{info.version || "no embedded version (pre-0.7 msb or a wrapper script)"} " \
|
|
650
|
+
"at #{info.msb_path} ≠ SDK #{sdk_runtime_version}: every local sandbox start will be refused"
|
|
651
|
+
end
|
|
453
652
|
end
|
|
454
653
|
|
|
455
654
|
send(:activate_bundled_runtime!)
|
data/rust-toolchain.toml
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# The microsandbox core crate uses Rust edition 2024 and pulls in dependencies
|
|
2
|
-
# (
|
|
2
|
+
# (sea-orm 2 / sqlx 0.9) that require a recent compiler. Stable >= 1.94 is the minimum
|
|
3
3
|
# supported Rust version (MSRV) for building this gem from source.
|
|
4
4
|
[toolchain]
|
|
5
5
|
channel = "stable"
|
data/sig/microsandbox.rbs
CHANGED
|
@@ -15,14 +15,17 @@ module Microsandbox
|
|
|
15
15
|
|
|
16
16
|
def self.version: () -> String
|
|
17
17
|
def self.runtime_version: () -> String
|
|
18
|
-
def self.install: () -> nil
|
|
18
|
+
def self.install: (?force: bool) -> nil
|
|
19
19
|
def self.setup: (?base_dir: String?, ?version: String?, ?force: bool, ?skip_verify: bool) -> nil
|
|
20
20
|
def self.installed?: () -> bool
|
|
21
|
+
def self.runtime_info: () -> RuntimeInfo
|
|
21
22
|
def self.ensure_runtime!: () -> nil
|
|
22
23
|
def self.runtime_path: () -> String
|
|
23
24
|
def self.runtime_path=: (String path) -> void
|
|
24
25
|
def self.libkrunfw_path=: (String path) -> void
|
|
25
26
|
def self.all_sandbox_metrics: () -> Hash[String, Metrics]
|
|
27
|
+
# Local runtime-home storage inspection (runtime v0.7); exactly one scope.
|
|
28
|
+
def self.diagnose_storage: (?names: (Array[String | Symbol] | String | Symbol)?, ?all_sandboxes: bool, ?home: String?) -> StorageDiagnosis
|
|
26
29
|
|
|
27
30
|
def self.set_default_backend: (String | Symbol kind, ?url: String?, ?api_key: String?, ?profile: String?) -> void
|
|
28
31
|
def self.with_backend: [T] (String | Symbol kind, ?url: String?, ?api_key: String?, ?profile: String?) { () -> T } -> T
|
|
@@ -35,11 +38,15 @@ module Microsandbox
|
|
|
35
38
|
end
|
|
36
39
|
|
|
37
40
|
class InvalidConfigError < Error end
|
|
41
|
+
class RuntimeNotInstalledError < Error end
|
|
42
|
+
class RuntimeIncompleteError < Error end
|
|
38
43
|
class SandboxNotFoundError < Error end
|
|
39
44
|
class SandboxNotRunningError < Error end
|
|
40
45
|
class SandboxAlreadyExistsError < Error end
|
|
41
46
|
class SandboxStillRunningError < Error end
|
|
42
47
|
class SandboxReplacedError < Error end
|
|
48
|
+
class StopTimeoutError < Error end
|
|
49
|
+
class SandboxStopTimedOutError < Error end
|
|
43
50
|
class ExecTimeoutError < Error end
|
|
44
51
|
class ExecFailedError < Error end
|
|
45
52
|
class NoDefaultCommandError < Error end
|
|
@@ -56,6 +63,19 @@ module Microsandbox
|
|
|
56
63
|
class SnapshotImageMissingError < Error end
|
|
57
64
|
class SnapshotIntegrityError < Error end
|
|
58
65
|
class SnapshotMigrationError < Error end
|
|
66
|
+
class SnapshotSourceRecoveryError < Error
|
|
67
|
+
def source_sandbox: () -> String?
|
|
68
|
+
def checkpoint_id: () -> String?
|
|
69
|
+
def checkpoint_root: () -> String?
|
|
70
|
+
def checkpoint_path: () -> String?
|
|
71
|
+
def artifact: () -> Hash[String, String]?
|
|
72
|
+
def detail: () -> String?
|
|
73
|
+
def publication_error: () -> String?
|
|
74
|
+
|
|
75
|
+
private
|
|
76
|
+
|
|
77
|
+
def __apply_recovery: (Hash[String, untyped] details) -> self
|
|
78
|
+
end
|
|
59
79
|
class NetworkPolicyError < Error end
|
|
60
80
|
class SecretViolationError < Error end
|
|
61
81
|
class TlsError < Error end
|
|
@@ -64,6 +84,7 @@ module Microsandbox
|
|
|
64
84
|
class MetricsUnavailableError < Error end
|
|
65
85
|
class UnsupportedOperationError < Error end
|
|
66
86
|
class CloudHttpError < Error end
|
|
87
|
+
class ModificationNotConfirmedError < Error end
|
|
67
88
|
class ForkedHandleError < Error end
|
|
68
89
|
class UnsupportedError < Error
|
|
69
90
|
def operation: () -> String?
|
|
@@ -260,7 +281,11 @@ module Microsandbox
|
|
|
260
281
|
|
|
261
282
|
class Sandbox
|
|
262
283
|
STATUSES: Array[Symbol]
|
|
284
|
+
# Graceful-stop budget (seconds) of the block forms before they kill.
|
|
285
|
+
BLOCK_STOP_TIMEOUT: Integer
|
|
263
286
|
|
|
287
|
+
# `from_snapshot:` and `on_secret_violation:` were removed in 0.18.0; they
|
|
288
|
+
# stay as `nil`-only keywords so passing one raises with directions.
|
|
264
289
|
def self.create: (String name, ?image: String?, ?cpus: Integer?, ?max_cpus: Integer?,
|
|
265
290
|
?memory: Integer?, ?max_memory: Integer?,
|
|
266
291
|
?env: Hash[untyped, untyped]?, ?workdir: String?, ?shell: String?,
|
|
@@ -271,11 +296,12 @@ module Microsandbox
|
|
|
271
296
|
?volumes: Hash[untyped, untyped]?, ?network: untyped?,
|
|
272
297
|
?dns: Hash[untyped, untyped]?, ?tls: Hash[untyped, untyped]?,
|
|
273
298
|
?ipv4_pool: String?, ?ipv6_pool: String?,
|
|
274
|
-
?max_connections: Integer?, ?
|
|
299
|
+
?max_connections: Integer?, ?max_tcp_connections: Integer?, ?max_udp_connections: Integer?,
|
|
300
|
+
?trust_host_cas: bool?, ?strict: bool?, ?http: Hash[untyped, untyped]?,
|
|
275
301
|
?rate_limiter: Hash[untyped, untyped]?,
|
|
276
302
|
?proxy: (OutboundProxy | Hash[untyped, untyped])?,
|
|
277
303
|
?vsock: (Hash[untyped, untyped] | Array[Hash[untyped, untyped]])?,
|
|
278
|
-
?patches: Array[Hash[untyped, untyped]]?, ?from_snapshot:
|
|
304
|
+
?patches: Array[Hash[untyped, untyped]]?, ?from_snapshot: nil,
|
|
279
305
|
?fstype: String?, ?init: (String | Symbol | Hash[untyped, untyped])?, ?ephemeral: bool,
|
|
280
306
|
?log_level: (String | Symbol)?, ?quiet_logs: bool, ?security: (String | Symbol)?,
|
|
281
307
|
?root_disk: (Integer | Hash[untyped, untyped])?,
|
|
@@ -283,8 +309,9 @@ module Microsandbox
|
|
|
283
309
|
?rlimits: Hash[untyped, untyped]?, ?pull_policy: (String | Symbol)?,
|
|
284
310
|
?registry_auth: Hash[untyped, untyped]?, ?registry_insecure: bool,
|
|
285
311
|
?registry_ca_certs: (String | Array[String])?,
|
|
286
|
-
?secrets: Array[Hash[untyped, untyped]]?,
|
|
287
|
-
?
|
|
312
|
+
?secrets: (Array[Hash[untyped, untyped]] | Hash[untyped, untyped])?,
|
|
313
|
+
?secret_violation_action: (String | Symbol)?,
|
|
314
|
+
?on_secret_violation: nil,
|
|
288
315
|
?detached: bool,
|
|
289
316
|
?replace: bool, ?replace_with_timeout: Numeric?)
|
|
290
317
|
?{ (Sandbox) -> untyped } -> untyped
|
|
@@ -295,6 +322,21 @@ module Microsandbox
|
|
|
295
322
|
# Accepts the same keyword options as {create}.
|
|
296
323
|
def self.create_with_progress: (String name, **untyped) -> PullSession
|
|
297
324
|
def self.start: (String name, ?detached: bool) -> Sandbox
|
|
325
|
+
# Boot a new (detached upstream) sandbox from a snapshot; the block form
|
|
326
|
+
# stops it on exit. Network/security/vsock/connection-cap overrides are
|
|
327
|
+
# not accepted.
|
|
328
|
+
def self.restore: ((String | Pathname | SnapshotInfo) snapshot, name: String | Symbol,
|
|
329
|
+
?cpus: Integer?, ?memory: Integer?, ?user: String?,
|
|
330
|
+
?log_level: (String | Symbol)?, ?max_duration: Integer?, ?idle_timeout: Integer?,
|
|
331
|
+
?volumes: Hash[untyped, untyped]?, ?ports: Hash[untyped, untyped]?,
|
|
332
|
+
?disable_network: bool, ?cow_memory: bool, ?forked: bool?, ?disk_only: bool,
|
|
333
|
+
?snapshot_base: String?, ?allow_missing_resources: bool,
|
|
334
|
+
?external_mount_policy: (String | Symbol)?)
|
|
335
|
+
?{ (Sandbox) -> untyped } -> untyped
|
|
336
|
+
# Import or resume a stopped sandbox's storage (runtime v0.7) without
|
|
337
|
+
# booting it. `selections:` maps disk id => candidate id.
|
|
338
|
+
def self.recover_storage: (String | Symbol name, ?selections: Hash[String | Symbol, String],
|
|
339
|
+
?accept_selected_view: bool, ?legacy_writers_stopped: bool) -> StorageRecovery
|
|
298
340
|
def self.get: (String name) -> SandboxHandle
|
|
299
341
|
def self.list: () -> SandboxPage
|
|
300
342
|
def self.list_with: (?labels: Hash[untyped, untyped], ?limit: Integer?, ?cursor: String?) -> SandboxPage
|
|
@@ -343,8 +385,10 @@ module Microsandbox
|
|
|
343
385
|
def log_stream: (?sources: Array[String | Symbol]?, ?since_ms: Numeric?,
|
|
344
386
|
?from_cursor: String?, ?until_ms: Numeric?, ?follow: bool) -> LogStream
|
|
345
387
|
def stop: () -> nil
|
|
388
|
+
def stop_with_timeout: (Numeric timeout) -> nil
|
|
346
389
|
def stop_and_wait: () -> ExitStatus
|
|
347
390
|
def kill: () -> nil
|
|
391
|
+
def kill_with_timeout: (Numeric timeout) -> nil
|
|
348
392
|
def drain: () -> nil
|
|
349
393
|
def wait: () -> ExitStatus
|
|
350
394
|
def wait_for_status: (Symbol | String status) -> SandboxHandle
|
|
@@ -504,7 +548,11 @@ module Microsandbox
|
|
|
504
548
|
class SnapshotInfo
|
|
505
549
|
def initialize: (Hash[String, untyped] data) -> void
|
|
506
550
|
def digest: () -> String
|
|
507
|
-
def
|
|
551
|
+
def id: () -> String?
|
|
552
|
+
def reference: () -> String?
|
|
553
|
+
def reference_kind: () -> String?
|
|
554
|
+
def parent_id: () -> String?
|
|
555
|
+
def path: () -> String?
|
|
508
556
|
def name: () -> String?
|
|
509
557
|
def parent_digest: () -> String?
|
|
510
558
|
def image_ref: () -> String?
|
|
@@ -538,9 +586,12 @@ module Microsandbox
|
|
|
538
586
|
end
|
|
539
587
|
|
|
540
588
|
class Snapshot
|
|
589
|
+
# `resumable:` was renamed to `full:` in 0.18.0; it stays as a `nil`-only
|
|
590
|
+
# keyword so passing it raises with directions.
|
|
541
591
|
def self.create: (String name, from_sandbox: String, ?dest_dir: String?,
|
|
542
592
|
?labels: Hash[untyped, untyped]?, ?force: bool, ?record_integrity: bool,
|
|
543
|
-
?
|
|
593
|
+
?full: bool, ?guest_flush: (String | Symbol)?,
|
|
594
|
+
?resumable: nil) -> SnapshotInfo
|
|
544
595
|
def self.open: (String name_or_path) -> SnapshotInfo
|
|
545
596
|
def self.get: (String name_or_digest) -> SnapshotInfo
|
|
546
597
|
def self.list: () -> Array[SnapshotInfo]
|
|
@@ -601,6 +652,61 @@ module Microsandbox
|
|
|
601
652
|
def cloud?: () -> bool
|
|
602
653
|
end
|
|
603
654
|
|
|
655
|
+
# The resolved host runtime pair (runtime v0.7).
|
|
656
|
+
class RuntimeInfo
|
|
657
|
+
def initialize: (Hash[String, untyped] data) -> void
|
|
658
|
+
attr_reader msb_path: String
|
|
659
|
+
attr_reader libkrunfw_path: String
|
|
660
|
+
def origin: () -> Symbol
|
|
661
|
+
def version: () -> String?
|
|
662
|
+
def legacy?: () -> bool
|
|
663
|
+
def matches_sdk?: () -> bool
|
|
664
|
+
end
|
|
665
|
+
|
|
666
|
+
# Storage diagnosis and recovery results (runtime v0.7).
|
|
667
|
+
class StorageCandidate
|
|
668
|
+
def initialize: (Hash[String, untyped] data) -> void
|
|
669
|
+
attr_reader id: String
|
|
670
|
+
attr_reader disk_id: String
|
|
671
|
+
attr_reader layers: Integer
|
|
672
|
+
attr_reader virtual_size: Integer
|
|
673
|
+
attr_reader estimated_bytes: Integer
|
|
674
|
+
end
|
|
675
|
+
|
|
676
|
+
class StorageInspection
|
|
677
|
+
def initialize: (Hash[String, untyped] data) -> void
|
|
678
|
+
attr_reader status: Symbol?
|
|
679
|
+
attr_reader reasons: Array[String]
|
|
680
|
+
attr_reader candidates: Array[StorageCandidate]
|
|
681
|
+
attr_reader estimated_bytes: Integer?
|
|
682
|
+
def preview_available?: () -> bool
|
|
683
|
+
end
|
|
684
|
+
|
|
685
|
+
class StorageSandboxDiagnosis
|
|
686
|
+
def initialize: (Hash[String, untyped] data) -> void
|
|
687
|
+
attr_reader name: String
|
|
688
|
+
attr_reader status: Symbol
|
|
689
|
+
attr_reader reason: Symbol?
|
|
690
|
+
attr_reader inspection: StorageInspection?
|
|
691
|
+
attr_reader guest_mounts: Hash[String, String]
|
|
692
|
+
def running?: () -> bool
|
|
693
|
+
def protection_registered?: () -> bool
|
|
694
|
+
end
|
|
695
|
+
|
|
696
|
+
class StorageDiagnosis
|
|
697
|
+
def initialize: (Hash[String, untyped] data) -> void
|
|
698
|
+
attr_reader home: String
|
|
699
|
+
attr_reader sandboxes: Array[StorageSandboxDiagnosis]
|
|
700
|
+
attr_reader required_runtime_capability: String
|
|
701
|
+
end
|
|
702
|
+
|
|
703
|
+
class StorageRecovery
|
|
704
|
+
def initialize: (Hash[String, untyped] data) -> void
|
|
705
|
+
attr_reader name: String
|
|
706
|
+
def ready?: () -> bool
|
|
707
|
+
def originals_retained?: () -> bool
|
|
708
|
+
end
|
|
709
|
+
|
|
604
710
|
# Host-side secret source (runtime v0.6.17): only `env` exists.
|
|
605
711
|
class SecretSource
|
|
606
712
|
KINDS: Array[String]
|