Skip to content

The agent that grows with you

test(e2e): login-shell and standard-user probes hold on Blacksmith runners

Teknium31f47ddc6bc1
diff --git a/tests/e2e/core/upgrade/_helpers.py b/tests/e2e/core/upgrade/_helpers.py
index c05d839e810..5a80fe7af9e 100644
--- a/tests/e2e/core/upgrade/_helpers.py
+++ b/tests/e2e/core/upgrade/_helpers.py
@@ -31,6 +31,25 @@ WORKTREE = Path(__file__).resolve().parents[4]
REAL_HOME = Path(pwd.getpwuid(os.getuid()).pw_dir)
UID = os.getuid()
+
+def _home_resetting_profile_scripts() -> tuple[Path, ...]:
+ """Host login scripts that export HOME (Blacksmith's /etc/profile.d/blacksmith.sh puts the
+ runner user's passwd home back on every login shell). A login-shell probe in a sandbox HOME
+ would read the runner's rc files instead of the ones the installer edited."""
+ found = []
+ for script in sorted(Path("/etc/profile.d").glob("*.sh")):
+ try:
+ text = script.read_text(encoding="utf-8-sig", errors="replace")
+ except OSError:
+ continue
+ if any(line.strip().startswith("export HOME=") for line in text.splitlines()):
+ found.append(script)
+ return tuple(found)
+
+
+# (host_path, sandbox_path) masks for login-shell probes: /dev/null over each HOME-resetting script.
+LOGIN_SHELL_RO_BINDS = tuple((Path("/dev/null"), s) for s in _home_resetting_profile_scripts())
+
_ENV_ALLOW = ("LANG", "LC_ALL", "TZ", "TERM", "SHELL", "USER", "LOGNAME", "TMPDIR", "SSL_CERT_FILE")
_SHIMMED = ("systemctl", "launchctl", "sudo", "loginctl", "journalctl")
diff --git a/tests/e2e/core/upgrade/hosts/_hosts.py b/tests/e2e/core/upgrade/hosts/_hosts.py
index 633756df651..9747cdcf770 100644
--- a/tests/e2e/core/upgrade/hosts/_hosts.py
+++ b/tests/e2e/core/upgrade/hosts/_hosts.py
@@ -85,7 +85,8 @@ def login_shell(sb: I.Sandbox, script: str, *, path: str = "/usr/local/bin:/usr/
env = dict(sb.env, PATH=path)
bash = shutil.which("bash")
assert bash is not None, "bash required"
- return H.run([bash, "-lic", script], env=env, cwd=sb.root, writable=[sb.root], timeout=120)
+ return H.run([bash, "-lic", script], env=env, cwd=sb.root, writable=[sb.root], timeout=120,
+ ro_binds=H.LOGIN_SHELL_RO_BINDS)
def interpreter_paths(sb: I.Sandbox, python: str | None = None) -> dict:
diff --git a/tests/e2e/core/upgrade/test_install_fresh.py b/tests/e2e/core/upgrade/test_install_fresh.py
index 784221e2cc3..0e92571b29e 100644
--- a/tests/e2e/core/upgrade/test_install_fresh.py
+++ b/tests/e2e/core/upgrade/test_install_fresh.py
@@ -58,7 +58,8 @@ def _login_shell_hermes(sb: I.Sandbox) -> str:
env["PATH"] = "/usr/local/bin:/usr/bin:/bin"
bash = shutil.which("bash")
assert bash is not None, "bash required for install.sh and the login-shell probe"
- cp = H.run([bash, "-lic", "command -v hermes"], env=env, cwd=sb.root, writable=[sb.root], timeout=60)
+ cp = H.run([bash, "-lic", "command -v hermes"], env=env, cwd=sb.root, writable=[sb.root], timeout=60,
+ ro_binds=H.LOGIN_SHELL_RO_BINDS)
assert cp.returncode == 0, H.describe(cp)
return cp.stdout.strip()
diff --git a/tests/e2e/core/windows_update/test_paths_and_acls.py b/tests/e2e/core/windows_update/test_paths_and_acls.py
index 6eca818fbe2..4bb147b06a9 100644
--- a/tests/e2e/core/windows_update/test_paths_and_acls.py
+++ b/tests/e2e/core/windows_update/test_paths_and_acls.py
@@ -83,6 +83,12 @@ def standard_user_access(paths: list[Path]) -> dict[Path, str]:
finally:
advapi32.SaferCloseLevel(level)
try:
+ # Some hosts (Blacksmith's Windows runners) hand back the SAFER token with Administrators
+ # still enabled. Mark it deny-only, as UAC's filtered token does, so the check never
+ # depends on the host's SAFER policy (a no-op where SAFER already did it).
+ restricted = _without_administrators(advapi32, kernel32, primary, check)
+ kernel32.CloseHandle(primary)
+ primary = restricted
check(advapi32.DuplicateToken(primary, 2, ctypes.byref(imp)), "DuplicateToken") # SecurityImpersonation
mapping = GENERIC_MAPPING(0x120089, 0x120116, 0x1200A0, 0x1F01FF)
verdicts: dict[Path, str] = {}
@@ -109,6 +115,33 @@ def standard_user_access(paths: list[Path]) -> dict[Path, str]:
kernel32.CloseHandle(h)
+def _without_administrators(advapi32, kernel32, token, check):
+ """A copy of ``token`` with BUILTIN\\Administrators deny-only (CreateRestrictedToken)."""
+ import ctypes
+ from ctypes import wintypes
+
+ class SID_AND_ATTRIBUTES(ctypes.Structure):
+ _fields_ = [("Sid", ctypes.c_void_p), ("Attributes", wintypes.DWORD)]
+
+ handle = wintypes.HANDLE
+ advapi32.ConvertStringSidToSidW.argtypes = [wintypes.LPCWSTR, ctypes.POINTER(ctypes.c_void_p)]
+ advapi32.CreateRestrictedToken.argtypes = [handle, wintypes.DWORD, wintypes.DWORD,
+ ctypes.POINTER(SID_AND_ATTRIBUTES), wintypes.DWORD, ctypes.c_void_p,
+ wintypes.DWORD, ctypes.c_void_p, ctypes.POINTER(handle)]
+ kernel32.LocalFree.argtypes = [ctypes.c_void_p]
+ sid = ctypes.c_void_p()
+ check(advapi32.ConvertStringSidToSidW("S-1-5-32-544", ctypes.byref(sid)), "ConvertStringSidToSidW")
+ try:
+ disable = (SID_AND_ATTRIBUTES * 1)(SID_AND_ATTRIBUTES(sid, 0))
+ out = handle()
+ # DISABLE_MAX_PRIVILEGE=0x1: drop every privilege but SeChangeNotify, as a standard user has.
+ check(advapi32.CreateRestrictedToken(token, 0x1, 1, disable, 0, None, 0, None, ctypes.byref(out)),
+ "CreateRestrictedToken")
+ return out
+ finally:
+ kernel32.LocalFree(sid)
+
+
def _standard_user_token_is_really_restricted(scratch: Path) -> str:
"""Harness control: the token reads System32 but not an Administrators+SYSTEM-only file."""
admin_only = scratch / "admin-only.txt"