mirror of
https://github.com/hasso5703/alzeo.git
synced 2026-12-05 20:34:17 +01:00
A plain clone of the renamed repository makes ~/alzeo, which the one-liner does not look for: run later from outside it, the one-liner made a second clone in ~/dgx-spark-qwen38. The sentence that sends the reader to clone first names the folder. The test of install.sh's refusal under sudo held the host only since the one-liner became get.alzeo.ai: it holds the whole command again (a refusal that printed `curl https://get.alzeo.ai/get.sh | sudo bash` passed it, it fails it now). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
155 lines
6.8 KiB
Python
155 lines
6.8 KiB
Python
#!/usr/bin/env python3
|
|
"""The installer refuses root, and says which mistake was made.
|
|
|
|
On 2026-09-13 the reference box was installed with
|
|
`curl .../get.sh | sudo bash`. Nothing failed: git cloned into /root, install.sh
|
|
wrote /root/.config/qwen38 with a brand new API key, rendered the units as
|
|
User=root pointing at that key, started the engine, ran its smoke test and
|
|
reported success. The box then answered 401 to every client on it, because they
|
|
all read ~/.config/qwen38/api-key, and finding out why took a read of the sudo
|
|
audit log. A silent success into the wrong home is the worst failure shape this
|
|
installer has, so both entry points refuse root before writing anything.
|
|
|
|
The refusal has two shapes because the mistakes are different. With SUDO_USER
|
|
set there is always a right answer (drop the sudo) and no override: the message
|
|
names the login and the path whose key would stop working. A genuine root login
|
|
is merely unusual, so it refuses by default and ALLOW_ROOT=1 gets through.
|
|
|
|
Root is faked by stubbing `id` on PATH rather than by being root: a test suite
|
|
must not need root to prove what happens under it, and a PATH that can lie
|
|
about `id` could edit the script it is lying to.
|
|
"""
|
|
import os
|
|
import pathlib
|
|
import stat
|
|
import subprocess
|
|
import sys
|
|
import tempfile
|
|
import unittest
|
|
|
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
import installer_wall as wall # noqa: E402
|
|
|
|
REPO = pathlib.Path(__file__).resolve().parents[1]
|
|
ONELINER = "https://get.alzeo.ai"
|
|
|
|
|
|
def fake_root_bin():
|
|
"""A PATH entry whose `id` claims uid 0, and nothing else."""
|
|
d = tempfile.mkdtemp(prefix="fake-root-bin-")
|
|
idsh = os.path.join(d, "id")
|
|
with open(idsh, "w") as f:
|
|
f.write("#!/bin/sh\n"
|
|
"case \"$*\" in\n"
|
|
" -u) echo 0 ;;\n"
|
|
" -un) echo root ;;\n"
|
|
" -g) echo 0 ;;\n"
|
|
" -gn) echo root ;;\n"
|
|
" *) exec /usr/bin/id \"$@\" ;;\n"
|
|
"esac\n")
|
|
os.chmod(idsh, os.stat(idsh).st_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
|
|
return d
|
|
|
|
|
|
def run(script, *, sudo_user=None, allow_root=None, args=(), past=False, **extra):
|
|
"""Run a walled copy of script with a faked root identity, in a throwaway HOME and a
|
|
directory that is not a clone of this repo, the commands that act on the box fenced.
|
|
|
|
The copy ends at a wall: install.sh before step 1, get.sh right after its root
|
|
refusal. These runs used to start the real scripts from the real checkout, so a root
|
|
refusal that stopped firing would have run step 1 on the box, or had get.sh fetch
|
|
GitHub into the checkout the suite runs from and reset it (found in review,
|
|
2026-09-24). `past`: the run is meant to get through the refusal, to the wall."""
|
|
extra_env = dict(extra)
|
|
if sudo_user is not None:
|
|
extra_env["SUDO_USER"] = sudo_user
|
|
if allow_root is not None:
|
|
extra_env["ALLOW_ROOT"] = allow_root
|
|
env, record = wall.fenced_env(home=tempfile.mkdtemp(prefix="root-refusal-home-"),
|
|
first=fake_root_bin(), **extra_env)
|
|
r = subprocess.run(["bash", wall.walled(script), *args],
|
|
capture_output=True, text=True, env=env, cwd=wall.cwd(), timeout=60)
|
|
out = r.stdout + r.stderr
|
|
assert (wall.WALL in out) == past, f"expected the run {'at' if past else 'before'} the wall:\n{out[-800:]}"
|
|
assert not wall.reached(record), wall.reached(record)
|
|
return r.returncode, out, env["HOME"]
|
|
|
|
|
|
class InstallRefusesSudo(unittest.TestCase):
|
|
def test_sudo_in_front_is_refused_by_name(self):
|
|
rc, out, _ = run("install.sh", sudo_user="alice")
|
|
self.assertEqual(rc, 1)
|
|
self.assertIn("do not put sudo in front of this installer", out)
|
|
|
|
def test_the_message_names_the_login_and_the_key_that_would_break(self):
|
|
rc, out, _ = run("install.sh", sudo_user="alice")
|
|
self.assertIn("alice", out)
|
|
self.assertIn("/.config/qwen38/api-key", out)
|
|
self.assertIn("401", out)
|
|
|
|
def test_the_message_gives_the_command_that_works(self):
|
|
_, out, _ = run("install.sh", sudo_user="alice")
|
|
self.assertIn("./install.sh", out)
|
|
self.assertIn(f"run instead : curl -fsSL {ONELINER} | bash", out)
|
|
|
|
def test_allow_root_does_not_excuse_sudo(self):
|
|
# ALLOW_ROOT is for a box with no other user. Under sudo there IS
|
|
# another user, and their home is the one the units must point at.
|
|
rc, out, _ = run("install.sh", sudo_user="alice", allow_root="1")
|
|
self.assertEqual(rc, 1)
|
|
self.assertIn("do not put sudo in front of this installer", out)
|
|
|
|
def test_nothing_is_written_before_the_refusal(self):
|
|
_, _, home = run("install.sh", sudo_user="alice")
|
|
self.assertEqual(os.listdir(home), [],
|
|
"the refusal must land before the first write")
|
|
|
|
|
|
class InstallRefusesPlainRoot(unittest.TestCase):
|
|
def test_plain_root_is_refused_with_the_way_out(self):
|
|
rc, out, _ = run("install.sh")
|
|
self.assertEqual(rc, 1)
|
|
self.assertIn("not as root", out)
|
|
self.assertIn("ALLOW_ROOT=1", out)
|
|
|
|
def test_allow_root_gets_through_the_wall(self):
|
|
# Proven without installing anything: a deliberately invalid PORT dies
|
|
# at the next refusal down, which can only be reached past the wall.
|
|
rc, out, _ = run("install.sh", allow_root="1", PORT="abc")
|
|
self.assertEqual(rc, 1)
|
|
self.assertIn("PORT must be a number", out)
|
|
self.assertNotIn("not as root", out)
|
|
|
|
|
|
class GetShRefusesRootBeforeTheClone(unittest.TestCase):
|
|
def test_piping_into_sudo_bash_is_refused(self):
|
|
rc, out, _ = run("get.sh", sudo_user="alice")
|
|
self.assertEqual(rc, 1)
|
|
self.assertIn('do not pipe this into "sudo bash"', out)
|
|
self.assertIn("alice", out)
|
|
# the one-liner as the README gives it (v1.41.0: get.alzeo.ai, which sends curl on to get.sh on GitHub)
|
|
self.assertIn(f"run : curl -fsSL {ONELINER} | bash", out)
|
|
|
|
def test_plain_root_is_refused_with_the_way_out(self):
|
|
rc, out, _ = run("get.sh")
|
|
self.assertEqual(rc, 1)
|
|
self.assertIn("not as root", out)
|
|
self.assertIn("ALLOW_ROOT=1", out)
|
|
|
|
def test_the_refusal_lands_before_any_clone(self):
|
|
_, out, home = run("get.sh", sudo_user="alice")
|
|
self.assertNotIn("Cloning", out)
|
|
self.assertEqual(os.listdir(home), [])
|
|
|
|
def test_allow_root_gets_through_the_wall(self):
|
|
# Through the root refusal and straight into the copy's own wall, which stands
|
|
# where the clone, the fetch and the reset begin: no network, nothing written.
|
|
rc, out, home = run("get.sh", allow_root="1", past=True)
|
|
self.assertEqual(rc, 97)
|
|
self.assertNotIn("not as root", out)
|
|
self.assertEqual(os.listdir(home), [])
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main(verbosity=2)
|