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
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
href="https://fonts.googleapis.com/css2?family=Inter:wght@400;450;510;590;600&family=JetBrains+Mono:wght@400;500&display=swap"
|
|
11
11
|
rel="stylesheet"
|
|
12
12
|
/>
|
|
13
|
-
<script type="module" crossorigin src="/assets/index-
|
|
13
|
+
<script type="module" crossorigin src="/assets/index-NpywVkQl.js"></script>
|
|
14
14
|
<link rel="stylesheet" crossorigin href="/assets/index-wFHgyM6i.css">
|
|
15
15
|
</head>
|
|
16
16
|
<body>
|
|
@@ -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
|
});
|