crewaid-selfhost 0.0.4 → 0.1.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.
- package/assets/compose.yml +73 -7
- package/package.json +1 -1
- package/src/cli.mjs +11 -3
- package/src/env.mjs +1 -1
- package/src/secrets.mjs +9 -0
package/assets/compose.yml
CHANGED
|
@@ -76,11 +76,64 @@ services:
|
|
|
76
76
|
networks:
|
|
77
77
|
- sandboxes
|
|
78
78
|
|
|
79
|
+
# The one service with the Docker socket (D-200). It starts, stops and
|
|
80
|
+
# removes computers for the orchestrator and refuses anything else: only the
|
|
81
|
+
# sandbox image, only the sandbox network, only a bot's own workspace volume,
|
|
82
|
+
# and only within these limits. It answers on the private `control` network
|
|
83
|
+
# alone, to requests signed with SANDBOX_SUPERVISOR_SECRET, and is never
|
|
84
|
+
# published. Same image as the orchestrator, a different program.
|
|
85
|
+
sandbox-supervisor:
|
|
86
|
+
image: ghcr.io/natanael-exe/crewaid-orchestrator:${CREWAID_VERSION:?Set CREWAID_VERSION to a release, e.g. 0.1.0}
|
|
87
|
+
restart: unless-stopped
|
|
88
|
+
environment:
|
|
89
|
+
NODE_ENV: production
|
|
90
|
+
SANDBOX_SUPERVISOR_SECRET: ${SANDBOX_SUPERVISOR_SECRET:?Set SANDBOX_SUPERVISOR_SECRET (openssl rand -hex 32)}
|
|
91
|
+
# Only during a rotation: the secret the orchestrator may still be using.
|
|
92
|
+
SANDBOX_SUPERVISOR_SECRET_PREVIOUS: ${SANDBOX_SUPERVISOR_SECRET_PREVIOUS:-}
|
|
93
|
+
SANDBOX_SUPERVISOR_HOST: 0.0.0.0
|
|
94
|
+
SANDBOX_SUPERVISOR_PORT: '7300'
|
|
95
|
+
SANDBOX_IMAGE: ghcr.io/natanael-exe/crewaid-sandbox:${CREWAID_VERSION}
|
|
96
|
+
SANDBOX_NETWORK: crewaid-sandboxes
|
|
97
|
+
# Nothing is published: the orchestrator reaches a computer's screen,
|
|
98
|
+
# DevTools and bridge at the computer's own address on the sandbox
|
|
99
|
+
# network, which it joins below — the one address the fence lets in.
|
|
100
|
+
# (Docker Desktop cannot publish on a bridge gateway.)
|
|
101
|
+
SANDBOX_CONNECT: network
|
|
102
|
+
# Starts no computer before the egress fence has installed its policy.
|
|
103
|
+
command:
|
|
104
|
+
- /bin/sh
|
|
105
|
+
- -ec
|
|
106
|
+
- |
|
|
107
|
+
until [ -e /run/crewaid/egress-ready ]; do sleep 2; done
|
|
108
|
+
exec node packages/sandbox-supervisor/dist/main.js
|
|
109
|
+
healthcheck:
|
|
110
|
+
test:
|
|
111
|
+
[
|
|
112
|
+
'CMD',
|
|
113
|
+
'node',
|
|
114
|
+
'-e',
|
|
115
|
+
"fetch('http://127.0.0.1:7300/v1/health').then((r) => process.exit(r.ok ? 0 : 1), () => process.exit(1))",
|
|
116
|
+
]
|
|
117
|
+
interval: 5s
|
|
118
|
+
timeout: 5s
|
|
119
|
+
retries: 30
|
|
120
|
+
networks:
|
|
121
|
+
- control
|
|
122
|
+
volumes:
|
|
123
|
+
- /var/run/docker.sock:/var/run/docker.sock
|
|
124
|
+
- egress-state:/run/crewaid:ro
|
|
125
|
+
depends_on:
|
|
126
|
+
networks-ready:
|
|
127
|
+
condition: service_completed_successfully
|
|
128
|
+
|
|
79
129
|
orchestrator:
|
|
80
130
|
image: ghcr.io/natanael-exe/crewaid-orchestrator:${CREWAID_VERSION:?Set CREWAID_VERSION to a release, e.g. 0.1.0}
|
|
81
131
|
restart: unless-stopped
|
|
82
132
|
environment:
|
|
83
133
|
CREWAID_EDITION: selfhosted
|
|
134
|
+
SEAT_CONTROL_DRAIN_MS: ${SEAT_CONTROL_DRAIN_MS:-5000}
|
|
135
|
+
SEAT_CONTROL_LEASE_MS: ${SEAT_CONTROL_LEASE_MS:-30000}
|
|
136
|
+
SEAT_CONTROL_AGENT_WAIT_MS: ${SEAT_CONTROL_AGENT_WAIT_MS:-120000}
|
|
84
137
|
NODE_ENV: production
|
|
85
138
|
PORT: '3000'
|
|
86
139
|
DATABASE_URL: postgresql://crewaid:${POSTGRES_PASSWORD}@postgres:5432/crewaid?schema=public
|
|
@@ -91,14 +144,19 @@ services:
|
|
|
91
144
|
CREWAID_CREDENTIAL_KEYRING: ${CREWAID_CREDENTIAL_KEYRING:?Set CREWAID_CREDENTIAL_KEYRING}
|
|
92
145
|
CREDENTIAL_KEY: ${CREDENTIAL_KEY:?Set CREDENTIAL_KEY}
|
|
93
146
|
ARTIFACT_DIR: /var/lib/crewaid/artifacts
|
|
147
|
+
# D-220: optional. Set all four to keep files in R2 instead of the
|
|
148
|
+
# artifacts volume; set none to keep them on this host.
|
|
149
|
+
ARTIFACT_R2_ACCOUNT_ID: ${ARTIFACT_R2_ACCOUNT_ID:-}
|
|
150
|
+
ARTIFACT_R2_ACCESS_KEY_ID: ${ARTIFACT_R2_ACCESS_KEY_ID:-}
|
|
151
|
+
ARTIFACT_R2_SECRET_ACCESS_KEY: ${ARTIFACT_R2_SECRET_ACCESS_KEY:-}
|
|
152
|
+
ARTIFACT_R2_BUCKET: ${ARTIFACT_R2_BUCKET:-}
|
|
94
153
|
SANDBOX_PROVIDER: docker
|
|
154
|
+
# Must match the supervisor's: it refuses any other image or network.
|
|
95
155
|
SANDBOX_IMAGE: ghcr.io/natanael-exe/crewaid-sandbox:${CREWAID_VERSION}
|
|
96
156
|
SANDBOX_NETWORK: crewaid-sandboxes
|
|
97
|
-
#
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
# cannot publish on a bridge gateway, and this needs no published port.)
|
|
101
|
-
SANDBOX_CONNECT: network
|
|
157
|
+
# No Docker socket here (D-200): computers are started by the supervisor.
|
|
158
|
+
SANDBOX_SUPERVISOR_URL: http://sandbox-supervisor:7300
|
|
159
|
+
SANDBOX_SUPERVISOR_SECRET: ${SANDBOX_SUPERVISOR_SECRET:?Set SANDBOX_SUPERVISOR_SECRET (openssl rand -hex 32)}
|
|
102
160
|
SANDBOX_MAX_RUNNING: ${SANDBOX_MAX_RUNNING:-2}
|
|
103
161
|
# Docker restarts this container on boot alongside the fence. Starting only
|
|
104
162
|
# once the fence's marker exists keeps a routine from waking a computer
|
|
@@ -117,10 +175,10 @@ services:
|
|
|
117
175
|
- ${CREWAID_BIND:-127.0.0.1}:${CREWAID_PORT:-3000}:3000
|
|
118
176
|
networks:
|
|
119
177
|
default: {}
|
|
178
|
+
control: {}
|
|
120
179
|
sandboxes:
|
|
121
180
|
ipv4_address: ${CREWAID_ORCHESTRATOR_ADDRESS:-10.231.0.2}
|
|
122
181
|
volumes:
|
|
123
|
-
- /var/run/docker.sock:/var/run/docker.sock
|
|
124
182
|
- egress-state:/run/crewaid:ro
|
|
125
183
|
- artifacts:/var/lib/crewaid/artifacts
|
|
126
184
|
depends_on:
|
|
@@ -130,6 +188,8 @@ services:
|
|
|
130
188
|
condition: service_healthy
|
|
131
189
|
networks-ready:
|
|
132
190
|
condition: service_completed_successfully
|
|
191
|
+
sandbox-supervisor:
|
|
192
|
+
condition: service_healthy
|
|
133
193
|
|
|
134
194
|
# HTTPS for a server reached by a domain name: `--profile https`, with
|
|
135
195
|
# CREWAID_DOMAIN pointing at this machine. Certificates come from Let's
|
|
@@ -138,7 +198,8 @@ services:
|
|
|
138
198
|
image: caddy:2.10-alpine
|
|
139
199
|
profiles: [https]
|
|
140
200
|
restart: unless-stopped
|
|
141
|
-
command:
|
|
201
|
+
command:
|
|
202
|
+
['caddy', 'reverse-proxy', '--from', '${CREWAID_DOMAIN:-}', '--to', 'orchestrator:3000']
|
|
142
203
|
ports:
|
|
143
204
|
- 80:80
|
|
144
205
|
- 443:443
|
|
@@ -149,6 +210,11 @@ services:
|
|
|
149
210
|
|
|
150
211
|
networks:
|
|
151
212
|
default: {}
|
|
213
|
+
# The orchestrator and the sandbox supervisor, and nothing else. Internal:
|
|
214
|
+
# no route out, so the supervisor talks to the Docker socket and to its one
|
|
215
|
+
# caller.
|
|
216
|
+
control:
|
|
217
|
+
internal: true
|
|
152
218
|
# Computers. The fence lets a computer out only to the internet on 80/443,
|
|
153
219
|
# and lets only the orchestrator's address open connections into it.
|
|
154
220
|
# 10.x on purpose: Docker hands out 172.17–31 and 192.168 to new networks,
|
package/package.json
CHANGED
package/src/cli.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import { homedir } from 'node:os';
|
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import { createInterface } from 'node:readline/promises';
|
|
5
5
|
import { fileURLToPath } from 'node:url';
|
|
6
|
-
import { generateSecrets } from './secrets.mjs';
|
|
6
|
+
import { generateSecrets, supervisorSecret } from './secrets.mjs';
|
|
7
7
|
import { parseEnv, renderEnv, setEnvValue } from './env.mjs';
|
|
8
8
|
import { lanAddress, pickSandboxSubnet, portIsFree } from './network.mjs';
|
|
9
9
|
import { capture, compose, dockerSubnets, existingProject, preflight } from './docker.mjs';
|
|
@@ -324,9 +324,9 @@ async function update(options) {
|
|
|
324
324
|
const version = options.version ?? (await ownVersion());
|
|
325
325
|
console.log(`Updating ${dir} from ${current} to ${version}.`);
|
|
326
326
|
// The compose file belongs to the release; .env belongs to the operator and
|
|
327
|
-
// only its version line changes.
|
|
327
|
+
// only its version line changes (and a secret a newer release needs is added).
|
|
328
328
|
await writeFile(path.join(dir, 'compose.yml'), await composeTemplate());
|
|
329
|
-
await writeFile(envFile,
|
|
329
|
+
await writeFile(envFile, updateEnvironment(text, version), { mode: 0o600 });
|
|
330
330
|
await returnOwnership(dir, ['compose.yml', '.env']);
|
|
331
331
|
let code = await compose(dir, ['pull']);
|
|
332
332
|
if (code !== 0) {
|
|
@@ -349,6 +349,14 @@ async function update(options) {
|
|
|
349
349
|
return 0;
|
|
350
350
|
}
|
|
351
351
|
|
|
352
|
+
/** Add the supervisor key once when upgrading an older install; retain every existing key. */
|
|
353
|
+
export function updateEnvironment(text, version) {
|
|
354
|
+
if (!parseEnv(text).SANDBOX_SUPERVISOR_SECRET) {
|
|
355
|
+
text = setEnvValue(text, 'SANDBOX_SUPERVISOR_SECRET', supervisorSecret());
|
|
356
|
+
}
|
|
357
|
+
return setEnvValue(text, 'CREWAID_VERSION', version);
|
|
358
|
+
}
|
|
359
|
+
|
|
352
360
|
async function status(options) {
|
|
353
361
|
const dir = installDir(options);
|
|
354
362
|
const code = await compose(dir, ['ps']);
|
package/src/env.mjs
CHANGED
|
@@ -23,7 +23,7 @@ function quote(value) {
|
|
|
23
23
|
export function renderEnv(entries) {
|
|
24
24
|
const lines = [
|
|
25
25
|
'# Written by crewaid-selfhost. Keep it private: it holds the keys to everything.',
|
|
26
|
-
'# `crewaid-selfhost update` changes CREWAID_VERSION and
|
|
26
|
+
'# `crewaid-selfhost update` changes CREWAID_VERSION, and adds a secret a new release needs.',
|
|
27
27
|
];
|
|
28
28
|
for (const [key, value] of Object.entries(entries)) {
|
|
29
29
|
if (value === undefined) continue;
|
package/src/secrets.mjs
CHANGED
|
@@ -11,5 +11,14 @@ export function generateSecrets() {
|
|
|
11
11
|
BETTER_AUTH_SECRET: randomBytes(32).toString('base64'),
|
|
12
12
|
CREWAID_CREDENTIAL_KEYRING: JSON.stringify({ 1: randomBytes(32).toString('hex') }),
|
|
13
13
|
CREDENTIAL_KEY: randomBytes(32).toString('hex'),
|
|
14
|
+
SANDBOX_SUPERVISOR_SECRET: supervisorSecret(),
|
|
14
15
|
};
|
|
15
16
|
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Signs the orchestrator's requests to the sandbox supervisor (D-200). Shared
|
|
20
|
+
* by the two services and nothing else; it never enters a computer.
|
|
21
|
+
*/
|
|
22
|
+
export function supervisorSecret() {
|
|
23
|
+
return randomBytes(32).toString('hex');
|
|
24
|
+
}
|