repoburg 1.3.309 → 1.3.311
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/agent-pane/frontend/dist/assets/{TerminalView-CldV8OPX.js → TerminalView-CdL80e84.js} +1 -1
- package/agent-pane/frontend/dist/assets/{index-YjXfH1jk.js → index-NpywVkQl.js} +118 -118
- package/agent-pane/frontend/dist/index.html +1 -1
- package/daemon/dist/auth/authManager.js +4 -3
- package/daemon/dist/index.js +19 -8
- package/daemon/dist/middleware/checkRemoteAuth.js +68 -68
- package/daemon/dist/middleware/checkRemoteAuth.spec.js +175 -121
- package/daemon/dist/middleware/corsOrigin.js +53 -0
- package/daemon/dist/middleware/corsOrigin.spec.js +46 -0
- package/daemon/dist/middleware/originGuard.js +12 -0
- package/daemon/dist/remote/edge-gate-move.js +40 -0
- package/daemon/dist/remote/edge-gate-move.spec.js +44 -0
- package/daemon/dist/remote/edge-jwt.js +83 -0
- package/daemon/dist/remote/probes.js +9 -9
- package/daemon/dist/remote/provisioner.js +29 -5
- package/daemon/dist/remote/provisioner.spec.js +80 -0
- package/daemon/dist/remote/routes.js +3 -0
- package/daemon/dist/remote/routes.spec.js +1 -0
- package/package.json +1 -1
- package/tabtape/extension/dist/build-info.json +3 -3
- package/tabtape/extension/dist/manifest.json +1 -1
- package/tabtape/ui/dist/build-info.json +3 -3
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.corsOrigin = corsOrigin;
|
|
4
|
+
exports.setExtraOriginsForTest = setExtraOriginsForTest;
|
|
5
|
+
/**
|
|
6
|
+
* CORS origin allowlist for the daemon.
|
|
7
|
+
*
|
|
8
|
+
* Spec: the daemon serves the embedded agent-pane to local tooling
|
|
9
|
+
* (vite dev servers, daemon-desktop) and, once a tunnel is provisioned, to
|
|
10
|
+
* `*.repoburg.com` machine hostnames. Everything else is rejected — the
|
|
11
|
+
* previous `origin: '*'` with `credentials: true` is an open API surface.
|
|
12
|
+
*
|
|
13
|
+
* Allowed:
|
|
14
|
+
* - no Origin header (same-origin / non-browser clients such as curl)
|
|
15
|
+
* - http://localhost:<any> and http://127.0.0.1:<any>
|
|
16
|
+
* - https://<anything>.repoburg.com (tunnel machine hostnames)
|
|
17
|
+
* - extra origins from REPOBURG_ALLOWED_ORIGINS (comma-separated)
|
|
18
|
+
*/
|
|
19
|
+
const REPORG_HOSTNAME_SUFFIX = '.repoburg.com';
|
|
20
|
+
const extraOrigins = (process.env.REPOBURG_ALLOWED_ORIGINS ?? '')
|
|
21
|
+
.split(',')
|
|
22
|
+
.map((value) => value.trim())
|
|
23
|
+
.filter(Boolean);
|
|
24
|
+
function isLocalOrigin(origin) {
|
|
25
|
+
return (origin.protocol === 'http:' &&
|
|
26
|
+
(origin.hostname === 'localhost' || origin.hostname === '127.0.0.1'));
|
|
27
|
+
}
|
|
28
|
+
function isTunnelOrigin(origin) {
|
|
29
|
+
return origin.protocol === 'https:' && origin.hostname.endsWith(REPORG_HOSTNAME_SUFFIX);
|
|
30
|
+
}
|
|
31
|
+
/** CORS origin callback. `false` = do not emit CORS headers for this origin. */
|
|
32
|
+
function corsOrigin(origin, callback) {
|
|
33
|
+
// Same-origin requests and non-browser clients send no Origin header.
|
|
34
|
+
if (origin === undefined) {
|
|
35
|
+
callback(null, true);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
let parsed;
|
|
39
|
+
try {
|
|
40
|
+
parsed = new URL(origin);
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
callback(null, false);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const allowed = isLocalOrigin(parsed) || isTunnelOrigin(parsed) || extraOrigins.includes(origin);
|
|
47
|
+
callback(null, allowed);
|
|
48
|
+
}
|
|
49
|
+
/** Exposed for tests. */
|
|
50
|
+
function setExtraOriginsForTest(origins) {
|
|
51
|
+
extraOrigins.length = 0;
|
|
52
|
+
extraOrigins.push(...origins);
|
|
53
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const corsOrigin_1 = require("./corsOrigin");
|
|
4
|
+
function evaluate(origin) {
|
|
5
|
+
let result = false;
|
|
6
|
+
(0, corsOrigin_1.corsOrigin)(origin, (err, allow) => {
|
|
7
|
+
if (err)
|
|
8
|
+
throw err;
|
|
9
|
+
result = !!allow;
|
|
10
|
+
});
|
|
11
|
+
return result;
|
|
12
|
+
}
|
|
13
|
+
describe('corsOrigin', () => {
|
|
14
|
+
afterEach(() => (0, corsOrigin_1.setExtraOriginsForTest)([]));
|
|
15
|
+
it('allows requests without an Origin header (same-origin / curl)', () => {
|
|
16
|
+
expect(evaluate(undefined)).toBe(true);
|
|
17
|
+
});
|
|
18
|
+
it('allows localhost and 127.0.0.1 on any port', () => {
|
|
19
|
+
expect(evaluate('http://localhost:3000')).toBe(true);
|
|
20
|
+
expect(evaluate('http://localhost:9998')).toBe(true);
|
|
21
|
+
expect(evaluate('http://127.0.0.1:5173')).toBe(true);
|
|
22
|
+
});
|
|
23
|
+
it('allows tunnel machine hostnames under repoburg.com (https only)', () => {
|
|
24
|
+
expect(evaluate('https://workstation.repoburg.com')).toBe(true);
|
|
25
|
+
expect(evaluate('https://a-b.repoburg.com')).toBe(true);
|
|
26
|
+
});
|
|
27
|
+
it('rejects unknown origins', () => {
|
|
28
|
+
expect(evaluate('https://evil.example.com')).toBe(false);
|
|
29
|
+
expect(evaluate('http://evil.com')).toBe(false);
|
|
30
|
+
});
|
|
31
|
+
it('rejects repoburg.com hostnames over http (tunnels are https)', () => {
|
|
32
|
+
expect(evaluate('http://workstation.repoburg.com')).toBe(false);
|
|
33
|
+
});
|
|
34
|
+
it('rejects lookalike suffixes', () => {
|
|
35
|
+
expect(evaluate('https://workstation.repoburg.com.evil.com')).toBe(false);
|
|
36
|
+
expect(evaluate('https://evilrepoburg.com')).toBe(false);
|
|
37
|
+
});
|
|
38
|
+
it('rejects malformed origins', () => {
|
|
39
|
+
expect(evaluate('not a url')).toBe(false);
|
|
40
|
+
});
|
|
41
|
+
it('allows extra origins configured via env list', () => {
|
|
42
|
+
(0, corsOrigin_1.setExtraOriginsForTest)(['https://staging.example.com']);
|
|
43
|
+
expect(evaluate('https://staging.example.com')).toBe(true);
|
|
44
|
+
expect(evaluate('https://other.example.com')).toBe(false);
|
|
45
|
+
});
|
|
46
|
+
});
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.corsOptions = void 0;
|
|
4
|
+
exports.hostnameOf = hostnameOf;
|
|
4
5
|
exports.isLoopbackHost = isLoopbackHost;
|
|
6
|
+
exports.isTunnelHost = isTunnelHost;
|
|
7
|
+
exports.isExtraOriginHost = isExtraOriginHost;
|
|
5
8
|
exports.isAllowedRequest = isAllowedRequest;
|
|
6
9
|
exports.originGuard = originGuard;
|
|
7
10
|
exports.setExtraOriginsForTest = setExtraOriginsForTest;
|
|
@@ -54,6 +57,15 @@ function hostnameOf(host) {
|
|
|
54
57
|
function isLoopbackHost(host) {
|
|
55
58
|
return LOOPBACK_HOSTNAMES.has(hostnameOf(host) ?? '');
|
|
56
59
|
}
|
|
60
|
+
/** A tunnel hostname (`<mahlas>.repoburg.com`): the request came through Cloudflare. */
|
|
61
|
+
function isTunnelHost(host) {
|
|
62
|
+
return (hostnameOf(host) ?? '').endsWith(TUNNEL_SUFFIX);
|
|
63
|
+
}
|
|
64
|
+
/** A host the owner trusts through REPOBURG_ALLOWED_ORIGINS (their own proxy). */
|
|
65
|
+
function isExtraOriginHost(host) {
|
|
66
|
+
const hostname = hostnameOf(host);
|
|
67
|
+
return hostname !== null && extraOrigins.some((origin) => parseUrl(origin)?.hostname === hostname);
|
|
68
|
+
}
|
|
57
69
|
function isAllowedHost(host) {
|
|
58
70
|
const hostname = hostnameOf(host);
|
|
59
71
|
if (hostname === null)
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.scheduleEdgeGateMove = scheduleEdgeGateMove;
|
|
4
|
+
/**
|
|
5
|
+
* Moves this machine's tunnel from Cloudflare Access to the account server's
|
|
6
|
+
* edge gate (MUH-108), in the background: soon after the daemon starts, then
|
|
7
|
+
* every few hours until it worked (no device token yet, account server
|
|
8
|
+
* unreachable). A tunnel without Access fields has nothing to move.
|
|
9
|
+
*/
|
|
10
|
+
const provisioner_1 = require("./provisioner");
|
|
11
|
+
const FIRST_TRY_MS = 15000;
|
|
12
|
+
const RETRY_MS = 6 * 60 * 60 * 1000;
|
|
13
|
+
/** Starts the attempts; the returned function stops them. Timers never keep the process alive. */
|
|
14
|
+
function scheduleEdgeGateMove(deps = {}) {
|
|
15
|
+
const move = deps.move ?? (() => (0, provisioner_1.moveTunnelToEdgeGate)());
|
|
16
|
+
const log = deps.log ?? ((message) => console.log(message));
|
|
17
|
+
let timer = null;
|
|
18
|
+
let stopped = false;
|
|
19
|
+
const attempt = async () => {
|
|
20
|
+
try {
|
|
21
|
+
if (await move())
|
|
22
|
+
log('[remote] Tunnel moved from Cloudflare Access to the Repoburg sign-in gate.');
|
|
23
|
+
return; // moved, or nothing to move
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
log(`[remote] Could not move the tunnel to the Repoburg sign-in gate yet: ${error.message}`);
|
|
27
|
+
}
|
|
28
|
+
if (!stopped) {
|
|
29
|
+
timer = setTimeout(() => void attempt(), deps.retryMs ?? RETRY_MS);
|
|
30
|
+
timer.unref();
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
timer = setTimeout(() => void attempt(), deps.firstTryMs ?? FIRST_TRY_MS);
|
|
34
|
+
timer.unref();
|
|
35
|
+
return () => {
|
|
36
|
+
stopped = true;
|
|
37
|
+
if (timer)
|
|
38
|
+
clearTimeout(timer);
|
|
39
|
+
};
|
|
40
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const edge_gate_move_1 = require("./edge-gate-move");
|
|
4
|
+
jest.useFakeTimers();
|
|
5
|
+
const flush = async () => {
|
|
6
|
+
for (let i = 0; i < 5; i++)
|
|
7
|
+
await Promise.resolve();
|
|
8
|
+
};
|
|
9
|
+
describe('scheduleEdgeGateMove', () => {
|
|
10
|
+
it('tries soon after start and stops once moved or nothing to move', async () => {
|
|
11
|
+
const move = jest.fn(async () => true);
|
|
12
|
+
const log = jest.fn();
|
|
13
|
+
(0, edge_gate_move_1.scheduleEdgeGateMove)({ move, log, firstTryMs: 1000, retryMs: 5000 });
|
|
14
|
+
expect(move).not.toHaveBeenCalled();
|
|
15
|
+
await jest.advanceTimersByTimeAsync(1000);
|
|
16
|
+
expect(move).toHaveBeenCalledTimes(1);
|
|
17
|
+
expect(log).toHaveBeenCalledWith(expect.stringMatching(/moved from Cloudflare Access/));
|
|
18
|
+
await jest.advanceTimersByTimeAsync(20000);
|
|
19
|
+
expect(move).toHaveBeenCalledTimes(1);
|
|
20
|
+
});
|
|
21
|
+
it('tries again later while it fails, until it works', async () => {
|
|
22
|
+
const move = jest
|
|
23
|
+
.fn()
|
|
24
|
+
.mockRejectedValueOnce(new Error('Not logged in'))
|
|
25
|
+
.mockRejectedValueOnce(new Error('offline'))
|
|
26
|
+
.mockResolvedValue(true);
|
|
27
|
+
(0, edge_gate_move_1.scheduleEdgeGateMove)({ move, log: jest.fn(), firstTryMs: 1000, retryMs: 5000 });
|
|
28
|
+
await jest.advanceTimersByTimeAsync(1000);
|
|
29
|
+
await jest.advanceTimersByTimeAsync(5000);
|
|
30
|
+
await jest.advanceTimersByTimeAsync(5000);
|
|
31
|
+
await flush();
|
|
32
|
+
expect(move).toHaveBeenCalledTimes(3);
|
|
33
|
+
await jest.advanceTimersByTimeAsync(50000);
|
|
34
|
+
expect(move).toHaveBeenCalledTimes(3);
|
|
35
|
+
});
|
|
36
|
+
it('stops when told to', async () => {
|
|
37
|
+
const move = jest.fn().mockRejectedValue(new Error('offline'));
|
|
38
|
+
const stop = (0, edge_gate_move_1.scheduleEdgeGateMove)({ move, log: jest.fn(), firstTryMs: 1000, retryMs: 5000 });
|
|
39
|
+
await jest.advanceTimersByTimeAsync(1000);
|
|
40
|
+
stop();
|
|
41
|
+
await jest.advanceTimersByTimeAsync(50000);
|
|
42
|
+
expect(move).toHaveBeenCalledTimes(1);
|
|
43
|
+
});
|
|
44
|
+
});
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.EDGE_AUTH_HEADER = void 0;
|
|
37
|
+
exports.edgeAudience = edgeAudience;
|
|
38
|
+
exports.verifyEdgeJwt = verifyEdgeJwt;
|
|
39
|
+
/**
|
|
40
|
+
* Edge token verification for requests arriving through the tunnel.
|
|
41
|
+
*
|
|
42
|
+
* The account server's edge gate (account-server/src/edge/gate.ts) signs in
|
|
43
|
+
* the machine's owner with Google and adds a short-lived EdDSA JWT to every
|
|
44
|
+
* request it lets through, in the `X-Repoburg-Edge-Auth` header. It is signed
|
|
45
|
+
* with the account server's key, the one device tokens use (its public half
|
|
46
|
+
* is built into the daemon, PUBLIC_KEY), and differs from a device token in
|
|
47
|
+
* its audience: `tunnel:<hostname>`, the one machine it is for.
|
|
48
|
+
*
|
|
49
|
+
* Checked: signature, issuer, audience = this machine's hostname, expiry, and
|
|
50
|
+
* the signed `email` = the owner email pinned in remote.json.
|
|
51
|
+
*/
|
|
52
|
+
const jose = __importStar(require("jose"));
|
|
53
|
+
const authManager_1 = require("../auth/authManager");
|
|
54
|
+
exports.EDGE_AUTH_HEADER = 'x-repoburg-edge-auth';
|
|
55
|
+
const ISSUER = 'repoburg.com';
|
|
56
|
+
/** Machines' clocks drift; the gate's tokens live five minutes. */
|
|
57
|
+
const CLOCK_TOLERANCE_SECONDS = 120;
|
|
58
|
+
function edgeAudience(hostname) {
|
|
59
|
+
return `tunnel:${hostname}`;
|
|
60
|
+
}
|
|
61
|
+
let builtInKey = null;
|
|
62
|
+
/** The verification key: the built-in one, or REPOBURG_EDGE_PUBLIC_KEY (a dev account server's). */
|
|
63
|
+
function verificationKey() {
|
|
64
|
+
const override = process.env.REPOBURG_EDGE_PUBLIC_KEY;
|
|
65
|
+
if (override)
|
|
66
|
+
return jose.importSPKI(override.replace(/\\n/g, '\n'), 'EdDSA');
|
|
67
|
+
builtInKey ?? (builtInKey = jose.importSPKI(authManager_1.PUBLIC_KEY, 'EdDSA'));
|
|
68
|
+
return builtInKey;
|
|
69
|
+
}
|
|
70
|
+
async function verifyEdgeJwt(token, options) {
|
|
71
|
+
const key = options.key ?? (await verificationKey());
|
|
72
|
+
const { payload } = await jose.jwtVerify(token, key, {
|
|
73
|
+
issuer: ISSUER,
|
|
74
|
+
audience: edgeAudience(options.hostname),
|
|
75
|
+
algorithms: ['EdDSA'],
|
|
76
|
+
clockTolerance: CLOCK_TOLERANCE_SECONDS,
|
|
77
|
+
requiredClaims: ['exp', 'sub'],
|
|
78
|
+
});
|
|
79
|
+
const email = typeof payload.email === 'string' ? payload.email : '';
|
|
80
|
+
if (email.toLowerCase() !== options.ownerEmail.toLowerCase()) {
|
|
81
|
+
throw new Error(`Edge token email does not match the machine owner (${email} !== ${options.ownerEmail}).`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -5,9 +5,9 @@ exports.probeTunnelConnected = probeTunnelConnected;
|
|
|
5
5
|
/**
|
|
6
6
|
* Connectivity probes shared by the /remote routes and the enable
|
|
7
7
|
* orchestrator. Both signals are needed: the public health probe only proves
|
|
8
|
-
* the edge knows the hostname (
|
|
9
|
-
* consulted), while the cloudflared metrics gauge proves
|
|
10
|
-
* connections through the tunnel.
|
|
8
|
+
* the edge knows the hostname (the edge gate answers 401, CF Access 302,
|
|
9
|
+
* before the tunnel is consulted), while the cloudflared metrics gauge proves
|
|
10
|
+
* live edge connections through the tunnel.
|
|
11
11
|
*/
|
|
12
12
|
const tunnel_state_1 = require("./tunnel-state");
|
|
13
13
|
const cloudflared_1 = require("./cloudflared");
|
|
@@ -17,11 +17,11 @@ function publicHealthUrl() {
|
|
|
17
17
|
return state ? `https://${state.hostname}/health` : null;
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
20
|
-
* Edge reachability probe.
|
|
21
|
-
* to
|
|
22
|
-
* prove the edge knows the hostname, never that
|
|
23
|
-
* `redirect: 'manual'` prevents the old false
|
|
24
|
-
* page's 200 was counted as a healthy daemon.
|
|
20
|
+
* Edge reachability probe. An anonymous request gets the edge gate's 401 (or,
|
|
21
|
+
* behind CF Access, a 302 to its login page) BEFORE the tunnel is ever
|
|
22
|
+
* consulted — so this can only prove the edge knows the hostname, never that
|
|
23
|
+
* the tunnel is connected. `redirect: 'manual'` prevents the old false
|
|
24
|
+
* positive where the login page's 200 was counted as a healthy daemon.
|
|
25
25
|
*/
|
|
26
26
|
async function probePublicHealth(timeoutMs = HEALTH_CHECK_TIMEOUT_MS) {
|
|
27
27
|
const url = publicHealthUrl();
|
|
@@ -29,7 +29,7 @@ async function probePublicHealth(timeoutMs = HEALTH_CHECK_TIMEOUT_MS) {
|
|
|
29
29
|
return false;
|
|
30
30
|
try {
|
|
31
31
|
const response = await fetch(url, { redirect: 'manual', signal: AbortSignal.timeout(timeoutMs) });
|
|
32
|
-
return response.status >= 200 && response.status < 400;
|
|
32
|
+
return (response.status >= 200 && response.status < 400) || response.status === 401;
|
|
33
33
|
}
|
|
34
34
|
catch {
|
|
35
35
|
return false;
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ProvisioningError = void 0;
|
|
4
4
|
exports.accountServerUrl = accountServerUrl;
|
|
5
5
|
exports.provisionTunnel = provisionTunnel;
|
|
6
|
+
exports.moveTunnelToEdgeGate = moveTunnelToEdgeGate;
|
|
6
7
|
exports.listTunnels = listTunnels;
|
|
7
8
|
exports.uninstallTunnel = uninstallTunnel;
|
|
8
9
|
/**
|
|
@@ -50,22 +51,45 @@ async function provisionTunnel(mahlas) {
|
|
|
50
51
|
if (!token) {
|
|
51
52
|
throw new ProvisioningError('Not logged in. Run `repoburg login` first.', 401);
|
|
52
53
|
}
|
|
53
|
-
|
|
54
|
-
//
|
|
55
|
-
//
|
|
54
|
+
// `edgeAuth`: this daemon checks the edge gate's tokens, so the tunnel
|
|
55
|
+
// needs no Cloudflare Access app (MUH-108). An account server from before
|
|
56
|
+
// the gate ignores it and answers with Access fields, which are kept.
|
|
57
|
+
const result = await callAccountServer('POST', '/device/tunnels', token, { mahlas, edgeAuth: true });
|
|
58
|
+
// The owner email arrives in the same response: the tunnel is gated from
|
|
59
|
+
// birth, and checkRemoteAuth can pin the owner's email.
|
|
56
60
|
const state = {
|
|
57
61
|
mahlas: result.mahlas,
|
|
58
62
|
hostname: result.hostname,
|
|
59
63
|
accountTunnelId: result.id,
|
|
60
64
|
tunnelToken: result.tunnel_token,
|
|
61
|
-
accessTeamDomain
|
|
62
|
-
|
|
65
|
+
...(result.accessTeamDomain && result.accessAud
|
|
66
|
+
? { accessTeamDomain: result.accessTeamDomain, accessAud: result.accessAud }
|
|
67
|
+
: {}),
|
|
63
68
|
ownerEmail: result.ownerEmail,
|
|
64
69
|
installedAt: new Date().toISOString(),
|
|
65
70
|
};
|
|
66
71
|
(0, tunnel_state_1.saveTunnelState)(state);
|
|
67
72
|
return state;
|
|
68
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* Moves a tunnel provisioned behind Cloudflare Access to the edge gate: the
|
|
76
|
+
* account server deletes the Access app, and remote.json drops the Access
|
|
77
|
+
* fields (Access JWTs are no longer accepted). Nothing to do for a tunnel
|
|
78
|
+
* without them. Returns whether it moved; throws when it could not (try again).
|
|
79
|
+
*/
|
|
80
|
+
async function moveTunnelToEdgeGate(home) {
|
|
81
|
+
const state = (0, tunnel_state_1.loadTunnelState)(home);
|
|
82
|
+
if (!state?.accessAud && !state?.accessTeamDomain)
|
|
83
|
+
return false;
|
|
84
|
+
const token = await authManager_1.authManager.readToken();
|
|
85
|
+
if (!token)
|
|
86
|
+
throw new ProvisioningError('Not logged in. Run `repoburg login` first.', 401);
|
|
87
|
+
const result = await callAccountServer('POST', `/device/tunnels/${state.accountTunnelId}/edge-auth`, token);
|
|
88
|
+
const { accessTeamDomain: _domain, accessAud: _aud, ...rest } = state;
|
|
89
|
+
// The pinned email stays as it was; a state from before pinning gets one.
|
|
90
|
+
(0, tunnel_state_1.saveTunnelState)({ ...rest, ownerEmail: state.ownerEmail ?? result.ownerEmail }, home);
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
69
93
|
/** List this user's machines (used by the pane machine list when local). */
|
|
70
94
|
async function listTunnels() {
|
|
71
95
|
const token = await authManager_1.authManager.readToken();
|
|
@@ -58,6 +58,35 @@ describe('provisioner', () => {
|
|
|
58
58
|
const [url, init] = fetchMock.mock.calls[0];
|
|
59
59
|
expect(url).toBe('http://account-server.test/device/tunnels');
|
|
60
60
|
expect(init.headers.Authorization).toBe('Bearer device-jwt');
|
|
61
|
+
// This daemon checks edge-gate tokens: no Access app needed.
|
|
62
|
+
expect(JSON.parse(init.body)).toEqual({ mahlas: 'workstation', edgeAuth: true });
|
|
63
|
+
}
|
|
64
|
+
finally {
|
|
65
|
+
os_1.default.homedir = origHomedir;
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
it('keeps no Access fields for a tunnel behind the edge gate', async () => {
|
|
69
|
+
mockedReadToken.mockResolvedValue('device-jwt');
|
|
70
|
+
global.fetch = jest.fn(async () => ({
|
|
71
|
+
ok: true,
|
|
72
|
+
status: 201,
|
|
73
|
+
json: async () => ({
|
|
74
|
+
id: 'tunnel-uuid',
|
|
75
|
+
mahlas: 'workstation',
|
|
76
|
+
hostname: 'workstation.repoburg.com',
|
|
77
|
+
tunnel_token: 'connector-token',
|
|
78
|
+
ownerEmail: 'owner@repoburg.com',
|
|
79
|
+
gate: 'repoburg',
|
|
80
|
+
}),
|
|
81
|
+
}));
|
|
82
|
+
const origHomedir = os_1.default.homedir;
|
|
83
|
+
os_1.default.homedir = () => tmpHome;
|
|
84
|
+
try {
|
|
85
|
+
await (0, provisioner_1.provisionTunnel)('workstation');
|
|
86
|
+
const state = (0, tunnel_state_1.loadTunnelState)(tmpHome);
|
|
87
|
+
expect(state).toMatchObject({ hostname: 'workstation.repoburg.com', ownerEmail: 'owner@repoburg.com' });
|
|
88
|
+
expect(state).not.toHaveProperty('accessAud');
|
|
89
|
+
expect(state).not.toHaveProperty('accessTeamDomain');
|
|
61
90
|
}
|
|
62
91
|
finally {
|
|
63
92
|
os_1.default.homedir = origHomedir;
|
|
@@ -102,3 +131,54 @@ describe('provisioner', () => {
|
|
|
102
131
|
await expect((0, provisioner_1.listTunnels)()).resolves.toEqual([]);
|
|
103
132
|
});
|
|
104
133
|
});
|
|
134
|
+
describe('moveTunnelToEdgeGate', () => {
|
|
135
|
+
const ACCESS_STATE = {
|
|
136
|
+
mahlas: 'workstation',
|
|
137
|
+
hostname: 'workstation.repoburg.com',
|
|
138
|
+
accountTunnelId: 'tunnel-uuid',
|
|
139
|
+
tunnelToken: 'connector-token',
|
|
140
|
+
accessTeamDomain: 'team.cloudflareaccess.com',
|
|
141
|
+
accessAud: 'aud-tag',
|
|
142
|
+
ownerEmail: 'owner@repoburg.com',
|
|
143
|
+
installedAt: '2026-01-01T00:00:00.000Z',
|
|
144
|
+
};
|
|
145
|
+
const reply = (status, body) => jest.fn(async () => ({ ok: status < 400, status, json: async () => body }));
|
|
146
|
+
it('asks the account server, then drops the Access fields and keeps the pinned email', async () => {
|
|
147
|
+
(0, tunnel_state_1.saveTunnelState)(ACCESS_STATE, tmpHome);
|
|
148
|
+
mockedReadToken.mockResolvedValue('device-jwt');
|
|
149
|
+
const fetchMock = reply(200, { ownerEmail: 'changed@repoburg.com', gate: 'repoburg' });
|
|
150
|
+
global.fetch = fetchMock;
|
|
151
|
+
await expect((0, provisioner_1.moveTunnelToEdgeGate)(tmpHome)).resolves.toBe(true);
|
|
152
|
+
const [url, init] = fetchMock.mock.calls[0];
|
|
153
|
+
expect(url).toBe('http://account-server.test/device/tunnels/tunnel-uuid/edge-auth');
|
|
154
|
+
expect(init.method).toBe('POST');
|
|
155
|
+
expect(init.headers.Authorization).toBe('Bearer device-jwt');
|
|
156
|
+
const { accessTeamDomain: _domain, accessAud: _aud, ...rest } = ACCESS_STATE;
|
|
157
|
+
expect((0, tunnel_state_1.loadTunnelState)(tmpHome)).toEqual(rest);
|
|
158
|
+
});
|
|
159
|
+
it('pins the account server’s email on a state from before pinning', async () => {
|
|
160
|
+
(0, tunnel_state_1.saveTunnelState)({ ...ACCESS_STATE, ownerEmail: undefined }, tmpHome);
|
|
161
|
+
mockedReadToken.mockResolvedValue('device-jwt');
|
|
162
|
+
global.fetch = reply(200, { ownerEmail: 'owner@repoburg.com' });
|
|
163
|
+
await (0, provisioner_1.moveTunnelToEdgeGate)(tmpHome);
|
|
164
|
+
expect((0, tunnel_state_1.loadTunnelState)(tmpHome)?.ownerEmail).toBe('owner@repoburg.com');
|
|
165
|
+
});
|
|
166
|
+
it('has nothing to do without Access fields or without a tunnel', async () => {
|
|
167
|
+
const fetchMock = jest.fn();
|
|
168
|
+
global.fetch = fetchMock;
|
|
169
|
+
await expect((0, provisioner_1.moveTunnelToEdgeGate)(tmpHome)).resolves.toBe(false);
|
|
170
|
+
const { accessTeamDomain: _domain, accessAud: _aud, ...gateState } = ACCESS_STATE;
|
|
171
|
+
(0, tunnel_state_1.saveTunnelState)(gateState, tmpHome);
|
|
172
|
+
await expect((0, provisioner_1.moveTunnelToEdgeGate)(tmpHome)).resolves.toBe(false);
|
|
173
|
+
expect(fetchMock).not.toHaveBeenCalled();
|
|
174
|
+
});
|
|
175
|
+
it('keeps the Access fields when it cannot move (not logged in, server error)', async () => {
|
|
176
|
+
(0, tunnel_state_1.saveTunnelState)(ACCESS_STATE, tmpHome);
|
|
177
|
+
mockedReadToken.mockResolvedValue(null);
|
|
178
|
+
await expect((0, provisioner_1.moveTunnelToEdgeGate)(tmpHome)).rejects.toBeInstanceOf(provisioner_1.ProvisioningError);
|
|
179
|
+
mockedReadToken.mockResolvedValue('device-jwt');
|
|
180
|
+
global.fetch = reply(503, { message: 'Cloudflare API error: denied' });
|
|
181
|
+
await expect((0, provisioner_1.moveTunnelToEdgeGate)(tmpHome)).rejects.toThrow(/denied/);
|
|
182
|
+
expect((0, tunnel_state_1.loadTunnelState)(tmpHome)).toEqual(ACCESS_STATE);
|
|
183
|
+
});
|
|
184
|
+
});
|
|
@@ -45,6 +45,9 @@ function createRemoteRouter() {
|
|
|
45
45
|
service: { running: await (0, cloudflared_1.isServiceRunning)().catch(() => false) },
|
|
46
46
|
connection: { ok: await (0, probes_1.probeTunnelConnected)() },
|
|
47
47
|
access: {
|
|
48
|
+
// Who signs visitors in: the account server's edge gate, or
|
|
49
|
+
// Cloudflare Access on a tunnel from before it (MUH-108).
|
|
50
|
+
gate: state ? (state.accessAud ? 'cloudflare-access' : 'repoburg') : null,
|
|
48
51
|
configured: Boolean(state?.accessTeamDomain && state?.accessAud),
|
|
49
52
|
ownerEmail: state?.ownerEmail ?? null,
|
|
50
53
|
teamDomain: state?.accessTeamDomain ?? null,
|
|
@@ -118,6 +118,7 @@ describe('remote routes', () => {
|
|
|
118
118
|
expect(res.json.service).toEqual({ running: true });
|
|
119
119
|
expect(res.json.connection).toEqual({ ok: true });
|
|
120
120
|
expect(res.json.access).toEqual({
|
|
121
|
+
gate: 'cloudflare-access',
|
|
121
122
|
configured: true,
|
|
122
123
|
ownerEmail: 'owner@repoburg.com',
|
|
123
124
|
teamDomain: 'team.cloudflareaccess.com',
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"tree": "3f01773d2dfcfcfee7b73a8c7d7497c15ad692bc",
|
|
3
|
-
"commit": "
|
|
3
|
+
"commit": "c8a8bf96995548760fca8d881f2f2017d816d5dd",
|
|
4
4
|
"dirty": false,
|
|
5
|
-
"repoburgVersion": "1.3.
|
|
6
|
-
"builtAt": "2026-11-
|
|
5
|
+
"repoburgVersion": "1.3.311",
|
|
6
|
+
"builtAt": "2026-11-09T02:56:59.735Z"
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"tree": "3f01773d2dfcfcfee7b73a8c7d7497c15ad692bc",
|
|
3
|
-
"commit": "
|
|
3
|
+
"commit": "c8a8bf96995548760fca8d881f2f2017d816d5dd",
|
|
4
4
|
"dirty": false,
|
|
5
|
-
"repoburgVersion": "1.3.
|
|
6
|
-
"builtAt": "2026-11-
|
|
5
|
+
"repoburgVersion": "1.3.311",
|
|
6
|
+
"builtAt": "2026-11-09T02:56:59.735Z"
|
|
7
7
|
}
|