@useconvoy/cli 0.63.0 → 0.81.1

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.
Files changed (232) hide show
  1. package/README.md +98 -0
  2. package/dist/bin/convoy.js +13 -1
  3. package/dist/bin/convoy.js.map +1 -1
  4. package/dist/src/agent/app/chunk-scrub.js +12 -0
  5. package/dist/src/agent/app/chunk-scrub.js.map +1 -1
  6. package/dist/src/agent/app/runner.d.ts +2 -0
  7. package/dist/src/agent/app/runner.js +2 -1
  8. package/dist/src/agent/app/runner.js.map +1 -1
  9. package/dist/src/agent/app/thread-processor.js +38 -10
  10. package/dist/src/agent/app/thread-processor.js.map +1 -1
  11. package/dist/src/agent/app/worktree-op-processor.js +28 -2
  12. package/dist/src/agent/app/worktree-op-processor.js.map +1 -1
  13. package/dist/src/agent/runtimes/claudeCode/interactions.d.ts +5 -1
  14. package/dist/src/agent/runtimes/claudeCode/interactions.js +36 -0
  15. package/dist/src/agent/runtimes/claudeCode/interactions.js.map +1 -1
  16. package/dist/src/agent/runtimes/claudeCode/models.d.ts +1 -1
  17. package/dist/src/agent/runtimes/claudeCode/models.js +1 -0
  18. package/dist/src/agent/runtimes/claudeCode/models.js.map +1 -1
  19. package/dist/src/agent/runtimes/claudeCode/runner.js +110 -51
  20. package/dist/src/agent/runtimes/claudeCode/runner.js.map +1 -1
  21. package/dist/src/agent/runtimes/codex/app-server-runner.d.ts +2 -0
  22. package/dist/src/agent/runtimes/codex/app-server-runner.js +75 -44
  23. package/dist/src/agent/runtimes/codex/app-server-runner.js.map +1 -1
  24. package/dist/src/agent/runtimes/codex/auth.d.ts +9 -0
  25. package/dist/src/agent/runtimes/codex/auth.js +90 -0
  26. package/dist/src/agent/runtimes/codex/auth.js.map +1 -0
  27. package/dist/src/agent/runtimes/codex/errors.d.ts +7 -0
  28. package/dist/src/agent/runtimes/codex/errors.js +60 -0
  29. package/dist/src/agent/runtimes/codex/errors.js.map +1 -0
  30. package/dist/src/agent/runtimes/codex/interactions.js +2 -52
  31. package/dist/src/agent/runtimes/codex/interactions.js.map +1 -1
  32. package/dist/src/agent/runtimes/codex/lifecycle.d.ts +12 -1
  33. package/dist/src/agent/runtimes/codex/lifecycle.js +97 -6
  34. package/dist/src/agent/runtimes/codex/lifecycle.js.map +1 -1
  35. package/dist/src/agent/runtimes/codex/runtime.js +2 -1
  36. package/dist/src/agent/runtimes/codex/runtime.js.map +1 -1
  37. package/dist/src/agent/runtimes/contracts.d.ts +4 -0
  38. package/dist/src/agent/runtimes/contracts.js.map +1 -1
  39. package/dist/src/agent/runtimes/cursor/models.js +1 -0
  40. package/dist/src/agent/runtimes/cursor/models.js.map +1 -1
  41. package/dist/src/agent/runtimes/message-format.js +3 -1
  42. package/dist/src/agent/runtimes/message-format.js.map +1 -1
  43. package/dist/src/agent/runtimes/registry.js +17 -1
  44. package/dist/src/agent/runtimes/registry.js.map +1 -1
  45. package/dist/src/agent/runtimes/validators.d.ts +4 -0
  46. package/dist/src/agent/runtimes/validators.js +101 -0
  47. package/dist/src/agent/runtimes/validators.js.map +1 -0
  48. package/dist/src/cli.js +10 -0
  49. package/dist/src/cli.js.map +1 -1
  50. package/dist/src/commands/browser/command.d.ts +2 -0
  51. package/dist/src/commands/browser/command.js +42 -0
  52. package/dist/src/commands/browser/command.js.map +1 -0
  53. package/dist/src/commands/browser/smoke.d.ts +10 -0
  54. package/dist/src/commands/browser/smoke.js +67 -0
  55. package/dist/src/commands/browser/smoke.js.map +1 -0
  56. package/dist/src/commands/browser/validators.d.ts +18 -0
  57. package/dist/src/commands/browser/validators.js +2 -0
  58. package/dist/src/commands/browser/validators.js.map +1 -0
  59. package/dist/src/commands/browser/workflow.d.ts +4 -0
  60. package/dist/src/commands/browser/workflow.js +86 -0
  61. package/dist/src/commands/browser/workflow.js.map +1 -0
  62. package/dist/src/commands/connect/command.js +1 -0
  63. package/dist/src/commands/connect/command.js.map +1 -1
  64. package/dist/src/commands/connect/workflow.d.ts +7 -0
  65. package/dist/src/commands/connect/workflow.js +68 -4
  66. package/dist/src/commands/connect/workflow.js.map +1 -1
  67. package/dist/src/commands/devcontainer/command.js +3 -1
  68. package/dist/src/commands/devcontainer/command.js.map +1 -1
  69. package/dist/src/commands/devcontainer/install.d.ts +1 -0
  70. package/dist/src/commands/devcontainer/install.js +17 -7
  71. package/dist/src/commands/devcontainer/install.js.map +1 -1
  72. package/dist/src/commands/environment/command.d.ts +5 -0
  73. package/dist/src/commands/environment/command.js +123 -0
  74. package/dist/src/commands/environment/command.js.map +1 -0
  75. package/dist/src/commands/environment/docker.d.ts +13 -0
  76. package/dist/src/commands/environment/docker.js +65 -0
  77. package/dist/src/commands/environment/docker.js.map +1 -0
  78. package/dist/src/commands/environment/index.d.ts +60 -0
  79. package/dist/src/commands/environment/index.js +36 -0
  80. package/dist/src/commands/environment/index.js.map +1 -0
  81. package/dist/src/commands/environment/paths.d.ts +6 -0
  82. package/dist/src/commands/environment/paths.js +58 -0
  83. package/dist/src/commands/environment/paths.js.map +1 -0
  84. package/dist/src/commands/environment/projects.d.ts +3 -0
  85. package/dist/src/commands/environment/projects.js +46 -0
  86. package/dist/src/commands/environment/projects.js.map +1 -0
  87. package/dist/src/commands/environment/resolution.d.ts +11 -0
  88. package/dist/src/commands/environment/resolution.js +4 -0
  89. package/dist/src/commands/environment/resolution.js.map +1 -0
  90. package/dist/src/commands/environment/setup-entrypoint.d.ts +1 -0
  91. package/dist/src/commands/environment/setup-entrypoint.js +17 -0
  92. package/dist/src/commands/environment/setup-entrypoint.js.map +1 -0
  93. package/dist/src/commands/environment/validators.d.ts +65 -0
  94. package/dist/src/commands/environment/validators.js +36 -0
  95. package/dist/src/commands/environment/validators.js.map +1 -0
  96. package/dist/src/commands/environment/workflow.d.ts +48 -0
  97. package/dist/src/commands/environment/workflow.js +172 -0
  98. package/dist/src/commands/environment/workflow.js.map +1 -0
  99. package/dist/src/commands/keys/command.js +99 -13
  100. package/dist/src/commands/keys/command.js.map +1 -1
  101. package/dist/src/commands/keys/workflow.d.ts +68 -0
  102. package/dist/src/commands/keys/workflow.js +147 -0
  103. package/dist/src/commands/keys/workflow.js.map +1 -0
  104. package/dist/src/commands/project/command.d.ts +2 -0
  105. package/dist/src/commands/project/command.js +53 -0
  106. package/dist/src/commands/project/command.js.map +1 -0
  107. package/dist/src/commands/project/launcher.d.ts +44 -0
  108. package/dist/src/commands/project/launcher.js +100 -0
  109. package/dist/src/commands/project/launcher.js.map +1 -0
  110. package/dist/src/commands/project/validators.d.ts +87 -0
  111. package/dist/src/commands/project/validators.js +53 -0
  112. package/dist/src/commands/project/validators.js.map +1 -0
  113. package/dist/src/commands/project/worker.d.ts +2 -0
  114. package/dist/src/commands/project/worker.js +90 -0
  115. package/dist/src/commands/project/worker.js.map +1 -0
  116. package/dist/src/commands/project/workflow.d.ts +47 -0
  117. package/dist/src/commands/project/workflow.js +238 -0
  118. package/dist/src/commands/project/workflow.js.map +1 -0
  119. package/dist/src/commands/service/attach.d.ts +3 -0
  120. package/dist/src/commands/service/attach.js +155 -0
  121. package/dist/src/commands/service/attach.js.map +1 -0
  122. package/dist/src/commands/service/bridge.d.ts +3 -0
  123. package/dist/src/commands/service/bridge.js +105 -0
  124. package/dist/src/commands/service/bridge.js.map +1 -0
  125. package/dist/src/commands/service/client.d.ts +26 -0
  126. package/dist/src/commands/service/client.js +154 -0
  127. package/dist/src/commands/service/client.js.map +1 -0
  128. package/dist/src/commands/service/command.d.ts +3 -0
  129. package/dist/src/commands/service/command.js +186 -0
  130. package/dist/src/commands/service/command.js.map +1 -0
  131. package/dist/src/commands/service/errors.d.ts +9 -0
  132. package/dist/src/commands/service/errors.js +13 -0
  133. package/dist/src/commands/service/errors.js.map +1 -0
  134. package/dist/src/commands/service/formatters.d.ts +5 -0
  135. package/dist/src/commands/service/formatters.js +58 -0
  136. package/dist/src/commands/service/formatters.js.map +1 -0
  137. package/dist/src/commands/service/logs.d.ts +19 -0
  138. package/dist/src/commands/service/logs.js +64 -0
  139. package/dist/src/commands/service/logs.js.map +1 -0
  140. package/dist/src/commands/service/output.d.ts +18 -0
  141. package/dist/src/commands/service/output.js +60 -0
  142. package/dist/src/commands/service/output.js.map +1 -0
  143. package/dist/src/commands/service/parsers.d.ts +4 -0
  144. package/dist/src/commands/service/parsers.js +41 -0
  145. package/dist/src/commands/service/parsers.js.map +1 -0
  146. package/dist/src/commands/service/paths.d.ts +7 -0
  147. package/dist/src/commands/service/paths.js +44 -0
  148. package/dist/src/commands/service/paths.js.map +1 -0
  149. package/dist/src/commands/service/resolution.d.ts +5 -0
  150. package/dist/src/commands/service/resolution.js +36 -0
  151. package/dist/src/commands/service/resolution.js.map +1 -0
  152. package/dist/src/commands/service/runs.d.ts +3 -0
  153. package/dist/src/commands/service/runs.js +58 -0
  154. package/dist/src/commands/service/runs.js.map +1 -0
  155. package/dist/src/commands/service/server.d.ts +7 -0
  156. package/dist/src/commands/service/server.js +206 -0
  157. package/dist/src/commands/service/server.js.map +1 -0
  158. package/dist/src/commands/service/service-entrypoint.d.ts +1 -0
  159. package/dist/src/commands/service/service-entrypoint.js +32 -0
  160. package/dist/src/commands/service/service-entrypoint.js.map +1 -0
  161. package/dist/src/commands/service/validators.d.ts +257 -0
  162. package/dist/src/commands/service/validators.js +48 -0
  163. package/dist/src/commands/service/validators.js.map +1 -0
  164. package/dist/src/commands/service/workflow.d.ts +12 -0
  165. package/dist/src/commands/service/workflow.js +355 -0
  166. package/dist/src/commands/service/workflow.js.map +1 -0
  167. package/dist/src/commands/setup/command.js +5 -0
  168. package/dist/src/commands/setup/command.js.map +1 -1
  169. package/dist/src/commands/setup/prompts.d.ts +1 -1
  170. package/dist/src/commands/setup/prompts.js +3 -1
  171. package/dist/src/commands/setup/prompts.js.map +1 -1
  172. package/dist/src/commands/setup/resolution.d.ts +14 -0
  173. package/dist/src/commands/setup/resolution.js +87 -0
  174. package/dist/src/commands/setup/resolution.js.map +1 -0
  175. package/dist/src/commands/setup/validators.d.ts +15 -0
  176. package/dist/src/commands/setup/validators.js +15 -0
  177. package/dist/src/commands/setup/validators.js.map +1 -0
  178. package/dist/src/commands/setup/workflow.d.ts +3 -1
  179. package/dist/src/commands/setup/workflow.js +56 -47
  180. package/dist/src/commands/setup/workflow.js.map +1 -1
  181. package/dist/src/commands/threads/done.d.ts +2 -0
  182. package/dist/src/commands/threads/done.js +20 -0
  183. package/dist/src/commands/threads/done.js.map +1 -0
  184. package/dist/src/commands/threads/index.js +3 -1
  185. package/dist/src/commands/threads/index.js.map +1 -1
  186. package/dist/src/lib/config/convex-client.d.ts +5 -0
  187. package/dist/src/lib/config/convex-client.js +27 -1
  188. package/dist/src/lib/config/convex-client.js.map +1 -1
  189. package/dist/src/lib/config/credentials/resolution.d.ts +11 -0
  190. package/dist/src/lib/config/credentials/resolution.js +101 -0
  191. package/dist/src/lib/config/credentials/resolution.js.map +1 -0
  192. package/dist/src/lib/config/credentials/store.d.ts +9 -0
  193. package/dist/src/lib/config/credentials/store.js +147 -0
  194. package/dist/src/lib/config/credentials/store.js.map +1 -0
  195. package/dist/src/lib/config/credentials/validators.d.ts +152 -0
  196. package/dist/src/lib/config/credentials/validators.js +87 -0
  197. package/dist/src/lib/config/credentials/validators.js.map +1 -0
  198. package/dist/src/lib/config/index.d.ts +1 -1
  199. package/dist/src/lib/config/index.js +1 -1
  200. package/dist/src/lib/config/index.js.map +1 -1
  201. package/dist/src/lib/config/toml.d.ts +4 -4
  202. package/dist/src/lib/config/toml.js +149 -83
  203. package/dist/src/lib/config/toml.js.map +1 -1
  204. package/dist/src/lib/config/types.d.ts +8 -0
  205. package/dist/src/lib/config/types.js +5 -0
  206. package/dist/src/lib/config/types.js.map +1 -1
  207. package/dist/src/lib/connect-events.d.ts +5 -0
  208. package/dist/src/lib/connect-events.js.map +1 -1
  209. package/dist/src/lib/git/checkpoint.d.ts +18 -3
  210. package/dist/src/lib/git/checkpoint.js +57 -24
  211. package/dist/src/lib/git/checkpoint.js.map +1 -1
  212. package/dist/src/lib/git/index.d.ts +1 -0
  213. package/dist/src/lib/git/index.js +1 -0
  214. package/dist/src/lib/git/index.js.map +1 -1
  215. package/dist/src/lib/git/working-tree.d.ts +12 -0
  216. package/dist/src/lib/git/working-tree.js +38 -0
  217. package/dist/src/lib/git/working-tree.js.map +1 -0
  218. package/dist/templates/devcontainer/Dockerfile +7 -0
  219. package/dist/templates/devcontainer/README.md +17 -0
  220. package/dist/templates/project-isolation/Dockerfile +28 -0
  221. package/dist/templates/project-isolation/README.md +206 -0
  222. package/dist/templates/project-isolation/devcontainer.json +20 -0
  223. package/dist/templates/project-isolation/environment.py +257 -0
  224. package/dist/templates/project-isolation/environment.test.py +156 -0
  225. package/dist/templates/project-isolation/install.py +69 -0
  226. package/dist/templates/project-isolation/launcher.py +401 -0
  227. package/dist/templates/project-isolation/launcher.test.py +265 -0
  228. package/dist/templates/project-isolation/seccomp-source.md +20 -0
  229. package/dist/templates/project-isolation/seccomp.LICENSE +202 -0
  230. package/dist/templates/project-isolation/seccomp.json +1173 -0
  231. package/dist/templates/project-isolation/start.sh +8 -0
  232. package/package.json +3 -2
