@fabrika/provider-zerops 0.9.0-dev.1 → 0.9.0-dev.11
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/package.json +17 -14
- package/sandbox/Dockerfile +16 -0
- package/sandbox/bin/postgres-auth.sh +38 -0
- package/sandbox/bin/reset.sh +12 -0
- package/sandbox/bin/run-build.sh +35 -0
- package/sandbox/bin/run-launcher.sh +18 -0
- package/sandbox/bin/start-launcher.sh +25 -0
- package/sandbox/bin/stop.sh +47 -0
- package/sandbox/init.sh +61 -0
- package/src/api/client.ts +15 -1
- package/src/api/errors.ts +7 -3
- package/src/api/readers.ts +29 -0
- package/src/api/types.ts +52 -0
- package/src/api.ts +2 -0
- package/src/cli.ts +11 -0
- package/src/collaborators.ts +0 -14
- package/src/compile.ts +1 -1
- package/src/control.ts +159 -92
- package/src/execution.ts +45 -195
- package/src/index.ts +2 -0
- package/src/installation/admin.ts +1 -1
- package/src/installation/deploy-options.ts +10 -2
- package/src/installation/deploy.ts +241 -81
- package/src/installation/generated/platform-console-schema.ts +3 -0
- package/src/installation/generated/platform-proxy-manifest.ts +1 -1
- package/src/installation/guide.md +53 -19
- package/src/installation/hosts.ts +1 -7
- package/src/installation/index.ts +20 -16
- package/src/installation/init-options.ts +2 -1
- package/src/installation/install-environment.ts +47 -108
- package/src/installation/install-options.ts +3 -1
- package/src/installation/install-secrets.ts +24 -68
- package/src/installation/install.ts +9 -4
- package/src/installation/plain-credentials.ts +91 -0
- package/src/installation/sidecar.ts +5 -26
- package/src/installation/templates/README.md +13 -12
- package/src/installation/templates/platform.yml +3 -0
- package/src/installation/topology/setups.ts +17 -4
- package/src/installation/topology/topology.ts +33 -23
- package/src/installation/upgrade-options.ts +2 -2
- package/src/managed-env.ts +1 -174
- package/src/manifest.ts +14 -17
- package/src/namespace/claims.ts +60 -1
- package/src/namespace/codec.ts +17 -0
- package/src/namespace/errors.ts +22 -1
- package/src/namespace/manifest.ts +36 -23
- package/src/namespace/provisioning.ts +88 -114
- package/src/namespace/proxy-attempt.ts +14 -2
- package/src/namespace/proxy-reads.ts +28 -23
- package/src/namespace/proxy-secrets.ts +18 -5
- package/src/namespace/sandbox-host.ts +212 -0
- package/src/namespace/subdomain.ts +113 -0
- package/src/namespace/topology.ts +1 -1
- package/src/namespace/types.ts +13 -0
- package/src/namespace/update.ts +1 -0
- package/src/namespace-cli.ts +152 -0
- package/src/plain-credentials.ts +90 -0
- package/src/plan.ts +1 -6
- package/src/provider.ts +88 -166
- package/src/proxy-manifest-carrier.ts +39 -0
- package/src/sandbox/base-image.ts +100 -0
- package/src/sandbox/constants.ts +44 -0
- package/src/sandbox/deploy.ts +471 -0
- package/src/sandbox/dev-artifact.ts +206 -0
- package/src/sandbox/lifecycle.ts +204 -0
- package/src/sandbox/scripts.ts +26 -0
- package/src/sandbox-host.ts +28 -0
- package/src/source/port.ts +5 -0
- package/src/types.ts +6 -2
- package/src/zbox/client.ts +259 -0
- package/src/zbox/errors.ts +45 -0
- package/src/zbox/index.ts +22 -0
- package/src/zbox/types.ts +165 -0
- package/types/src/api/client.d.ts +5 -0
- package/types/src/api/errors.d.ts +26 -0
- package/types/src/api/polling.d.ts +41 -0
- package/types/src/api/readers.d.ts +1115 -0
- package/types/src/api/service-env-limit.d.ts +17 -0
- package/types/src/api/service-env-response.d.ts +23 -0
- package/types/src/api/types.d.ts +687 -0
- package/types/src/api.d.ts +6 -0
- package/types/src/authoring.d.ts +9 -0
- package/types/src/cli-args.d.ts +19 -0
- package/types/src/cli.d.ts +13 -0
- package/types/src/collaborators.d.ts +16 -0
- package/types/src/compile.d.ts +91 -0
- package/types/src/control.d.ts +51 -0
- package/types/src/database-budget.d.ts +38 -0
- package/types/src/descriptor.d.ts +28 -0
- package/types/src/execution.d.ts +114 -0
- package/types/src/exposure.d.ts +47 -0
- package/types/src/index.d.ts +31 -0
- package/types/src/installation/admin-options.d.ts +24 -0
- package/types/src/installation/admin.d.ts +35 -0
- package/types/src/installation/checker-release.d.ts +12 -0
- package/types/src/installation/deploy-options.d.ts +42 -0
- package/types/src/installation/deploy.d.ts +136 -0
- package/types/src/installation/generated/platform-console-schema.d.ts +2 -0
- package/types/src/installation/generated/platform-proxy-manifest.d.ts +2 -0
- package/types/src/installation/hosts.d.ts +34 -0
- package/types/src/installation/index.d.ts +7 -0
- package/types/src/installation/init-options.d.ts +38 -0
- package/types/src/installation/init.d.ts +60 -0
- package/types/src/installation/install-collaborators.d.ts +24 -0
- package/types/src/installation/install-environment.d.ts +63 -0
- package/types/src/installation/install-options.d.ts +49 -0
- package/types/src/installation/install-project.d.ts +13 -0
- package/types/src/installation/install-provisioning.d.ts +58 -0
- package/types/src/installation/install-secrets.d.ts +17 -0
- package/types/src/installation/install-token.d.ts +10 -0
- package/types/src/installation/install.d.ts +23 -0
- package/types/src/installation/installation-source.d.ts +8 -0
- package/types/src/installation/log.d.ts +44 -0
- package/types/src/installation/machine-key.d.ts +19 -0
- package/types/src/installation/placement-options.d.ts +11 -0
- package/types/src/installation/plain-credentials.d.ts +20 -0
- package/types/src/installation/platform-archive.d.ts +7 -0
- package/types/src/installation/platform-source.d.ts +8 -0
- package/types/src/installation/platform-upload.d.ts +3 -0
- package/types/src/installation/sidecar.d.ts +49 -0
- package/types/src/installation/source-options.d.ts +1 -0
- package/types/src/installation/topology/artifacts.d.ts +8 -0
- package/types/src/installation/topology/index.d.ts +5 -0
- package/types/src/installation/topology/installation-schemas.d.ts +2242 -0
- package/types/src/installation/topology/invariants.d.ts +23 -0
- package/types/src/installation/topology/setups.d.ts +59 -0
- package/types/src/installation/topology/topology.d.ts +153 -0
- package/types/src/installation/topology/validate.d.ts +11 -0
- package/types/src/installation/upgrade-options.d.ts +26 -0
- package/types/src/installation/upgrade-output.d.ts +6 -0
- package/types/src/installation/upgrade.d.ts +88 -0
- package/types/src/managed-env.d.ts +24 -0
- package/types/src/manifest.d.ts +199 -0
- package/types/src/namespace/claims.d.ts +16 -0
- package/types/src/namespace/codec.d.ts +352 -0
- package/types/src/namespace/constants.d.ts +25 -0
- package/types/src/namespace/errors.d.ts +25 -0
- package/types/src/namespace/manifest.d.ts +4 -0
- package/types/src/namespace/operator.d.ts +12 -0
- package/types/src/namespace/provisioning.d.ts +4 -0
- package/types/src/namespace/proxy-attempt.d.ts +39 -0
- package/types/src/namespace/proxy-reads.d.ts +27 -0
- package/types/src/namespace/proxy-secrets.d.ts +8 -0
- package/types/src/namespace/proxy-source.d.ts +74 -0
- package/types/src/namespace/sandbox-host.d.ts +23 -0
- package/types/src/namespace/subdomain.d.ts +43 -0
- package/types/src/namespace/topology.d.ts +9 -0
- package/types/src/namespace/types.d.ts +111 -0
- package/types/src/namespace/update.d.ts +6 -0
- package/types/src/namespace/validation.d.ts +12 -0
- package/types/src/namespace-cli.d.ts +2 -0
- package/types/src/namespace.d.ts +9 -0
- package/types/src/plain-credentials.d.ts +7 -0
- package/types/src/plan.d.ts +11 -0
- package/types/src/provider.d.ts +60 -0
- package/types/src/proxy-manifest-carrier.d.ts +37 -0
- package/types/src/sandbox/base-image.d.ts +28 -0
- package/types/src/sandbox/constants.d.ts +30 -0
- package/types/src/sandbox/deploy.d.ts +75 -0
- package/types/src/sandbox/dev-artifact.d.ts +51 -0
- package/types/src/sandbox/lifecycle.d.ts +27 -0
- package/types/src/sandbox/scripts.d.ts +11 -0
- package/types/src/sandbox-host.d.ts +16 -0
- package/types/src/schema.generated.d.ts +376 -0
- package/types/src/service-names.d.ts +4 -0
- package/types/src/service-references.d.ts +13 -0
- package/types/src/source/constants.d.ts +6 -0
- package/types/src/source/port.d.ts +65 -0
- package/types/src/source/types.d.ts +4 -0
- package/types/src/source/validation.d.ts +19 -0
- package/types/src/source.d.ts +2 -0
- package/types/src/types.d.ts +125 -0
- package/types/src/version-attempt.d.ts +8 -0
- package/types/src/zbox/client.d.ts +2 -0
- package/types/src/zbox/errors.d.ts +25 -0
- package/types/src/zbox/index.d.ts +3 -0
- package/types/src/zbox/types.d.ts +433 -0
- package/src/installation/mcp.ts +0 -102
- package/src/installation/proxy-manifest.ts +0 -214
- package/src/installation/secrets.ts +0 -78
package/src/namespace/errors.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ProviderNamespaceError } from '@fabrika/provider-contract'
|
|
2
2
|
import { ZeropsApiError, ZeropsServiceEnvValueTooLargeError } from '../api'
|
|
3
3
|
import { ZeropsSourceRateLimitedError } from '../source/port'
|
|
4
|
+
import { ZboxApiError, ZboxOperationFailed } from '../zbox'
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Lifecycle codes this provider defines where the platform has none of its own. They are an
|
|
@@ -19,6 +20,21 @@ export const ZEROPS_SUBDOMAIN_NOT_PUBLISHED = 'subdomainNotPublished'
|
|
|
19
20
|
|
|
20
21
|
export const ZEROPS_SOURCE_RATE_LIMITED = 'githubRateLimited'
|
|
21
22
|
|
|
23
|
+
/** A dev sandbox entry would be published to a namespace whose pinned proxy cannot parse one. */
|
|
24
|
+
export const ZEROPS_PROXY_SANDBOXES_UNSUPPORTED = 'proxySandboxesUnsupported'
|
|
25
|
+
|
|
26
|
+
/** A sandbox host was asked of a namespace that serves no custom domain, which a dev environment's wildcard needs. */
|
|
27
|
+
export const ZEROPS_SANDBOX_HOST_UNSUPPORTED = 'sandboxHostUnsupported'
|
|
28
|
+
|
|
29
|
+
/** The Box API did not accept the namespace's key after the service restarted with it. */
|
|
30
|
+
export const ZEROPS_SANDBOX_HOST_KEY_REFUSED = 'sandboxHostKeyRefused'
|
|
31
|
+
|
|
32
|
+
/** The Box API answered a request that carried no key, even after a restart with the namespace's key. */
|
|
33
|
+
export const ZEROPS_SANDBOX_HOST_API_OPEN = 'sandboxHostApiOpen'
|
|
34
|
+
|
|
35
|
+
/** A dev environment an older release registered with its own Zerops service, which runs in no sandbox. */
|
|
36
|
+
export const ZEROPS_DEV_TARGET_RETIRED = 'devTargetRetired'
|
|
37
|
+
|
|
22
38
|
export const namespaceError = (code: string, message: string, retryable: boolean, detail?: string): ProviderNamespaceError =>
|
|
23
39
|
new ProviderNamespaceError(message, code, retryable, detail)
|
|
24
40
|
|
|
@@ -42,12 +58,17 @@ const splitApiMessage = (message: string, code: string): { summary: string; deta
|
|
|
42
58
|
}
|
|
43
59
|
|
|
44
60
|
/** Every namespace lifecycle failure leaves this provider as one typed, coded error. */
|
|
45
|
-
export const asNamespaceError = (cause: unknown, mode: 'provision' | 'reconcile' | 'update'): ProviderNamespaceError => {
|
|
61
|
+
export const asNamespaceError = (cause: unknown, mode: 'provision' | 'reconcile' | 'update' | 'claim check'): ProviderNamespaceError => {
|
|
46
62
|
if (cause instanceof ProviderNamespaceError) return cause
|
|
47
63
|
// The same value is refused again on every retry; only a smaller manifest or a new carrier fixes it.
|
|
48
64
|
if (cause instanceof ZeropsServiceEnvValueTooLargeError) return namespaceError(cause.code, cause.message, false)
|
|
49
65
|
// The limit resets on its own: the namespace stays `provisioning` and the cron's reconcile retries it.
|
|
50
66
|
if (cause instanceof ZeropsSourceRateLimitedError) return namespaceError(ZEROPS_SOURCE_RATE_LIMITED, cause.message, true)
|
|
67
|
+
// The message is the operation, the status and Box's code only: Box echoes request data in its bodies.
|
|
68
|
+
if (cause instanceof ZboxApiError) {
|
|
69
|
+
return namespaceError(cause.code, cause.message, cause.status === 0 || cause.status === 429 || cause.status >= 500)
|
|
70
|
+
}
|
|
71
|
+
if (cause instanceof ZboxOperationFailed) return namespaceError(cause.code ?? 'zboxOperationFailed', cause.message, false)
|
|
51
72
|
if (cause instanceof ZeropsApiError) {
|
|
52
73
|
const { summary, detail } = splitApiMessage(cause.message, cause.code)
|
|
53
74
|
return namespaceError(
|
|
@@ -1,15 +1,43 @@
|
|
|
1
1
|
import { appEnvironmentId } from '@fabrika/auth-core'
|
|
2
2
|
import { decodeEnvelope, type ProviderNamespaceMember } from '@fabrika/provider-contract'
|
|
3
|
-
import {
|
|
4
|
-
import { contractProxyTable, type ProxyManifest } from '@fabrika/proxy-core/manifest'
|
|
3
|
+
import { contractProxyEntry, contractProxyTable, devSandboxEntryId, type ProxyManifest } from '@fabrika/proxy-core/manifest'
|
|
5
4
|
import { assertFabrikaManifestCoordinates, zeropsArtifactCodec } from '../manifest'
|
|
5
|
+
import { SANDBOX_UPSTREAM } from '../sandbox-host'
|
|
6
6
|
|
|
7
7
|
/** Compile every public member of one deployment namespace into its strict proxy manifest. */
|
|
8
8
|
export function compileNamespaceProxyManifest(namespaceId: string, members: readonly ProviderNamespaceMember[]): ProxyManifest {
|
|
9
9
|
const apps: ProxyManifest['apps'] = []
|
|
10
10
|
const ids = new Set<string>()
|
|
11
11
|
const hosts = new Set<string>()
|
|
12
|
+
const claim = (id: string, host: string): void => {
|
|
13
|
+
if (ids.has(id)) throw new Error(`duplicate proxy app id \`${id}\` in deployment namespace ${namespaceId}`)
|
|
14
|
+
if (hosts.has(host)) throw new Error(`duplicate proxy host \`${host}\` in deployment namespace ${namespaceId}`)
|
|
15
|
+
ids.add(id)
|
|
16
|
+
hosts.add(host)
|
|
17
|
+
}
|
|
12
18
|
for (const member of members) {
|
|
19
|
+
// A dev member is served only through its workspaces' sandboxes, each behind the namespace's own sandbox host; its
|
|
20
|
+
// upstream is never the artifact's, so the artifact is not decoded.
|
|
21
|
+
if (member.devSandboxes !== undefined) {
|
|
22
|
+
const audience = appEnvironmentId(member.appId, member.env)
|
|
23
|
+
for (const sandbox of member.devSandboxes) {
|
|
24
|
+
const id = devSandboxEntryId(member.appId, sandbox.workspaceId)
|
|
25
|
+
const host = sandbox.host.toLowerCase()
|
|
26
|
+
claim(id, host)
|
|
27
|
+
apps.push(contractProxyEntry({
|
|
28
|
+
id,
|
|
29
|
+
audience,
|
|
30
|
+
hosts: [host],
|
|
31
|
+
upstream: SANDBOX_UPSTREAM,
|
|
32
|
+
upstreamHost: sandbox.upstreamHost,
|
|
33
|
+
scheme: 'https',
|
|
34
|
+
table: contractProxyTable(sandbox.access.contract, sandbox.access.contractDigest),
|
|
35
|
+
...(member.operationsOrigin === undefined ? {} : { operationsOrigin: member.operationsOrigin }),
|
|
36
|
+
...(member.crossOrigins === undefined ? {} : { crossOrigins: member.crossOrigins }),
|
|
37
|
+
}))
|
|
38
|
+
}
|
|
39
|
+
continue
|
|
40
|
+
}
|
|
13
41
|
// Only Control decides what routes a member (ADR-0050): its approved contract's endpoint table. A member without
|
|
14
42
|
// one is not routed, and its artifact is not decoded, so a legacy one cannot stop the others' republish.
|
|
15
43
|
const access = member.access
|
|
@@ -24,33 +52,18 @@ export function compileNamespaceProxyManifest(namespaceId: string, members: read
|
|
|
24
52
|
const host = member.domain.toLowerCase()
|
|
25
53
|
// The proxy mints for the IAM application id of this environment (ADR-0022 rule 6).
|
|
26
54
|
const id = appEnvironmentId(member.appId, member.env)
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
ids.add(id)
|
|
30
|
-
hosts.add(host)
|
|
31
|
-
const operationsOrigin = member.operationsOrigin
|
|
32
|
-
if (operationsOrigin !== undefined && !isPolicyOrigin(operationsOrigin, ['https:', 'http:'])) {
|
|
33
|
-
throw new Error(`Zerops proxy target ${member.appId}/${member.env} has an Operations ingest origin that is not an http(s) origin`)
|
|
34
|
-
}
|
|
35
|
-
const crossOrigins = member.crossOrigins ?? []
|
|
36
|
-
if (
|
|
37
|
-
crossOrigins.length > MAX_CROSS_ORIGINS
|
|
38
|
-
|| new Set(crossOrigins).size !== crossOrigins.length
|
|
39
|
-
|| crossOrigins.some((origin) => !isCrossOrigin(origin) || new URL(origin).hostname === host)
|
|
40
|
-
) {
|
|
41
|
-
throw new Error(`Zerops proxy target ${member.appId}/${member.env} has a cross-origin list the proxy manifest refuses`)
|
|
42
|
-
}
|
|
43
|
-
apps.push({
|
|
55
|
+
claim(id, host)
|
|
56
|
+
apps.push(contractProxyEntry({
|
|
44
57
|
id,
|
|
45
58
|
hosts: [host],
|
|
46
59
|
upstream: proxy.upstream,
|
|
47
60
|
// A Zerops public domain is always served over the project's TLS-terminating L7 balancer, so the
|
|
48
61
|
// browser speaks https even though the proxy itself is reached over plain HTTP (ADR-0022).
|
|
49
62
|
scheme: 'https',
|
|
50
|
-
|
|
51
|
-
...(operationsOrigin === undefined ? {} : { operationsOrigin }),
|
|
52
|
-
...(crossOrigins
|
|
53
|
-
})
|
|
63
|
+
table: contractProxyTable(access.contract, access.contractDigest),
|
|
64
|
+
...(member.operationsOrigin === undefined ? {} : { operationsOrigin: member.operationsOrigin }),
|
|
65
|
+
...(member.crossOrigins === undefined ? {} : { crossOrigins: member.crossOrigins }),
|
|
66
|
+
}))
|
|
54
67
|
}
|
|
55
68
|
return { apps }
|
|
56
69
|
}
|
|
@@ -6,71 +6,43 @@ import {
|
|
|
6
6
|
type ProviderNamespaceRepublishInput,
|
|
7
7
|
type ProviderNamespaceRepublishResult,
|
|
8
8
|
} from '@fabrika/provider-contract'
|
|
9
|
-
import {
|
|
10
|
-
enableSubdomainAccessWhenHttp,
|
|
11
|
-
readableContent,
|
|
12
|
-
waitForProcess,
|
|
13
|
-
ZEROPS_SERVICE_NOT_HTTP,
|
|
14
|
-
ZEROPS_TERMINAL,
|
|
15
|
-
ZeropsApiError,
|
|
16
|
-
type ZeropsProject,
|
|
17
|
-
type ZeropsService,
|
|
18
|
-
} from '../api'
|
|
9
|
+
import { waitForProcess, ZEROPS_TERMINAL, type ZeropsProject, type ZeropsService } from '../api'
|
|
19
10
|
import { defaultSleep } from '../collaborators'
|
|
20
|
-
import {
|
|
11
|
+
import { SANDBOX_HOST_HOSTNAME } from '../sandbox-host'
|
|
12
|
+
import { claimedResources, namespaceResourceClaims, projectExists, registrationResourceClaims, ZEROPS_PROJECT_NOT_FOUND } from './claims'
|
|
21
13
|
import { checkpoint, decodeEnvelope, normalizedNamespace, normalizeTarget } from './codec'
|
|
22
|
-
import { ZEROPS_NAMESPACE_POSTGRES_HOSTNAME, ZEROPS_NAMESPACE_PROXY_HOSTNAME
|
|
23
|
-
import { asNamespaceError, namespaceError
|
|
14
|
+
import { ZEROPS_NAMESPACE_POSTGRES_HOSTNAME, ZEROPS_NAMESPACE_PROXY_HOSTNAME } from './constants'
|
|
15
|
+
import { asNamespaceError, namespaceError } from './errors'
|
|
24
16
|
import { compileNamespaceProxyManifest } from './manifest'
|
|
25
17
|
import { createZeropsNamespaceOperator } from './operator'
|
|
26
18
|
import { republishProxy } from './proxy-attempt'
|
|
19
|
+
import { assertNamespaceProxyAcceptsSandboxes } from './proxy-reads'
|
|
27
20
|
import { namespaceProxySecrets } from './proxy-secrets'
|
|
28
21
|
import { verifyZeropsNamespaceProxySource } from './proxy-source'
|
|
22
|
+
import { assertSandboxHostAllowed, ensureSandboxHost } from './sandbox-host'
|
|
23
|
+
import { ensureSubdomainAccess, readSubdomainHosts } from './subdomain'
|
|
29
24
|
import { compileZeropsNamespaceTopology, projectMarker, PROXY_TYPE } from './topology'
|
|
30
|
-
import type { NormalizedZeropsNamespaceTarget, ZeropsNamespaceOptions, ZeropsNamespaceProxySource } from './types'
|
|
25
|
+
import type { NormalizedZeropsNamespaceTarget, ZeropsNamespaceOptions, ZeropsNamespaceProxySource, ZeropsNamespaceSandboxHost } from './types'
|
|
31
26
|
import { createZeropsNamespaceUpdates } from './update'
|
|
32
27
|
import { validateService } from './validation'
|
|
33
28
|
|
|
34
|
-
const POLL_INTERVAL_MS = 3000
|
|
35
|
-
|
|
36
|
-
/** The live enable finishes in under a second, but one run still read `false` once before flipping; ten reads is slack. */
|
|
37
|
-
const SUBDOMAIN_READBACK_ATTEMPTS = 10
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* One host per published HTTP port, out of the newline-separated URLs the platform writes.
|
|
41
|
-
*
|
|
42
|
-
* The form is `<hostname>-<hash>-<port>.<region>.zerops.app` (e.g. `proxy-2ec8-8080`). Read as URLs
|
|
43
|
-
* rather than split on `-`, so a hostname whose own first label ends in digits cannot be misread; a line
|
|
44
|
-
* that is not a URL, or whose first label carries no trailing port — the single portless line a proxy
|
|
45
|
-
* that has never deployed publishes — is skipped rather than guessed at.
|
|
46
|
-
*/
|
|
47
|
-
const parseZeropsProxyHosts = (value: string): ProviderNamespaceHost[] => {
|
|
48
|
-
const hosts: ProviderNamespaceHost[] = []
|
|
49
|
-
for (const line of value.split('\n')) {
|
|
50
|
-
const trimmed = line.trim()
|
|
51
|
-
if (trimmed === '') continue
|
|
52
|
-
let hostname: string
|
|
53
|
-
try {
|
|
54
|
-
hostname = new URL(trimmed).hostname
|
|
55
|
-
} catch {
|
|
56
|
-
continue
|
|
57
|
-
}
|
|
58
|
-
const port = /-(\d+)$/.exec(hostname.split('.')[0] ?? '')?.[1]
|
|
59
|
-
if (port === undefined) continue
|
|
60
|
-
hosts.push({ host: hostname, port: Number.parseInt(port, 10) })
|
|
61
|
-
}
|
|
62
|
-
return hosts.sort((left, right) => left.port - right.port)
|
|
63
|
-
}
|
|
64
|
-
|
|
65
29
|
const validateProject = (
|
|
66
30
|
namespace: ProviderDeploymentNamespace,
|
|
67
31
|
target: NormalizedZeropsNamespaceTarget,
|
|
68
32
|
project: ZeropsProject,
|
|
69
33
|
adopting: boolean,
|
|
34
|
+
installationProjectId: string | undefined,
|
|
70
35
|
): void => {
|
|
71
36
|
if (project.id === '') {
|
|
72
37
|
throw new Error('Zerops namespace project returned an empty id')
|
|
73
38
|
}
|
|
39
|
+
// Checked on every reconcile, before the import and the proxy build, so a namespace that already adopted it stops
|
|
40
|
+
// here instead of rebuilding the platform's enforcement point with an empty manifest (ADR-0034).
|
|
41
|
+
if (project.id === installationProjectId) {
|
|
42
|
+
throw new Error(
|
|
43
|
+
`Zerops project ${project.id} is the installation's own project; a deployment namespace needs a project of its own`,
|
|
44
|
+
)
|
|
45
|
+
}
|
|
74
46
|
if (target.projectName !== project.name) {
|
|
75
47
|
throw new Error(`Zerops namespace project name mismatch: expected \`${target.projectName}\`, got \`${project.name}\``)
|
|
76
48
|
}
|
|
@@ -160,6 +132,7 @@ const resolveServices = async (
|
|
|
160
132
|
const reserved = new Set([
|
|
161
133
|
ZEROPS_NAMESPACE_PROXY_HOSTNAME,
|
|
162
134
|
...(target.postgres === undefined ? [] : [ZEROPS_NAMESPACE_POSTGRES_HOSTNAME]),
|
|
135
|
+
...(target.sandboxHost === undefined ? [] : [SANDBOX_HOST_HOSTNAME]),
|
|
163
136
|
])
|
|
164
137
|
const unexpected = services.filter((service) => !reserved.has(service.name))
|
|
165
138
|
if (unexpected.length > 0) {
|
|
@@ -187,9 +160,7 @@ const readProxyHosts = async (
|
|
|
187
160
|
throw new Error('Zerops namespace has no proxy service id')
|
|
188
161
|
}
|
|
189
162
|
try {
|
|
190
|
-
|
|
191
|
-
const subdomains = readableContent(variables.find((variable) => variable.key === ZEROPS_NAMESPACE_SUBDOMAIN_VARIABLE))
|
|
192
|
-
return subdomains === undefined ? [] : parseZeropsProxyHosts(subdomains)
|
|
163
|
+
return await readSubdomainHosts(options.api, proxyServiceId, signal)
|
|
193
164
|
} catch {
|
|
194
165
|
// A host listing is a convenience; the proxy is already built, deployed and published. Failing the
|
|
195
166
|
// namespace over it would report a placement that WORKS as broken. Never the cause: it can carry
|
|
@@ -230,6 +201,7 @@ const deployProxy = async (
|
|
|
230
201
|
namespaceId: namespace.id,
|
|
231
202
|
target,
|
|
232
203
|
manifest,
|
|
204
|
+
brand: input.brand ?? null,
|
|
233
205
|
proxySecrets: namespaceProxySecrets(manifest, input.members),
|
|
234
206
|
...(options.source === undefined ? {} : { source: options.source }),
|
|
235
207
|
api: options.api,
|
|
@@ -247,6 +219,37 @@ const deployProxy = async (
|
|
|
247
219
|
return { namespace: currentNamespace, target: { ...target, ...result } }
|
|
248
220
|
}
|
|
249
221
|
|
|
222
|
+
/**
|
|
223
|
+
* Refused before any platform write: an older pin's strict parser would fail the build on a sandbox entry, and a sandbox
|
|
224
|
+
* host on such a pin could serve nothing. Never dropped silently.
|
|
225
|
+
*/
|
|
226
|
+
const assertSandboxesAccepted = (input: ProviderNamespaceMutationInput, namespaceId: string, target: NormalizedZeropsNamespaceTarget): void => {
|
|
227
|
+
if (input.sandboxKey === undefined && !input.members.some((member) => (member.devSandboxes?.length ?? 0) > 0)) return
|
|
228
|
+
assertNamespaceProxyAcceptsSandboxes(namespaceId, target.proxySource)
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
const sandboxHost = async (
|
|
232
|
+
input: ProviderNamespaceMutationInput,
|
|
233
|
+
sandboxKey: string,
|
|
234
|
+
namespace: ProviderDeploymentNamespace,
|
|
235
|
+
target: NormalizedZeropsNamespaceTarget,
|
|
236
|
+
options: ZeropsNamespaceOptions,
|
|
237
|
+
): Promise<ZeropsNamespaceSandboxHost> => {
|
|
238
|
+
try {
|
|
239
|
+
return await ensureSandboxHost({
|
|
240
|
+
namespaceId: namespace.id,
|
|
241
|
+
target,
|
|
242
|
+
sandboxKey,
|
|
243
|
+
api: options.api,
|
|
244
|
+
...(options.zboxFetch === undefined ? {} : { zboxFetch: options.zboxFetch }),
|
|
245
|
+
...(options.sleep === undefined ? {} : { sleep: options.sleep }),
|
|
246
|
+
signal: input.signal,
|
|
247
|
+
})
|
|
248
|
+
} catch (cause) {
|
|
249
|
+
throw asNamespaceError(cause, 'reconcile')
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
250
253
|
/** Rebuild a ready namespace's proxy from its current members; provisioning stays with `provision`/`reconcile`. */
|
|
251
254
|
const republishNamespace = async (
|
|
252
255
|
input: ProviderNamespaceRepublishInput,
|
|
@@ -257,70 +260,15 @@ const republishNamespace = async (
|
|
|
257
260
|
if (target.proxyServiceId === undefined || (target.proxyBuild === undefined && !target.ready)) {
|
|
258
261
|
throw new Error(`Namespace ${namespace.id} is not ready`)
|
|
259
262
|
}
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
*
|
|
267
|
-
* `enableSubdomainAccess: true` is accepted by the import and then silently dropped, on a service the
|
|
268
|
-
* document CREATES as much as on one `override` leaves alone; a service imported with it reads back
|
|
269
|
-
* `subdomainAccess: false` for ever. The subdomain is established by
|
|
270
|
-
* `PUT /service-stack/{id}/enable-subdomain-access` and by nothing else, and that call needs a DEPLOYED
|
|
271
|
-
* HTTP port — which is why this runs after `deployProxy` rather than beside the import.
|
|
272
|
-
*
|
|
273
|
-
* It runs on RECONCILE too, so a subdomain someone turned off in the GUI comes back. What it must never
|
|
274
|
-
* do is finish quietly: `zerops-subdomain` is the only public entry a namespace has, so this either
|
|
275
|
-
* observes `subdomainAccess === true` or throws naming what is missing.
|
|
276
|
-
*
|
|
277
|
-
* The decision is the READ-BACK, never the call returning. On an already-published service the platform
|
|
278
|
-
* answers 2xx and then fails the process it handed back — live-verified — so a 2xx proves nothing.
|
|
279
|
-
*
|
|
280
|
-
* The HTTP ports lag the proxy's ACTIVE version, so `serviceStackIsNotHttp` is retried for a bounded
|
|
281
|
-
* window (`enableSubdomainAccessWhenHttp`) before it fails the namespace.
|
|
282
|
-
*/
|
|
283
|
-
const ensureSubdomainAccess = async (
|
|
284
|
-
target: NormalizedZeropsNamespaceTarget,
|
|
285
|
-
options: ZeropsNamespaceOptions,
|
|
286
|
-
signal: AbortSignal,
|
|
287
|
-
): Promise<void> => {
|
|
288
|
-
const proxyServiceId = target.proxyServiceId
|
|
289
|
-
if (proxyServiceId === undefined) {
|
|
290
|
-
throw new Error('Zerops namespace has no proxy service id')
|
|
291
|
-
}
|
|
292
|
-
const published = async (): Promise<boolean> => (await options.api.getService({ serviceId: proxyServiceId, signal })).subdomainAccess === true
|
|
293
|
-
if (await published()) {
|
|
294
|
-
return
|
|
295
|
-
}
|
|
296
|
-
try {
|
|
297
|
-
await enableSubdomainAccessWhenHttp({ api: options.api, serviceId: proxyServiceId, sleep: options.sleep ?? defaultSleep, signal })
|
|
298
|
-
} catch (error) {
|
|
299
|
-
if (error instanceof ZeropsApiError && error.code === ZEROPS_SERVICE_NOT_HTTP) {
|
|
300
|
-
throw namespaceError(
|
|
301
|
-
ZEROPS_SERVICE_NOT_HTTP,
|
|
302
|
-
`Zerops namespace proxy ${proxyServiceId} cannot be published on a zerops.app subdomain: it still exposes no deployed HTTP port (${ZEROPS_SERVICE_NOT_HTTP}) minutes after its deploy`,
|
|
303
|
-
false,
|
|
304
|
-
)
|
|
305
|
-
}
|
|
306
|
-
throw error
|
|
307
|
-
}
|
|
308
|
-
for (let attempt = 0;; attempt += 1) {
|
|
309
|
-
if (signal.aborted) {
|
|
310
|
-
throw namespaceError(ZEROPS_NAMESPACE_CANCELLED, 'Zerops namespace provisioning was cancelled', true)
|
|
311
|
-
}
|
|
312
|
-
if (await published()) {
|
|
313
|
-
return
|
|
314
|
-
}
|
|
315
|
-
if (attempt >= SUBDOMAIN_READBACK_ATTEMPTS) {
|
|
316
|
-
throw namespaceError(
|
|
317
|
-
ZEROPS_SUBDOMAIN_NOT_PUBLISHED,
|
|
318
|
-
`Zerops namespace proxy ${proxyServiceId} accepted enable-subdomain-access but still reads subdomainAccess: false — the namespace has no public entry point`,
|
|
319
|
-
true,
|
|
320
|
-
)
|
|
321
|
-
}
|
|
322
|
-
await (options.sleep ?? defaultSleep)(POLL_INTERVAL_MS, signal)
|
|
263
|
+
assertSandboxesAccepted(input, namespace.id, target)
|
|
264
|
+
let current = namespace
|
|
265
|
+
let ready = target
|
|
266
|
+
if (input.sandboxKey !== undefined && target.sandboxHost === undefined) {
|
|
267
|
+
ready = { ...target, sandboxHost: await sandboxHost(input, input.sandboxKey, namespace, target, options) }
|
|
268
|
+
current = await checkpoint(input, namespace, ready)
|
|
323
269
|
}
|
|
270
|
+
const deployed = await deployProxy(input, current, ready, options, input.wait, true)
|
|
271
|
+
return { namespace: deployed.namespace, settled: deployed.target.proxyBuild === undefined && deployed.target.ready }
|
|
324
272
|
}
|
|
325
273
|
|
|
326
274
|
/** Every exit from the lifecycle below is a `ProviderNamespaceError`, so a caller never has to guess. */
|
|
@@ -350,6 +298,8 @@ const runNamespaceMutation = async (
|
|
|
350
298
|
throw new Error('Proxy build is missing checkpointed project or service identity')
|
|
351
299
|
}
|
|
352
300
|
await verifyZeropsNamespaceProxySource(target.proxySource)
|
|
301
|
+
assertSandboxesAccepted(input, namespace.id, target)
|
|
302
|
+
if (input.sandboxKey !== undefined) assertSandboxHostAllowed(namespace.id, target)
|
|
353
303
|
input.signal.throwIfAborted()
|
|
354
304
|
if (target.proxyBuild === undefined && target.proxyDeployment !== undefined) {
|
|
355
305
|
try {
|
|
@@ -360,6 +310,14 @@ const runNamespaceMutation = async (
|
|
|
360
310
|
} catch {
|
|
361
311
|
input.signal.throwIfAborted()
|
|
362
312
|
await checkpoint(input, namespace, { ...target, ready: false })
|
|
313
|
+
// A deleted project never resolves the version: retrying would hold the namespace `provisioning`, unremovable.
|
|
314
|
+
if (target.projectId !== undefined && !(await projectExists(options.api, target.projectId, input.signal))) {
|
|
315
|
+
throw namespaceError(
|
|
316
|
+
ZEROPS_PROJECT_NOT_FOUND,
|
|
317
|
+
`Zerops project ${target.projectId} of namespace \`${namespace.id}\` no longer exists; remove the namespace`,
|
|
318
|
+
false,
|
|
319
|
+
)
|
|
320
|
+
}
|
|
363
321
|
throw namespaceError('proxyAttemptUnresolved', `Proxy version ${target.proxyDeployment.appVersionId} remains unresolved`, true)
|
|
364
322
|
}
|
|
365
323
|
}
|
|
@@ -400,7 +358,7 @@ const runNamespaceMutation = async (
|
|
|
400
358
|
target = { ...target, projectName: project.name }
|
|
401
359
|
namespace = await checkpoint(input, namespace, target)
|
|
402
360
|
}
|
|
403
|
-
validateProject(namespace, target, project, initiallyAdopted)
|
|
361
|
+
validateProject(namespace, target, project, initiallyAdopted, options.installationProjectId)
|
|
404
362
|
|
|
405
363
|
if (initiallyAdopted) {
|
|
406
364
|
// Validate before the first mutation; the import below then enforces service-level envIsolation.
|
|
@@ -441,7 +399,16 @@ const runNamespaceMutation = async (
|
|
|
441
399
|
// After the deploy, because the platform refuses a service with no HTTP port — and never before `ready`
|
|
442
400
|
// is checkpointed, because a namespace with no public entry point is not ready.
|
|
443
401
|
if (target.publicAccess === 'zerops-subdomain') {
|
|
444
|
-
|
|
402
|
+
const proxyServiceId = target.proxyServiceId
|
|
403
|
+
if (proxyServiceId === undefined) throw new Error('Zerops namespace has no proxy service id')
|
|
404
|
+
await ensureSubdomainAccess({
|
|
405
|
+
api: options.api,
|
|
406
|
+
serviceId: proxyServiceId,
|
|
407
|
+
label: 'Zerops namespace proxy',
|
|
408
|
+
consequence: 'the namespace has no public entry point',
|
|
409
|
+
...(options.sleep === undefined ? {} : { sleep: options.sleep }),
|
|
410
|
+
signal: input.signal,
|
|
411
|
+
})
|
|
445
412
|
}
|
|
446
413
|
const proxyHosts = target.publicAccess === 'zerops-subdomain' ? await readProxyHosts(namespace, target, options, input.signal) : []
|
|
447
414
|
target = {
|
|
@@ -452,7 +419,13 @@ const runNamespaceMutation = async (
|
|
|
452
419
|
proxyHosts: proxyHosts.length === 0 ? undefined : proxyHosts,
|
|
453
420
|
ready: true,
|
|
454
421
|
}
|
|
455
|
-
|
|
422
|
+
namespace = await checkpoint(input, namespace, target)
|
|
423
|
+
// After the proxy converged and `ready` is recorded, so a sandbox host failure never holds back the namespace's proxy.
|
|
424
|
+
if (input.sandboxKey !== undefined) {
|
|
425
|
+
target = { ...target, sandboxHost: await sandboxHost(input, input.sandboxKey, namespace, target, options) }
|
|
426
|
+
namespace = await checkpoint(input, namespace, target)
|
|
427
|
+
}
|
|
428
|
+
return namespace
|
|
456
429
|
}
|
|
457
430
|
|
|
458
431
|
/** Build the provider-owned namespace lifecycle capability. */
|
|
@@ -472,6 +445,7 @@ export const createZeropsNamespaceCapabilities = (options: ZeropsNamespaceOption
|
|
|
472
445
|
provision: (input) => mutateNamespace(input, options, 'provision'),
|
|
473
446
|
reconcile: (input) => mutateNamespace(input, options, 'reconcile'),
|
|
474
447
|
republish: (input) => republishNamespace(input, options),
|
|
448
|
+
claimedResources: (input) => claimedResources(options.api, input),
|
|
475
449
|
updates: createZeropsNamespaceUpdates(options),
|
|
476
450
|
operator: createZeropsNamespaceOperator({ proxySource: options.proxySource }),
|
|
477
451
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { followLeaseLoss, isLeaseLoss, ProviderNamespaceError } from '@fabrika/provider-contract'
|
|
2
|
+
import type { InstallationBrand } from '@fabrika/proxy-core/brand'
|
|
2
3
|
import { encodeProxyManifestJson, FABRIKA_PROXY_MANIFEST_JSON, type ProxyManifest } from '@fabrika/proxy-core/manifest'
|
|
3
4
|
import {
|
|
4
5
|
readableContent,
|
|
@@ -11,7 +12,12 @@ import {
|
|
|
11
12
|
} from '../api'
|
|
12
13
|
import type { Sleeper } from '../collaborators'
|
|
13
14
|
import { prepareZeropsDescriptor } from '../descriptor'
|
|
14
|
-
import {
|
|
15
|
+
import {
|
|
16
|
+
ZEROPS_PROXY_MANIFEST_PATH,
|
|
17
|
+
zeropsProxyAcceptsBrand,
|
|
18
|
+
type ZeropsProxyManifestCarrier,
|
|
19
|
+
zeropsProxyManifestCarrier,
|
|
20
|
+
} from '../proxy-manifest-carrier'
|
|
15
21
|
import { isZeropsUploadDestination } from '../source'
|
|
16
22
|
import type { ZeropsSourcePort } from '../source/port'
|
|
17
23
|
import { deleteVersion } from '../version-attempt'
|
|
@@ -35,6 +41,8 @@ export interface ZeropsProxyRepublishInput {
|
|
|
35
41
|
readonly namespaceId: string
|
|
36
42
|
readonly target: ZeropsNamespaceTarget
|
|
37
43
|
readonly manifest: ProxyManifest
|
|
44
|
+
/** The installation's client logo (ADR-0066); added to the manifest only when the pinned proxy can parse it. */
|
|
45
|
+
readonly brand?: InstallationBrand | null
|
|
38
46
|
readonly source?: ZeropsSourcePort
|
|
39
47
|
readonly api: ZeropsProxyApi
|
|
40
48
|
readonly iamUrl: string
|
|
@@ -127,7 +135,11 @@ export async function republishProxy(input: ZeropsProxyRepublishInput): Promise<
|
|
|
127
135
|
await verifyZeropsNamespaceProxySource(pin)
|
|
128
136
|
// The pinned descriptor decides: a namespace kept on an older proxy revision still lifts the variable (ADR-0045).
|
|
129
137
|
const carrier = zeropsProxyManifestCarrier(pin.descriptor.contents)
|
|
130
|
-
|
|
138
|
+
// So does it for the logo: an older parser refuses the key, and the namespace keeps the mark until it is re-pinned.
|
|
139
|
+
const brand = input.brand ?? null
|
|
140
|
+
const manifest = encodeProxyManifestJson(
|
|
141
|
+
brand !== null && zeropsProxyAcceptsBrand(pin.descriptor.contents) ? { ...input.manifest, brand } : input.manifest,
|
|
142
|
+
)
|
|
131
143
|
// The attempt's identity covers the IAM configuration and the proxy secrets too, so rotating any forces a rebuild.
|
|
132
144
|
const proxySecrets = input.proxySecrets ?? new Map<string, string>()
|
|
133
145
|
const secrets = proxySecrets.size === 0 ? '' : `\n${await proxySecretsDigest(proxySecrets)}`
|
|
@@ -1,36 +1,28 @@
|
|
|
1
|
-
// What a namespace proxy pinned to an older source cannot read. Its manifest parser is strict: one row of a form
|
|
2
|
-
// not know, or a CSP directive it does not know, refuses the whole manifest and blocks the namespace's next
|
|
3
|
-
// So a deploy that would publish either is refused before
|
|
4
|
-
// this control plane's own.
|
|
1
|
+
// What a namespace proxy pinned to an older source cannot read or serve. Its manifest parser is strict: one row of a form
|
|
2
|
+
// it does not know, or a CSP directive it does not know, refuses the whole manifest and blocks the namespace's next
|
|
3
|
+
// republish; and it has no terminal sign-out. So a deploy that would publish either, or a terminal, is refused before
|
|
4
|
+
// publication while the namespace's proxy source is not this control plane's own.
|
|
5
5
|
|
|
6
|
-
import type
|
|
7
|
-
import type
|
|
8
|
-
import {
|
|
6
|
+
import { type ProviderApprovedAccess, ProviderNamespaceError } from '@fabrika/provider-contract'
|
|
7
|
+
import { contractProxyTable, type OlderProxyReaders } from '@fabrika/proxy-core/manifest'
|
|
8
|
+
import { zeropsProxyAcceptsSandboxes } from '../proxy-manifest-carrier'
|
|
9
|
+
import { ZEROPS_PROXY_SANDBOXES_UNSUPPORTED } from './errors'
|
|
9
10
|
import type { ZeropsNamespaceProxySource } from './types'
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
* What the namespace proxy of one older platform release parses of an application's manifest entry: a row, and the
|
|
13
|
-
* entry's CSP directives, each by that release's own parser.
|
|
14
|
-
*/
|
|
15
|
-
export interface OlderProxyReader {
|
|
16
|
-
readonly row: (row: ProxyEndpointRow) => boolean
|
|
17
|
-
readonly csp: (csp: CspOrigins) => boolean
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* The namespace proxies of the older releases this platform serves (ADR-0062). Control holds their parsers, as it holds
|
|
22
|
-
* their contract readers; a pin's release is not recorded, so what any of them reads is what the pin may read.
|
|
23
|
-
*/
|
|
24
|
-
export type OlderProxyReaders = readonly [OlderProxyReader, ...OlderProxyReader[]]
|
|
12
|
+
export type { OlderProxyReader, OlderProxyReaders } from '@fabrika/proxy-core/manifest'
|
|
25
13
|
|
|
26
14
|
/**
|
|
27
15
|
* What of the approved contract's manifest entry no older release's proxy parses, as the namespace publishes it: each
|
|
28
16
|
* such row by its id, and `csp` when no older proxy parses the entry's CSP (`workerSrc`, which only this release knows).
|
|
17
|
+
* A contract that declares a terminal adds `terminal` when no older proxy serves the sign-out its sessions end at
|
|
18
|
+
* (ADR-0067 §5).
|
|
29
19
|
*/
|
|
30
20
|
export function entriesNeedingCurrentProxy(access: ProviderApprovedAccess, olderProxies: OlderProxyReaders): string[] {
|
|
31
21
|
const table = contractProxyTable(access.contract, access.contractDigest)
|
|
32
22
|
const rows = table.endpoints.filter((row) => !olderProxies.some((proxy) => proxy.row(row))).map((row) => row.id)
|
|
33
|
-
|
|
23
|
+
const csp = olderProxies.some((proxy) => proxy.csp(table.csp)) ? [] : ['csp']
|
|
24
|
+
const terminal = access.contract.terminal === undefined || olderProxies.some((proxy) => proxy.signsOut) ? [] : ['terminal']
|
|
25
|
+
return [...rows, ...csp, ...terminal]
|
|
34
26
|
}
|
|
35
27
|
|
|
36
28
|
/** This control plane's own proxy source, and the parsers of the older releases a pinned proxy may run. */
|
|
@@ -58,8 +50,21 @@ export function assertNamespaceProxyReads(
|
|
|
58
50
|
return
|
|
59
51
|
}
|
|
60
52
|
throw new Error(
|
|
61
|
-
`the proxy of deployment namespace \`${namespace}\` is pinned to an older source than this platform's, and no older release's proxy reads ${
|
|
53
|
+
`the proxy of deployment namespace \`${namespace}\` is pinned to an older source than this platform's, and no older release's proxy reads or serves ${
|
|
62
54
|
rows.map((row) => `\`${row}\``).join(', ')
|
|
63
55
|
}; re-pin it with \`fabrika control namespaces update --namespace=${namespace} --proxy-source=current\`, then deploy again`,
|
|
64
56
|
)
|
|
65
57
|
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Refuses dev sandbox entries for a namespace whose pinned proxy cannot parse their `audience` and `upstreamHost`: its
|
|
61
|
+
* strict parser would fail the proxy build. The row and CSP judges above see neither field, so this marker is their gate.
|
|
62
|
+
*/
|
|
63
|
+
export function assertNamespaceProxyAcceptsSandboxes(namespace: string, pinned: ZeropsNamespaceProxySource): void {
|
|
64
|
+
if (zeropsProxyAcceptsSandboxes(pinned.descriptor.contents)) return
|
|
65
|
+
throw new ProviderNamespaceError(
|
|
66
|
+
`the proxy of deployment namespace \`${namespace}\` is pinned to a source that cannot serve dev sandboxes; re-pin it with \`fabrika control namespaces update --namespace=${namespace} --proxy-source=current\`, then try again`,
|
|
67
|
+
ZEROPS_PROXY_SANDBOXES_UNSUPPORTED,
|
|
68
|
+
false,
|
|
69
|
+
)
|
|
70
|
+
}
|
|
@@ -1,21 +1,34 @@
|
|
|
1
1
|
import { appEnvironmentId, proxySecretVariable } from '@fabrika/auth-core'
|
|
2
2
|
import type { ProviderNamespaceMember } from '@fabrika/provider-contract'
|
|
3
|
-
import { isApplicationEntry, type ProxyManifest } from '@fabrika/proxy-core/manifest'
|
|
3
|
+
import { devSandboxEntryId, isApplicationEntry, type ProxyManifest } from '@fabrika/proxy-core/manifest'
|
|
4
|
+
|
|
5
|
+
/** The secret Control handed for one manifest entry: a dev sandbox's own, else its member's. */
|
|
6
|
+
const entrySecret = (id: string, members: readonly ProviderNamespaceMember[]): string | undefined => {
|
|
7
|
+
for (const member of members) {
|
|
8
|
+
if (member.devSandboxes !== undefined) {
|
|
9
|
+
const sandbox = member.devSandboxes.find((candidate) => devSandboxEntryId(member.appId, candidate.workspaceId) === id)
|
|
10
|
+
if (sandbox !== undefined) return sandbox.proxySecret
|
|
11
|
+
continue
|
|
12
|
+
}
|
|
13
|
+
if (appEnvironmentId(member.appId, member.env) === id) return member.proxySecret
|
|
14
|
+
}
|
|
15
|
+
return undefined
|
|
16
|
+
}
|
|
4
17
|
|
|
5
18
|
/**
|
|
6
19
|
* The proxy service variables a manifest needs: for each contract application, the secret Caddy sends it
|
|
7
|
-
* (ADR-0022 rule 5), keyed by `proxySecretVariable`. A contract
|
|
20
|
+
* (ADR-0022 rule 5), keyed by `proxySecretVariable`. A contract entry without a secret is refused, because
|
|
8
21
|
* its application would refuse every request the proxy sends.
|
|
9
22
|
*/
|
|
10
23
|
export function namespaceProxySecrets(manifest: ProxyManifest, members: readonly ProviderNamespaceMember[]): ReadonlyMap<string, string> {
|
|
11
24
|
const secrets = new Map<string, string>()
|
|
12
25
|
for (const app of manifest.apps) {
|
|
13
26
|
if (!isApplicationEntry(app)) continue
|
|
14
|
-
const
|
|
15
|
-
if (
|
|
27
|
+
const secret = entrySecret(app.id, members)
|
|
28
|
+
if (secret === undefined || secret === '') {
|
|
16
29
|
throw new Error(`Zerops proxy target ${app.id} is a contract application, and Control supplied no proxy secret for it`)
|
|
17
30
|
}
|
|
18
|
-
secrets.set(proxySecretVariable(app.id),
|
|
31
|
+
secrets.set(proxySecretVariable(app.id), secret)
|
|
19
32
|
}
|
|
20
33
|
return secrets
|
|
21
34
|
}
|