-
Notifications
You must be signed in to change notification settings - Fork 824
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Register binfmt #2499
Register binfmt #2499
Conversation
Replying inline:
Is there any way we can reuse the installed wasmer binary without copying?
I think giving access to
Wat is fully a a text-format so it will hard to recognize it properly (if we take on account comments and so, the first bytes might vary). |
Even when doing some very terrible things to command line parsing, I don't think so. With binfmt_misc, it doesn't seem like you get any extra environment variables, and you can only get the command line to be either of
But I don't see any way of distinguishing that from a normal wasmer invocation, where you might do Without changing the behavior of invoking wasmer/cli normally, I can only think of
It would be recognized by the |
I think it should be possible to create a new subcommand:
Cool, let's roll with that for now then! (running executable |
I don't see how you would get binfmt_misc to pass you this (The format of registering with binfmt_misc is
Yes. This is what I meant by:
But then you can't register wasmer on the "host" and run it in a docker container, or vice versa. Personally, I kind of want that feature. For example, try this:
(backing Dockerfile, in case you'd rather build from source.) I'm curious, is there anything that really speaks against the copying (other than probably being unexplored solution space)? |
My main concern is that things will get outdated when you run Here's my proposal: |
That is a problem, indeed. The qemu interpreters I've used so far all handled this by being installed through the distro and having their registrations re-done on install/update. I could of course get the self-update command to be aware of binfmts, but there is a caveat about feature interaction and complexity. Hm. (Note to self: Remove |
Hm, if the "copy self to /tmp" thing is through, then this entire PR is unnecessary. All you need is two files
#!/usr/bin/env sh
set -eu
wasmer="$(dirname "$0")/wasmer"
if ! test -x "$wasmer"; then
if ! wasmer="$(which wasmer 2>/dev/null)"; then
echo Could not locate wasmer binary 1>&2
exit 137
fi
fi
dir="${WASMER_BINFMT_MISC_PREOPEN-.}"
wasm="$1"
shift
cm="$1"
shift
exec "$wasmer" run --dir "$dir" --command-name "$cm" "$wasm" -- "$@" [Edit:] OpenRC support
#!/sbin/openrc-run
description="Register wasmer as wasm and wat interpreter"
depend()
{
after clock procfs
use modules devfs
keyword -docker -lxc -openvz -prefix -systemd-nspawn -vserver
}
start() {
ebegin "Registering wasmer binfmt"
if [ ! -d /proc/sys/fs/binfmt_misc ] ; then
modprobe -q binfmt_misc
fi
if [ ! -d /proc/sys/fs/binfmt_misc ] ; then
eend 1 "You need support for 'misc binaries' in your kernel!"
return
fi
if [ ! -f /proc/sys/fs/binfmt_misc/register ] ; then
mount -t binfmt_misc -o nodev,noexec,nosuid \
binfmt_misc /proc/sys/fs/binfmt_misc >/dev/null 2>&1
eend $? || return
fi
echo ':wasm32:M::\x00asm\x01\x00\x00::/usr/bin/wasmer-binfmt:P' >/proc/sys/fs/binfmt_misc/register
echo ':wasm32-wat:E::wat::/usr/bin/wasmer-binfmt:P' >/proc/sys/fs/binfmt_misc/register
eend 0
}
stop() {
ebegin "Unregistering wasmer binfmt"
local f
for f in /proc/sys/fs/binfmt_misc/wasm32{,-wat} ; do
if test -f $f ; then
echo -1 >$f
fi
done
eend 0
} but how to install those as part of the install script is something that the wasmer team will know better than I do. Adding a |
What about calling That way we can also have a Do you think that's a reasonable approach?
|
That solves the "self-update won't update the binfmt registration" problem with this PR, but the command needs to be re-executed after every boot. Systemd service installation is a bit meh.. if test $OS == "linux" && which systemctl 1>/dev/null 2>/dev/null; then
cat <<EoF >/etc/systemd/system/wasmer-binfmt.service
[Unit]
Description=Set up wasmer to handle execution of wasm binaries
DefaultDependencies=no
Conflicts=shutdown.target
After=proc-sys-fs-binfmt_misc.automount
After=proc-sys-fs-binfmt_misc.mount
Before=sysinit.target shutdown.target
ConditionPathIsReadWrite=/proc/sys/
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=$INSTALL_DIRECTORY/bin/wasmer binfmt reregister
ExecStop=$INSTALL_DIRECTORY/bin/wasmer binfmt unregister
EoF
systemctl daemon-reload
systemctl enable wasmer-binfmt
systemctl restart wasmer-binfmt
fi
|
Looked into this a bit more: The C flag (use security context of interpreted binary - I think this mostly applies to SUID/SGID) requires the O flag (pre-open the interpreted binary so it can be read even if the mount namespace differs(?)). However, a script starting with |
Just had a look through the installer script, and… that's supposed to install something to |
bors r+ |
👎 Rejected by too few approved reviews |
bors r+ |
Description
Specialized command line parsing for when running wasmer/cli as a binfmt_misc "interpreter", and a new subcommand to manage the binfmt_misc registration, as described in #483.
Effect: e.g. this works
What you may want to consider during review:
/tmp
to register it from a specially named path anywhere else. It might be a bad idea..
and nothing else is preopened. Am I correct in the assumption that there is no way of giving WASI full filesystem access (because it has no concept of a working directory)..wat
?Review