@@ -0,0 +1,401 @@
1
+ #!/usr/bin/python3 -I
2
+ """Restricted Linux project launcher. See docs/specs/cli-project-isolation.md."""
3
+ import ctypes
4
+ import fcntl
5
+ import grp
6
+ import json
7
+ import os
8
+ from pathlib import Path
9
+ import pwd
10
+ import re
11
+ import selectors
12
+ import select
13
+ import signal
14
+ import stat
15
+ import subprocess
16
+ import sys
17
+ import time
18
+ from urllib.parse import urlparse
19
+
20
+ CONFIG = Path("/etc/convoy-projects.json")
21
+ SAFE_ENV = {"PATH": "/usr/local/bin:/usr/bin:/bin", "LANG": "C.UTF-8"}
22
+
23
+
24
+ def require(condition, message):
25
+ if not condition:
26
+ raise ValueError(message)
27
+
28
+
29
+ def trusted_path(path, owners=(0,)):
30
+ path = Path(path)
31
+ require(path.is_absolute() and path.resolve() == path, "Expected a canonical absolute path")
32
+ for item in [path, *path.parents]:
33
+ info = item.stat()
34
+ require(info.st_uid in owners and not info.st_mode & 0o022,
35
+ "Launcher paths must be administrator-owned and not group/world writable")
36
+ return path
37
+
38
+
39
+ def load_config():
40
+ require(os.geteuid() == 0, "Invoke the administrator-installed launcher through sudo")
41
+ trusted_path(CONFIG)
42
+ config = json.loads(CONFIG.read_text())
43
+ require(str(config["control_uid"]) == os.environ.get("SUDO_UID"), "Unauthorized control identity")
44
+ require(config["control_uid"] > 0, "The control account must be unprivileged")
45
+ trusted_path(config["workspace"], (0, config["control_uid"]))
46
+ trusted_path(config["state"])
47
+ trusted_path(config["cli"])
48
+ trusted_path(config["node"])
49
+ trusted_path(config["package_root"])
50
+ trusted_path(config["installation_root"])
51
+ require(Path("/usr/bin/bwrap").is_file(), "Install bubblewrap before registering projects")
52
+ return config
53
+
54
+
55
+ def read_registry(config):
56
+ file = Path(config["state"]) / "registry.json"
57
+ return json.loads(file.read_text()) if file.exists() else {}
58
+
59
+
60
+ def save_registry(config, registry):
61
+ file = Path(config["state"]) / "registry.json"
62
+ temporary = file.with_suffix(".tmp")
63
+ with open(temporary, "w", opener=lambda p, f: os.open(p, f, 0o600)) as stream:
64
+ json.dump(registry, stream)
65
+ stream.flush()
66
+ os.fsync(stream.fileno())
67
+ temporary.replace(file)
68
+ fd = os.open(config["state"], os.O_DIRECTORY)
69
+ try:
70
+ os.fsync(fd)
71
+ finally:
72
+ os.close(fd)
73
+
74
+
75
+ def lock_file(config, name, nonblocking=False, control=None):
76
+ fd = os.open(Path(config["state"]) / name, os.O_CREAT | os.O_RDWR | os.O_NOFOLLOW, 0o600)
77
+ deadline = time.monotonic() + 10
78
+ try:
79
+ while True:
80
+ if control is not None and select.select([control], [], [], 0)[0]:
81
+ if not os.read(control.fileno(), 1024):
82
+ os.close(fd)
83
+ return None
84
+ try:
85
+ fcntl.flock(fd, fcntl.LOCK_EX | fcntl.LOCK_NB)
86
+ return fd
87
+ except BlockingIOError:
88
+ if nonblocking:
89
+ raise ValueError("Project is active. Stop its service, foreground connection or shell before continuing.") from None
90
+ if time.monotonic() >= deadline:
91
+ raise ValueError("Project registry is busy. Wait for registration to finish and retry.") from None
92
+ time.sleep(0.05)
93
+ except BaseException:
94
+ os.close(fd)
95
+ raise
96
+
97
+
98
+ def is_active(config, identity):
99
+ try:
100
+ fd = lock_file(config, identity + ".lease", True)
101
+ except ValueError:
102
+ return True
103
+ os.close(fd)
104
+ return False
105
+
106
+
107
+ def validate_target(config, registry, identity, target):
108
+ root = Path(config["workspace"])
109
+ target = Path(target)
110
+ require(target.is_absolute() and target.parent == root and target.resolve() == target,
111
+ "Workspace must be a canonical direct child of the configured root; symlinks are not allowed")
112
+ require(re.fullmatch(r"[A-Za-z0-9][A-Za-z0-9._-]{0,99}", target.name) and not target.name.endswith("-worktrees"),
113
+ "Use a simple folder name that does not end in -worktrees")
114
+ for key, entry in registry.items():
115
+ if key == identity:
116
+ require(entry["path"] == str(target), "This project already has a different workspace")
117
+ else:
118
+ reserved = {entry["path"], entry["path"] + "-worktrees"}
119
+ require(str(target) not in reserved and str(target) + "-worktrees" not in reserved,
120
+ "Workspace or worktree path already reserved, including retained registrations")
121
+ return target
122
+
123
+
124
+ def allocate_uid(registry, identity):
125
+ existing = registry.get(identity)
126
+ if existing:
127
+ require(existing["uid"] not in {item.pw_uid for item in pwd.getpwall()} and
128
+ existing["uid"] not in {item.gr_gid for item in grp.getgrall()},
129
+ "Retained UID/GID now belongs to a system account; administrator intervention required")
130
+ return existing["uid"]
131
+ used = {item["uid"] for item in registry.values()} | {item.pw_uid for item in pwd.getpwall()} | {item.gr_gid for item in grp.getgrall()}
132
+ for uid in range(20000, 60000):
133
+ if uid not in used:
134
+ return uid
135
+ raise ValueError("No project UIDs available")
136
+
137
+
138
+ def private_directory(directory, uid, create=False):
139
+ directory = Path(directory)
140
+ if create:
141
+ directory.mkdir(mode=0o700)
142
+ os.chown(directory, uid, uid)
143
+ info = directory.lstat()
144
+ require(stat.S_ISDIR(info.st_mode) and info.st_uid == uid and info.st_gid == uid and stat.S_IMODE(info.st_mode) == 0o700,
145
+ f"Existing project folders must already be owned by UID/GID {uid} with mode 0700. No ownership migration was performed.")
146
+
147
+
148
+ def audit_tree(directory, uid):
149
+ # Existing hard links could retain access outside this mount after migration.
150
+ for root, dirs, files in os.walk(directory, followlinks=False):
151
+ for name in dirs + files:
152
+ info = (Path(root) / name).lstat()
153
+ if stat.S_ISLNK(info.st_mode):
154
+ continue
155
+ require(info.st_uid == uid and (stat.S_ISDIR(info.st_mode) or stat.S_ISREG(info.st_mode)),
156
+ "Reuse requires project-owned regular files/directories, without devices or sockets")
157
+ require(not stat.S_ISREG(info.st_mode) or info.st_nlink == 1,
158
+ "Reuse rejects hard-linked files; copy them to independent files before migration")
159
+
160
+
161
+ def drop_privileges(uid):
162
+ os.setgroups([])
163
+ os.setgid(uid)
164
+ os.setuid(uid)
165
+ libc = ctypes.CDLL(None, use_errno=True)
166
+ if libc.prctl(38, 1, 0, 0, 0) != 0: # PR_SET_NO_NEW_PRIVS
167
+ raise OSError(ctypes.get_errno(), "Cannot disable privilege escalation")
168
+ os.umask(0o077)
169
+
170
+
171
+ def write_identity_files(config, entry):
172
+ uid = entry["uid"]
173
+ records = {
174
+ "passwd": f"root:x:0:0:root:/root:/bin/false\nconvoy-project:x:{uid}:{uid}:Convoy:/home/convoy:/bin/bash\n",
175
+ "group": f"root:x:0:\nconvoy-project:x:{uid}:\n",
176
+ }
177
+ for suffix, content in records.items():
178
+ file = Path(config["state"]) / (entry["identity"] + "." + suffix)
179
+ fd = os.open(file, os.O_WRONLY | os.O_CREAT | os.O_TRUNC | os.O_NOFOLLOW, 0o444)
180
+ with os.fdopen(fd, "w") as stream:
181
+ stream.write(content)
182
+
183
+
184
+ def sandbox_args(config, entry):
185
+ args = ["/usr/bin/bwrap", "--unshare-user", "--unshare-pid", "--unshare-ipc", "--unshare-uts",
186
+ "--die-with-parent", "--new-session", "--cap-drop", "ALL", "--clearenv"]
187
+ for item in ["/usr", "/bin", "/sbin", "/lib", "/lib64"]:
188
+ if Path(item).exists():
189
+ args += ["--ro-bind", item, item]
190
+ for item in ["/etc/ssl", "/etc/fonts", "/etc/resolv.conf", "/etc/hosts", "/etc/nsswitch.conf", "/etc/localtime"]:
191
+ if Path(item).exists():
192
+ args += ["--ro-bind", item, item]
193
+ for suffix in ["passwd", "group"]:
194
+ args += ["--ro-bind", str(Path(config["state"]) / (entry["identity"] + "." + suffix)), "/etc/" + suffix]
195
+ cli = config["package_root"]
196
+ installation = config["installation_root"]
197
+ if not installation.startswith("/usr/"):
198
+ args += ["--ro-bind", installation, installation]
199
+ home = str(Path(config["state"]) / entry["identity"])
200
+ args += ["--bind", home, "/home/convoy", "--bind", entry["path"], entry["path"],
201
+ "--bind", entry["path"] + "-worktrees", entry["path"] + "-worktrees",
202
+ "--proc", "/proc", "--dev", "/dev", "--tmpfs", "/tmp", "--dir", "/run/user"]
203
+ env = {**SAFE_ENV, "PATH": f"{installation}/node_modules/.bin:{cli}/dist/bin:/home/convoy/.local/bin:/usr/local/bin:/usr/bin:/bin",
204
+ "HOME": "/home/convoy", "USER": "convoy-project", "LOGNAME": "convoy-project",
205
+ "TMPDIR": "/tmp", "XDG_RUNTIME_DIR": "/run/user", "XDG_CONFIG_HOME": "/home/convoy/.config",
206
+ "XDG_CACHE_HOME": "/home/convoy/.cache", "XDG_DATA_HOME": "/home/convoy/.local/share",
207
+ "CODEX_HOME": "/home/convoy/.codex", "CLAUDE_CONFIG_DIR": "/home/convoy/.claude",
208
+ "CONVOY_PROJECT_IDENTITY": entry["identity"], "TERM": "xterm-256color",
209
+ "CONVOY_PROJECT_RUNTIMES": ",".join(config.get("verified_runtimes", []))}
210
+ for key, value in env.items():
211
+ args += ["--setenv", key, value]
212
+ return args + ["--chdir", entry["path"]]
213
+
214
+
215
+ def run_bounded(config, entry, command):
216
+ result = subprocess.run(sandbox_args(config, entry) + command, env=SAFE_ENV,
217
+ preexec_fn=lambda: drop_privileges(entry["uid"]),
218
+ stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL,
219
+ stderr=subprocess.PIPE, timeout=300, close_fds=True)
220
+ require(result.returncode == 0, "Project preparation failed inside the Linux boundary. Check user namespaces, bubblewrap and HTTPS clone access. Private files were retained.")
221
+
222
+
223
+ def add(config, registry, request):
224
+ identity = request["identity"]
225
+ target = validate_target(config, registry, identity, request["path"])
226
+ uid = allocate_uid(registry, identity)
227
+ clone = request.get("clone")
228
+ if clone:
229
+ parsed = urlparse(clone)
230
+ require(parsed.scheme == "https" and parsed.hostname and not parsed.username and not parsed.password,
231
+ "Clone requires an HTTPS URL without embedded credentials")
232
+ if identity in registry:
233
+ entry = registry[identity]
234
+ if entry.get("ready"):
235
+ require(not clone or clone == entry.get("clone"), "Project already exists with a different clone source")
236
+ private_directory(target, entry["uid"])
237
+ entry["enabled"] = True
238
+ save_registry(config, registry)
239
+ return entry
240
+ require(not clone or clone == entry.get("clone"), "Pending project has a different clone source")
241
+ clone = entry.get("clone")
242
+ else:
243
+ require(not target.exists() or request.get("reuse"), "Folder exists; use --reuse after preparing private ownership")
244
+ require(not clone or not target.exists(), "Clone requires an absent target folder")
245
+ require(not Path(str(target) + "-worktrees").exists(), "Worktree directory already exists")
246
+ entry = {"identity": identity, "uid": uid, "path": str(target), "ready": False,
247
+ "enabled": False, "clone": clone, "reuse": bool(request.get("reuse"))}
248
+ registry[identity] = entry
249
+ # Reserve the UID before creating any retained project data.
250
+ save_registry(config, registry)
251
+ uid = entry["uid"]
252
+ home = Path(config["state"]) / identity
253
+ for directory in [home, target, Path(str(target) + "-worktrees")]:
254
+ private_directory(directory, uid, create=not directory.exists())
255
+ # Audit retained input even when a retry omits its original flags.
256
+ audit_tree(target, uid)
257
+ write_identity_files(config, entry)
258
+ run_bounded(config, entry, ["/bin/true"])
259
+ if clone:
260
+ require(not any(target.iterdir()), "Clone target is not empty; inspect retained files before retrying")
261
+ run_bounded(config, entry, ["/usr/bin/git", "-c", "protocol.file.allow=never", "clone", "--", clone, str(target)])
262
+ entry["ready"] = True
263
+ entry["enabled"] = True
264
+ save_registry(config, registry)
265
+ return entry
266
+
267
+
268
+ def validate_credentials(request):
269
+ auth = request.get("config", {}).get("codexAuth")
270
+ if auth is None:
271
+ return
272
+ require(isinstance(auth, dict), "Invalid managed credential payload")
273
+ mode = auth.get("mode")
274
+ require(mode in {"managed", "disabled", "native"}, "Invalid managed credential mode")
275
+ allowed = {"mode", "secret"} if mode == "managed" else {"mode"}
276
+ require(set(auth) == allowed, "Invalid managed credential fields")
277
+ if mode == "managed":
278
+ secret = auth["secret"]
279
+ require(isinstance(secret, str) and 0 < len(secret) <= 4096 and
280
+ not any(c in secret for c in "\r\n\0"), "Invalid managed credential value")
281
+ require(request["config"].get("codexAppServer") is not False,
282
+ "Managed credentials require app-server mode")
283
+
284
+
285
+ def supervise(config, entry, request, shell=False):
286
+ if not shell:
287
+ validate_credentials(request)
288
+ require(entry["uid"] not in {item.pw_uid for item in pwd.getpwall()} and
289
+ entry["uid"] not in {item.gr_gid for item in grp.getgrall()},
290
+ "Retained UID/GID now belongs to a system account; administrator intervention required")
291
+ require(shell or config.get("verified_runtimes"),
292
+ "No runtime has passed acceptance on this environment. Run the isolation smoke procedure and configure verified_runtimes before connecting.")
293
+ private_directory(entry["path"], entry["uid"])
294
+ private_directory(entry["path"] + "-worktrees", entry["uid"])
295
+ private_directory(Path(config["state"]) / entry["identity"], entry["uid"])
296
+ write_identity_files(config, entry)
297
+ # Allocate the controlling terminal inside the boundary, after --new-session.
298
+ command = ["/usr/bin/script", "--quiet", "--return", "--command",
299
+ "/bin/bash --noprofile --norc", "/dev/null"] if shell else [config["node"], config["cli"]]
300
+ child = subprocess.Popen(sandbox_args(config, entry) + command, env=SAFE_ENV,
301
+ preexec_fn=lambda: drop_privileges(entry["uid"]),
302
+ stdin=None if shell else subprocess.PIPE, close_fds=True,
303
+ start_new_session=not shell)
304
+ stopping = False
305
+ deadline = None
306
+
307
+ def stop(*_):
308
+ nonlocal stopping, deadline
309
+ if not stopping:
310
+ stopping = True
311
+ deadline = time.monotonic() + 30
312
+ if shell:
313
+ child.terminate()
314
+ else:
315
+ child.stdin.close()
316
+
317
+ for signum in (signal.SIGINT, signal.SIGTERM, signal.SIGHUP):
318
+ signal.signal(signum, stop)
319
+ selector = selectors.DefaultSelector()
320
+ try:
321
+ if not shell:
322
+ payload = {**request["config"], "paths": [entry["path"]], "projectIdentity": entry["identity"]}
323
+ child.stdin.write((json.dumps(payload) + "\n").encode())
324
+ child.stdin.flush()
325
+ selector.register(sys.stdin, selectors.EVENT_READ)
326
+ while child.poll() is None:
327
+ if not shell and selector.select(0.1):
328
+ if not os.read(sys.stdin.fileno(), 1024):
329
+ stop()
330
+ else:
331
+ time.sleep(0.1)
332
+ if deadline and time.monotonic() >= deadline:
333
+ child.kill()
334
+ return 0 if stopping else child.returncode
335
+ finally:
336
+ selector.close()
337
+ if child.poll() is None:
338
+ child.kill()
339
+ child.wait()
340
+
341
+
342
+ def main():
343
+ config = load_config()
344
+ shell = len(sys.argv) == 3 and sys.argv[1] == "shell"
345
+ if shell:
346
+ request = {"action": "shell", "identity": sys.argv[2]}
347
+ else:
348
+ require(len(sys.argv) == 1, "Unsupported launcher arguments")
349
+ raw = sys.stdin.buffer.readline(65537)
350
+ require(len(raw) <= 65536, "Request too large")
351
+ request = json.loads(raw)
352
+ action = request.get("action")
353
+ require(action in {"list", "add", "remove", "connect", "shell"}, "Unsupported operation")
354
+ identity = request.get("identity")
355
+ if action != "list":
356
+ require(isinstance(identity, str) and re.fullmatch(r"[a-f0-9]{64}", identity), "Invalid project identity")
357
+ registry_lock = lock_file(config, "registry.lock", control=sys.stdin if action == "connect" else None)
358
+ if registry_lock is None:
359
+ return 0
360
+ lease = None
361
+ try:
362
+ registry = read_registry(config)
363
+ if action == "list":
364
+ result = {"capabilities": ["credentials-v1"], "workspace": config["workspace"], "registrations": [
365
+ {**entry, "active": is_active(config, key),
366
+ "status": "pending" if not entry.get("ready") else "stopped" if entry.get("enabled", True) else "removed"}
367
+ for key, entry in registry.items()
368
+ ]}
369
+ else:
370
+ lease = lock_file(config, identity + ".lease", True)
371
+ if action == "add":
372
+ result = {**add(config, registry, request), "active": False}
373
+ else:
374
+ require(identity in registry and registry[identity].get("ready") and registry[identity].get("enabled", True),
375
+ "Project is not registered or is disabled; repeat project add")
376
+ entry = registry[identity]
377
+ validate_target(config, registry, identity, entry["path"])
378
+ if action in {"connect", "shell"}:
379
+ os.close(registry_lock)
380
+ registry_lock = None
381
+ return supervise(config, entry, request, shell)
382
+ entry["enabled"] = False
383
+ save_registry(config, registry)
384
+ result = {"retained": True}
385
+ print(json.dumps(result))
386
+ return 0
387
+ finally:
388
+ if lease is not None:
389
+ os.close(lease)
390
+ if registry_lock is not None:
391
+ os.close(registry_lock)
392
+
393
+
394
+ if __name__ == "__main__":
395
+ try:
396
+ sys.exit(main())
397
+ except (ValueError, OSError, KeyError, subprocess.SubprocessError) as error:
398
+ # Requests can contain credentials. Never echo request data or tracebacks.
399
+ print(str(error) if isinstance(error, ValueError) and not isinstance(error, json.JSONDecodeError)
400
+ else "Linux project launcher failed; verify administrator configuration and retained state.", file=sys.stderr)
401
+ sys.exit(1)
@@ -0,0 +1,265 @@
1
+ import importlib.util
2
+ import os
3
+ import io
4
+ import fcntl
5
+ import json
6
+ import time
7
+ from types import SimpleNamespace
8
+ import subprocess
9
+ from pathlib import Path
10
+ import tempfile
11
+ import unittest
12
+ from unittest.mock import patch
13
+
14
+ spec = importlib.util.spec_from_file_location("launcher", Path(__file__).with_name("launcher.py"))
15
+ launcher = importlib.util.module_from_spec(spec)
16
+ spec.loader.exec_module(launcher)
17
+
18
+
19
+ class LauncherPolicyTests(unittest.TestCase):
20
+ def setUp(self):
21
+ self.temp = tempfile.TemporaryDirectory()
22
+ self.root = Path(self.temp.name)
23
+ self.identity = "a" * 64
24
+ self.config = {"workspace": str(self.root), "state": str(self.root),
25
+ "package_root": "/opt/convoy/node_modules/@useconvoy/cli", "installation_root": "/opt/convoy"}
26
+
27
+ def test_managed_credentials_are_bounded_and_cannot_inject_environment(self):
28
+ launcher.validate_credentials({"config": {"codexAuth": {"mode": "managed", "secret": "sentinel"}}})
29
+ for auth in [{"mode": "managed", "secret": "x" * 4097},
30
+ {"mode": "managed", "secret": "sentinel", "env": {"PATH": "/tmp"}},
31
+ {"mode": "disabled", "secret": "sentinel"},
32
+ {"mode": "unexpected"}]:
33
+ with self.assertRaises(ValueError):
34
+ launcher.validate_credentials({"config": {"codexAuth": auth}})
35
+
36
+ def tearDown(self):
37
+ self.temp.cleanup()
38
+
39
+ def test_connect_waiting_for_registry_lock_exits_on_owner_eof(self):
40
+ lock = os.open(self.root / "registry.lock", os.O_CREAT | os.O_RDWR, 0o600)
41
+ fcntl.flock(lock, fcntl.LOCK_EX)
42
+ source = str(Path(__file__).with_name("launcher.py"))
43
+ script = (
44
+ "import importlib.util,sys;"
45
+ f"s=importlib.util.spec_from_file_location('launcher',{source!r});"
46
+ "m=importlib.util.module_from_spec(s);s.loader.exec_module(m);"
47
+ f"m.load_config=lambda:{{'state':{str(self.root)!r}}};"
48
+ "sys.exit(m.main())"
49
+ )
50
+ child = subprocess.Popen(["python3", "-c", script], stdin=subprocess.PIPE,
51
+ stdout=subprocess.PIPE, stderr=subprocess.PIPE)
52
+ try:
53
+ child.stdin.write((json.dumps({"action": "connect", "identity": self.identity}) + "\n").encode())
54
+ child.stdin.flush()
55
+ time.sleep(0.15)
56
+ child.stdin.close()
57
+ try:
58
+ code = child.wait(timeout=1)
59
+ except subprocess.TimeoutExpired:
60
+ self.fail("Launcher remained blocked on registry.lock after owner EOF")
61
+ self.assertEqual(code, 0, child.stderr.read().decode())
62
+ finally:
63
+ if child.poll() is None:
64
+ child.kill()
65
+ child.wait()
66
+ child.stdout.close()
67
+ child.stderr.close()
68
+ os.close(lock)
69
+
70
+ def test_browser_system_fonts_are_read_only_and_no_display_socket_is_shared(self):
71
+ entry = {"identity": self.identity, "uid": 20001, "path": str(self.root / "a")}
72
+ with patch.object(launcher.Path, "exists", return_value=True):
73
+ args = launcher.sandbox_args(self.config, entry)
74
+ index = args.index("/etc/fonts")
75
+ self.assertEqual(args[index - 1:index + 2], ["--ro-bind", "/etc/fonts", "/etc/fonts"])
76
+ self.assertNotIn("/tmp/.X11-unix", args)
77
+
78
+ def test_failed_reuse_is_audited_again_without_flag(self):
79
+ target = self.root / "a"
80
+ target.mkdir()
81
+ (target / "original").write_text("private")
82
+ os.link(target / "original", target / "alias")
83
+ request = {"identity": self.identity, "path": str(target), "reuse": True}
84
+ registry = {}
85
+ with patch.object(launcher, "allocate_uid", return_value=os.getuid()), \
86
+ patch.object(launcher, "private_directory"), patch.object(launcher, "write_identity_files"), \
87
+ patch.object(launcher, "run_bounded"):
88
+ with self.assertRaisesRegex(ValueError, "hard-linked"):
89
+ launcher.add(self.config, registry, request)
90
+ with self.assertRaisesRegex(ValueError, "hard-linked"):
91
+ launcher.add(self.config, launcher.read_registry(self.config), {**request, "reuse": False})
92
+
93
+ def test_failed_clone_retains_clone_requirement_on_plain_retry(self):
94
+ target = self.root / "a"
95
+ request = {"identity": self.identity, "path": str(target), "clone": "https://example.com/repo.git"}
96
+ with patch.object(launcher, "private_directory", side_effect=lambda p, *a, **k: Path(p).mkdir(exist_ok=True)), \
97
+ patch.object(launcher, "write_identity_files"), patch.object(launcher, "run_bounded") as run:
98
+ run.side_effect = [None, ValueError("clone failed")]
99
+ with self.assertRaisesRegex(ValueError, "clone failed"):
100
+ launcher.add(self.config, {}, request)
101
+ run.reset_mock(side_effect=True)
102
+ launcher.add(self.config, launcher.read_registry(self.config), {"identity": self.identity, "path": str(target)})
103
+ self.assertEqual(run.call_count, 2)
104
+ self.assertIn(request["clone"], run.call_args.args[2])
105
+
106
+ def test_remove_revokes_execution_and_readd_restores_it(self):
107
+ entry = {"identity": self.identity, "uid": 20001, "path": str(self.root / "a"), "ready": True}
108
+ launcher.save_registry(self.config, {self.identity: entry})
109
+ request = {"action": "remove", "identity": self.identity}
110
+ with patch.object(launcher, "load_config", return_value=self.config), \
111
+ patch.object(launcher.sys, "argv", ["launcher"]), \
112
+ patch.object(launcher.sys, "stdin", SimpleNamespace(buffer=io.BytesIO(launcher.json.dumps(request).encode()))), \
113
+ patch("builtins.print"):
114
+ launcher.main()
115
+ with patch.object(launcher, "load_config", return_value=self.config), \
116
+ patch.object(launcher.sys, "argv", ["launcher", "shell", self.identity]), \
117
+ patch.object(launcher, "supervise") as supervise:
118
+ with self.assertRaisesRegex(ValueError, "registered|disabled"):
119
+ launcher.main()
120
+ supervise.assert_not_called()
121
+ with patch.object(launcher, "private_directory"):
122
+ restored = launcher.add(self.config, launcher.read_registry(self.config), request | {"path": entry["path"]})
123
+ self.assertTrue(restored["enabled"])
124
+ self.assertEqual(restored["uid"], entry["uid"])
125
+
126
+ def test_worker_pipe_stays_open_until_stop_without_terminating_bwrap(self):
127
+ entry = {"identity": self.identity, "uid": 20001, "path": str(self.root / "a")}
128
+ config = self.config | {"node": "/usr/bin/node", "cli": "/cli.js", "verified_runtimes": ["codex"]}
129
+ pipe = io.BytesIO()
130
+ observed = []
131
+ with patch.object(launcher, "private_directory"), patch.object(launcher, "write_identity_files"), \
132
+ patch.object(launcher.pwd, "getpwall", return_value=[]), patch.object(launcher.grp, "getgrall", return_value=[]), \
133
+ patch.object(launcher.signal, "signal"), patch.object(launcher.os, "read", return_value=b""), \
134
+ patch.object(launcher.selectors, "DefaultSelector") as selector, \
135
+ patch.object(launcher.subprocess, "Popen") as spawn:
136
+ child = spawn.return_value
137
+ child.stdin = pipe
138
+ statuses = iter([None, 0, 0])
139
+ child.poll.side_effect = lambda: (observed.append(pipe.closed), next(statuses))[1]
140
+ child.returncode = 0
141
+ selector.return_value.select.return_value = [True]
142
+ launcher.supervise(config, entry, {"config": {}})
143
+ self.assertFalse(observed[0])
144
+ self.assertTrue(pipe.closed)
145
+ child.terminate.assert_not_called()
146
+ self.assertTrue(spawn.call_args.kwargs.get("start_new_session"))
147
+
148
+ def test_private_shell_has_job_control_in_a_detached_session(self):
149
+ entry = {"identity": self.identity, "uid": 20001, "path": str(self.root / "a")}
150
+ with patch.object(launcher, "private_directory"), patch.object(launcher, "write_identity_files"), \
151
+ patch.object(launcher, "sandbox_args", return_value=[]), \
152
+ patch.object(launcher.pwd, "getpwall", return_value=[]), \
153
+ patch.object(launcher.grp, "getgrall", return_value=[]), \
154
+ patch.object(launcher.signal, "signal"), patch.object(launcher.subprocess, "Popen") as spawn:
155
+ spawn.return_value.poll.return_value = 0
156
+ spawn.return_value.returncode = 0
157
+ launcher.supervise(self.config, entry, {}, shell=True)
158
+ command = spawn.call_args.args[0]
159
+ result = subprocess.run(command, input="set -o\nexit\n", capture_output=True,
160
+ text=True, start_new_session=True, env=launcher.SAFE_ENV, timeout=10)
161
+ self.assertEqual(result.returncode, 0, result.stderr)
162
+ self.assertRegex(result.stdout, r"monitor\s+on")
163
+ self.assertNotIn("no job control", result.stdout + result.stderr)
164
+
165
+ def test_registry_persists_private_atomic_snapshots(self):
166
+ registry = {self.identity: {"uid": 20001, "path": str(self.root / "a"), "ready": False}}
167
+ launcher.save_registry(self.config, registry)
168
+ file = self.root / "registry.json"
169
+ self.assertEqual(launcher.read_registry(self.config), registry)
170
+ self.assertEqual(file.stat().st_mode & 0o777, 0o600)
171
+ with file.open() as previous:
172
+ registry[self.identity]["ready"] = True
173
+ launcher.save_registry(self.config, registry)
174
+ self.assertFalse(launcher.json.load(previous)[self.identity]["ready"])
175
+ self.assertEqual(launcher.read_registry(self.config), registry)
176
+ self.assertEqual(file.stat().st_mode & 0o777, 0o600)
177
+ self.assertFalse((self.root / "registry.tmp").exists())
178
+
179
+ def test_paths_reject_traversal_symlinks_and_reserved_worktrees(self):
180
+ (self.root / "link").symlink_to("/tmp")
181
+ for name in ["../escape", "link", "a-worktrees", "a/../b", ".", "nested/child"]:
182
+ with self.subTest(name=name), self.assertRaises(ValueError):
183
+ launcher.validate_target(self.config, {}, self.identity, str(self.root) + "/" + name)
184
+ target = str(self.root / "a")
185
+ self.assertEqual(launcher.validate_target(self.config, {}, self.identity, target), Path(target))
186
+ registry = {"b" * 64: {"path": target, "uid": 20000}}
187
+ with self.assertRaises(ValueError):
188
+ launcher.validate_target(self.config, registry, self.identity, target)
189
+
190
+ def test_same_project_keeps_uid_and_path(self):
191
+ registry = {self.identity: {"uid": 20001, "path": str(self.root / "a")}}
192
+ self.assertEqual(launcher.allocate_uid(registry, self.identity), 20001)
193
+ with self.assertRaises(ValueError):
194
+ launcher.validate_target(self.config, registry, self.identity, str(self.root / "b"))
195
+
196
+ def test_retained_uid_collision_fails_before_preparation(self):
197
+ registry = {self.identity: {"uid": 20001, "path": str(self.root / "a")}}
198
+ account = type("Account", (), {"pw_uid": 20001})()
199
+ with patch.object(launcher.pwd, "getpwall", return_value=[account]):
200
+ with self.assertRaisesRegex(ValueError, "system account"):
201
+ launcher.allocate_uid(registry, self.identity)
202
+
203
+ def test_matching_clone_add_is_idempotent(self):
204
+ entry = {"identity": self.identity, "uid": 20001, "path": str(self.root / "a"),
205
+ "ready": True, "clone": "https://example.com/repo.git"}
206
+ with patch.object(launcher, "private_directory"):
207
+ self.assertEqual(launcher.add(self.config, {self.identity: entry}, {
208
+ "identity": self.identity, "path": entry["path"], "clone": entry["clone"],
209
+ }), entry)
210
+
211
+ def test_private_shell_can_find_the_prefix_installed_cli(self):
212
+ entry = {"identity": self.identity, "uid": 20001, "path": str(self.root / "a")}
213
+ args = launcher.sandbox_args(self.config, entry)
214
+ self.assertIn("/opt/convoy/node_modules/.bin", args[args.index("PATH") + 1].split(":"))
215
+
216
+ def test_project_has_private_passwd_and_group_records(self):
217
+ entry = {"identity": self.identity, "uid": 20001, "path": str(self.root / "a")}
218
+ args = launcher.sandbox_args(self.config, entry)
219
+ self.assertIn(str(self.root / (self.identity + ".passwd")), args)
220
+ self.assertIn(str(self.root / (self.identity + ".group")), args)
221
+
222
+ def test_exclusive_lease_and_recovery_after_close(self):
223
+ fd = launcher.lock_file(self.config, self.identity + ".lease", True)
224
+ try:
225
+ self.assertTrue(launcher.is_active(self.config, self.identity))
226
+ with self.assertRaisesRegex(ValueError, "active"):
227
+ launcher.lock_file(self.config, self.identity + ".lease", True)
228
+ finally:
229
+ os.close(fd)
230
+ self.assertFalse(launcher.is_active(self.config, self.identity))
231
+
232
+ def test_boundary_does_not_mount_control_home_root_or_sockets(self):
233
+ entry = {"identity": self.identity, "uid": 20001, "path": str(self.root / "a")}
234
+ args = launcher.sandbox_args(self.config, entry)
235
+ for flag in ["--unshare-user", "--unshare-pid", "--unshare-ipc", "--die-with-parent", "--clearenv", "--new-session"]:
236
+ self.assertIn(flag, args)
237
+ self.assertNotIn("/", args)
238
+ self.assertNotIn("/home/node", args)
239
+ self.assertNotIn("/var/run/docker.sock", args)
240
+ self.assertNotIn("--unshare-net", args)
241
+ self.assertIn("/home/convoy", args)
242
+ self.assertIn(entry["path"] + "-worktrees", args)
243
+
244
+ def test_reuse_rejects_hardlinks(self):
245
+ directory = self.root / "a"
246
+ directory.mkdir()
247
+ (directory / "original").write_text("private")
248
+ os.link(directory / "original", directory / "alias")
249
+ with self.assertRaisesRegex(ValueError, "hard-linked"):
250
+ launcher.audit_tree(directory, os.getuid())
251
+
252
+ def test_privilege_drop_clears_groups_before_uid_and_sets_no_new_privs(self):
253
+ with patch.object(launcher.os, "setgroups") as groups, patch.object(launcher.os, "setgid") as gid, \
254
+ patch.object(launcher.os, "setuid") as uid, patch.object(launcher.ctypes, "CDLL") as libc, \
255
+ patch.object(launcher.os, "umask"):
256
+ libc.return_value.prctl.return_value = 0
257
+ launcher.drop_privileges(20001)
258
+ groups.assert_called_once_with([])
259
+ gid.assert_called_once_with(20001)
260
+ uid.assert_called_once_with(20001)
261
+ libc.return_value.prctl.assert_called_once_with(38, 1, 0, 0, 0)
262
+
263
+
264
+ if __name__ == "__main__":
265
+ unittest.main()