workbox 0.2.0__tar.gz → 0.2.2__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: workbox
3
- Version: 0.2.0
3
+ Version: 0.2.2
4
4
  Summary: Workbox: SSH into your GPU boxes, and log metrics and samples from training jobs.
5
5
  Classifier: Environment :: Console
6
6
  Classifier: Operating System :: OS Independent
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "workbox"
3
- version = "0.2.0"
3
+ version = "0.2.2"
4
4
  description = "Workbox: SSH into your GPU boxes, and log metrics and samples from training jobs."
5
5
  requires-python = ">=3.10"
6
6
  readme = "README.md"
@@ -13,8 +13,8 @@ dependencies = []
13
13
 
14
14
  [project.scripts]
15
15
  workbox = "workbox.cli:main"
16
- workbox-runner = "workbox.runner:main"
17
- workbox-box = "workbox.box:main"
16
+ workbox-runner = "workbox.start:runner"
17
+ workbox-box = "workbox.start:box"
18
18
 
19
19
  [build-system]
20
20
  requires = ["hatchling"]
@@ -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(
@@ -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
- fail("the box refused the connection. Check it is running, then try again.")
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
 
@@ -0,0 +1,44 @@
1
+ """Where `workbox-runner` and `workbox-box` start (specs/boxes.md §5).
2
+
3
+ Some providers (Modal) start the container as root, with HOME=/root, whatever the image's USER says. Everything a
4
+ person uses runs as `learner`, so files they make in Jupyter are theirs over SSH too. The runner and the agent work
5
+ out their paths (~/work, ~/.workbox) when they are imported, so this drops to learner first, and only then imports
6
+ them. Standard library only.
7
+ """
8
+
9
+ from __future__ import annotations
10
+
11
+ import os
12
+ import subprocess
13
+
14
+
15
+ def become_learner() -> None:
16
+ """As root, hand the learner's home folder to them and drop to them, with their HOME."""
17
+ if os.name != "posix" or os.geteuid() != 0:
18
+ return
19
+ import pwd
20
+
21
+ try:
22
+ user = pwd.getpwnam("learner")
23
+ except KeyError:
24
+ return
25
+ subprocess.run(["chown", "-R", f"{user.pw_uid}:{user.pw_gid}", user.pw_dir], check=False)
26
+ os.setgroups([])
27
+ os.setgid(user.pw_gid)
28
+ os.setuid(user.pw_uid)
29
+ os.environ.update(HOME=user.pw_dir, USER=user.pw_name, LOGNAME=user.pw_name)
30
+ os.chdir(user.pw_dir)
31
+
32
+
33
+ def runner() -> None:
34
+ become_learner()
35
+ from workbox.runner import main
36
+
37
+ main()
38
+
39
+
40
+ def box() -> None:
41
+ become_learner()
42
+ from workbox.box import main
43
+
44
+ main()
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes