kobako 0.29.0 → 0.31.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/.release-please-manifest.json +1 -1
- data/CHANGELOG.md +552 -10
- data/Cargo.lock +595 -139
- data/README.md +126 -564
- data/ROADMAP.md +3 -2
- data/crates/kobako-runtime/CHANGELOG.md +488 -1
- data/crates/kobako-runtime/Cargo.toml +73 -15
- data/crates/kobako-runtime/README.md +11 -4
- data/crates/kobako-runtime/src/cred.rs +124 -0
- data/crates/kobako-runtime/src/dispatch.rs +5 -6
- data/crates/kobako-runtime/src/endpoint/buffer.rs +301 -0
- data/crates/kobako-runtime/src/endpoint/dispatch.rs +292 -0
- data/crates/kobako-runtime/src/endpoint/invoke.rs +181 -0
- data/crates/kobako-runtime/src/endpoint.rs +267 -0
- data/crates/kobako-runtime/src/errno.rs +391 -0
- data/crates/kobako-runtime/src/error.rs +31 -10
- data/crates/kobako-runtime/src/filesystem/anon_inodes.rs +52 -0
- data/crates/kobako-runtime/src/filesystem/bind/fid.rs +82 -0
- data/crates/kobako-runtime/src/filesystem/bind/lookup.rs +274 -0
- data/crates/kobako-runtime/src/filesystem/bind/walk.rs +248 -0
- data/crates/kobako-runtime/src/filesystem/bind.rs +2857 -0
- data/crates/kobako-runtime/src/filesystem/overlay/file.rs +89 -0
- data/crates/kobako-runtime/src/filesystem/overlay/inode.rs +106 -0
- data/crates/kobako-runtime/src/filesystem/overlay/path.rs +263 -0
- data/crates/kobako-runtime/src/filesystem/overlay/stack/copy_up.rs +128 -0
- data/crates/kobako-runtime/src/filesystem/overlay/stack/dir.rs +238 -0
- data/crates/kobako-runtime/src/filesystem/overlay/stack/namei.rs +135 -0
- data/crates/kobako-runtime/src/filesystem/overlay/stack/readdir.rs +54 -0
- data/crates/kobako-runtime/src/filesystem/overlay/stack.rs +316 -739
- data/crates/kobako-runtime/src/filesystem/overlay.rs +2627 -1154
- data/crates/kobako-runtime/src/filesystem/pipe.rs +224 -0
- data/crates/kobako-runtime/src/filesystem/rdir.rs +84 -0
- data/crates/kobako-runtime/src/filesystem/tmpfs/seed.rs +32 -0
- data/crates/kobako-runtime/src/filesystem/tmpfs/tmpfile.rs +32 -0
- data/crates/kobako-runtime/src/filesystem/tmpfs/whiteout.rs +107 -0
- data/crates/kobako-runtime/src/filesystem/tmpfs/xattr.rs +22 -0
- data/crates/kobako-runtime/src/filesystem/tmpfs.rs +1997 -0
- data/crates/kobako-runtime/src/filesystem/wrap.rs +208 -0
- data/crates/kobako-runtime/src/filesystem.rs +25 -388
- data/crates/kobako-runtime/src/fork.rs +96 -0
- data/crates/kobako-runtime/src/grant.rs +3 -0
- data/crates/kobako-runtime/src/hashtable.rs +46 -0
- data/crates/kobako-runtime/src/lib.rs +27 -11
- data/crates/kobako-runtime/src/limits.rs +195 -0
- data/crates/kobako-runtime/src/locking/seqlock.rs +66 -0
- data/crates/kobako-runtime/src/locking.rs +228 -0
- data/crates/kobako-runtime/src/memcg.rs +383 -0
- data/crates/kobako-runtime/src/mount.rs +86 -101
- data/crates/kobako-runtime/src/net/backends.rs +43 -0
- data/crates/kobako-runtime/src/net/connections.rs +179 -0
- data/crates/kobako-runtime/src/net/credential.rs +125 -0
- data/crates/kobako-runtime/src/net/egress.rs +160 -0
- data/crates/kobako-runtime/src/net/family.rs +181 -0
- data/crates/kobako-runtime/src/net/http.rs +2733 -0
- data/crates/kobako-runtime/src/net/lookup.rs +285 -0
- data/crates/kobako-runtime/src/net/mock.rs +251 -0
- data/crates/kobako-runtime/src/net/namespace.rs +1366 -0
- data/crates/kobako-runtime/src/net/reactor.rs +531 -0
- data/crates/kobako-runtime/src/net/resolv/darwin.rs +275 -0
- data/crates/kobako-runtime/src/net/resolv/stub/tests.rs +469 -0
- data/crates/kobako-runtime/src/net/resolv/stub.rs +536 -0
- data/crates/kobako-runtime/src/net/resolv/windows.rs +248 -0
- data/crates/kobako-runtime/src/net/resolv.rs +227 -0
- data/crates/kobako-runtime/src/net/socket.rs +870 -0
- data/crates/kobako-runtime/src/net/tcp.rs +1588 -0
- data/crates/kobako-runtime/src/net/tls.rs +58 -0
- data/crates/kobako-runtime/src/net/transport.rs +279 -0
- data/crates/kobako-runtime/src/net/udp.rs +1003 -0
- data/crates/kobako-runtime/src/net.rs +42 -0
- data/crates/kobako-runtime/src/network/builder.rs +177 -0
- data/crates/kobako-runtime/src/network/ruleset.rs +777 -0
- data/crates/kobako-runtime/src/network.rs +551 -0
- data/crates/kobako-runtime/src/policy.rs +16 -0
- data/crates/kobako-runtime/src/profile.rs +37 -16
- data/crates/kobako-runtime/src/runtime.rs +3 -5
- data/crates/kobako-runtime/src/sched.rs +311 -0
- data/crates/kobako-runtime/src/security/entry_policy.rs +22 -0
- data/crates/kobako-runtime/src/security/hooks.rs +242 -0
- data/crates/kobako-runtime/src/security/mount_policy.rs +158 -0
- data/crates/kobako-runtime/src/security.rs +601 -0
- data/crates/kobako-runtime/src/snapshot.rs +121 -2
- data/crates/kobako-runtime/src/vfs/attr.rs +162 -0
- data/crates/kobako-runtime/src/vfs/dentry.rs +1466 -0
- data/crates/kobako-runtime/src/vfs/file.rs +1911 -0
- data/crates/kobako-runtime/src/vfs/inode.rs +425 -0
- data/crates/kobako-runtime/src/vfs/kern_path.rs +213 -0
- data/crates/kobako-runtime/src/vfs/mount.rs +60 -0
- data/crates/kobako-runtime/src/vfs/namei.rs +5837 -0
- data/crates/kobako-runtime/src/vfs/namespace.rs +162 -0
- data/crates/kobako-runtime/src/vfs/open_files.rs +69 -0
- data/crates/kobako-runtime/src/vfs/openat2.rs +116 -0
- data/crates/kobako-runtime/src/vfs/path.rs +64 -0
- data/crates/kobako-runtime/src/vfs/readdir.rs +163 -0
- data/crates/kobako-runtime/src/vfs/stat.rs +293 -0
- data/crates/kobako-runtime/src/vfs/super_block.rs +126 -0
- data/crates/kobako-runtime/src/vfs/utimes.rs +299 -0
- data/crates/kobako-runtime/src/vfs.rs +63 -0
- data/crates/kobako-runtime/src/wait.rs +356 -0
- data/crates/kobako-transport/CHANGELOG.md +39 -2
- data/crates/kobako-transport/Cargo.toml +3 -3
- data/crates/kobako-transport/README.md +8 -8
- data/crates/kobako-transport/src/abi.rs +78 -72
- data/crates/kobako-transport/src/envelope/bytes.rs +49 -30
- data/crates/kobako-transport/src/envelope/call.rs +37 -9
- data/crates/kobako-transport/src/envelope/compile_reply.rs +2 -2
- data/crates/kobako-transport/src/envelope/error_record.rs +24 -3
- data/crates/kobako-transport/src/envelope/fault.rs +2 -2
- data/crates/kobako-transport/src/envelope/name.rs +99 -0
- data/crates/kobako-transport/src/envelope/outcome.rs +11 -11
- data/crates/kobako-transport/src/envelope/preamble.rs +34 -31
- data/crates/kobako-transport/src/envelope/reply.rs +29 -29
- data/crates/kobako-transport/src/envelope/request.rs +2 -2
- data/crates/kobako-transport/src/envelope/run.rs +1 -1
- data/crates/kobako-transport/src/envelope/unsupported.rs +12 -12
- data/crates/kobako-transport/src/envelope.rs +15 -10
- data/crates/kobako-wasmtime/CHANGELOG.md +315 -8
- data/crates/kobako-wasmtime/Cargo.toml +35 -15
- data/crates/kobako-wasmtime/README.md +11 -6
- data/crates/kobako-wasmtime/build/preview2.rs +1339 -0
- data/crates/kobako-wasmtime/build.rs +16 -0
- data/crates/kobako-wasmtime/src/abi.rs +19 -47
- data/crates/kobako-wasmtime/src/ambient.rs +33 -19
- data/crates/kobako-wasmtime/src/cache.rs +28 -20
- data/crates/kobako-wasmtime/src/config.rs +59 -60
- data/crates/kobako-wasmtime/src/driver.rs +63 -145
- data/crates/kobako-wasmtime/src/exports.rs +147 -32
- data/crates/kobako-wasmtime/src/guest.rs +44 -0
- data/crates/kobako-wasmtime/src/guest_binary.rs +14 -0
- data/crates/kobako-wasmtime/src/imports.rs +48 -18
- data/crates/kobako-wasmtime/src/instance_pre.rs +7 -7
- data/crates/kobako-wasmtime/src/invocation.rs +93 -51
- data/crates/kobako-wasmtime/src/lib.rs +6 -7
- data/crates/kobako-wasmtime/src/limiter.rs +52 -211
- data/crates/kobako-wasmtime/src/preview1/descriptors.rs +309 -0
- data/crates/kobako-wasmtime/src/preview1/differential/mount.rs +70 -57
- data/crates/kobako-wasmtime/src/preview1/differential.rs +137 -27
- data/crates/kobako-wasmtime/src/preview1/errno.rs +90 -233
- data/crates/kobako-wasmtime/src/preview1/fd.rs +1301 -522
- data/crates/kobako-wasmtime/src/preview1/memory.rs +126 -150
- data/crates/kobako-wasmtime/src/preview1/mount_view/wrap.rs +192 -0
- data/crates/kobako-wasmtime/src/preview1/mount_view.rs +1989 -708
- data/crates/kobako-wasmtime/src/preview1/path.rs +181 -365
- data/crates/kobako-wasmtime/src/preview1/poll.rs +345 -173
- data/crates/kobako-wasmtime/src/preview1/sock.rs +10 -25
- data/crates/kobako-wasmtime/src/preview1/testsuite-expected.txt +6 -0
- data/crates/kobako-wasmtime/src/preview1/testsuite.rs +147 -0
- data/crates/kobako-wasmtime/src/preview1.rs +471 -416
- data/crates/kobako-wasmtime/src/preview2/abi.rs +227 -0
- data/crates/kobako-wasmtime/src/preview2/error.rs +118 -0
- data/crates/kobako-wasmtime/src/preview2/filesystem.rs +122 -0
- data/crates/kobako-wasmtime/src/preview2/host.rs +3959 -0
- data/crates/kobako-wasmtime/src/preview2/http.rs +1503 -0
- data/crates/kobako-wasmtime/src/preview2/io.rs +315 -0
- data/crates/kobako-wasmtime/src/preview2/sockets.rs +379 -0
- data/crates/kobako-wasmtime/src/preview2/table.rs +305 -0
- data/crates/kobako-wasmtime/src/preview2.rs +57 -0
- data/crates/kobako-wasmtime/src/trap.rs +31 -16
- data/crates/kobako-wasmtime/src/wasi.rs +238 -93
- data/crates/kobako-wasmtime/wit/deps/cli.wit +233 -0
- data/crates/kobako-wasmtime/wit/deps/clocks.wit +162 -0
- data/crates/kobako-wasmtime/wit/deps/filesystem.wit +589 -0
- data/crates/kobako-wasmtime/wit/deps/http.wit +733 -0
- data/crates/kobako-wasmtime/wit/deps/io.wit +299 -0
- data/crates/kobako-wasmtime/wit/deps/random.wit +92 -0
- data/crates/kobako-wasmtime/wit/deps/sockets.wit +949 -0
- data/crates/kobako-wasmtime/witx/typenames.witx +750 -0
- data/crates/kobako-wasmtime/witx/wasi_snapshot_preview1.witx +441 -0
- data/data/kobako.wasm +0 -0
- data/ext/kobako/Cargo.toml +1 -1
- data/ext/kobako/src/{runtime/errors.rs → errors.rs} +35 -27
- data/ext/kobako/src/escape.rs +98 -0
- data/ext/kobako/src/{runtime/filesystem → filesystem}/grants.rs +36 -16
- data/ext/kobako/src/filesystem/ruby.rs +689 -0
- data/ext/kobako/src/filesystem.rs +217 -0
- data/ext/kobako/src/gvl.rs +306 -0
- data/ext/kobako/src/lib.rs +64 -3
- data/ext/kobako/src/network/mock.rs +187 -0
- data/ext/kobako/src/network.rs +591 -0
- data/ext/kobako/src/runtime/bridge.rs +31 -30
- data/ext/kobako/src/runtime/snapshot.rs +5 -5
- data/ext/kobako/src/runtime.rs +221 -138
- data/ext/kobako/src/wire.rs +42 -0
- data/lib/kobako/catalog/extensions.rb +19 -7
- data/lib/kobako/catalog/flags.rb +4 -6
- data/lib/kobako/catalog/grants.rb +5 -4
- data/lib/kobako/catalog/handles.rb +9 -31
- data/lib/kobako/catalog/mount.rb +12 -12
- data/lib/kobako/catalog/network.rb +35 -0
- data/lib/kobako/catalog/replacements.rb +28 -0
- data/lib/kobako/catalog/services.rb +7 -21
- data/lib/kobako/catalog/snippets.rb +10 -25
- data/lib/kobako/catalog.rb +4 -1
- data/lib/kobako/codec/{utils.rb → boundary.rb} +5 -3
- data/lib/kobako/codec/decoder.rb +12 -12
- data/lib/kobako/codec/ext_types.rb +5 -7
- data/lib/kobako/codec/handle_walk.rb +5 -47
- data/lib/kobako/codec/nesting.rb +7 -7
- data/lib/kobako/codec/value_budget.rb +134 -42
- data/lib/kobako/codec.rb +1 -1
- data/lib/kobako/context.rb +28 -15
- data/lib/kobako/errors.rb +15 -12
- data/lib/kobako/extension.rb +3 -2
- data/lib/kobako/filesystem.rb +53 -15
- data/lib/kobako/handle.rb +2 -2
- data/lib/kobako/names.rb +28 -0
- data/lib/kobako/network.rb +210 -0
- data/lib/kobako/outcome.rb +7 -7
- data/lib/kobako/payload/arguments.rb +2 -2
- data/lib/kobako/pool.rb +47 -25
- data/lib/kobako/runtime.rb +3 -2
- data/lib/kobako/sandbox.rb +113 -56
- data/lib/kobako/sandbox_options.rb +41 -107
- data/lib/kobako/snippet/bytecode.rb +1 -1
- data/lib/kobako/snippet/source.rb +1 -1
- data/lib/kobako/transport/argument_wrap.rb +64 -0
- data/lib/kobako/transport/block_failure.rb +1 -1
- data/lib/kobako/transport/dispatcher.rb +10 -10
- data/lib/kobako/transport/exposure.rb +28 -17
- data/lib/kobako/transport/reflection.rb +28 -11
- data/lib/kobako/transport/run.rb +13 -28
- data/lib/kobako/transport/yielder.rb +3 -10
- data/lib/kobako/transport.rb +1 -0
- data/lib/kobako/version.rb +1 -1
- data/lib/kobako.rb +38 -0
- data/release-please-config.json +16 -0
- data/sig/core/thread.rbs +6 -0
- data/sig/kobako/catalog/extensions.rbs +5 -3
- data/sig/kobako/catalog/grants.rbs +7 -4
- data/sig/kobako/catalog/handles.rbs +2 -4
- data/sig/kobako/catalog/mount.rbs +3 -5
- data/sig/kobako/catalog/network.rbs +20 -0
- data/sig/kobako/catalog/replacements.rbs +14 -0
- data/sig/kobako/catalog/services.rbs +1 -5
- data/sig/kobako/catalog/snippets.rbs +3 -5
- data/sig/kobako/catalog.rbs +1 -1
- data/sig/kobako/codec/boundary.rbs +9 -0
- data/sig/kobako/codec/decoder.rbs +1 -1
- data/sig/kobako/codec/handle_walk.rbs +0 -6
- data/sig/kobako/codec/nesting.rbs +2 -2
- data/sig/kobako/codec/value_budget.rbs +48 -5
- data/sig/kobako/codec.rbs +1 -2
- data/sig/kobako/context.rbs +4 -2
- data/sig/kobako/errors.rbs +4 -4
- data/sig/kobako/filesystem.rbs +38 -15
- data/sig/kobako/guest_yielder.rbs +1 -1
- data/sig/kobako/network.rbs +115 -0
- data/sig/kobako/outcome.rbs +1 -1
- data/sig/kobako/payload/arguments.rbs +1 -1
- data/sig/kobako/pool.rbs +8 -4
- data/sig/kobako/runtime.rbs +32 -3
- data/sig/kobako/sandbox.rbs +22 -7
- data/sig/kobako/sandbox_options.rbs +29 -38
- data/sig/kobako/transport/argument_wrap.rbs +15 -0
- data/sig/kobako/transport/dispatcher.rbs +2 -2
- data/sig/kobako/transport/error.rbs +1 -1
- data/sig/kobako/transport/exposure.rbs +3 -5
- data/sig/kobako/transport/reflection.rbs +12 -2
- data/sig/kobako/transport/run.rbs +3 -5
- data/sig/kobako/transport/yielder.rbs +0 -3
- data/sig/kobako/transport.rbs +2 -2
- data/sig/kobako.rbs +13 -0
- metadata +131 -34
- data/crates/kobako-runtime/src/filesystem/directory/spelling.rs +0 -194
- data/crates/kobako-runtime/src/filesystem/directory.rs +0 -1082
- data/crates/kobako-runtime/src/filesystem/memory.rs +0 -1100
- data/crates/kobako-runtime/src/filesystem/overlay/exclusive.rs +0 -88
- data/crates/kobako-runtime/src/filesystem/path.rs +0 -60
- data/crates/kobako-runtime/src/filesystem/temporary.rs +0 -167
- data/crates/kobako-wasmtime/src/capture.rs +0 -96
- data/crates/kobako-wasmtime/src/descriptors.rs +0 -167
- data/crates/kobako-wasmtime/src/dispatch.rs +0 -125
- data/crates/kobako-wasmtime/src/guest_mem.rs +0 -271
- data/crates/kobako-wasmtime/src/io.rs +0 -89
- data/crates/kobako-wasmtime/src/preview1/args.rs +0 -60
- data/crates/kobako-wasmtime/src/preview1/beneath.rs +0 -188
- data/crates/kobako-wasmtime/tests/compile_posture.rs +0 -43
- data/crates/kobako-wasmtime/tests/guest_file.rs +0 -1054
- data/crates/kobako-wasmtime/tests/preamble_flags.rs +0 -70
- data/crates/kobako-wasmtime/tests/snippet_compile.rs +0 -95
- data/crates/kobako-wasmtime/tests/support/mod.rs +0 -30
- data/crates/kobako-wasmtime/tests/unanswered_call.rs +0 -86
- data/crates/kobako-wasmtime/tests/unsupported_call.rs +0 -51
- data/ext/kobako/src/runtime/escape.rs +0 -53
- data/ext/kobako/src/runtime/filesystem/ruby.rs +0 -400
- data/ext/kobako/src/runtime/filesystem.rs +0 -236
- data/ext/kobako/src/runtime/gvl.rs +0 -112
- data/lib/kobako/constant_name.rb +0 -8
- data/sig/kobako/codec/utils.rbs +0 -9
- data/sig/kobako/constant_name.rbs +0 -3
- /data/ext/kobako/src/{runtime/pinned_value.rs → pinned_value.rs} +0 -0
data/lib/kobako/sandbox.rb
CHANGED
|
@@ -25,25 +25,26 @@ module Kobako
|
|
|
25
25
|
attr_reader :options
|
|
26
26
|
|
|
27
27
|
def_delegators :@options, :timeout, :setup_timeout, :memory_limit, :stdout_limit, :stderr_limit,
|
|
28
|
-
:open_file_limit, :profile, :gvl
|
|
28
|
+
:open_file_limit, :open_connection_limit, :connection_limit, :profile, :gvl
|
|
29
29
|
|
|
30
30
|
# Build a Sandbox on the Guest Binary at +wasm_path+, the one bundled
|
|
31
31
|
# with the gem by default. The other keywords are the options
|
|
32
32
|
# SandboxOptions describes.
|
|
33
33
|
#
|
|
34
|
-
# Raises
|
|
35
|
-
#
|
|
36
|
-
#
|
|
34
|
+
# Raises TypeError for an option of another class, RangeError for a cap
|
|
35
|
+
# past what the host counts, ArgumentError for any other invalid option,
|
|
36
|
+
# and SetupError when the runtime cannot be built or provides less
|
|
37
|
+
# isolation than +profile+ asks for.
|
|
37
38
|
def initialize(wasm_path: nil, **)
|
|
38
39
|
@wasm_path = wasm_path || Kobako::Runtime.default_path
|
|
39
|
-
@options = SandboxOptions.new(**)
|
|
40
|
+
@options = SandboxOptions.new(**Kobako::Runtime.default_options, **)
|
|
40
41
|
@services = Kobako::Catalog::Services.new
|
|
41
42
|
@snippets = Catalog::Snippets.new
|
|
42
43
|
@flags = Catalog::Flags.new
|
|
43
44
|
@extensions = Catalog::Extensions.new
|
|
44
45
|
@grants = Catalog::Grants.new
|
|
45
46
|
@sealed = false
|
|
46
|
-
@runtime = build_runtime
|
|
47
|
+
@runtime = build_runtime
|
|
47
48
|
end
|
|
48
49
|
|
|
49
50
|
# Make +object+ reachable from the guest as the constant at +path+, a
|
|
@@ -58,11 +59,12 @@ module Kobako
|
|
|
58
59
|
# the constant, and Context#bind supplies the object for each invocation.
|
|
59
60
|
# A call to one left unfilled fails as a ServiceError.
|
|
60
61
|
#
|
|
61
|
-
# Raises
|
|
62
|
-
#
|
|
63
|
-
#
|
|
62
|
+
# Raises TypeError for a path that is no Symbol or String, ArgumentError
|
|
63
|
+
# for a malformed path, a path under the reserved
|
|
64
|
+
# +Kobako+ namespace, or a path that collides with an existing binding,
|
|
65
|
+
# and FrozenError for a call after the first invocation.
|
|
64
66
|
def bind(path, object = Unresolved)
|
|
65
|
-
refuse_once_invoked
|
|
67
|
+
refuse_once_invoked("bind")
|
|
66
68
|
@services.bind(path, object)
|
|
67
69
|
self
|
|
68
70
|
end
|
|
@@ -71,10 +73,11 @@ module Kobako
|
|
|
71
73
|
# backend. Any object answering +name+, +source+, +backend+ and
|
|
72
74
|
# +depends_on+ works; Extension is the bundled one. Returns +self+.
|
|
73
75
|
#
|
|
74
|
-
# Raises
|
|
75
|
-
# invocation,
|
|
76
|
+
# Raises TypeError for an Extension of another shape, FrozenError for a
|
|
77
|
+
# call after the first invocation, and, at the first invocation,
|
|
78
|
+
# ArgumentError for a missing dependency.
|
|
76
79
|
def install(*extensions)
|
|
77
|
-
refuse_once_invoked
|
|
80
|
+
refuse_once_invoked("install")
|
|
78
81
|
|
|
79
82
|
extensions.each { |extension| @extensions.install(extension, snippets: @snippets, services: @services) }
|
|
80
83
|
self
|
|
@@ -85,22 +88,46 @@ module Kobako
|
|
|
85
88
|
# +:read_write+; a write beneath a read-only mount fails as
|
|
86
89
|
# <tt>Errno::EROFS</tt> in the guest. Returns +self+.
|
|
87
90
|
#
|
|
88
|
-
# A given block
|
|
89
|
-
#
|
|
90
|
-
#
|
|
91
|
+
# A given block judges each open and each change +access+ allows, asked
|
|
92
|
+
# with the guest path and +:read+ or +:read_write+, and can only refuse
|
|
93
|
+
# more; an open that may create asks +:read_write+ first, then what it
|
|
94
|
+
# opens for. A falsy answer,
|
|
91
95
|
# or a StandardError, fails that call as <tt>Errno::EACCES</tt> in the
|
|
92
96
|
# guest and leaves the script running.
|
|
93
97
|
#
|
|
98
|
+
# A path may sit beneath another mount, standing where Linux's +mount+
|
|
99
|
+
# would place it, and a run fails where Linux would refuse it.
|
|
100
|
+
#
|
|
94
101
|
# Raises TypeError for a path that is no String or something other than
|
|
95
|
-
# a Filesystem,
|
|
96
|
-
#
|
|
102
|
+
# a Filesystem, ArgumentError for a malformed or duplicate path or an
|
|
103
|
+
# unknown access, and FrozenError for a call after the first invocation.
|
|
97
104
|
def mount(at, filesystem, access: :read, &policy)
|
|
98
|
-
refuse_once_invoked
|
|
99
|
-
Runtime.validate_mount!(at, access, filesystem)
|
|
105
|
+
refuse_once_invoked("mount")
|
|
100
106
|
@grants.register(Catalog::Mount.new(at: at, access: access, filesystem: filesystem, policy: policy))
|
|
101
107
|
self
|
|
102
108
|
end
|
|
103
109
|
|
|
110
|
+
# Give the guest the network entry +entry+ under +name+, any object
|
|
111
|
+
# answering any of +endpoints+, +credentials+, +resolve?+, +connect?+, and
|
|
112
|
+
# +request?+. A given block yields a Kobako::Network::Builder adding to
|
|
113
|
+
# +entry+, so the block's +self+ stays the caller's. Each entry's endpoints
|
|
114
|
+
# and credentials are read afresh for every invocation. Its +resolve?+ is
|
|
115
|
+
# handed each name the guest looks up, its +connect?+ each
|
|
116
|
+
# Kobako::Network::Connection, and its +request?+ each
|
|
117
|
+
# Kobako::Network::Request; any entry refusing refuses. Returns +self+.
|
|
118
|
+
#
|
|
119
|
+
# Raises TypeError for a name that is no Symbol or String, ArgumentError
|
|
120
|
+
# for an empty or duplicate name, an endpoint with an
|
|
121
|
+
# empty host, a port outside 1 to 65535, or an unknown protocol, and
|
|
122
|
+
# FrozenError for a call after the first invocation. An
|
|
123
|
+
# endpoint the ruleset refuses, such as a wildcard leading to +:private+,
|
|
124
|
+
# raises ArgumentError from the invocation that compiles it.
|
|
125
|
+
def network(name, entry = nil, &builder)
|
|
126
|
+
refuse_once_invoked("network")
|
|
127
|
+
@grants.register(Catalog::Network.new(name: name, entry: entry, &builder))
|
|
128
|
+
self
|
|
129
|
+
end
|
|
130
|
+
|
|
104
131
|
# Register a snippet that every invocation runs, in the order registered,
|
|
105
132
|
# before its own code. Returns +self+.
|
|
106
133
|
#
|
|
@@ -110,11 +137,12 @@ module Kobako
|
|
|
110
137
|
# Precompiled RITE bytecode, trusted as host code: the unmodified
|
|
111
138
|
# compiler output of the mruby release the Guest Binary is built on.
|
|
112
139
|
#
|
|
113
|
-
# Raises
|
|
114
|
-
#
|
|
140
|
+
# Raises TypeError for a snippet part of another class, ArgumentError for
|
|
141
|
+
# a malformed or duplicate snippet, and FrozenError for a call after the
|
|
142
|
+
# first invocation. A snippet that fails to load fails every
|
|
115
143
|
# invocation with SandboxError, or BytecodeError for bytecode.
|
|
116
144
|
def preload(code: nil, name: nil, binary: nil)
|
|
117
|
-
refuse_once_invoked
|
|
145
|
+
refuse_once_invoked("preload")
|
|
118
146
|
|
|
119
147
|
@snippets.register(code: code, name: name, binary: binary)
|
|
120
148
|
self
|
|
@@ -127,10 +155,10 @@ module Kobako
|
|
|
127
155
|
# Mark a flag advisory only when a script cannot tell it was skipped.
|
|
128
156
|
# Returns +self+.
|
|
129
157
|
#
|
|
130
|
-
# Raises
|
|
131
|
-
# the first invocation.
|
|
158
|
+
# Raises TypeError for a name or value of another class, ArgumentError for
|
|
159
|
+
# a duplicate flag, and FrozenError for a call after the first invocation.
|
|
132
160
|
def flag(name, value = "", advisory: false)
|
|
133
|
-
refuse_once_invoked
|
|
161
|
+
refuse_once_invoked("flag")
|
|
134
162
|
|
|
135
163
|
@flags.register(name, value, advisory: advisory)
|
|
136
164
|
self
|
|
@@ -140,45 +168,39 @@ module Kobako
|
|
|
140
168
|
# and +kwargs+, and return the Execution. A given block receives the
|
|
141
169
|
# invocation's Context before the guest runs.
|
|
142
170
|
#
|
|
143
|
-
# Raises TypeError when +target+ is not a Symbol or String,
|
|
144
|
-
#
|
|
145
|
-
#
|
|
171
|
+
# Raises TypeError when +target+ is not a Symbol or String, a keyword is
|
|
172
|
+
# not a Symbol, or an argument holds a Hash key or a reflective object
|
|
173
|
+
# that cannot cross, and ArgumentError when +target+ is not a constant
|
|
174
|
+
# name, the arguments carry a Handle, or an argument nests past what the
|
|
175
|
+
# wire carries. A failed run raises as #eval does.
|
|
146
176
|
def run(target, *args, **kwargs, &block)
|
|
147
177
|
request = Transport::Run.new(entrypoint: target, args: args, kwargs: kwargs)
|
|
148
|
-
Codec.within_value_budget(@options.value_budget) {
|
|
178
|
+
Codec.within_value_budget(@options.value_budget) { begin_invocation.run(request, &block) }
|
|
149
179
|
end
|
|
150
180
|
|
|
151
181
|
# Evaluate +code+, mruby source as a String, and return the Execution,
|
|
152
182
|
# whose +value+ is the last expression. A given block receives the
|
|
153
183
|
# invocation's Context before the guest runs.
|
|
154
184
|
#
|
|
155
|
-
# Raises
|
|
156
|
-
#
|
|
157
|
-
#
|
|
158
|
-
#
|
|
185
|
+
# Raises TypeError when +code+ is no String, and ArgumentError when it is
|
|
186
|
+
# not UTF-8 text, before the guest runs; TrapError when the engine
|
|
187
|
+
# stopped the guest, a deadline or memory budget included; SandboxError
|
|
188
|
+
# when the guest failed, the Guest Binary not starting the run included;
|
|
189
|
+
# and ServiceError when a Service call failed and the guest left it
|
|
159
190
|
# unrescued.
|
|
160
191
|
def eval(code, &block)
|
|
161
|
-
raise
|
|
192
|
+
raise TypeError, "code must be a String, got #{code.class}" unless code.is_a?(String)
|
|
162
193
|
|
|
163
|
-
|
|
194
|
+
source = code.dup.force_encoding(Encoding::UTF_8)
|
|
195
|
+
raise ArgumentError, "code must be UTF-8 text" unless source.valid_encoding?
|
|
196
|
+
|
|
197
|
+
Codec.within_value_budget(@options.value_budget) { begin_invocation.eval(source, &block) }
|
|
164
198
|
end
|
|
165
199
|
|
|
166
200
|
private
|
|
167
201
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
def build_runtime!
|
|
171
|
-
runtime = Kobako::Runtime.from_path(@wasm_path, **@options.to_h)
|
|
172
|
-
@options.enforce_floor!(runtime.profile)
|
|
173
|
-
runtime
|
|
174
|
-
end
|
|
175
|
-
|
|
176
|
-
# Per-invocation state lives on the Context, so nothing an invocation
|
|
177
|
-
# does is written back onto the shared config.
|
|
178
|
-
def new_invocation
|
|
179
|
-
begin_invocation!
|
|
180
|
-
Context.new(runtime: @runtime, services: @services, extensions: @extensions, grants: @grants,
|
|
181
|
-
preamble: preamble(@snippets.entries))
|
|
202
|
+
def build_runtime
|
|
203
|
+
Kobako::Runtime.from_path(@wasm_path, **@options.to_h)
|
|
182
204
|
end
|
|
183
205
|
|
|
184
206
|
# The one place the Preamble's parts are put together, for a compile
|
|
@@ -189,17 +211,52 @@ module Kobako
|
|
|
189
211
|
|
|
190
212
|
# Registration closes at the first invocation, so every invocation ships
|
|
191
213
|
# the same Services, snippets, flags, Extensions and mounts.
|
|
192
|
-
def refuse_once_invoked
|
|
193
|
-
raise
|
|
214
|
+
def refuse_once_invoked(verb)
|
|
215
|
+
raise FrozenError, "cannot #{verb} #{@sealed}" if @sealed
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
# Close registration, saying why for the refusal that follows.
|
|
219
|
+
def seal(reason)
|
|
220
|
+
@sealed = reason
|
|
194
221
|
end
|
|
195
222
|
|
|
196
223
|
# Sealing before the dependency check keeps a Sandbox whose check failed
|
|
197
224
|
# closed to further registration. The sealed snippets are compiled once,
|
|
198
|
-
# before the first invocation replays them.
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
225
|
+
# before the first invocation replays them. Per-invocation state lives on
|
|
226
|
+
# the Context it answers, so nothing an invocation does is written back
|
|
227
|
+
# onto the shared config.
|
|
228
|
+
def begin_invocation
|
|
229
|
+
warn_release_on_main_thread
|
|
230
|
+
seal("after first Sandbox invocation")
|
|
231
|
+
@extensions.assert_dependencies
|
|
202
232
|
@snippets.compile { |entries| @runtime.compile(preamble(entries)) }
|
|
233
|
+
Context.new(runtime: @runtime, services: @services, extensions: @extensions, grants: @grants,
|
|
234
|
+
preamble: preamble(@snippets.entries))
|
|
235
|
+
end
|
|
236
|
+
|
|
237
|
+
# Ruby runs a signal's trap handler, and a Ractor's +require+, on the main
|
|
238
|
+
# Thread alone, and either raising as a run releasing the GVL takes it back
|
|
239
|
+
# after a Service call leaves the run where it cannot unwind. The first such
|
|
240
|
+
# run warns once.
|
|
241
|
+
def warn_release_on_main_thread
|
|
242
|
+
MainThreadRelease.warn_once if @options.gvl == :release && Thread.current == Thread.main
|
|
243
|
+
end
|
|
244
|
+
|
|
245
|
+
# The process's one warning that a run releasing the GVL ran on the main
|
|
246
|
+
# Thread.
|
|
247
|
+
module MainThreadRelease
|
|
248
|
+
MESSAGE = "Kobako::Sandbox with gvl: :release runs on the main Thread, where a trap handler " \
|
|
249
|
+
"that raises or exits, or another Ractor's require, can stop the run where it cannot " \
|
|
250
|
+
"unwind; run it on another Thread, or keep trap handlers to setting a flag"
|
|
251
|
+
@warned = false
|
|
252
|
+
|
|
253
|
+
def self.warn_once
|
|
254
|
+
return if @warned
|
|
255
|
+
|
|
256
|
+
@warned = true
|
|
257
|
+
warn(MESSAGE)
|
|
258
|
+
end
|
|
203
259
|
end
|
|
260
|
+
private_constant :MainThreadRelease
|
|
204
261
|
end
|
|
205
262
|
end
|
|
@@ -4,123 +4,57 @@ require_relative "errors"
|
|
|
4
4
|
|
|
5
5
|
module Kobako
|
|
6
6
|
# The options a Sandbox was built with, read through Sandbox#options or
|
|
7
|
-
# directly on the Sandbox, as in Sandbox#timeout.
|
|
8
|
-
# default, and +nil+ switches
|
|
7
|
+
# directly on the Sandbox, as in Sandbox#timeout. An option Sandbox.new
|
|
8
|
+
# leaves out takes the runtime's default, given below, and +nil+ switches a
|
|
9
|
+
# cap off.
|
|
9
10
|
#
|
|
10
|
-
# [+timeout+] Float seconds one invocation may run.
|
|
11
|
+
# [+timeout+] Float seconds one invocation may run; 60.
|
|
11
12
|
# [+setup_timeout+] Float seconds the Guest Binary may take to be set up
|
|
12
|
-
# the first time its path is loaded.
|
|
13
|
-
# [+memory_limit+] Integer bytes one invocation may grow guest memory by
|
|
13
|
+
# the first time its path is loaded; 10.
|
|
14
|
+
# [+memory_limit+] Integer bytes one invocation may grow guest memory by;
|
|
15
|
+
# 4 MiB.
|
|
14
16
|
# [+stdout_limit+, +stderr_limit+]
|
|
15
|
-
# Integer bytes kept from each output channel.
|
|
17
|
+
# Integer bytes kept from each output channel; 1 MiB.
|
|
16
18
|
# [+open_file_limit+]
|
|
17
19
|
# Integer descriptors one invocation may hold open, the
|
|
18
|
-
# standard ones and each
|
|
19
|
-
# [+
|
|
20
|
-
#
|
|
20
|
+
# standard ones and each outermost mount's included; 1024.
|
|
21
|
+
# [+open_connection_limit+]
|
|
22
|
+
# Integer connections one invocation holds open at once, each
|
|
23
|
+
# socket once it dials, HTTP request, and name lookup in
|
|
24
|
+
# flight one; 6.
|
|
25
|
+
# [+connection_limit+]
|
|
26
|
+
# Integer connections one invocation makes in all, each
|
|
27
|
+
# socket's dial and HTTP request one; 50.
|
|
28
|
+
# [+profile+] The isolation the runtime must provide at least:
|
|
29
|
+
# +:hermetic+, which denies the guest the clock and
|
|
30
|
+
# entropy, or the weaker +:permissive+, which leaves them
|
|
31
|
+
# live; +:hermetic+.
|
|
32
|
+
# [+gvl+] How an invocation holds Ruby's GVL: +:hold+ through
|
|
33
|
+
# the invocation, or +:release+ while the guest runs, so
|
|
34
|
+
# Sandboxes on different Threads run in parallel; +:hold+.
|
|
35
|
+
# [+network+] What the guest's network dials and looks names up
|
|
36
|
+
# through, beneath every rule its entries make: +nil+
|
|
37
|
+
# for the host's own, or a Kobako::Network::Mock a test
|
|
38
|
+
# writes; +nil+.
|
|
21
39
|
#
|
|
22
|
-
# Raises
|
|
23
|
-
#
|
|
40
|
+
# Raises TypeError for a cap of another class, RangeError for one past
|
|
41
|
+
# what the host counts, and ArgumentError for another value outside these
|
|
42
|
+
# shapes. The runtime judges every cap, and +profile+, +gvl+, and
|
|
43
|
+
# +network+ as Sandbox.new builds it.
|
|
24
44
|
class SandboxOptions < Data.define(:timeout, :setup_timeout, :memory_limit, :stdout_limit, :stderr_limit,
|
|
25
|
-
:open_file_limit, :profile, :gvl
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
DEFAULT_MEMORY_LIMIT = 4 << 20
|
|
35
|
-
|
|
36
|
-
# The default +stdout_limit+ and +stderr_limit+: 1 MiB each.
|
|
37
|
-
DEFAULT_OUTPUT_LIMIT = 1 << 20
|
|
38
|
-
|
|
39
|
-
# The default +open_file_limit+: 1024, the soft limit Linux gives a
|
|
40
|
-
# process.
|
|
41
|
-
DEFAULT_OPEN_FILE_LIMIT = 1024
|
|
42
|
-
|
|
43
|
-
# The isolation profiles, weakest first. +:hermetic+ denies the guest the
|
|
44
|
-
# clock and entropy; +:permissive+ leaves them live.
|
|
45
|
-
PROFILES = %i[permissive hermetic].freeze
|
|
46
|
-
|
|
47
|
-
# The default +profile+, the strictest.
|
|
48
|
-
DEFAULT_PROFILE = :hermetic
|
|
49
|
-
|
|
50
|
-
# +:hold+ keeps the GVL through the invocation; +:release+ drops it while
|
|
51
|
-
# the guest runs, so Sandboxes on different Threads run in parallel.
|
|
52
|
-
GVL_MODES = %i[hold release].freeze
|
|
53
|
-
|
|
54
|
-
# The default +gvl+, +:hold+.
|
|
55
|
-
DEFAULT_GVL = :hold
|
|
56
|
-
|
|
57
|
-
def initialize(timeout: DEFAULT_TIMEOUT_SECONDS,
|
|
58
|
-
setup_timeout: DEFAULT_SETUP_TIMEOUT_SECONDS,
|
|
59
|
-
memory_limit: DEFAULT_MEMORY_LIMIT,
|
|
60
|
-
stdout_limit: DEFAULT_OUTPUT_LIMIT,
|
|
61
|
-
stderr_limit: DEFAULT_OUTPUT_LIMIT,
|
|
62
|
-
open_file_limit: DEFAULT_OPEN_FILE_LIMIT,
|
|
63
|
-
profile: DEFAULT_PROFILE,
|
|
64
|
-
gvl: DEFAULT_GVL)
|
|
65
|
-
timeout = normalize_timeout(timeout, "timeout")
|
|
66
|
-
setup_timeout = normalize_timeout(setup_timeout, "setup_timeout")
|
|
67
|
-
memory_limit = normalize_limit(memory_limit, "memory_limit")
|
|
68
|
-
stdout_limit = normalize_limit(stdout_limit, "stdout_limit")
|
|
69
|
-
stderr_limit = normalize_limit(stderr_limit, "stderr_limit")
|
|
70
|
-
open_file_limit = normalize_limit(open_file_limit, "open_file_limit")
|
|
71
|
-
profile = normalize_choice(profile, PROFILES, "profile")
|
|
72
|
-
gvl = normalize_choice(gvl, GVL_MODES, "gvl")
|
|
73
|
-
super
|
|
45
|
+
:open_file_limit, :open_connection_limit, :connection_limit, :profile, :gvl,
|
|
46
|
+
:network)
|
|
47
|
+
# Every option is required; Sandbox.new fills each one left out from
|
|
48
|
+
# the runtime's defaults.
|
|
49
|
+
def initialize(timeout:, setup_timeout:, memory_limit:, stdout_limit:, stderr_limit:, open_file_limit:,
|
|
50
|
+
open_connection_limit:, connection_limit:, profile:, gvl:, network:)
|
|
51
|
+
caps = Kobako::Runtime.normalize_caps({ timeout:, setup_timeout:, memory_limit:, stdout_limit:, stderr_limit:,
|
|
52
|
+
open_file_limit:, open_connection_limit:, connection_limit: })
|
|
53
|
+
super(**caps.merge(profile:, gvl:, network:))
|
|
74
54
|
end
|
|
75
55
|
|
|
76
|
-
# The least guest memory one value occupies, so a guest payload may hold
|
|
77
|
-
# one value for each of these bytes of +memory_limit+
|
|
78
|
-
# (docs/wire/payload-msgpack.md § Value Budget).
|
|
79
|
-
VALUE_BYTES = 16
|
|
80
|
-
private_constant :VALUE_BYTES
|
|
81
|
-
|
|
82
56
|
def value_budget # :nodoc:
|
|
83
|
-
memory_limit
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
# Both fallbacks fail closed: an unknown declaration ranks below every
|
|
87
|
-
# request, and an unknown request refuses every declaration.
|
|
88
|
-
def enforce_floor!(declared) # :nodoc:
|
|
89
|
-
return if (PROFILES.index(declared) || -1) >= (PROFILES.index(profile) || PROFILES.size)
|
|
90
|
-
|
|
91
|
-
raise Kobako::SetupError, "runtime declares isolation profile #{declared.inspect}, " \
|
|
92
|
-
"below the requested floor #{profile.inspect}"
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
private
|
|
96
|
-
|
|
97
|
-
# A zero or negative timeout would either fire instantly or never, both
|
|
98
|
-
# more surprising than an early ArgumentError.
|
|
99
|
-
def normalize_timeout(timeout, name)
|
|
100
|
-
return nil if timeout.nil?
|
|
101
|
-
raise ArgumentError, "#{name} must be Numeric or nil, got #{timeout.class}" unless timeout.is_a?(Numeric)
|
|
102
|
-
|
|
103
|
-
seconds = timeout.to_f
|
|
104
|
-
raise ArgumentError, "#{name} must be > 0 (got #{timeout})" unless seconds.positive? && seconds.finite?
|
|
105
|
-
|
|
106
|
-
seconds
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
def normalize_limit(limit, name)
|
|
110
|
-
return nil if limit.nil?
|
|
111
|
-
unless limit.is_a?(Integer) && limit.positive?
|
|
112
|
-
raise ArgumentError, "#{name} must be a positive Integer or nil, got #{limit.inspect}"
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
limit
|
|
116
|
-
end
|
|
117
|
-
|
|
118
|
-
# Unlike the caps there is no +nil+ form: every choice, the weakest
|
|
119
|
-
# included, is requested by name, as in +:permissive+.
|
|
120
|
-
def normalize_choice(value, choices, name)
|
|
121
|
-
return value if choices.include?(value)
|
|
122
|
-
|
|
123
|
-
raise ArgumentError, "#{name} must be one of #{choices.map(&:inspect).join(", ")}, got #{value.inspect}"
|
|
57
|
+
Kobako::Runtime.value_budget_of(memory_limit)
|
|
124
58
|
end
|
|
125
59
|
end
|
|
126
60
|
end
|
|
@@ -4,7 +4,7 @@ module Kobako
|
|
|
4
4
|
module Snippet
|
|
5
5
|
class Bytecode < Data.define(:body) # :nodoc:
|
|
6
6
|
# Names the snippet form the guest replays this entry as. The wire's
|
|
7
|
-
# discriminant byte is assigned by the
|
|
7
|
+
# discriminant byte is assigned by the Envelope, not here.
|
|
8
8
|
KIND = :bytecode
|
|
9
9
|
end
|
|
10
10
|
end
|
|
@@ -4,7 +4,7 @@ module Kobako
|
|
|
4
4
|
module Snippet
|
|
5
5
|
class Source < Data.define(:name, :body) # :nodoc:
|
|
6
6
|
# Names the snippet form the guest replays this entry as. The wire's
|
|
7
|
-
# discriminant byte is assigned by the
|
|
7
|
+
# discriminant byte is assigned by the Envelope, not here.
|
|
8
8
|
KIND = :source
|
|
9
9
|
end
|
|
10
10
|
end
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "../codec"
|
|
4
|
+
require_relative "exposure"
|
|
5
|
+
|
|
6
|
+
module Kobako
|
|
7
|
+
module Transport
|
|
8
|
+
# The walk a #run argument takes on its way to the guest: a leaf with no
|
|
9
|
+
# wire form becomes a Capability Handle in the invocation's table, and
|
|
10
|
+
# the rest crosses as it stands. An argument the walk refuses is the
|
|
11
|
+
# Host App's mistake, raised as +Marshal.dump+ raises it: +TypeError+
|
|
12
|
+
# for what has no form to cross as, +ArgumentError+ past the depth.
|
|
13
|
+
module ArgumentWrap # :nodoc:
|
|
14
|
+
# Only Hash values are wrapped: a non-representable key raises rather
|
|
15
|
+
# than crossing as a token the guest→host restore walk could not
|
|
16
|
+
# round-trip.
|
|
17
|
+
def self.wrap(value, handles, depth = 0)
|
|
18
|
+
refuse_past_nesting(depth)
|
|
19
|
+
case value
|
|
20
|
+
when ::Array then value.map { |element| wrap(element, handles, depth + 1) }
|
|
21
|
+
when ::Hash then wrap_hash(value, handles, depth)
|
|
22
|
+
else
|
|
23
|
+
Codec::HandleWalk.representable?(value) ? value : wrap_leaf(value, handles)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
class << self
|
|
28
|
+
private
|
|
29
|
+
|
|
30
|
+
# A reference cycle necessarily trips the nesting bound, so an
|
|
31
|
+
# argument fails as a clean +ArgumentError+ rather than an unbounded
|
|
32
|
+
# host recursion.
|
|
33
|
+
def refuse_past_nesting(depth)
|
|
34
|
+
return unless depth > Codec::MAX_NESTING_DEPTH
|
|
35
|
+
|
|
36
|
+
raise ArgumentError,
|
|
37
|
+
"a #run argument nests deeper than #{Codec::MAX_NESTING_DEPTH} levels within the Run payload " \
|
|
38
|
+
"and cannot cross the sandbox boundary (possible reference cycle)"
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def wrap_leaf(value, handles)
|
|
42
|
+
refused = Exposure.refused_class_of(value)
|
|
43
|
+
raise TypeError, "a #{refused} cannot cross as a Capability Handle" if refused
|
|
44
|
+
|
|
45
|
+
handles.alloc(value)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# A stateful object may cross the boundary as a Hash value but not as
|
|
49
|
+
# a key — the one deliberate asymmetry with the guest→host restore
|
|
50
|
+
# walk, which resolves Handle keys the guest built.
|
|
51
|
+
def wrap_hash(hash, handles, depth)
|
|
52
|
+
hash.to_h do |key, val|
|
|
53
|
+
unless Codec::HandleWalk.representable?(key, depth + 1)
|
|
54
|
+
raise TypeError,
|
|
55
|
+
"a Hash passed to #run has a key that cannot cross the sandbox boundary " \
|
|
56
|
+
"(#{key.class}); only wire-representable values may be Hash keys"
|
|
57
|
+
end
|
|
58
|
+
[key, wrap(val, handles, depth + 1)]
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
@@ -60,17 +60,18 @@ module Kobako
|
|
|
60
60
|
# stays uncaught and traps the invocation rather than being masked as a
|
|
61
61
|
# rescuable fault.
|
|
62
62
|
rescue StandardError => e
|
|
63
|
-
[:fault, *
|
|
64
|
-
ensure
|
|
65
|
-
yielder&.invalidate
|
|
63
|
+
[:fault, *fault_of(e, failure)] # : [Symbol, String, String?]
|
|
66
64
|
end
|
|
67
65
|
|
|
68
66
|
class << self
|
|
69
67
|
private
|
|
70
68
|
|
|
69
|
+
# Routing reads only the target and the method, so a dispatch that
|
|
70
|
+
# cannot route answers before its arguments are read.
|
|
71
71
|
def run(call, resolver, handles, yielder)
|
|
72
|
-
arguments, carried_handle = decode_arguments(call.payload)
|
|
73
72
|
exposure = resolve_target(call.target, resolver, handles)
|
|
73
|
+
reject_unreachable(exposure, call.method_name.to_sym)
|
|
74
|
+
arguments, carried_handle = decode_arguments(call.payload)
|
|
74
75
|
args, kwargs = resolve_call_args(arguments, handles, carried_handle)
|
|
75
76
|
invoke(exposure, call.method_name, args, kwargs, yielder)
|
|
76
77
|
end
|
|
@@ -97,7 +98,7 @@ module Kobako
|
|
|
97
98
|
# The guest's own block failing is not the Service's to report at
|
|
98
99
|
# all, so the Yielder that raised it is asked first — it recognises
|
|
99
100
|
# its own by identity and words the failure the guest's way.
|
|
100
|
-
def
|
|
101
|
+
def fault_of(error, failure)
|
|
101
102
|
block_failure = failure.fault_text(error)
|
|
102
103
|
return fault("block", block_failure) if block_failure
|
|
103
104
|
|
|
@@ -111,20 +112,19 @@ module Kobako
|
|
|
111
112
|
# unsplatted for methods that take no keywords.
|
|
112
113
|
def invoke(exposure, method, args, kwargs, yielder)
|
|
113
114
|
name = method.to_sym
|
|
114
|
-
reject_unreachable!(exposure, name)
|
|
115
115
|
target = exposure.object
|
|
116
116
|
block = yielder&.to_proc
|
|
117
117
|
if kwargs.empty?
|
|
118
|
-
target.
|
|
118
|
+
Reflection::PUBLIC_SEND.bind(target).call(name, *args, &block)
|
|
119
119
|
else
|
|
120
|
-
target.
|
|
120
|
+
Reflection::PUBLIC_SEND.bind(target).call(name, *args, **kwargs, &block)
|
|
121
121
|
end
|
|
122
122
|
end
|
|
123
123
|
|
|
124
124
|
# Both the ambient-surface floor and the reference's Exposure answer
|
|
125
125
|
# through Reflection, so a rejected name discloses nothing about
|
|
126
126
|
# which of the two refused.
|
|
127
|
-
def reject_unreachable
|
|
127
|
+
def reject_unreachable(exposure, name)
|
|
128
128
|
reason = Reflection.refusal(exposure, name)
|
|
129
129
|
raise UndefinedTargetError, reason if reason
|
|
130
130
|
end
|
|
@@ -163,7 +163,7 @@ module Kobako
|
|
|
163
163
|
# Service can change — so it is named here, where the direction is
|
|
164
164
|
# known, instead of falling to the boundary's codec floor.
|
|
165
165
|
def encode_ok(value, handles)
|
|
166
|
-
Kobako::Codec::Nesting.assert_within_bound
|
|
166
|
+
Kobako::Codec::Nesting.assert_within_bound(value)
|
|
167
167
|
Kobako::Codec::Encoder.encode(value)
|
|
168
168
|
rescue Kobako::Codec::UnsupportedTypeError
|
|
169
169
|
encode_ok(handles.alloc(value), handles)
|