workbox 0.2.0__tar.gz → 0.2.1__tar.gz
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.
- {workbox-0.2.0 → workbox-0.2.1}/PKG-INFO +1 -1
- {workbox-0.2.0 → workbox-0.2.1}/pyproject.toml +1 -1
- {workbox-0.2.0 → workbox-0.2.1}/workbox/box.py +6 -1
- {workbox-0.2.0 → workbox-0.2.1}/workbox/cli.py +2 -1
- {workbox-0.2.0 → workbox-0.2.1}/workbox/runner.py +21 -0
- {workbox-0.2.0 → workbox-0.2.1}/.gitignore +0 -0
- {workbox-0.2.0 → workbox-0.2.1}/README.md +0 -0
- {workbox-0.2.0 → workbox-0.2.1}/workbox/__init__.py +0 -0
- {workbox-0.2.0 → workbox-0.2.1}/workbox/gateway.py +0 -0
- {workbox-0.2.0 → workbox-0.2.1}/workbox/ws.py +0 -0
|
@@ -20,7 +20,7 @@ from pathlib import Path
|
|
|
20
20
|
from typing import Any
|
|
21
21
|
|
|
22
22
|
from workbox.gateway import Gateway, Tool
|
|
23
|
-
from workbox.runner import Workbox, download, fetch_input, gpu_metrics, sh, upload
|
|
23
|
+
from workbox.runner import Workbox, become_learner, download, fetch_input, gpu_metrics, sh, upload
|
|
24
24
|
|
|
25
25
|
HOME = Path.home()
|
|
26
26
|
WORK = HOME / "work"
|
|
@@ -103,6 +103,10 @@ def start_sshd(ssh: dict[str, Any], log: Log) -> int | None:
|
|
|
103
103
|
(SSH / "ca.pub").write_text(ssh["caPublicKey"].strip() + "\n")
|
|
104
104
|
(SSH / "principals").write_text(ssh["principal"] + "\n")
|
|
105
105
|
user = os.environ.get("USER") or Path.home().name
|
|
106
|
+
# Run as root (when dropping to learner wasn't possible), sshd needs its privilege separation folder.
|
|
107
|
+
if os.name == "posix" and os.geteuid() == 0:
|
|
108
|
+
os.makedirs("/run/sshd", mode=0o755, exist_ok=True)
|
|
109
|
+
user = "learner"
|
|
106
110
|
config = SSH / "sshd_config"
|
|
107
111
|
config.write_text(
|
|
108
112
|
"\n".join(
|
|
@@ -255,6 +259,7 @@ def main() -> None:
|
|
|
255
259
|
if len(sys.argv) == 3 and sys.argv[1] == "input":
|
|
256
260
|
fetch_input(sys.argv[2], Log())
|
|
257
261
|
return
|
|
262
|
+
become_learner()
|
|
258
263
|
asyncio.run(agent())
|
|
259
264
|
|
|
260
265
|
|
|
@@ -191,7 +191,8 @@ def connect(args: argparse.Namespace) -> None:
|
|
|
191
191
|
name_, _, value = line.partition(":")
|
|
192
192
|
headers[name_.strip().lower()] = value.strip()
|
|
193
193
|
if " 101 " not in status or headers.get("sec-websocket-accept") != ws.accept_key(key):
|
|
194
|
-
|
|
194
|
+
answer = status.strip().split(" ", 1)[-1] if status.strip() else "no answer"
|
|
195
|
+
fail(f"the box refused the connection ({answer}). Check it is running, then try again.")
|
|
195
196
|
sock.settimeout(None)
|
|
196
197
|
lock = threading.Lock()
|
|
197
198
|
|
|
@@ -41,6 +41,26 @@ MAX_REPORT_SAMPLES = 50
|
|
|
41
41
|
TENSORBOARD_SCAN_SECONDS = 10
|
|
42
42
|
|
|
43
43
|
|
|
44
|
+
def become_learner() -> None:
|
|
45
|
+
"""Some providers (Modal) start the container as root whatever the image's USER says. Everything a person uses
|
|
46
|
+
runs as `learner`, so files they make in Jupyter are theirs over SSH too: as root, hand the home folder to
|
|
47
|
+
learner and drop to it, before anything else starts."""
|
|
48
|
+
if os.name != "posix" or os.geteuid() != 0:
|
|
49
|
+
return
|
|
50
|
+
import pwd
|
|
51
|
+
|
|
52
|
+
try:
|
|
53
|
+
user = pwd.getpwnam("learner")
|
|
54
|
+
except KeyError:
|
|
55
|
+
return
|
|
56
|
+
subprocess.run(["chown", "-R", f"{user.pw_uid}:{user.pw_gid}", user.pw_dir], check=False)
|
|
57
|
+
os.setgroups([])
|
|
58
|
+
os.setgid(user.pw_gid)
|
|
59
|
+
os.setuid(user.pw_uid)
|
|
60
|
+
os.environ.update(HOME=user.pw_dir, USER=user.pw_name, LOGNAME=user.pw_name)
|
|
61
|
+
os.chdir(user.pw_dir)
|
|
62
|
+
|
|
63
|
+
|
|
44
64
|
class Failure(Exception):
|
|
45
65
|
"""A failure the runner can name (specs/jobs.md §9): Workbox turns its kind into advice."""
|
|
46
66
|
|
|
@@ -487,6 +507,7 @@ def attach(gateway: dict[str, Any]) -> None:
|
|
|
487
507
|
|
|
488
508
|
|
|
489
509
|
def main() -> None:
|
|
510
|
+
become_learner()
|
|
490
511
|
workbox = Workbox()
|
|
491
512
|
output = Output()
|
|
492
513
|
events = Events()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|