Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

Merge origin/main into feat/box-channel-a2

milind-soni9d7e188470ad
diff --cc connector/e2e/run.sh
index 32853507b3,ffa7d00a66..07aca30041
--- a/connector/e2e/run.sh
+++ b/connector/e2e/run.sh
@@@ -177,8 -170,25 +178,25 @@@ expect '.result.home.health.box.checks
step "nothing secret in the connector's log"
docker logs mausbot-connector >"$OUT/connector.log" 2>&1
if grep -qF "$SECRET" "$OUT/connector.log"; then fail "the bootstrap secret reached the connector's log"; fi
-if grep -q "ombs_" "$OUT/connector.log"; then fail "the agent token reached the connector's log"; fi
+if grep -qF "$(sudo jq -r .privateKey "$state_dir/agent.json")" "$OUT/connector.log"; then fail "the box's private key reached the connector's log"; fi
+ step "the audit log: every job, its steps and its result, each line linked to the one before, nothing secret"
+ local_status=$(docker exec mausbot-connector mausbot-connector job status '{}')
+ expect '.ok and .result.home.state == "running"' "$local_status" "a job from root on this server"
+ expect '.ok == false and .error.code == "unknown_job"' "$(docker exec mausbot-connector mausbot-connector job shell '{}' || true)" "a job outside the list"
+ [ "$(sudo stat -c %a /var/log/mausbot/audit.jsonl)" = 600 ] || fail "the audit log is not root's alone"
+ sudo cat /var/log/mausbot/audit.jsonl >"$OUT/audit.jsonl"
+ docker exec mausbot-connector mausbot-connector audit --verify | tee "$OUT/audit-verify.txt"
+ grep -q "each linked to the one before it" "$OUT/audit-verify.txt" || fail "the audit log's chain is broken"
+ audit=$(jq -cs . "$OUT/audit.jsonl")
+ expect 'any(.[]; .event == "job" and .by == "admin" and .id == "start-1" and (.args.env | index("OMB_CLOUD_BOOTSTRAP_SECRET")))' "$audit" "the start, with its environment's names"
+ expect '[.[] | select(.id == "update-1" and .event == "step") | .step] == ["pull", "checked", "stop", "snapshot", "swap", "wait", "healthy"]' "$audit" "the update's steps"
+ expect 'any(.[]; .event == "result" and .id == "update-1" and .ok)' "$audit" "the update's result"
+ expect 'any(.[]; .event == "result" and .id == "update-2" and .error.code == "update_rolled_back")' "$audit" "the rollback's result"
+ expect 'any(.[]; .event == "step" and .id == "update-2" and .step == "rollback")' "$audit" "the rollback step"
+ expect 'any(.[]; .event == "job" and .by == "local" and .type == "status")' "$audit" "the job from this server"
+ if grep -qF "$SECRET" "$OUT/audit.jsonl"; then fail "the bootstrap secret reached the audit log"; fi
+
step "uninstall stops everything and keeps the data; --delete-data deletes it"
sudo env "${INSTALL_ENV[@]}" sh "$ROOT/connector/install.sh" uninstall | tee "$OUT/uninstall.txt"
for container in mausbot-connector mausbot-home; do
diff --cc connector/src/protocol.ts
index 3f7dc4df82,b11ec065ea..7982cd6094
--- a/connector/src/protocol.ts
+++ b/connector/src/protocol.ts
@@@ -180,10 -154,9 +180,10 @@@ export interface JobResults
}
export type JobErrorCode =
- | "invalid_job" | "unknown_job" | "invalid_args" | "busy" | "interrupted" | "audit_unavailable" | "refused_by_policy"
+ | "invalid_job" | "unknown_job" | "invalid_args" | "busy" | "interrupted" | "audit_unavailable" | "refused_by_policy" | "image_refused"
| "no_home" | "docker" | "pull_failed" | "unhealthy" | "update_rolled_back" | "rollback_failed"
- | "not_found" | "disk_full" | "port_in_use" | "box_unavailable" | "transfer_failed" | "self_update_failed";
+ | "not_found" | "disk_full" | "port_in_use" | "box_unavailable" | "transfer_failed" | "self_update_failed"
+ | "unsigned_job" | "wrong_box" | "expired_job" | "pending_box";
/** `message` is plain words for the Admin's log and alerts; it never carries a secret. */
export interface JobError {
diff --cc connector/test/self-update.test.ts
index 265d9ecfbf,80aa05c224..858cfd92db
--- a/connector/test/self-update.test.ts
+++ b/connector/test/self-update.test.ts
@@@ -57,6 -57,18 +57,18 @@@ async function fixture()
}
describe("the connector replacing itself", () => {
+ it("never starts a new connector the image check refuses", async () => {
+ const f = await fixture();
+ const updater = new SelfUpdater({
+ docker: f.docker, state: f.state, log: () => {}, instance: "instance-old",
- identity: () => ({ version: "1.0.0", protocol: 1, image: OLD }),
++ identity: () => ({ version: "1.0.0", protocol: 2, image: OLD }),
+ checkImage: async (image, context) => { if (image === NEW && context.kind === "connector" && context.current === OLD) throw new Error("it is older than this one"); },
+ });
+ expect(await updater.run(f.job, f.agent)).toEqual({ id: "self-1", ok: false, error: { code: "image_refused", message: `${NEW} was refused (it is older than this one). The connector was not changed.` } });
+ expect([...f.docker.containers.keys()]).toEqual(["mausbot-connector"]);
+ expect(f.agent).toMatchObject({ paused: 0, resumed: 0 });
+ });
+
it("hands over once the new connector has connected: it answers the job, removes the old one and takes its name", async () => {
const f = await fixture();
let candidateReply: JobReply | null = null;