@studiometa/trafic-agent 0.1.25 → 0.1.26

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/dist/cli.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { _ as validateConfig, c as info, d as success, f as warn, h as loadConfig, i as runPendingMigrations, l as isRoot, n as setup, p as startIdleScheduler, r as listMigrations, s as exec, t as audit, u as step } from "./setup-D61uhYiJ.js";
2
+ import { _ as validateConfig, c as info, d as success, f as warn, h as loadConfig, i as runPendingMigrations, l as isRoot, n as setup, p as startIdleScheduler, r as listMigrations, s as exec, t as audit, u as step } from "./setup-4TI2lreq.js";
3
3
  import { o as closeDb, t as startServer } from "./server-VlzPosuk.js";
4
4
  import { readFileSync } from "node:fs";
5
5
  import { execSync, spawnSync } from "node:child_process";
@@ -108,7 +108,7 @@ function runUpgrade(dryRun = false, reExecArgs) {
108
108
  }
109
109
  const alreadyReExeced = process.env["TRAFIC_UPGRADE_REEXEC"] === "1";
110
110
  step("Check for updates");
111
- const current = "0.1.25";
111
+ const current = "0.1.26";
112
112
  info(`Current version: ${current}`);
113
113
  const latest = fetchLatestVersion();
114
114
  if (!latest) warn("Could not reach npm registry — skipping version check");
@@ -187,7 +187,7 @@ function printHelp() {
187
187
  console.log(HELP.trim());
188
188
  }
189
189
  function printVersion() {
190
- console.log("0.1.25");
190
+ console.log("0.1.26");
191
191
  }
192
192
  async function runStart(values) {
193
193
  const config = loadConfig(values.config);
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
- import { _ as validateConfig, a as printAuditResults, g as parseDuration, h as loadConfig, m as stopIdleProjects, n as setup, o as runAudit, p as startIdleScheduler, t as audit } from "./setup-D61uhYiJ.js";
1
+ import { _ as validateConfig, a as printAuditResults, g as parseDuration, h as loadConfig, m as stopIdleProjects, n as setup, o as runAudit, p as startIdleScheduler, t as audit } from "./setup-4TI2lreq.js";
2
2
  import { C as checkAuth, D as parseBearerToken, E as parseBasicAuth, S as watchProjectList, T as matchIp, _ as getProjectInfo, a as cleanOldLogs, b as startProject, c as getDb, d as initDb, f as logAccess, g as getProjectFromHostname, h as buildHostnameIndex, i as shouldNeverStop, l as getIdleProjects, m as updateProjectAccess, n as getIdleTimeoutMs, o as closeDb, p as setProjectStatus, r as loadProjectConfig, s as getAccessLogs, t as startServer, u as getProject, v as listProjects, w as matchHostname, x as stopProject, y as loadProjectList } from "./server-VlzPosuk.js";
3
3
  export { audit, buildHostnameIndex, checkAuth, cleanOldLogs, closeDb, getAccessLogs, getDb, getIdleProjects, getIdleTimeoutMs, getProject, getProjectFromHostname, getProjectInfo, initDb, listProjects, loadConfig, loadProjectConfig, loadProjectList, logAccess, matchHostname, matchIp, parseBasicAuth, parseBearerToken, parseDuration, printAuditResults, runAudit, setProjectStatus, setup, shouldNeverStop, startIdleScheduler, startProject, startServer, stopIdleProjects, stopProject, updateProjectAccess, validateConfig, watchProjectList };
@@ -1,3 +1,4 @@
1
+ import { type SetupIo } from "./io.js";
1
2
  /**
2
3
  * Add the NodeSource apt repository and GPG key.
3
4
  * Idempotent: safe to call even if the repository is already configured.
@@ -5,7 +6,7 @@
5
6
  * nodejs.org points at NodeSource for apt installs. The Ubuntu 24.04
6
7
  * `nodejs` package is 18.x, far below what the agent needs.
7
8
  */
8
- export declare function addNodeSourceAptRepo(): void;
9
+ export declare function addNodeSourceAptRepo(io?: SetupIo): void;
9
10
  /**
10
11
  * Install Node.js from the NodeSource apt repository.
11
12
  *
@@ -13,17 +14,17 @@ export declare function addNodeSourceAptRepo(): void;
13
14
  * trafic-agent` resolves for the systemd unit — and unattended-upgrades
14
15
  * patches them, which a version manager install never gets.
15
16
  */
16
- export declare function installNode(): void;
17
+ export declare function installNode(io?: SetupIo): void;
17
18
  /**
18
19
  * Install the Trafic agent
19
20
  */
20
- export declare function installAgent(): void;
21
+ export declare function installAgent(io?: SetupIo): void;
21
22
  /**
22
23
  * Create the agent configuration
23
24
  */
24
- export declare function createAgentConfig(tld: string, _email?: string): void;
25
+ export declare function createAgentConfig(tld: string, _email?: string, io?: SetupIo): void;
25
26
  /**
26
27
  * Create systemd service for the agent
27
28
  */
28
- export declare function createSystemdService(): void;
29
+ export declare function createSystemdService(io?: SetupIo): void;
29
30
  //# sourceMappingURL=agent.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../../src/setup/agent.ts"],"names":[],"mappings":"AASA;;;;;;GAMG;AACH,wBAAgB,oBAAoB,IAAI,IAAI,CAuB3C;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,IAAI,IAAI,CAqBlC;AAED;;GAEG;AACH,wBAAgB,YAAY,IAAI,IAAI,CAOnC;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAiDpE;AAED;;GAEG;AACH,wBAAgB,oBAAoB,IAAI,IAAI,CAkD3C"}
1
+ {"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../../src/setup/agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,OAAO,EAAE,MAAM,SAAS,CAAC;AAS/C;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,EAAE,GAAE,OAAgB,GAAG,IAAI,CAuB/D;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,EAAE,GAAE,OAAgB,GAAG,IAAI,CAqBtD;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,EAAE,GAAE,OAAgB,GAAG,IAAI,CAOvD;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,GAAG,EAAE,MAAM,EACX,MAAM,CAAC,EAAE,MAAM,EACf,EAAE,GAAE,OAAgB,GACnB,IAAI,CAiDN;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,EAAE,GAAE,OAAgB,GAAG,IAAI,CAkD/D"}
@@ -1,16 +1,17 @@
1
+ import { type SetupIo } from "./io.js";
1
2
  /**
2
3
  * Install system dependencies required by Trafic
3
4
  */
4
- export declare function installSystemDeps(): void;
5
+ export declare function installSystemDeps(io?: SetupIo): void;
5
6
  /**
6
7
  * Add the official DDEV apt repository and GPG key.
7
8
  * Idempotent: safe to call even if the repository is already configured.
8
9
  */
9
- export declare function addDdevAptRepo(): void;
10
+ export declare function addDdevAptRepo(io?: SetupIo): void;
10
11
  /**
11
12
  * Install DDEV
12
13
  */
13
- export declare function installDdev(): void;
14
+ export declare function installDdev(io?: SetupIo): void;
14
15
  /**
15
16
  * Configure DDEV global settings for production
16
17
  *
@@ -22,22 +23,22 @@ export declare function installDdev(): void;
22
23
  *
23
24
  * With proper DNS, DDEV won't need sudo for hostname management.
24
25
  */
25
- export declare function configureDdev(tld: string, email?: string): void;
26
+ export declare function configureDdev(tld: string, email?: string, io?: SetupIo): void;
26
27
  /**
27
28
  * Install dnsmasq for local DNS resolution (optional)
28
29
  * This allows the server itself to resolve *.{tld} hostnames
29
30
  * without needing to edit /etc/hosts for each project
30
31
  */
31
- export declare function installDnsmasq(tld: string): void;
32
+ export declare function installDnsmasq(tld: string, io?: SetupIo): void;
32
33
  /**
33
34
  * Get the Docker gateway IP reachable from inside DDEV containers on Linux.
34
35
  * DDEV runs containers on the `ddev_default` network — we inspect that first.
35
36
  * Falls back to the default `bridge` network, then to 172.17.0.1.
36
37
  * `host.docker.internal` is not available on Linux without extra configuration.
37
38
  */
38
- export declare function getDockerGatewayIp(): string;
39
+ export declare function getDockerGatewayIp(io?: SetupIo): string;
39
40
  /**
40
41
  * Configure Traefik for forward auth
41
42
  */
42
- export declare function configureTraefik(): void;
43
+ export declare function configureTraefik(io?: SetupIo): void;
43
44
  //# sourceMappingURL=ddev.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ddev.d.ts","sourceRoot":"","sources":["../../src/setup/ddev.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,IAAI,CAYxC;AAED;;;GAGG;AACH,wBAAgB,cAAc,IAAI,IAAI,CAWrC;AAED;;GAEG;AACH,wBAAgB,WAAW,IAAI,IAAI,CA2BlC;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAsB/D;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAsChD;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,IAAI,MAAM,CAc3C;AAED;;GAEG;AACH,wBAAgB,gBAAgB,IAAI,IAAI,CAkEvC"}
1
+ {"version":3,"file":"ddev.d.ts","sourceRoot":"","sources":["../../src/setup/ddev.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,OAAO,EAAE,MAAM,SAAS,CAAC;AAG/C;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,EAAE,GAAE,OAAgB,GAAG,IAAI,CAY5D;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,EAAE,GAAE,OAAgB,GAAG,IAAI,CAWzD;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,EAAE,GAAE,OAAgB,GAAG,IAAI,CA2BtD;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,aAAa,CAC3B,GAAG,EAAE,MAAM,EACX,KAAK,CAAC,EAAE,MAAM,EACd,EAAE,GAAE,OAAgB,GACnB,IAAI,CAsBN;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,GAAE,OAAgB,GAAG,IAAI,CAsCtE;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,EAAE,GAAE,OAAgB,GAAG,MAAM,CAc/D;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,EAAE,GAAE,OAAgB,GAAG,IAAI,CAkE3D"}
@@ -1,13 +1,14 @@
1
+ import { type SetupIo } from "./io.js";
1
2
  /**
2
3
  * Install Docker using the official script
3
4
  */
4
- export declare function installDocker(): void;
5
+ export declare function installDocker(io?: SetupIo): void;
5
6
  /**
6
7
  * Configure Docker for production use
7
8
  */
8
- export declare function configureDocker(): void;
9
+ export declare function configureDocker(io?: SetupIo): void;
9
10
  /**
10
11
  * Setup Docker system prune cron job
11
12
  */
12
- export declare function setupDockerPrune(): void;
13
+ export declare function setupDockerPrune(io?: SetupIo): void;
13
14
  //# sourceMappingURL=docker.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"docker.d.ts","sourceRoot":"","sources":["../../src/setup/docker.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,wBAAgB,aAAa,IAAI,IAAI,CAwBpC;AAED;;GAEG;AACH,wBAAgB,eAAe,IAAI,IAAI,CAqCtC;AAED;;GAEG;AACH,wBAAgB,gBAAgB,IAAI,IAAI,CAWvC"}
1
+ {"version":3,"file":"docker.d.ts","sourceRoot":"","sources":["../../src/setup/docker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,OAAO,EAAE,MAAM,SAAS,CAAC;AAG/C;;GAEG;AACH,wBAAgB,aAAa,CAAC,EAAE,GAAE,OAAgB,GAAG,IAAI,CAwBxD;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,EAAE,GAAE,OAAgB,GAAG,IAAI,CAqC1D;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,EAAE,GAAE,OAAgB,GAAG,IAAI,CAW3D"}
@@ -1,29 +1,39 @@
1
+ import { type SetupIo } from "./io.js";
2
+ /**
3
+ * Resolve the users listed in AllowUsers.
4
+ *
5
+ * The user who invoked sudo is always included. Without them, the
6
+ * AllowUsers directive locks them out on their next connection, and
7
+ * reloading sshd keeps the current session alive so nothing looks wrong
8
+ * until it is too late. root needs no entry — it is always listed.
9
+ */
10
+ export declare function resolveAllowedUsers(allowedUsers: string[], sudoUser: string | undefined): string[];
1
11
  /**
2
12
  * Configure SSH hardening
3
13
  */
4
- export declare function hardenSsh(allowedUsers?: string[]): void;
14
+ export declare function hardenSsh(allowedUsers?: string[], io?: SetupIo): void;
5
15
  /**
6
16
  * Configure UFW firewall
7
17
  */
8
- export declare function configureFirewall(): void;
18
+ export declare function configureFirewall(io?: SetupIo): void;
9
19
  /**
10
20
  * Configure automatic security updates
11
21
  */
12
- export declare function configureUnattendedUpgrades(): void;
22
+ export declare function configureUnattendedUpgrades(io?: SetupIo): void;
13
23
  /**
14
24
  * Configure Fail2ban
15
25
  */
16
- export declare function configureFail2ban(): void;
26
+ export declare function configureFail2ban(io?: SetupIo): void;
17
27
  /**
18
28
  * Configure system limits
19
29
  */
20
- export declare function configureSystemLimits(): void;
30
+ export declare function configureSystemLimits(io?: SetupIo): void;
21
31
  /**
22
32
  * Set proper file permissions
23
33
  */
24
- export declare function configureFilePermissions(): void;
34
+ export declare function configureFilePermissions(io?: SetupIo): void;
25
35
  /**
26
36
  * Run all hardening steps
27
37
  */
28
- export declare function hardenServer(sshUsers?: string[]): void;
38
+ export declare function hardenServer(sshUsers?: string[], io?: SetupIo): void;
29
39
  //# sourceMappingURL=hardening.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"hardening.d.ts","sourceRoot":"","sources":["../../src/setup/hardening.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,wBAAgB,SAAS,CAAC,YAAY,GAAE,MAAM,EAAa,GAAG,IAAI,CAiDjE;AAED;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,IAAI,CAuBxC;AAED;;GAEG;AACH,wBAAgB,2BAA2B,IAAI,IAAI,CA+ClD;AAED;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,IAAI,CAiCxC;AAED;;GAEG;AACH,wBAAgB,qBAAqB,IAAI,IAAI,CAc5C;AAED;;GAEG;AACH,wBAAgB,wBAAwB,IAAI,IAAI,CAuB/C;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,QAAQ,GAAE,MAAM,EAAa,GAAG,IAAI,CAOhE"}
1
+ {"version":3,"file":"hardening.d.ts","sourceRoot":"","sources":["../../src/setup/hardening.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,OAAO,EAAE,MAAM,SAAS,CAAC;AAG/C;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CACjC,YAAY,EAAE,MAAM,EAAE,EACtB,QAAQ,EAAE,MAAM,GAAG,SAAS,GAC3B,MAAM,EAAE,CAQV;AAED;;GAEG;AACH,wBAAgB,SAAS,CACvB,YAAY,GAAE,MAAM,EAAa,EACjC,EAAE,GAAE,OAAgB,GACnB,IAAI,CAmDN;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,EAAE,GAAE,OAAgB,GAAG,IAAI,CAuB5D;AAED;;GAEG;AACH,wBAAgB,2BAA2B,CAAC,EAAE,GAAE,OAAgB,GAAG,IAAI,CA+CtE;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,EAAE,GAAE,OAAgB,GAAG,IAAI,CAiC5D;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,EAAE,GAAE,OAAgB,GAAG,IAAI,CAchE;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,EAAE,GAAE,OAAgB,GAAG,IAAI,CAuBnE;AAED;;GAEG;AACH,wBAAgB,YAAY,CAC1B,QAAQ,GAAE,MAAM,EAAa,EAC7B,EAAE,GAAE,OAAgB,GACnB,IAAI,CAON"}
@@ -0,0 +1,31 @@
1
+ /**
2
+ * The effectful operations the setup steps need.
3
+ *
4
+ * Injected into every setup function so tests can drive them with plain
5
+ * fakes — no module mocking — and so dry-run has one place to intercept
6
+ * writes instead of each module reaching for `node:fs` itself.
7
+ */
8
+ export interface SetupIo {
9
+ /** Run a shell command. Returns its stdout when silent. */
10
+ exec(command: string, options?: {
11
+ silent?: boolean;
12
+ }): string;
13
+ /** Whether a command is on the PATH. */
14
+ commandExists(command: string): boolean;
15
+ /** Write a file. Honours dry-run. */
16
+ writeFile(path: string, content: string): void;
17
+ /** Whether a path exists. */
18
+ fileExists(path: string): boolean;
19
+ /** Read a UTF-8 file. */
20
+ readFile(path: string): string;
21
+ /** Process environment, for values like SUDO_USER. */
22
+ env: Record<string, string | undefined>;
23
+ }
24
+ /**
25
+ * The real implementation, used when no io is injected.
26
+ *
27
+ * `writeFile` comes from steps.js rather than `node:fs` so writes are
28
+ * skipped in dry-run mode. Reads stay direct: they change nothing.
29
+ */
30
+ export declare const nodeIo: SetupIo;
31
+ //# sourceMappingURL=io.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"io.d.ts","sourceRoot":"","sources":["../../src/setup/io.ts"],"names":[],"mappings":"AAGA;;;;;;GAMG;AACH,MAAM,WAAW,OAAO;IACtB,2DAA2D;IAC3D,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,MAAM,CAAC;IAC9D,wCAAwC;IACxC,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC;IACxC,qCAAqC;IACrC,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/C,6BAA6B;IAC7B,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;IAClC,yBAAyB;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;IAC/B,sDAAsD;IACtD,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;CACzC;AAED;;;;;GAKG;AACH,eAAO,MAAM,MAAM,EAAE,OAOpB,CAAC"}
@@ -1,14 +1,15 @@
1
+ import { type SetupIo } from "./io.js";
1
2
  /**
2
3
  * Write /etc/sudoers.d/trafic-ddev allowing the ddev user to run
3
4
  * ddev-hostname without a password. Idempotent — safe to call multiple times.
4
5
  */
5
- export declare function configureDdevSudoers(): void;
6
+ export declare function configureDdevSudoers(io?: SetupIo): void;
6
7
  /**
7
8
  * Create the ddev user with proper permissions
8
9
  */
9
- export declare function createDdevUser(): void;
10
+ export declare function createDdevUser(io?: SetupIo): void;
10
11
  /**
11
12
  * Setup authorized_keys for ddev user
12
13
  */
13
- export declare function setupAuthorizedKeys(publicKey?: string): void;
14
+ export declare function setupAuthorizedKeys(publicKey?: string, io?: SetupIo): void;
14
15
  //# sourceMappingURL=user.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"user.d.ts","sourceRoot":"","sources":["../../src/setup/user.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,wBAAgB,oBAAoB,IAAI,IAAI,CAQ3C;AAED;;GAEG;AACH,wBAAgB,cAAc,IAAI,IAAI,CAiCrC;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAqB5D"}
1
+ {"version":3,"file":"user.d.ts","sourceRoot":"","sources":["../../src/setup/user.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,OAAO,EAAE,MAAM,SAAS,CAAC;AAG/C;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,EAAE,GAAE,OAAgB,GAAG,IAAI,CAQ/D;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,EAAE,GAAE,OAAgB,GAAG,IAAI,CAiCzD;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,SAAS,CAAC,EAAE,MAAM,EAClB,EAAE,GAAE,OAAgB,GACnB,IAAI,CAqBN"}