@tianacloud/dsh-remote 0.2.5 → 0.2.7
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/client.js +306 -32
- package/host-main.js +196 -15
- package/package.json +1 -1
- package/src/connect.js +55 -5
- package/src/dsh-packages.js +96 -7
- package/src/frontend-assets.js +90 -32
- package/src/host-bridge.js +76 -12
- package/src/remote-api.js +60 -1
- package/src/state.js +90 -2
- package/src/tiana-cli.js +126 -86
package/src/tiana-cli.js
CHANGED
|
@@ -27,6 +27,7 @@ const RELAY_GO_DIR = join(PROJECT_ROOT, 'relay-go');
|
|
|
27
27
|
export const DEFAULT_FUNCTION_NAME = 'dsh-remote-relay';
|
|
28
28
|
export const DEFAULT_WEB_NAME = 'DSH Remote';
|
|
29
29
|
export const DEFAULT_TOKEN_NAME = 'dsh-remote-host';
|
|
30
|
+
const WEB_APP_OWNERSHIP_ERROR = 'Only the verified owner of this DSH Remote Web app can bind a host to it.';
|
|
30
31
|
|
|
31
32
|
export function tianaBinary(overrideBin) {
|
|
32
33
|
if (typeof overrideBin === 'string' && overrideBin.trim()) return overrideBin.trim();
|
|
@@ -346,11 +347,12 @@ export async function ensureHostToken(state, functionId, { rotateToken = false,
|
|
|
346
347
|
return { token: receipt.token, tokenId: receipt.token_id || '', expiresAt };
|
|
347
348
|
}
|
|
348
349
|
|
|
349
|
-
async function ensureWebApp({ webName, webId, log = console.log, ...cliOpts }) {
|
|
350
|
+
async function ensureWebApp({ webName, webId, status, log = console.log, ...cliOpts }) {
|
|
351
|
+
requireTianaSpaceMatch(status, { webId });
|
|
350
352
|
if (webId) {
|
|
351
|
-
const items = await
|
|
353
|
+
const items = await listWebAppsForOwnership(webId, status, cliOpts);
|
|
352
354
|
const existing = items.find((item) => item.id === webId);
|
|
353
|
-
if (!existing) throw
|
|
355
|
+
if (!existing) throw webAppNotFound(webId, status);
|
|
354
356
|
return existing;
|
|
355
357
|
}
|
|
356
358
|
log(`[dsh-remote] Creating Web app "${webName}"...`);
|
|
@@ -363,7 +365,7 @@ async function ensureWebApp({ webName, webId, log = console.log, ...cliOpts }) {
|
|
|
363
365
|
], cliOpts);
|
|
364
366
|
const createdApp = created?.project ?? created?.app ?? created;
|
|
365
367
|
if (createdApp?.id && !normalizeIdentityValue(createdApp.owner_id) && !normalizeIdentityValue(createdApp.tenant_id)) {
|
|
366
|
-
const items = await
|
|
368
|
+
const items = await listWebAppsForOwnership(createdApp.id, status, cliOpts);
|
|
367
369
|
const listed = items.find((item) => item.id === createdApp.id);
|
|
368
370
|
if (listed) return listed;
|
|
369
371
|
}
|
|
@@ -374,89 +376,141 @@ function normalizeIdentityValue(value) {
|
|
|
374
376
|
return value == null ? '' : String(value).trim();
|
|
375
377
|
}
|
|
376
378
|
|
|
379
|
+
function formatOwnershipError(baseMsg, { webId, status, webApp, binding, reason }) {
|
|
380
|
+
const { user, space } = status ?? {};
|
|
381
|
+
const account = [user?.display_name, user?.email, user?.user_id].map(normalizeIdentityValue).filter(Boolean);
|
|
382
|
+
const spaceId = normalizeIdentityValue(space?.tenant_id) || normalizeIdentityValue(user?.tenant_id);
|
|
383
|
+
const currentSpace = [space?.display_name, spaceId, space?.role].map(normalizeIdentityValue).filter(Boolean);
|
|
384
|
+
if (!reason) {
|
|
385
|
+
if (binding?.canManage === false) reason = '`tiana web functions get` returned `can_manage: false`.';
|
|
386
|
+
else if (binding?.canManage == null) reason = '`tiana web functions get` did not return `can_manage`.';
|
|
387
|
+
else reason = '`tiana web functions get` did not return `can_manage: true`.';
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
return [
|
|
391
|
+
baseMsg,
|
|
392
|
+
`Current Tiana CLI account: ${account.join(' / ') || '(unknown)'}`,
|
|
393
|
+
`Current Tiana space: ${currentSpace.join(' / ') || '(unknown)'}`,
|
|
394
|
+
`Target Web app: ${webId || webApp?.id || '(unknown)'}`,
|
|
395
|
+
`Reason: ${reason}`,
|
|
396
|
+
'',
|
|
397
|
+
'Run `tiana status` to verify the active Tiana CLI account and space.',
|
|
398
|
+
'If you are signed in with a different account, run `tiana logout && tiana login` and sign in as the Web app owner.',
|
|
399
|
+
'If you are in a different space, run `tiana space list`, then `tiana space switch <spaceId>`, or pass `--space <spaceId>` to `dsh-remote connect`.',
|
|
400
|
+
].join('\n');
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
function webAppNotFound(webId, status) {
|
|
404
|
+
return new Error(formatOwnershipError(`Web app "${webId}" was not found in the current Tiana space.`, {
|
|
405
|
+
webId, status, reason: '`tiana web list` did not include this Web app.',
|
|
406
|
+
}));
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
async function listWebAppsForOwnership(webId, status, cliOpts) {
|
|
410
|
+
try {
|
|
411
|
+
return await listTianaWebApps(cliOpts);
|
|
412
|
+
} catch {
|
|
413
|
+
throw new Error(formatOwnershipError(`Could not look up Web app "${webId}" in the current Tiana space.`, {
|
|
414
|
+
webId, status, reason: '`tiana web list` failed to retrieve Web apps in the active space.',
|
|
415
|
+
}));
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
async function getWebBindingForOwnership(webId, status, cliOpts) {
|
|
420
|
+
try {
|
|
421
|
+
return await getWebFunctionBinding(webId, cliOpts);
|
|
422
|
+
} catch {
|
|
423
|
+
throw new Error(formatOwnershipError(WEB_APP_OWNERSHIP_ERROR, {
|
|
424
|
+
webId, status, reason: '`tiana web functions get` failed to retrieve the app’s management permissions.',
|
|
425
|
+
}));
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
function requireTianaSpaceMatch(status, { webId, webApp, errorMessage } = {}) {
|
|
430
|
+
const spaceTenantId = normalizeIdentityValue(status?.space?.tenant_id);
|
|
431
|
+
if (spaceTenantId && spaceTenantId !== normalizeIdentityValue(status?.user?.tenant_id)) {
|
|
432
|
+
throw new Error(formatOwnershipError(errorMessage || WEB_APP_OWNERSHIP_ERROR, {
|
|
433
|
+
webId, webApp, status, reason: 'The space `tenant_id` in Tiana status does not match the account `tenant_id`.',
|
|
434
|
+
}));
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
|
|
377
438
|
export function verifyWebAppOwnership(webApp, status, { binding = null, requireBindingProof = false, errorMessage } = {}) {
|
|
378
|
-
const
|
|
439
|
+
const reject = (reason) => {
|
|
440
|
+
throw new Error(formatOwnershipError(errorMessage || WEB_APP_OWNERSHIP_ERROR, { webApp, status, binding, reason }));
|
|
441
|
+
};
|
|
379
442
|
const expectedUserId = normalizeIdentityValue(status?.user?.user_id);
|
|
380
443
|
const expectedTenantId = normalizeIdentityValue(status?.user?.tenant_id);
|
|
381
444
|
if (!expectedUserId || !expectedTenantId) {
|
|
382
|
-
|
|
445
|
+
reject('Tiana login status is missing `user_id` or `tenant_id`.');
|
|
383
446
|
}
|
|
384
447
|
|
|
385
448
|
// Explicit management denial ALWAYS rejects fail-closed, even when webApp.owner_id matches.
|
|
386
449
|
if (binding?.canManage === false) {
|
|
387
|
-
|
|
450
|
+
reject();
|
|
388
451
|
}
|
|
389
452
|
|
|
453
|
+
requireTianaSpaceMatch(status, { webApp, errorMessage });
|
|
454
|
+
|
|
390
455
|
const webTenantId = normalizeIdentityValue(webApp?.tenant_id);
|
|
391
456
|
if (webTenantId && webTenantId !== expectedTenantId) {
|
|
392
|
-
|
|
457
|
+
reject('The Web app `tenant_id` does not match the active Tiana account `tenant_id`.');
|
|
393
458
|
}
|
|
394
459
|
|
|
395
460
|
const webOwnerId = normalizeIdentityValue(webApp?.owner_id);
|
|
396
461
|
if (webOwnerId) {
|
|
397
462
|
if (webOwnerId !== expectedUserId) {
|
|
398
|
-
|
|
463
|
+
reject('The Web app `owner_id` does not match the active Tiana account `user_id`.');
|
|
399
464
|
}
|
|
400
465
|
return { mode: 'owner_id', verified: true };
|
|
401
466
|
}
|
|
402
467
|
|
|
403
|
-
//
|
|
404
|
-
//
|
|
405
|
-
// management
|
|
406
|
-
if (!webTenantId
|
|
407
|
-
|
|
468
|
+
// Online `web list --json` can return an empty owner_id. MGR's `web functions get`
|
|
469
|
+
// can_manage supplies Web app management proof. status.space.can_manage reflects
|
|
470
|
+
// multi-member team management and is false in standard personal default spaces.
|
|
471
|
+
if (!webTenantId) {
|
|
472
|
+
reject('The Web app is missing `tenant_id` and has no `owner_id`.');
|
|
408
473
|
}
|
|
409
|
-
if (
|
|
410
|
-
|
|
411
|
-
}
|
|
412
|
-
if (requireBindingProof) {
|
|
413
|
-
if (binding?.canManage !== true) {
|
|
414
|
-
throw new Error(msg);
|
|
415
|
-
}
|
|
416
|
-
return { mode: 'tenant_can_manage', verified: true };
|
|
417
|
-
}
|
|
418
|
-
return { mode: 'tenant_pending_manage_proof', verified: false };
|
|
474
|
+
if (!requireBindingProof) return { mode: 'tenant_pending_manage_proof', verified: false };
|
|
475
|
+
if (binding?.canManage !== true) reject();
|
|
476
|
+
return { mode: 'tenant_can_manage', verified: true };
|
|
419
477
|
}
|
|
420
478
|
|
|
421
479
|
async function revalidateWebAppAuthorization(webId, {
|
|
422
480
|
expectedTenantId = '',
|
|
423
481
|
expectedUserId = '',
|
|
424
|
-
errorMessage,
|
|
425
482
|
cliOpts = {},
|
|
426
483
|
fallbackWebApp = null,
|
|
427
484
|
allowCreatedFallback = false,
|
|
428
485
|
} = {}) {
|
|
429
|
-
const msg = errorMessage || 'Only the verified owner of this DSH Remote Web app can bind a host to it.';
|
|
430
486
|
const latestStatus = await getTianaStatus(cliOpts);
|
|
431
|
-
if (!latestStatus?.user?.user_id || !latestStatus?.user?.tenant_id) {
|
|
432
|
-
throw new Error('Tiana login status is missing user_id or tenant_id.');
|
|
433
|
-
}
|
|
434
487
|
if (expectedTenantId && latestStatus.user.tenant_id !== expectedTenantId) {
|
|
435
|
-
throw new Error(
|
|
488
|
+
throw new Error(formatOwnershipError(WEB_APP_OWNERSHIP_ERROR, {
|
|
489
|
+
webId, status: latestStatus, reason: 'The active Tiana space changed while verifying the Web app.',
|
|
490
|
+
}));
|
|
436
491
|
}
|
|
437
492
|
if (expectedUserId && latestStatus.user.user_id !== expectedUserId) {
|
|
438
|
-
throw new Error(
|
|
493
|
+
throw new Error(formatOwnershipError(WEB_APP_OWNERSHIP_ERROR, {
|
|
494
|
+
webId, status: latestStatus, reason: 'The active Tiana CLI account changed while verifying the Web app.',
|
|
495
|
+
}));
|
|
439
496
|
}
|
|
497
|
+
requireTianaSpaceMatch(latestStatus, { webId });
|
|
440
498
|
|
|
441
|
-
const latestWebApps = await
|
|
499
|
+
const latestWebApps = await listWebAppsForOwnership(webId, latestStatus, cliOpts);
|
|
442
500
|
const listedWebApp = latestWebApps.find((item) => item.id === webId);
|
|
443
501
|
if (!listedWebApp) {
|
|
444
502
|
if (!allowCreatedFallback || !fallbackWebApp || latestWebApps.length > 0) {
|
|
445
|
-
throw
|
|
446
|
-
}
|
|
447
|
-
// Stale owner_id from an earlier `web create` response is NOT current proof when `web list` is empty:
|
|
448
|
-
// require current server-side management proof (`can_manage: true`) from `web functions get` + space check.
|
|
449
|
-
if (latestStatus?.space && typeof latestStatus.space.can_manage === 'boolean' && latestStatus.space.can_manage !== true) {
|
|
450
|
-
throw new Error(msg);
|
|
503
|
+
throw webAppNotFound(webId, latestStatus);
|
|
451
504
|
}
|
|
452
|
-
|
|
505
|
+
// An earlier `web create` response needs fresh proof from `web functions get`
|
|
506
|
+
// when `web list` is empty, including when the create response had an owner_id.
|
|
507
|
+
const latestBinding = await getWebBindingForOwnership(webId, latestStatus, cliOpts);
|
|
453
508
|
if (latestBinding?.canManage !== true) {
|
|
454
|
-
throw new Error(
|
|
509
|
+
throw new Error(formatOwnershipError(WEB_APP_OWNERSHIP_ERROR, { webId, status: latestStatus, binding: latestBinding }));
|
|
455
510
|
}
|
|
456
511
|
verifyWebAppOwnership(fallbackWebApp, latestStatus, {
|
|
457
512
|
binding: latestBinding,
|
|
458
513
|
requireBindingProof: true,
|
|
459
|
-
errorMessage: msg,
|
|
460
514
|
});
|
|
461
515
|
if (fallbackWebApp.enabled === false) {
|
|
462
516
|
throw new Error(`Web app "${webId}" is disabled.`);
|
|
@@ -474,10 +528,7 @@ async function revalidateWebAppAuthorization(webId, {
|
|
|
474
528
|
};
|
|
475
529
|
}
|
|
476
530
|
|
|
477
|
-
verifyWebAppOwnership(listedWebApp, latestStatus
|
|
478
|
-
requireBindingProof: false,
|
|
479
|
-
errorMessage: msg,
|
|
480
|
-
});
|
|
531
|
+
verifyWebAppOwnership(listedWebApp, latestStatus);
|
|
481
532
|
if (listedWebApp.enabled === false) {
|
|
482
533
|
throw new Error(`Web app "${webId}" is disabled.`);
|
|
483
534
|
}
|
|
@@ -486,11 +537,10 @@ async function revalidateWebAppAuthorization(webId, {
|
|
|
486
537
|
}
|
|
487
538
|
const latestWebUrl = validateWebEndpoint(listedWebApp, webId);
|
|
488
539
|
|
|
489
|
-
const latestBinding = await
|
|
540
|
+
const latestBinding = await getWebBindingForOwnership(webId, latestStatus, cliOpts);
|
|
490
541
|
const verified = verifyWebAppOwnership(listedWebApp, latestStatus, {
|
|
491
542
|
binding: latestBinding,
|
|
492
543
|
requireBindingProof: true,
|
|
493
|
-
errorMessage: msg,
|
|
494
544
|
});
|
|
495
545
|
return {
|
|
496
546
|
status: latestStatus,
|
|
@@ -506,7 +556,7 @@ async function ensureWebFunctionBinding(webId, functionId, {
|
|
|
506
556
|
requireManage = false,
|
|
507
557
|
initialBinding = null,
|
|
508
558
|
revalidate = null,
|
|
509
|
-
|
|
559
|
+
status,
|
|
510
560
|
log = console.log,
|
|
511
561
|
...cliOpts
|
|
512
562
|
} = {}) {
|
|
@@ -516,12 +566,13 @@ async function ensureWebFunctionBinding(webId, functionId, {
|
|
|
516
566
|
const fresh = await revalidate();
|
|
517
567
|
current = fresh.binding;
|
|
518
568
|
requireManage = fresh.requiresManageProof;
|
|
569
|
+
status = fresh.status;
|
|
519
570
|
} else {
|
|
520
|
-
current = await
|
|
571
|
+
current = await getWebBindingForOwnership(webId, status, cliOpts);
|
|
521
572
|
}
|
|
522
573
|
}
|
|
523
|
-
if (requireManage && current.canManage !== true) {
|
|
524
|
-
throw new Error(
|
|
574
|
+
if (current.canManage === false || (requireManage && current.canManage !== true)) {
|
|
575
|
+
throw new Error(formatOwnershipError(WEB_APP_OWNERSHIP_ERROR, { webId, status, binding: current }));
|
|
525
576
|
}
|
|
526
577
|
const bound = current.functionInstanceIds;
|
|
527
578
|
if (bound.length === 1 && bound[0] === functionId) {
|
|
@@ -553,11 +604,12 @@ async function ensureWebFunctionBinding(webId, functionId, {
|
|
|
553
604
|
const fresh = await revalidate();
|
|
554
605
|
rechecked = fresh.binding;
|
|
555
606
|
recheckedRequireManage = fresh.requiresManageProof;
|
|
607
|
+
status = fresh.status;
|
|
556
608
|
} else {
|
|
557
|
-
rechecked = await
|
|
609
|
+
rechecked = await getWebBindingForOwnership(webId, status, cliOpts);
|
|
558
610
|
}
|
|
559
|
-
if (recheckedRequireManage && rechecked.canManage !== true) {
|
|
560
|
-
throw new Error(
|
|
611
|
+
if (rechecked.canManage === false || (recheckedRequireManage && rechecked.canManage !== true)) {
|
|
612
|
+
throw new Error(formatOwnershipError(WEB_APP_OWNERSHIP_ERROR, { webId, status, binding: rechecked }));
|
|
561
613
|
}
|
|
562
614
|
if (rechecked.functionInstanceIds[0]) {
|
|
563
615
|
log(`[dsh-remote] Adopting Relay Function ${rechecked.functionInstanceIds[0]} bound concurrently to Web ${webId}`);
|
|
@@ -601,9 +653,10 @@ export function hasBindingIdentityConflict(existingPolicy, { hostId, registratio
|
|
|
601
653
|
* Writes DSH_REMOTE_POLICY via `tiana function parameters set` without rebuilding Go or .tweb.
|
|
602
654
|
*
|
|
603
655
|
* Transactional safety:
|
|
604
|
-
* 1. Validates
|
|
605
|
-
*
|
|
606
|
-
*
|
|
656
|
+
* 1. Validates account and space IDs and checks ownership. A non-empty `owner_id` must match the
|
|
657
|
+
* account `user_id`. An empty `owner_id` requires a matching non-empty Web app `tenant_id` and
|
|
658
|
+
* MGR's Web app `can_manage: true` from `tiana web functions get`. `status.space.can_manage`
|
|
659
|
+
* describes multi-member team management and is false in ordinary personal default spaces.
|
|
607
660
|
* 2. Validates Relay Function is ACTIVE, HTTPS, and passes `/healthz` check.
|
|
608
661
|
* 3. Reads existing function parameters strictly (never swallows errors).
|
|
609
662
|
* 4. Checks rebind conflict across hostId + hostDigest + hostPublicKey.
|
|
@@ -633,18 +686,15 @@ export async function bindTianaRemoteWeb(options = {}) {
|
|
|
633
686
|
throw new Error(`Failed to switch Tiana space to "${options.spaceId}".`);
|
|
634
687
|
}
|
|
635
688
|
|
|
636
|
-
|
|
689
|
+
requireTianaSpaceMatch(status, { webId });
|
|
637
690
|
const targetTenantId = options.spaceId || status.user.tenant_id;
|
|
638
691
|
const targetUserId = status.user.user_id;
|
|
639
|
-
const webApps = await
|
|
692
|
+
const webApps = await listWebAppsForOwnership(webId, status, cliOpts);
|
|
640
693
|
let webApp = webApps.find((item) => item.id === webId);
|
|
641
694
|
if (!webApp) {
|
|
642
|
-
throw
|
|
695
|
+
throw webAppNotFound(webId, status);
|
|
643
696
|
}
|
|
644
|
-
verifyWebAppOwnership(webApp, status
|
|
645
|
-
requireBindingProof: false,
|
|
646
|
-
errorMessage: bindOwnerError,
|
|
647
|
-
});
|
|
697
|
+
verifyWebAppOwnership(webApp, status);
|
|
648
698
|
if (webApp.enabled === false) {
|
|
649
699
|
throw new Error(`Web app "${webId}" is disabled.`);
|
|
650
700
|
}
|
|
@@ -654,17 +704,15 @@ export async function bindTianaRemoteWeb(options = {}) {
|
|
|
654
704
|
let webUrl = validateWebEndpoint(webApp, webId);
|
|
655
705
|
|
|
656
706
|
// Locate bound Relay Function (and verify can_manage proof when owner_id is empty) before any mutation
|
|
657
|
-
const binding = await
|
|
707
|
+
const binding = await getWebBindingForOwnership(webId, status, cliOpts);
|
|
658
708
|
verifyWebAppOwnership(webApp, status, {
|
|
659
709
|
binding,
|
|
660
710
|
requireBindingProof: true,
|
|
661
|
-
errorMessage: bindOwnerError,
|
|
662
711
|
});
|
|
663
712
|
|
|
664
713
|
const revalidateBindAuth = () => revalidateWebAppAuthorization(webId, {
|
|
665
714
|
expectedTenantId: targetTenantId,
|
|
666
715
|
expectedUserId: targetUserId,
|
|
667
|
-
errorMessage: bindOwnerError,
|
|
668
716
|
cliOpts,
|
|
669
717
|
});
|
|
670
718
|
|
|
@@ -693,7 +741,7 @@ export async function bindTianaRemoteWeb(options = {}) {
|
|
|
693
741
|
const boundFnId = await ensureWebFunctionBinding(webId, fnId, {
|
|
694
742
|
adoptExisting: true,
|
|
695
743
|
revalidate: revalidateBindAuth,
|
|
696
|
-
|
|
744
|
+
status,
|
|
697
745
|
log,
|
|
698
746
|
...cliOpts,
|
|
699
747
|
});
|
|
@@ -748,7 +796,7 @@ export async function bindTianaRemoteWeb(options = {}) {
|
|
|
748
796
|
initialBinding: activeBinding,
|
|
749
797
|
requireManage: freshAuth.requiresManageProof,
|
|
750
798
|
revalidate: revalidateBindAuth,
|
|
751
|
-
|
|
799
|
+
status,
|
|
752
800
|
log,
|
|
753
801
|
...cliOpts,
|
|
754
802
|
});
|
|
@@ -1020,10 +1068,13 @@ export async function provisionTianaRemote(options = {}) {
|
|
|
1020
1068
|
const hostName = options.hostName || prevState.host?.hostName || identity.hostName;
|
|
1021
1069
|
|
|
1022
1070
|
if (!/^[a-z0-9_-]{1,48}$/u.test(hostId)) throw new Error('Invalid host ID');
|
|
1071
|
+
const configuredWebId = prevState.web?.id || pending.webId;
|
|
1023
1072
|
const previousOwner = prevState.owner || pending.owner;
|
|
1024
1073
|
if ((previousOwner?.userId && previousOwner.userId !== status.user.user_id) ||
|
|
1025
1074
|
(previousOwner?.tenantId && previousOwner.tenantId !== status.user.tenant_id)) {
|
|
1026
|
-
throw new Error(
|
|
1075
|
+
throw new Error(formatOwnershipError(WEB_APP_OWNERSHIP_ERROR, {
|
|
1076
|
+
webId: configuredWebId, status, reason: 'Use the Tiana account and space that originally configured this DSH host.',
|
|
1077
|
+
}));
|
|
1027
1078
|
}
|
|
1028
1079
|
if ((prevState.host?.hostId || pending.hostId || hostId) !== hostId) {
|
|
1029
1080
|
throw new Error('This installation is already bound to a different host ID');
|
|
@@ -1046,17 +1097,11 @@ export async function provisionTianaRemote(options = {}) {
|
|
|
1046
1097
|
lastWrittenPendingSetup = snapshotPending;
|
|
1047
1098
|
};
|
|
1048
1099
|
|
|
1049
|
-
const setupOwnerError = 'The configured Web app does not belong to the DSH owner and space';
|
|
1050
|
-
const configuredWebId = prevState.web?.id || pending.webId;
|
|
1051
1100
|
const hadExistingWebId = Boolean(configuredWebId);
|
|
1052
|
-
let webApp = await ensureWebApp({ webName, webId: configuredWebId, log, ...cliOpts });
|
|
1101
|
+
let webApp = await ensureWebApp({ webName, webId: configuredWebId, status, log, ...cliOpts });
|
|
1053
1102
|
const webId = webApp?.id;
|
|
1054
1103
|
if (!/^[a-z][a-z0-9]{11}$/u.test(webId || '')) throw new Error('Invalid Web app ID');
|
|
1055
|
-
|
|
1056
|
-
requireBindingProof: false,
|
|
1057
|
-
errorMessage: setupOwnerError,
|
|
1058
|
-
});
|
|
1059
|
-
let requiresManageProof = ownershipCheck.mode !== 'owner_id';
|
|
1104
|
+
verifyWebAppOwnership(webApp, status);
|
|
1060
1105
|
if (webApp.enabled === false) {
|
|
1061
1106
|
throw new Error(`Web app "${webId}" is disabled.`);
|
|
1062
1107
|
}
|
|
@@ -1067,11 +1112,10 @@ export async function provisionTianaRemote(options = {}) {
|
|
|
1067
1112
|
let webEndpoint = webUrl.href;
|
|
1068
1113
|
// Always query web functions binding during preflight (even when owner_id matches)
|
|
1069
1114
|
// so an explicit can_manage: false rejects before creating/publishing a Relay Function or minting a token.
|
|
1070
|
-
const initialBinding = await
|
|
1115
|
+
const initialBinding = await getWebBindingForOwnership(webId, status, cliOpts);
|
|
1071
1116
|
verifyWebAppOwnership(webApp, status, {
|
|
1072
1117
|
binding: initialBinding,
|
|
1073
1118
|
requireBindingProof: true,
|
|
1074
|
-
errorMessage: setupOwnerError,
|
|
1075
1119
|
});
|
|
1076
1120
|
await checkpoint({ webId, owner, hostId, registrationKey, e2ee });
|
|
1077
1121
|
|
|
@@ -1101,7 +1145,6 @@ export async function provisionTianaRemote(options = {}) {
|
|
|
1101
1145
|
preRelayAuth = await revalidateWebAppAuthorization(webId, {
|
|
1102
1146
|
expectedTenantId: owner.tenantId,
|
|
1103
1147
|
expectedUserId: owner.userId,
|
|
1104
|
-
errorMessage: setupOwnerError,
|
|
1105
1148
|
cliOpts,
|
|
1106
1149
|
fallbackWebApp: hadExistingWebId ? null : webApp,
|
|
1107
1150
|
allowCreatedFallback: !hadExistingWebId,
|
|
@@ -1114,7 +1157,6 @@ export async function provisionTianaRemote(options = {}) {
|
|
|
1114
1157
|
webApp = preRelayAuth.webApp;
|
|
1115
1158
|
webUrl = preRelayAuth.webUrl;
|
|
1116
1159
|
webEndpoint = webUrl.href;
|
|
1117
|
-
requiresManageProof = preRelayAuth.requiresManageProof;
|
|
1118
1160
|
|
|
1119
1161
|
const fnShown = await syncAndPublishRelayFunction(fnInstance.id, webId, {
|
|
1120
1162
|
forcePublish: Boolean(options.forcePublish), log, ...cliOpts,
|
|
@@ -1139,7 +1181,6 @@ export async function provisionTianaRemote(options = {}) {
|
|
|
1139
1181
|
freshAuth = await revalidateWebAppAuthorization(webId, {
|
|
1140
1182
|
expectedTenantId: owner.tenantId,
|
|
1141
1183
|
expectedUserId: owner.userId,
|
|
1142
|
-
errorMessage: setupOwnerError,
|
|
1143
1184
|
cliOpts,
|
|
1144
1185
|
fallbackWebApp: hadExistingWebId ? null : webApp,
|
|
1145
1186
|
allowCreatedFallback: !hadExistingWebId,
|
|
@@ -1152,7 +1193,6 @@ export async function provisionTianaRemote(options = {}) {
|
|
|
1152
1193
|
webApp = freshAuth.webApp;
|
|
1153
1194
|
webUrl = freshAuth.webUrl;
|
|
1154
1195
|
webEndpoint = webUrl.href;
|
|
1155
|
-
requiresManageProof = freshAuth.requiresManageProof;
|
|
1156
1196
|
|
|
1157
1197
|
const policy = buildRemotePolicy({
|
|
1158
1198
|
hostId,
|
|
@@ -1167,8 +1207,8 @@ export async function provisionTianaRemote(options = {}) {
|
|
|
1167
1207
|
await updateRemotePolicy(fnInstance.id, policy, { log, ...cliOpts });
|
|
1168
1208
|
await ensureWebFunctionBinding(webId, fnInstance.id, {
|
|
1169
1209
|
initialBinding: freshAuth.binding,
|
|
1170
|
-
requireManage: requiresManageProof,
|
|
1171
|
-
|
|
1210
|
+
requireManage: freshAuth.requiresManageProof,
|
|
1211
|
+
status,
|
|
1172
1212
|
log,
|
|
1173
1213
|
...cliOpts,
|
|
1174
1214
|
});
|