Skip to content

Commit d5bffcc

Browse files
committed
feat(suidhelper): mix suidhelper.install wrapping cargo xtask install
1 parent 3603c45 commit d5bffcc

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
defmodule Mix.Tasks.Suidhelper.Install do
2+
@shortdoc "Build, stamp, and install the setuid helper (wraps `cargo xtask install`)"
3+
@moduledoc """
4+
Builds, stamps, and installs the Rust setuid helper by wrapping
5+
`cargo xtask install` in `native/suidhelper`.
6+
7+
mix suidhelper.install
8+
9+
The xtask first stamps the release binary (BLAKE3 self-checksum into
10+
`.note.sum`, the same step the `:suidhelper_stamp` compiler runs) and then
11+
installs it setuid-root to `/usr/local/bin/hyper-suidhelper` via `sudo
12+
install`. `sudo` may prompt for a password on the controlling terminal.
13+
14+
This is the privileged counterpart to `mix suidhelper.stamp`: that one only
15+
rebuilds, stamps, and re-captures the embedded build identity; this one also
16+
places the binary on `PATH` setuid-root. `cargo` and the helper's toolchain
17+
(see `native/suidhelper/rust-toolchain.toml`) must be installed.
18+
"""
19+
20+
use Mix.Task
21+
22+
@helper_dir "native/suidhelper"
23+
24+
@impl Mix.Task
25+
def run(argv) do
26+
{_, 0} =
27+
System.cmd("cargo", ["xtask", "install" | argv],
28+
cd: @helper_dir,
29+
into: IO.stream(:stdio, :line)
30+
)
31+
rescue
32+
MatchError ->
33+
Mix.raise("""
34+
`cargo xtask install` failed installing the suidhelper.
35+
36+
Ensure `cargo` and the helper's toolchain (see #{@helper_dir}/rust-toolchain.toml)
37+
are installed, and that `sudo` is available for the setuid install step.
38+
""")
39+
end
40+
end

0 commit comments

Comments
 (0)