repoburg 1.3.310 → 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/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
|
@@ -36,14 +36,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
36
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.authManager = void 0;
|
|
39
|
+
exports.authManager = exports.PUBLIC_KEY = void 0;
|
|
40
40
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
41
41
|
const path_1 = __importDefault(require("path"));
|
|
42
42
|
const os_1 = __importDefault(require("os"));
|
|
43
43
|
const jose = __importStar(require("jose"));
|
|
44
44
|
const REPOBURG_DIR = path_1.default.join(os_1.default.homedir(), '.repoburg');
|
|
45
45
|
const TOKEN_PATH = path_1.default.join(REPOBURG_DIR, 'token.jwt');
|
|
46
|
-
|
|
46
|
+
/** The public half of the account server's signing key (device tokens, edge tokens). */
|
|
47
|
+
exports.PUBLIC_KEY = `-----BEGIN PUBLIC KEY-----
|
|
47
48
|
MCowBQYDK2VwAyEAcNJkxXJrYEa4cZmcq80A1Ns0y/HIt/WWEiWJ5F3E9ZE=
|
|
48
49
|
-----END PUBLIC KEY-----`;
|
|
49
50
|
class AuthManager {
|
|
@@ -53,7 +54,7 @@ class AuthManager {
|
|
|
53
54
|
}
|
|
54
55
|
async loadPublicKey() {
|
|
55
56
|
try {
|
|
56
|
-
const keyData = PUBLIC_KEY;
|
|
57
|
+
const keyData = exports.PUBLIC_KEY;
|
|
57
58
|
console.log(`[AuthManager] Loading hardcoded public key: ${keyData.substring(0, 50)}...`);
|
|
58
59
|
this.publicKey = await jose.importSPKI(keyData, 'EdDSA');
|
|
59
60
|
}
|
package/daemon/dist/index.js
CHANGED
|
@@ -18,6 +18,7 @@ const mcp_gateway_1 = require("./mcp-gateway");
|
|
|
18
18
|
const agentPane_1 = require("./agentPane");
|
|
19
19
|
const routes_1 = require("./remote/routes");
|
|
20
20
|
const checkRemoteAuth_1 = require("./middleware/checkRemoteAuth");
|
|
21
|
+
const edge_gate_move_1 = require("./remote/edge-gate-move");
|
|
21
22
|
const staticServing_1 = require("./staticServing");
|
|
22
23
|
const router_1 = require("./recorder/router");
|
|
23
24
|
const tabtape_1 = require("./tabtape");
|
|
@@ -77,9 +78,10 @@ async function main() {
|
|
|
77
78
|
// route. See middleware/originGuard.ts for who is allowed and why.
|
|
78
79
|
app.use(originGuard_1.originGuard);
|
|
79
80
|
app.use((0, cors_1.default)(originGuard_1.corsOptions));
|
|
80
|
-
//
|
|
81
|
-
//
|
|
82
|
-
|
|
81
|
+
// Tunnel guard: a request that came through the tunnel needs the edge
|
|
82
|
+
// gate's token (or, on a tunnel still behind CF Access, an Access JWT) on
|
|
83
|
+
// every route. Local requests pass. See middleware/checkRemoteAuth.ts.
|
|
84
|
+
app.use(checkRemoteAuth_1.checkRemoteAuth);
|
|
83
85
|
// Embedded agent-pane API. MUST precede express.json() — Fastify parses its
|
|
84
86
|
// own request bodies; the stream can only be consumed once.
|
|
85
87
|
app.all('/api/*', (0, agentPane_1.createPaneDelegate)(pane));
|
|
@@ -138,10 +140,10 @@ async function main() {
|
|
|
138
140
|
ws.on('error', (error) => console.error('WebSocket error:', error));
|
|
139
141
|
});
|
|
140
142
|
// Single upgrade router: '/tabtape/...' -> tabtape live viewing, '/ws' ->
|
|
141
|
-
// embedded agent-pane
|
|
142
|
-
//
|
|
143
|
-
//
|
|
144
|
-
const paneUpgrade = (0, agentPane_1.createUpgradeRouter)(pane, wss
|
|
143
|
+
// embedded agent-pane, '/ws/terminal' -> a shell of the pane, '/vscode' ->
|
|
144
|
+
// VS Code, everything else -> daemon wss. Tunnel upgrades of any kind pass
|
|
145
|
+
// the tunnel guard first (checkRemoteWsAuth), the same one as HTTP routes.
|
|
146
|
+
const paneUpgrade = (0, agentPane_1.createUpgradeRouter)(pane, wss);
|
|
145
147
|
server.on('upgrade', (req, socket, head) => {
|
|
146
148
|
const url = req.url ?? '';
|
|
147
149
|
if (url === tabtape_1.TABTAPE_MOUNT || url.startsWith(`${tabtape_1.TABTAPE_MOUNT}/`)) {
|
|
@@ -151,7 +153,14 @@ async function main() {
|
|
|
151
153
|
socket.destroy();
|
|
152
154
|
return;
|
|
153
155
|
}
|
|
154
|
-
|
|
156
|
+
void (0, checkRemoteAuth_1.checkRemoteWsAuth)(req).then((allowed) => {
|
|
157
|
+
if (allowed) {
|
|
158
|
+
paneUpgrade(req, socket, head);
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
socket.write('HTTP/1.1 401 Unauthorized\r\n\r\n');
|
|
162
|
+
socket.destroy();
|
|
163
|
+
}, () => socket.destroy());
|
|
155
164
|
});
|
|
156
165
|
// Spec: loopback binding only — remote access is exclusively via the
|
|
157
166
|
// cloudflared tunnel; the daemon must never listen on public interfaces.
|
|
@@ -159,6 +168,8 @@ async function main() {
|
|
|
159
168
|
console.log(`Repoburg Platform Daemon listening on http://127.0.0.1:${PORT}`);
|
|
160
169
|
console.log(`MCP Gateway available at http://localhost:${PORT}/mcp`);
|
|
161
170
|
tabtape = loadTabtape();
|
|
171
|
+
// A tunnel still behind Cloudflare Access moves to the edge gate.
|
|
172
|
+
(0, edge_gate_move_1.scheduleEdgeGateMove)();
|
|
162
173
|
// Adopt the agents the previous daemon left running in session hosts and
|
|
163
174
|
// resume the turns it left interrupted (restart, crash, power loss) —
|
|
164
175
|
// only now that the port is ours.
|
|
@@ -1,87 +1,87 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.remoteAuthFailure = remoteAuthFailure;
|
|
3
4
|
exports.checkRemoteAuth = checkRemoteAuth;
|
|
4
5
|
exports.checkRemoteWsAuth = checkRemoteWsAuth;
|
|
5
|
-
exports.checkTerminalWsAuth = checkTerminalWsAuth;
|
|
6
6
|
const tunnel_state_1 = require("../remote/tunnel-state");
|
|
7
7
|
const access_jwt_1 = require("../remote/access-jwt");
|
|
8
|
+
const edge_jwt_1 = require("../remote/edge-jwt");
|
|
8
9
|
const originGuard_1 = require("./originGuard");
|
|
9
10
|
/**
|
|
10
|
-
* Guard for
|
|
11
|
-
*
|
|
11
|
+
* Guard for requests that ARRIVED THROUGH THE TUNNEL: every route, every
|
|
12
|
+
* WebSocket upgrade (the pane API, the shell, the MCP gateway, the SPA).
|
|
12
13
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
14
|
+
* Who needs a credential is decided by the Host header:
|
|
15
|
+
* - loopback (the local pane at localhost:9998, agent.repoburg.com calling
|
|
16
|
+
* the visitor's own daemon, the Mac app): no — the loopback binding is the
|
|
17
|
+
* boundary there;
|
|
18
|
+
* - `<mahlas>.repoburg.com` (tunnel traffic; remote clients cannot forge the
|
|
19
|
+
* Host through the CF edge, routing is by hostname/SNI): yes, always;
|
|
20
|
+
* - a host of REPOBURG_ALLOWED_ORIGINS (the owner's own proxy): no;
|
|
21
|
+
* - anything else: yes (it cannot be this machine's tunnel, so it fails).
|
|
22
|
+
*
|
|
23
|
+
* Accepted credentials, either one (fail closed: without one, 401):
|
|
24
|
+
* - an edge token (X-Repoburg-Edge-Auth) from the account server's edge
|
|
25
|
+
* gate, for this hostname and the pinned owner email (MUH-108);
|
|
26
|
+
* - a Cloudflare Access JWT (Cf-Access-Jwt-Assertion), while this tunnel
|
|
27
|
+
* still has its Access app (remote.json has accessTeamDomain + accessAud),
|
|
28
|
+
* also pinned to the owner email.
|
|
20
29
|
*/
|
|
21
|
-
function
|
|
30
|
+
function needsCredential(host) {
|
|
22
31
|
if (!host)
|
|
23
|
-
return
|
|
24
|
-
|
|
32
|
+
return false; // no Host header = non-HTTP client tooling, not a browser
|
|
33
|
+
if ((0, originGuard_1.isLoopbackHost)(host))
|
|
34
|
+
return false;
|
|
35
|
+
if ((0, originGuard_1.isTunnelHost)(host))
|
|
36
|
+
return true;
|
|
37
|
+
return !(0, originGuard_1.isExtraOriginHost)(host);
|
|
25
38
|
}
|
|
26
|
-
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
// Fail closed: Access is configured but the owner email was never pinned
|
|
37
|
-
// (state from before email pinging). Re-provision the machine.
|
|
38
|
-
if (!state.ownerEmail) {
|
|
39
|
-
res.status(401).json({ error: 'Tunnel owner email is missing — re-provision this machine.' });
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
const assertion = req.headers['cf-access-jwt-assertion'];
|
|
43
|
-
if (typeof assertion !== 'string') {
|
|
44
|
-
res.status(401).json({ error: 'Cloudflare Access authentication required.' });
|
|
45
|
-
return;
|
|
39
|
+
const header = (headers, name) => {
|
|
40
|
+
const value = headers[name];
|
|
41
|
+
return typeof value === 'string' ? value : undefined;
|
|
42
|
+
};
|
|
43
|
+
/** Why the request may not pass, or null when it may. */
|
|
44
|
+
async function remoteAuthFailure(headers, state = (0, tunnel_state_1.loadTunnelState)()) {
|
|
45
|
+
if (!needsCredential(headers.host))
|
|
46
|
+
return null;
|
|
47
|
+
if (!state || (0, originGuard_1.hostnameOf)(headers.host ?? '') !== state.hostname) {
|
|
48
|
+
return 'This machine has no tunnel at this address.';
|
|
46
49
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
+
// Fail closed: state from before email pinning. Re-provision the machine.
|
|
51
|
+
if (!state.ownerEmail)
|
|
52
|
+
return 'Tunnel owner email is missing — re-provision this machine.';
|
|
53
|
+
const edgeToken = header(headers, edge_jwt_1.EDGE_AUTH_HEADER);
|
|
54
|
+
if (edgeToken) {
|
|
55
|
+
try {
|
|
56
|
+
await (0, edge_jwt_1.verifyEdgeJwt)(edgeToken, { hostname: state.hostname, ownerEmail: state.ownerEmail });
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
return 'Invalid or expired sign-in token.';
|
|
61
|
+
}
|
|
50
62
|
}
|
|
51
|
-
|
|
52
|
-
|
|
63
|
+
const assertion = header(headers, 'cf-access-jwt-assertion');
|
|
64
|
+
if (assertion && state.accessTeamDomain && state.accessAud) {
|
|
65
|
+
try {
|
|
66
|
+
await (0, access_jwt_1.verifyAccessJwt)(assertion, { teamDomain: state.accessTeamDomain, aud: state.accessAud }, { ownerEmail: state.ownerEmail });
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
return 'Invalid or expired Cloudflare Access token.';
|
|
71
|
+
}
|
|
53
72
|
}
|
|
73
|
+
return 'Sign in to this machine first.';
|
|
54
74
|
}
|
|
55
|
-
/**
|
|
56
|
-
async function
|
|
57
|
-
const
|
|
58
|
-
if (
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
return true; // local usage
|
|
62
|
-
if (!state.ownerEmail)
|
|
63
|
-
return false; // fail closed: no pinned owner email
|
|
64
|
-
const assertion = req.headers['cf-access-jwt-assertion'];
|
|
65
|
-
if (typeof assertion !== 'string')
|
|
66
|
-
return false;
|
|
67
|
-
try {
|
|
68
|
-
await (0, access_jwt_1.verifyAccessJwt)(assertion, { teamDomain: state.accessTeamDomain, aud: state.accessAud }, { ownerEmail: state.ownerEmail });
|
|
69
|
-
return true;
|
|
70
|
-
}
|
|
71
|
-
catch {
|
|
72
|
-
return false;
|
|
75
|
+
/** Express middleware for every route. */
|
|
76
|
+
async function checkRemoteAuth(req, res, next) {
|
|
77
|
+
const failure = await remoteAuthFailure(req.headers);
|
|
78
|
+
if (failure) {
|
|
79
|
+
res.status(401).json({ error: failure });
|
|
80
|
+
return;
|
|
73
81
|
}
|
|
82
|
+
next();
|
|
74
83
|
}
|
|
75
|
-
/**
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
* Access configured.
|
|
79
|
-
*/
|
|
80
|
-
async function checkTerminalWsAuth(req) {
|
|
81
|
-
if (isLocalHostHeader(req.headers.host))
|
|
82
|
-
return true;
|
|
83
|
-
const state = (0, tunnel_state_1.loadTunnelState)();
|
|
84
|
-
if (!state?.accessTeamDomain || !state.accessAud)
|
|
85
|
-
return false;
|
|
86
|
-
return checkRemoteWsAuth(req);
|
|
84
|
+
/** The same guard for WebSocket upgrades: false = reject and destroy the socket. */
|
|
85
|
+
async function checkRemoteWsAuth(req) {
|
|
86
|
+
return (await remoteAuthFailure(req.headers)) === null;
|
|
87
87
|
}
|
|
@@ -1,156 +1,210 @@
|
|
|
1
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
|
+
})();
|
|
2
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
const jose = __importStar(require("jose"));
|
|
3
37
|
const checkRemoteAuth_1 = require("./checkRemoteAuth");
|
|
38
|
+
const originGuard_1 = require("./originGuard");
|
|
4
39
|
const tunnel_state_1 = require("../remote/tunnel-state");
|
|
5
40
|
const access_jwt_1 = require("../remote/access-jwt");
|
|
6
41
|
jest.mock('../remote/tunnel-state');
|
|
7
42
|
jest.mock('../remote/access-jwt');
|
|
8
43
|
const mockedLoad = tunnel_state_1.loadTunnelState;
|
|
9
|
-
const
|
|
44
|
+
const mockedVerifyAccess = access_jwt_1.verifyAccessJwt;
|
|
10
45
|
/** Requests THROUGH THE TUNNEL carry the machine hostname as Host. */
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
const
|
|
46
|
+
const HOSTNAME = 'zztest.repoburg.com';
|
|
47
|
+
const TUNNEL_HOST = `${HOSTNAME}:443`;
|
|
48
|
+
const OWNER = 'owner@repoburg.com';
|
|
49
|
+
/** A tunnel behind the edge gate (provisioned with edgeAuth, or moved). */
|
|
50
|
+
const GATE_STATE = {
|
|
51
|
+
mahlas: 'zztest',
|
|
52
|
+
hostname: HOSTNAME,
|
|
53
|
+
accountTunnelId: 'tunnel-id',
|
|
54
|
+
tunnelToken: 'connector',
|
|
55
|
+
ownerEmail: OWNER,
|
|
56
|
+
};
|
|
57
|
+
/** A tunnel still behind Cloudflare Access. */
|
|
58
|
+
const ACCESS_STATE = {
|
|
59
|
+
...GATE_STATE,
|
|
14
60
|
accessTeamDomain: 'team.cloudflareaccess.com',
|
|
15
61
|
accessAud: 'aud-tag',
|
|
16
|
-
ownerEmail: 'owner@repoburg.com',
|
|
17
|
-
};
|
|
18
|
-
const makeRes = () => {
|
|
19
|
-
const res = { status: jest.fn(), json: jest.fn() };
|
|
20
|
-
res.status.mockReturnValue(res);
|
|
21
|
-
return res;
|
|
22
62
|
};
|
|
23
|
-
|
|
63
|
+
let signingKey;
|
|
64
|
+
/** An edge token as the account server's gate signs it. */
|
|
65
|
+
async function edgeToken(claims = {}, key = signingKey) {
|
|
66
|
+
const jwt = new jose.SignJWT({ email: claims.email ?? OWNER })
|
|
67
|
+
.setProtectedHeader({ alg: 'EdDSA' })
|
|
68
|
+
.setIssuedAt()
|
|
69
|
+
.setIssuer(claims.iss ?? 'repoburg.com')
|
|
70
|
+
.setAudience(claims.aud ?? `tunnel:${HOSTNAME}`)
|
|
71
|
+
.setExpirationTime(claims.exp ?? '5m');
|
|
72
|
+
if (claims.sub !== '')
|
|
73
|
+
jwt.setSubject(claims.sub ?? 'user-id');
|
|
74
|
+
return jwt.sign(key);
|
|
75
|
+
}
|
|
76
|
+
beforeAll(async () => {
|
|
77
|
+
const pair = await jose.generateKeyPair('EdDSA', { extractable: true });
|
|
78
|
+
signingKey = pair.privateKey;
|
|
79
|
+
process.env.REPOBURG_EDGE_PUBLIC_KEY = await jose.exportSPKI(pair.publicKey);
|
|
80
|
+
});
|
|
81
|
+
afterAll(() => {
|
|
82
|
+
delete process.env.REPOBURG_EDGE_PUBLIC_KEY;
|
|
83
|
+
});
|
|
24
84
|
beforeEach(() => {
|
|
25
85
|
mockedLoad.mockReset().mockReturnValue(null);
|
|
26
|
-
|
|
86
|
+
mockedVerifyAccess.mockReset().mockResolvedValue(undefined);
|
|
87
|
+
(0, originGuard_1.setExtraOriginsForTest)([]);
|
|
27
88
|
});
|
|
28
|
-
describe('
|
|
29
|
-
it('
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
it('passes through when Access is not configured yet', async () => {
|
|
35
|
-
mockedLoad.mockReturnValue({ accessTeamDomain: undefined, accessAud: undefined });
|
|
36
|
-
const next = jest.fn();
|
|
37
|
-
await (0, checkRemoteAuth_1.checkRemoteAuth)(makeReq({ host: TUNNEL_HOST }), makeRes(), next);
|
|
38
|
-
expect(next).toHaveBeenCalled();
|
|
39
|
-
});
|
|
40
|
-
it('passes local requests even when Access is configured (local pane + agent.repoburg.com FE)', async () => {
|
|
41
|
-
mockedLoad.mockReturnValue(PINNED_STATE);
|
|
42
|
-
for (const host of ['localhost:9998', '127.0.0.1:9998', '0.0.0.0:9998']) {
|
|
43
|
-
const next = jest.fn();
|
|
44
|
-
await (0, checkRemoteAuth_1.checkRemoteAuth)(makeReq({ host }), makeRes(), next);
|
|
45
|
-
expect(next).toHaveBeenCalledWith();
|
|
89
|
+
describe('remoteAuthFailure: who needs a credential', () => {
|
|
90
|
+
it('lets local requests through, whatever the tunnel state', async () => {
|
|
91
|
+
for (const state of [null, GATE_STATE, ACCESS_STATE]) {
|
|
92
|
+
for (const host of ['localhost:9998', '127.0.0.1:9998', '0.0.0.0:9998', undefined]) {
|
|
93
|
+
expect(await (0, checkRemoteAuth_1.remoteAuthFailure)({ host }, state)).toBeNull();
|
|
94
|
+
}
|
|
46
95
|
}
|
|
47
|
-
expect(
|
|
96
|
+
expect(mockedVerifyAccess).not.toHaveBeenCalled();
|
|
48
97
|
});
|
|
49
98
|
it('does not take a lookalike Host for a local one', async () => {
|
|
50
|
-
mockedLoad.mockReturnValue(PINNED_STATE);
|
|
51
99
|
for (const host of ['localhost.evil.com', '127.0.0.1.evil.com:9998', '0.0.0.0.evil.com']) {
|
|
52
|
-
|
|
53
|
-
const next = jest.fn();
|
|
54
|
-
await (0, checkRemoteAuth_1.checkRemoteAuth)(makeReq({ host }), res, next);
|
|
55
|
-
expect(res.status).toHaveBeenCalledWith(401);
|
|
56
|
-
expect(next).not.toHaveBeenCalled();
|
|
100
|
+
expect(await (0, checkRemoteAuth_1.remoteAuthFailure)({ host }, GATE_STATE)).not.toBeNull();
|
|
57
101
|
}
|
|
58
102
|
});
|
|
59
|
-
it('
|
|
60
|
-
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
await (0, checkRemoteAuth_1.
|
|
64
|
-
expect(res.status).toHaveBeenCalledWith(401);
|
|
65
|
-
expect(next).not.toHaveBeenCalled();
|
|
103
|
+
it('fails closed on tunnel traffic with no tunnel, or for another hostname', async () => {
|
|
104
|
+
const token = await edgeToken();
|
|
105
|
+
const headers = { host: TUNNEL_HOST, 'x-repoburg-edge-auth': token };
|
|
106
|
+
expect(await (0, checkRemoteAuth_1.remoteAuthFailure)(headers, null)).toBe('This machine has no tunnel at this address.');
|
|
107
|
+
expect(await (0, checkRemoteAuth_1.remoteAuthFailure)({ ...headers, host: 'other.repoburg.com' }, GATE_STATE)).toBe('This machine has no tunnel at this address.');
|
|
66
108
|
});
|
|
67
|
-
it('
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
const next = jest.fn();
|
|
71
|
-
await (0, checkRemoteAuth_1.checkRemoteAuth)(makeReq({ host: TUNNEL_HOST, 'cf-access-jwt-assertion': 'jwt' }), res, next);
|
|
72
|
-
expect(res.status).toHaveBeenCalledWith(401);
|
|
73
|
-
expect(mockedVerify).not.toHaveBeenCalled();
|
|
74
|
-
expect(next).not.toHaveBeenCalled();
|
|
109
|
+
it('fails closed without a pinned owner email', async () => {
|
|
110
|
+
const headers = { host: TUNNEL_HOST, 'x-repoburg-edge-auth': await edgeToken() };
|
|
111
|
+
expect(await (0, checkRemoteAuth_1.remoteAuthFailure)(headers, { ...GATE_STATE, ownerEmail: undefined })).toBe('Tunnel owner email is missing — re-provision this machine.');
|
|
75
112
|
});
|
|
113
|
+
it('lets the owner’s own proxy host through (REPOBURG_ALLOWED_ORIGINS), but never a tunnel host', async () => {
|
|
114
|
+
(0, originGuard_1.setExtraOriginsForTest)(['https://pane.example.org', `https://${HOSTNAME}`]);
|
|
115
|
+
expect(await (0, checkRemoteAuth_1.remoteAuthFailure)({ host: 'pane.example.org' }, null)).toBeNull();
|
|
116
|
+
expect(await (0, checkRemoteAuth_1.remoteAuthFailure)({ host: TUNNEL_HOST }, GATE_STATE)).toBe('Sign in to this machine first.');
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
describe('remoteAuthFailure: edge tokens', () => {
|
|
120
|
+
const withToken = async (token, state = GATE_STATE) => (0, checkRemoteAuth_1.remoteAuthFailure)({ host: TUNNEL_HOST, 'x-repoburg-edge-auth': token }, state);
|
|
121
|
+
it('accepts the gate’s token for this hostname and the owner', async () => {
|
|
122
|
+
expect(await withToken(await edgeToken())).toBeNull();
|
|
123
|
+
expect(await withToken(await edgeToken({ email: 'Owner@Repoburg.com' }))).toBeNull();
|
|
124
|
+
});
|
|
125
|
+
it('accepts it on a tunnel still behind Access too (the move is under way)', async () => {
|
|
126
|
+
expect(await withToken(await edgeToken(), ACCESS_STATE)).toBeNull();
|
|
127
|
+
});
|
|
128
|
+
it('refuses a token without credentials, of another machine, owner, issuer or key, or expired', async () => {
|
|
129
|
+
const other = await jose.generateKeyPair('EdDSA');
|
|
130
|
+
const bad = [
|
|
131
|
+
await edgeToken({ aud: 'tunnel:other.repoburg.com' }),
|
|
132
|
+
await edgeToken({ aud: 'repoburg-daemon' }), // a device token is no edge token
|
|
133
|
+
await edgeToken({ email: 'hacker@evil.com' }),
|
|
134
|
+
await edgeToken({ iss: 'evil.com' }),
|
|
135
|
+
await edgeToken({ exp: Math.floor(Date.now() / 1000) - 600 }),
|
|
136
|
+
await edgeToken({ sub: '' }),
|
|
137
|
+
await edgeToken({}, other.privateKey),
|
|
138
|
+
'not-a-jwt',
|
|
139
|
+
];
|
|
140
|
+
for (const token of bad) {
|
|
141
|
+
expect(await withToken(token)).toBe('Invalid or expired sign-in token.');
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
it('tolerates a machine clock a minute off', async () => {
|
|
145
|
+
const token = await edgeToken({ exp: Math.floor(Date.now() / 1000) - 60 });
|
|
146
|
+
expect(await withToken(token)).toBeNull();
|
|
147
|
+
});
|
|
148
|
+
it('asks to sign in when there is no credential at all', async () => {
|
|
149
|
+
expect(await (0, checkRemoteAuth_1.remoteAuthFailure)({ host: TUNNEL_HOST }, GATE_STATE)).toBe('Sign in to this machine first.');
|
|
150
|
+
});
|
|
151
|
+
it('does not take an Access JWT on a tunnel that moved to the gate', async () => {
|
|
152
|
+
const headers = { host: TUNNEL_HOST, 'cf-access-jwt-assertion': 'jwt' };
|
|
153
|
+
expect(await (0, checkRemoteAuth_1.remoteAuthFailure)(headers, GATE_STATE)).toBe('Sign in to this machine first.');
|
|
154
|
+
expect(mockedVerifyAccess).not.toHaveBeenCalled();
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
describe('remoteAuthFailure: Cloudflare Access (tunnels from before the gate)', () => {
|
|
158
|
+
const headers = { host: TUNNEL_HOST, 'cf-access-jwt-assertion': 'jwt' };
|
|
76
159
|
it('accepts a valid Access JWT and pins the owner email', async () => {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
await (0, checkRemoteAuth_1.checkRemoteAuth)(makeReq({ host: TUNNEL_HOST, 'cf-access-jwt-assertion': 'jwt' }), makeRes(), next);
|
|
80
|
-
expect(mockedVerify).toHaveBeenCalledWith('jwt', { teamDomain: 'team.cloudflareaccess.com', aud: 'aud-tag' }, { ownerEmail: 'owner@repoburg.com' });
|
|
81
|
-
expect(next).toHaveBeenCalled();
|
|
82
|
-
});
|
|
83
|
-
it('rejects a valid-signature JWT for the WRONG email with 401 (email pinning)', async () => {
|
|
84
|
-
mockedLoad.mockReturnValue(PINNED_STATE);
|
|
85
|
-
// Simulates a policy edited by a compromised account-server: CF signed
|
|
86
|
-
// the token, but common_name is the attacker's email.
|
|
87
|
-
mockedVerify.mockRejectedValue(new Error('Access token email does not match the machine owner'));
|
|
88
|
-
const res = makeRes();
|
|
89
|
-
const next = jest.fn();
|
|
90
|
-
await (0, checkRemoteAuth_1.checkRemoteAuth)(makeReq({ host: TUNNEL_HOST, 'cf-access-jwt-assertion': 'jwt' }), res, next);
|
|
91
|
-
expect(res.status).toHaveBeenCalledWith(401);
|
|
92
|
-
expect(next).not.toHaveBeenCalled();
|
|
160
|
+
expect(await (0, checkRemoteAuth_1.remoteAuthFailure)(headers, ACCESS_STATE)).toBeNull();
|
|
161
|
+
expect(mockedVerifyAccess).toHaveBeenCalledWith('jwt', { teamDomain: 'team.cloudflareaccess.com', aud: 'aud-tag' }, { ownerEmail: OWNER });
|
|
93
162
|
});
|
|
94
|
-
it('rejects an invalid
|
|
95
|
-
|
|
96
|
-
|
|
163
|
+
it('rejects an invalid one, or one for the wrong email (email pinning)', async () => {
|
|
164
|
+
mockedVerifyAccess.mockRejectedValue(new Error('Access token email does not match the machine owner'));
|
|
165
|
+
expect(await (0, checkRemoteAuth_1.remoteAuthFailure)(headers, ACCESS_STATE)).toBe('Invalid or expired Cloudflare Access token.');
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
describe('checkRemoteAuth (HTTP, every route)', () => {
|
|
169
|
+
const makeRes = () => {
|
|
170
|
+
const res = { status: jest.fn(), json: jest.fn() };
|
|
171
|
+
res.status.mockReturnValue(res);
|
|
172
|
+
return res;
|
|
173
|
+
};
|
|
174
|
+
const makeReq = (headers) => ({ headers });
|
|
175
|
+
it('answers 401 with the reason and runs no route', async () => {
|
|
176
|
+
mockedLoad.mockReturnValue(GATE_STATE);
|
|
97
177
|
const res = makeRes();
|
|
98
178
|
const next = jest.fn();
|
|
99
|
-
await (0, checkRemoteAuth_1.checkRemoteAuth)(makeReq({ host: TUNNEL_HOST
|
|
179
|
+
await (0, checkRemoteAuth_1.checkRemoteAuth)(makeReq({ host: TUNNEL_HOST }), res, next);
|
|
100
180
|
expect(res.status).toHaveBeenCalledWith(401);
|
|
181
|
+
expect(res.json).toHaveBeenCalledWith({ error: 'Sign in to this machine first.' });
|
|
101
182
|
expect(next).not.toHaveBeenCalled();
|
|
102
183
|
});
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
it('denies tunnel-host upgrades without an assertion when configured', async () => {
|
|
115
|
-
mockedLoad.mockReturnValue(PINNED_STATE);
|
|
116
|
-
await expect((0, checkRemoteAuth_1.checkRemoteWsAuth)(makeReq({ host: TUNNEL_HOST }))).resolves.toBe(false);
|
|
117
|
-
});
|
|
118
|
-
it('fails closed when configured without a pinned owner email', async () => {
|
|
119
|
-
mockedLoad.mockReturnValue({ accessTeamDomain: 'team.cloudflareaccess.com', accessAud: 'aud' });
|
|
120
|
-
await expect((0, checkRemoteAuth_1.checkRemoteWsAuth)(makeReq({ host: TUNNEL_HOST }))).resolves.toBe(false);
|
|
121
|
-
});
|
|
122
|
-
it('allows tunnel-host upgrades with a valid assertion and pins the owner email', async () => {
|
|
123
|
-
mockedLoad.mockReturnValue(PINNED_STATE);
|
|
124
|
-
await expect((0, checkRemoteAuth_1.checkRemoteWsAuth)(makeReq({ host: TUNNEL_HOST, 'cf-access-jwt-assertion': 'jwt' }))).resolves.toBe(true);
|
|
125
|
-
expect(mockedVerify).toHaveBeenCalledWith('jwt', { teamDomain: 'team.cloudflareaccess.com', aud: 'aud-tag' }, { ownerEmail: 'owner@repoburg.com' });
|
|
184
|
+
it('runs the route for the owner’s edge token and for local requests', async () => {
|
|
185
|
+
mockedLoad.mockReturnValue(GATE_STATE);
|
|
186
|
+
const requests = [
|
|
187
|
+
{ host: TUNNEL_HOST, 'x-repoburg-edge-auth': await edgeToken() },
|
|
188
|
+
{ host: 'localhost:9998' },
|
|
189
|
+
];
|
|
190
|
+
for (const headers of requests) {
|
|
191
|
+
const next = jest.fn();
|
|
192
|
+
await (0, checkRemoteAuth_1.checkRemoteAuth)(makeReq(headers), makeRes(), next);
|
|
193
|
+
expect(next).toHaveBeenCalledWith();
|
|
194
|
+
}
|
|
126
195
|
});
|
|
127
196
|
});
|
|
128
|
-
describe('
|
|
197
|
+
describe('checkRemoteWsAuth (every WebSocket upgrade, the shell included)', () => {
|
|
129
198
|
const upgrade = (headers) => ({ headers });
|
|
130
|
-
it('
|
|
131
|
-
expect(await (0, checkRemoteAuth_1.
|
|
132
|
-
mockedLoad.mockReturnValue(
|
|
133
|
-
expect(await (0, checkRemoteAuth_1.
|
|
134
|
-
expect(
|
|
135
|
-
});
|
|
136
|
-
it('
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
expect(await (0, checkRemoteAuth_1.
|
|
140
|
-
mockedLoad.mockReturnValue({ accessTeamDomain: 'team.cloudflareaccess.com' });
|
|
141
|
-
expect(await (0, checkRemoteAuth_1.checkTerminalWsAuth)(upgrade({ host: TUNNEL_HOST }))).toBe(false);
|
|
142
|
-
});
|
|
143
|
-
it('refuses the tunnel without a valid Access token', async () => {
|
|
144
|
-
mockedLoad.mockReturnValue(PINNED_STATE);
|
|
145
|
-
expect(await (0, checkRemoteAuth_1.checkTerminalWsAuth)(upgrade({ host: TUNNEL_HOST }))).toBe(false);
|
|
146
|
-
mockedVerify.mockRejectedValue(new Error('bad signature'));
|
|
147
|
-
const forged = { host: TUNNEL_HOST, 'cf-access-jwt-assertion': 'forged' };
|
|
148
|
-
expect(await (0, checkRemoteAuth_1.checkTerminalWsAuth)(upgrade(forged))).toBe(false);
|
|
149
|
-
});
|
|
150
|
-
it('lets the owner through the tunnel with a valid Access token', async () => {
|
|
151
|
-
mockedLoad.mockReturnValue(PINNED_STATE);
|
|
152
|
-
mockedVerify.mockResolvedValue({ email: PINNED_STATE.ownerEmail });
|
|
153
|
-
const headers = { host: TUNNEL_HOST, 'cf-access-jwt-assertion': 'valid' };
|
|
154
|
-
expect(await (0, checkRemoteAuth_1.checkTerminalWsAuth)(upgrade(headers))).toBe(true);
|
|
199
|
+
it('never gives the tunnel a socket without a credential, even when nothing is configured', async () => {
|
|
200
|
+
expect(await (0, checkRemoteAuth_1.checkRemoteWsAuth)(upgrade({ host: TUNNEL_HOST }))).toBe(false);
|
|
201
|
+
mockedLoad.mockReturnValue(GATE_STATE);
|
|
202
|
+
expect(await (0, checkRemoteAuth_1.checkRemoteWsAuth)(upgrade({ host: TUNNEL_HOST }))).toBe(false);
|
|
203
|
+
expect(await (0, checkRemoteAuth_1.checkRemoteWsAuth)(upgrade({ host: TUNNEL_HOST, 'x-repoburg-edge-auth': 'forged' }))).toBe(false);
|
|
204
|
+
});
|
|
205
|
+
it('lets the owner through the tunnel, and local upgrades', async () => {
|
|
206
|
+
mockedLoad.mockReturnValue(GATE_STATE);
|
|
207
|
+
expect(await (0, checkRemoteAuth_1.checkRemoteWsAuth)(upgrade({ host: TUNNEL_HOST, 'x-repoburg-edge-auth': await edgeToken() }))).toBe(true);
|
|
208
|
+
expect(await (0, checkRemoteAuth_1.checkRemoteWsAuth)(upgrade({ host: 'localhost:9998' }))).toBe(true);
|
|
155
209
|
});
|
|
156
210
|
});
|
|
@@ -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
|
}
|