@useconvoy/cli 0.63.0 → 0.89.0
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.
- package/README.md +98 -0
- package/dist/bin/convoy.js +13 -1
- package/dist/bin/convoy.js.map +1 -1
- package/dist/src/agent/app/chunk-scrub.js +12 -0
- package/dist/src/agent/app/chunk-scrub.js.map +1 -1
- package/dist/src/agent/app/runner.d.ts +2 -0
- package/dist/src/agent/app/runner.js +2 -1
- package/dist/src/agent/app/runner.js.map +1 -1
- package/dist/src/agent/app/thread-processor.d.ts +1 -1
- package/dist/src/agent/app/thread-processor.js +46 -14
- package/dist/src/agent/app/thread-processor.js.map +1 -1
- package/dist/src/agent/app/worktree-op-processor.js +50 -5
- package/dist/src/agent/app/worktree-op-processor.js.map +1 -1
- package/dist/src/agent/runtimes/claudeCode/interactions.d.ts +6 -2
- package/dist/src/agent/runtimes/claudeCode/interactions.js +36 -0
- package/dist/src/agent/runtimes/claudeCode/interactions.js.map +1 -1
- package/dist/src/agent/runtimes/claudeCode/models.d.ts +1 -1
- package/dist/src/agent/runtimes/claudeCode/models.js +2 -0
- package/dist/src/agent/runtimes/claudeCode/models.js.map +1 -1
- package/dist/src/agent/runtimes/claudeCode/runner.js +132 -57
- package/dist/src/agent/runtimes/claudeCode/runner.js.map +1 -1
- package/dist/src/agent/runtimes/claudeCode/runtime.js +7 -0
- package/dist/src/agent/runtimes/claudeCode/runtime.js.map +1 -1
- package/dist/src/agent/runtimes/claudeCode/usage/errors.d.ts +3 -0
- package/dist/src/agent/runtimes/claudeCode/usage/errors.js +4 -0
- package/dist/src/agent/runtimes/claudeCode/usage/errors.js.map +1 -0
- package/dist/src/agent/runtimes/claudeCode/usage/index.d.ts +4 -0
- package/dist/src/agent/runtimes/claudeCode/usage/index.js +44 -0
- package/dist/src/agent/runtimes/claudeCode/usage/index.js.map +1 -0
- package/dist/src/agent/runtimes/claudeCode/usage/parsers.d.ts +7 -0
- package/dist/src/agent/runtimes/claudeCode/usage/parsers.js +84 -0
- package/dist/src/agent/runtimes/claudeCode/usage/parsers.js.map +1 -0
- package/dist/src/agent/runtimes/claudeCode/usage/validators.d.ts +25 -0
- package/dist/src/agent/runtimes/claudeCode/usage/validators.js +2 -0
- package/dist/src/agent/runtimes/claudeCode/usage/validators.js.map +1 -0
- package/dist/src/agent/runtimes/codex/app-server-runner.d.ts +4 -0
- package/dist/src/agent/runtimes/codex/app-server-runner.js +115 -57
- package/dist/src/agent/runtimes/codex/app-server-runner.js.map +1 -1
- package/dist/src/agent/runtimes/codex/auth.d.ts +9 -0
- package/dist/src/agent/runtimes/codex/auth.js +90 -0
- package/dist/src/agent/runtimes/codex/auth.js.map +1 -0
- package/dist/src/agent/runtimes/codex/commands.d.ts +1 -1
- package/dist/src/agent/runtimes/codex/commands.js +1 -1
- package/dist/src/agent/runtimes/codex/commands.js.map +1 -1
- package/dist/src/agent/runtimes/codex/errors.d.ts +7 -0
- package/dist/src/agent/runtimes/codex/errors.js +60 -0
- package/dist/src/agent/runtimes/codex/errors.js.map +1 -0
- package/dist/src/agent/runtimes/codex/interactions.js +2 -52
- package/dist/src/agent/runtimes/codex/interactions.js.map +1 -1
- package/dist/src/agent/runtimes/codex/lifecycle.d.ts +12 -1
- package/dist/src/agent/runtimes/codex/lifecycle.js +97 -6
- package/dist/src/agent/runtimes/codex/lifecycle.js.map +1 -1
- package/dist/src/agent/runtimes/codex/runner.js +6 -0
- package/dist/src/agent/runtimes/codex/runner.js.map +1 -1
- package/dist/src/agent/runtimes/codex/runtime.js +2 -1
- package/dist/src/agent/runtimes/codex/runtime.js.map +1 -1
- package/dist/src/agent/runtimes/codex/usage/index.d.ts +7 -0
- package/dist/src/agent/runtimes/codex/usage/index.js +63 -0
- package/dist/src/agent/runtimes/codex/usage/index.js.map +1 -0
- package/dist/src/agent/runtimes/codex/usage/parsers.d.ts +6 -0
- package/dist/src/agent/runtimes/codex/usage/parsers.js +58 -0
- package/dist/src/agent/runtimes/codex/usage/parsers.js.map +1 -0
- package/dist/src/agent/runtimes/codex/usage/validators.d.ts +16 -0
- package/dist/src/agent/runtimes/codex/usage/validators.js +2 -0
- package/dist/src/agent/runtimes/codex/usage/validators.js.map +1 -0
- package/dist/src/agent/runtimes/contracts.d.ts +10 -0
- package/dist/src/agent/runtimes/contracts.js +2 -0
- package/dist/src/agent/runtimes/contracts.js.map +1 -1
- package/dist/src/agent/runtimes/cursor/models.js +2 -0
- package/dist/src/agent/runtimes/cursor/models.js.map +1 -1
- package/dist/src/agent/runtimes/message-format.js +3 -1
- package/dist/src/agent/runtimes/message-format.js.map +1 -1
- package/dist/src/agent/runtimes/registry.js +17 -1
- package/dist/src/agent/runtimes/registry.js.map +1 -1
- package/dist/src/agent/runtimes/validators.d.ts +4 -0
- package/dist/src/agent/runtimes/validators.js +101 -0
- package/dist/src/agent/runtimes/validators.js.map +1 -0
- package/dist/src/cli.js +10 -0
- package/dist/src/cli.js.map +1 -1
- package/dist/src/commands/browser/command.d.ts +2 -0
- package/dist/src/commands/browser/command.js +42 -0
- package/dist/src/commands/browser/command.js.map +1 -0
- package/dist/src/commands/browser/smoke.d.ts +10 -0
- package/dist/src/commands/browser/smoke.js +67 -0
- package/dist/src/commands/browser/smoke.js.map +1 -0
- package/dist/src/commands/browser/validators.d.ts +18 -0
- package/dist/src/commands/browser/validators.js +2 -0
- package/dist/src/commands/browser/validators.js.map +1 -0
- package/dist/src/commands/browser/workflow.d.ts +4 -0
- package/dist/src/commands/browser/workflow.js +86 -0
- package/dist/src/commands/browser/workflow.js.map +1 -0
- package/dist/src/commands/connect/command.js +1 -0
- package/dist/src/commands/connect/command.js.map +1 -1
- package/dist/src/commands/connect/workflow.d.ts +7 -0
- package/dist/src/commands/connect/workflow.js +68 -4
- package/dist/src/commands/connect/workflow.js.map +1 -1
- package/dist/src/commands/devcontainer/command.js +3 -1
- package/dist/src/commands/devcontainer/command.js.map +1 -1
- package/dist/src/commands/devcontainer/install.d.ts +1 -0
- package/dist/src/commands/devcontainer/install.js +17 -7
- package/dist/src/commands/devcontainer/install.js.map +1 -1
- package/dist/src/commands/environment/command.d.ts +5 -0
- package/dist/src/commands/environment/command.js +123 -0
- package/dist/src/commands/environment/command.js.map +1 -0
- package/dist/src/commands/environment/docker.d.ts +13 -0
- package/dist/src/commands/environment/docker.js +65 -0
- package/dist/src/commands/environment/docker.js.map +1 -0
- package/dist/src/commands/environment/index.d.ts +60 -0
- package/dist/src/commands/environment/index.js +36 -0
- package/dist/src/commands/environment/index.js.map +1 -0
- package/dist/src/commands/environment/paths.d.ts +6 -0
- package/dist/src/commands/environment/paths.js +58 -0
- package/dist/src/commands/environment/paths.js.map +1 -0
- package/dist/src/commands/environment/projects.d.ts +3 -0
- package/dist/src/commands/environment/projects.js +46 -0
- package/dist/src/commands/environment/projects.js.map +1 -0
- package/dist/src/commands/environment/resolution.d.ts +11 -0
- package/dist/src/commands/environment/resolution.js +4 -0
- package/dist/src/commands/environment/resolution.js.map +1 -0
- package/dist/src/commands/environment/setup-entrypoint.d.ts +1 -0
- package/dist/src/commands/environment/setup-entrypoint.js +17 -0
- package/dist/src/commands/environment/setup-entrypoint.js.map +1 -0
- package/dist/src/commands/environment/validators.d.ts +65 -0
- package/dist/src/commands/environment/validators.js +36 -0
- package/dist/src/commands/environment/validators.js.map +1 -0
- package/dist/src/commands/environment/workflow.d.ts +48 -0
- package/dist/src/commands/environment/workflow.js +172 -0
- package/dist/src/commands/environment/workflow.js.map +1 -0
- package/dist/src/commands/keys/command.js +99 -13
- package/dist/src/commands/keys/command.js.map +1 -1
- package/dist/src/commands/keys/workflow.d.ts +68 -0
- package/dist/src/commands/keys/workflow.js +147 -0
- package/dist/src/commands/keys/workflow.js.map +1 -0
- package/dist/src/commands/project/command.d.ts +2 -0
- package/dist/src/commands/project/command.js +53 -0
- package/dist/src/commands/project/command.js.map +1 -0
- package/dist/src/commands/project/launcher.d.ts +44 -0
- package/dist/src/commands/project/launcher.js +100 -0
- package/dist/src/commands/project/launcher.js.map +1 -0
- package/dist/src/commands/project/validators.d.ts +87 -0
- package/dist/src/commands/project/validators.js +53 -0
- package/dist/src/commands/project/validators.js.map +1 -0
- package/dist/src/commands/project/worker.d.ts +2 -0
- package/dist/src/commands/project/worker.js +90 -0
- package/dist/src/commands/project/worker.js.map +1 -0
- package/dist/src/commands/project/workflow.d.ts +47 -0
- package/dist/src/commands/project/workflow.js +238 -0
- package/dist/src/commands/project/workflow.js.map +1 -0
- package/dist/src/commands/service/attach.d.ts +3 -0
- package/dist/src/commands/service/attach.js +155 -0
- package/dist/src/commands/service/attach.js.map +1 -0
- package/dist/src/commands/service/bridge.d.ts +3 -0
- package/dist/src/commands/service/bridge.js +105 -0
- package/dist/src/commands/service/bridge.js.map +1 -0
- package/dist/src/commands/service/client.d.ts +26 -0
- package/dist/src/commands/service/client.js +154 -0
- package/dist/src/commands/service/client.js.map +1 -0
- package/dist/src/commands/service/command.d.ts +3 -0
- package/dist/src/commands/service/command.js +186 -0
- package/dist/src/commands/service/command.js.map +1 -0
- package/dist/src/commands/service/errors.d.ts +9 -0
- package/dist/src/commands/service/errors.js +13 -0
- package/dist/src/commands/service/errors.js.map +1 -0
- package/dist/src/commands/service/formatters.d.ts +5 -0
- package/dist/src/commands/service/formatters.js +58 -0
- package/dist/src/commands/service/formatters.js.map +1 -0
- package/dist/src/commands/service/logs.d.ts +19 -0
- package/dist/src/commands/service/logs.js +64 -0
- package/dist/src/commands/service/logs.js.map +1 -0
- package/dist/src/commands/service/output.d.ts +18 -0
- package/dist/src/commands/service/output.js +60 -0
- package/dist/src/commands/service/output.js.map +1 -0
- package/dist/src/commands/service/parsers.d.ts +4 -0
- package/dist/src/commands/service/parsers.js +41 -0
- package/dist/src/commands/service/parsers.js.map +1 -0
- package/dist/src/commands/service/paths.d.ts +7 -0
- package/dist/src/commands/service/paths.js +44 -0
- package/dist/src/commands/service/paths.js.map +1 -0
- package/dist/src/commands/service/resolution.d.ts +5 -0
- package/dist/src/commands/service/resolution.js +36 -0
- package/dist/src/commands/service/resolution.js.map +1 -0
- package/dist/src/commands/service/runs.d.ts +3 -0
- package/dist/src/commands/service/runs.js +58 -0
- package/dist/src/commands/service/runs.js.map +1 -0
- package/dist/src/commands/service/server.d.ts +7 -0
- package/dist/src/commands/service/server.js +206 -0
- package/dist/src/commands/service/server.js.map +1 -0
- package/dist/src/commands/service/service-entrypoint.d.ts +1 -0
- package/dist/src/commands/service/service-entrypoint.js +32 -0
- package/dist/src/commands/service/service-entrypoint.js.map +1 -0
- package/dist/src/commands/service/validators.d.ts +257 -0
- package/dist/src/commands/service/validators.js +48 -0
- package/dist/src/commands/service/validators.js.map +1 -0
- package/dist/src/commands/service/workflow.d.ts +12 -0
- package/dist/src/commands/service/workflow.js +355 -0
- package/dist/src/commands/service/workflow.js.map +1 -0
- package/dist/src/commands/setup/command.js +5 -0
- package/dist/src/commands/setup/command.js.map +1 -1
- package/dist/src/commands/setup/prompts.d.ts +1 -1
- package/dist/src/commands/setup/prompts.js +3 -1
- package/dist/src/commands/setup/prompts.js.map +1 -1
- package/dist/src/commands/setup/resolution.d.ts +14 -0
- package/dist/src/commands/setup/resolution.js +87 -0
- package/dist/src/commands/setup/resolution.js.map +1 -0
- package/dist/src/commands/setup/validators.d.ts +15 -0
- package/dist/src/commands/setup/validators.js +15 -0
- package/dist/src/commands/setup/validators.js.map +1 -0
- package/dist/src/commands/setup/workflow.d.ts +3 -1
- package/dist/src/commands/setup/workflow.js +56 -47
- package/dist/src/commands/setup/workflow.js.map +1 -1
- package/dist/src/commands/tasks/attachments/transfer.js +5 -20
- package/dist/src/commands/tasks/attachments/transfer.js.map +1 -1
- package/dist/src/commands/threads/done.d.ts +2 -0
- package/dist/src/commands/threads/done.js +20 -0
- package/dist/src/commands/threads/done.js.map +1 -0
- package/dist/src/commands/threads/index.js +3 -1
- package/dist/src/commands/threads/index.js.map +1 -1
- package/dist/src/convex/_generated/api.d.ts +2 -0
- package/dist/src/lib/config/convex-client.d.ts +5 -0
- package/dist/src/lib/config/convex-client.js +27 -1
- package/dist/src/lib/config/convex-client.js.map +1 -1
- package/dist/src/lib/config/credentials/resolution.d.ts +11 -0
- package/dist/src/lib/config/credentials/resolution.js +101 -0
- package/dist/src/lib/config/credentials/resolution.js.map +1 -0
- package/dist/src/lib/config/credentials/store.d.ts +9 -0
- package/dist/src/lib/config/credentials/store.js +147 -0
- package/dist/src/lib/config/credentials/store.js.map +1 -0
- package/dist/src/lib/config/credentials/validators.d.ts +152 -0
- package/dist/src/lib/config/credentials/validators.js +87 -0
- package/dist/src/lib/config/credentials/validators.js.map +1 -0
- package/dist/src/lib/config/index.d.ts +1 -1
- package/dist/src/lib/config/index.js +1 -1
- package/dist/src/lib/config/index.js.map +1 -1
- package/dist/src/lib/config/toml.d.ts +4 -4
- package/dist/src/lib/config/toml.js +149 -83
- package/dist/src/lib/config/toml.js.map +1 -1
- package/dist/src/lib/config/types.d.ts +8 -0
- package/dist/src/lib/config/types.js +5 -0
- package/dist/src/lib/config/types.js.map +1 -1
- package/dist/src/lib/connect-events.d.ts +5 -0
- package/dist/src/lib/connect-events.js.map +1 -1
- package/dist/src/lib/git/checkpoint.d.ts +19 -3
- package/dist/src/lib/git/checkpoint.js +58 -25
- package/dist/src/lib/git/checkpoint.js.map +1 -1
- package/dist/src/lib/git/exec.js +6 -0
- package/dist/src/lib/git/exec.js.map +1 -1
- package/dist/src/lib/git/index.d.ts +1 -0
- package/dist/src/lib/git/index.js +1 -0
- package/dist/src/lib/git/index.js.map +1 -1
- package/dist/src/lib/git/working-tree.d.ts +21 -0
- package/dist/src/lib/git/working-tree.js +90 -0
- package/dist/src/lib/git/working-tree.js.map +1 -0
- package/dist/src/lib/git/worktrees.d.ts +1 -1
- package/dist/src/lib/git/worktrees.js +4 -2
- package/dist/src/lib/git/worktrees.js.map +1 -1
- package/dist/src/lib/storage-upload.d.ts +10 -0
- package/dist/src/lib/storage-upload.js +21 -0
- package/dist/src/lib/storage-upload.js.map +1 -0
- package/dist/src/lib/thread-attachments.js +6 -27
- package/dist/src/lib/thread-attachments.js.map +1 -1
- package/dist/templates/devcontainer/Dockerfile +7 -0
- package/dist/templates/devcontainer/README.md +17 -0
- package/dist/templates/project-isolation/Dockerfile +28 -0
- package/dist/templates/project-isolation/README.md +206 -0
- package/dist/templates/project-isolation/devcontainer.json +20 -0
- package/dist/templates/project-isolation/environment.py +257 -0
- package/dist/templates/project-isolation/environment.test.py +156 -0
- package/dist/templates/project-isolation/install.py +69 -0
- package/dist/templates/project-isolation/launcher.py +401 -0
- package/dist/templates/project-isolation/launcher.test.py +265 -0
- package/dist/templates/project-isolation/seccomp-source.md +20 -0
- package/dist/templates/project-isolation/seccomp.LICENSE +202 -0
- package/dist/templates/project-isolation/seccomp.json +1173 -0
- package/dist/templates/project-isolation/start.sh +8 -0
- package/package.json +5 -3
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
#!/usr/bin/python3 -I
|
|
2
|
+
"""Administrator installation; never invoked by a project worker."""
|
|
3
|
+
import argparse
|
|
4
|
+
import json
|
|
5
|
+
import os
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
import pwd
|
|
8
|
+
import re
|
|
9
|
+
import shutil
|
|
10
|
+
import sys
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def main():
|
|
14
|
+
parser = argparse.ArgumentParser()
|
|
15
|
+
parser.add_argument("--control-user", required=True)
|
|
16
|
+
parser.add_argument("--workspace", required=True)
|
|
17
|
+
parser.add_argument("--package-root", required=True)
|
|
18
|
+
parser.add_argument("--node", default="/usr/local/bin/node")
|
|
19
|
+
parser.add_argument("--state", default="/var/lib/convoy-projects")
|
|
20
|
+
args = parser.parse_args()
|
|
21
|
+
if os.geteuid() != 0:
|
|
22
|
+
parser.error("Administrator installation requires root")
|
|
23
|
+
if not re.fullmatch(r"[a-z_][a-z0-9_-]*", args.control_user):
|
|
24
|
+
parser.error("Invalid control account")
|
|
25
|
+
account = pwd.getpwnam(args.control_user)
|
|
26
|
+
if account.pw_uid == 0:
|
|
27
|
+
parser.error("The control account must be unprivileged")
|
|
28
|
+
package = Path(args.package_root).resolve(strict=True)
|
|
29
|
+
cli = package / "dist/src/commands/project/worker.js"
|
|
30
|
+
if not cli.is_file():
|
|
31
|
+
parser.error("Install/build the Convoy CLI package first")
|
|
32
|
+
for root in [package, Path(args.node).resolve(strict=True)]:
|
|
33
|
+
for item in [root, *root.parents]:
|
|
34
|
+
info = item.stat()
|
|
35
|
+
if info.st_uid != 0 or info.st_mode & 0o022:
|
|
36
|
+
parser.error("CLI, Node and their parent directories must be root-owned without group/world writes")
|
|
37
|
+
workspace = Path(args.workspace).resolve(strict=True)
|
|
38
|
+
state = Path(args.state)
|
|
39
|
+
state.mkdir(mode=0o711, parents=True, exist_ok=True)
|
|
40
|
+
if state.is_symlink() or state.stat().st_uid != 0 or state.stat().st_mode & 0o022:
|
|
41
|
+
parser.error("State must be a root-owned directory without group/world writes")
|
|
42
|
+
launcher = Path("/usr/local/libexec/convoy-project-launcher")
|
|
43
|
+
launcher.parent.mkdir(mode=0o755, exist_ok=True)
|
|
44
|
+
shutil.copyfile(Path(__file__).with_name("launcher.py"), launcher)
|
|
45
|
+
launcher.chmod(0o755)
|
|
46
|
+
config_file = Path("/etc/convoy-projects.json")
|
|
47
|
+
config = {"control_uid": account.pw_uid, "workspace": str(workspace), "state": str(state.resolve()),
|
|
48
|
+
"package_root": str(package), "cli": str(cli), "node": str(Path(args.node).resolve()),
|
|
49
|
+
"installation_root": str(package.parents[2]) if package.parent.name == "@useconvoy" and package.parent.parent.name == "node_modules" else str(package),
|
|
50
|
+
"verified_runtimes": []}
|
|
51
|
+
if config_file.exists():
|
|
52
|
+
old = json.loads(config_file.read_text())
|
|
53
|
+
if any(old.get(key) != value for key, value in config.items() if key != "verified_runtimes"):
|
|
54
|
+
parser.error("An environment is already configured differently; perform an explicit administrator migration")
|
|
55
|
+
config["verified_runtimes"] = old.get("verified_runtimes", [])
|
|
56
|
+
config_file.write_text(json.dumps(config, indent=2) + "\n")
|
|
57
|
+
config_file.chmod(0o600)
|
|
58
|
+
sudoers = Path("/etc/sudoers.d/convoy-projects")
|
|
59
|
+
sudoers.write_text(f"{args.control_user} ALL=(root) NOPASSWD: {launcher}\n")
|
|
60
|
+
sudoers.chmod(0o440)
|
|
61
|
+
print("Project launcher installed. Complete the acceptance procedure before enabling runtime execution.")
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
if __name__ == "__main__":
|
|
65
|
+
try:
|
|
66
|
+
main()
|
|
67
|
+
except (OSError, KeyError, ValueError):
|
|
68
|
+
print("Installation failed. Check the administrator paths and account.", file=sys.stderr)
|
|
69
|
+
sys.exit(1)
|
|
@@ -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)
|