@serve.zone/interfaces 32.88.0 → 32.89.0
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/changelog.md +11 -0
- package/dist_ts/00_commitinfo_data.js +1 -1
- package/dist_ts/data/cloudaccess.d.ts +402 -0
- package/dist_ts/data/cloudaccess.js +685 -0
- package/dist_ts/data/cloudlyconfig.d.ts +20 -0
- package/dist_ts/data/cloudlyconfig.js +21 -1
- package/dist_ts/data/gatewayareas.d.ts +114 -19
- package/dist_ts/data/gatewayareas.js +36 -1
- package/dist_ts/data/gatewayareas.validation.js +178 -36
- package/dist_ts/data/gatewayconnector.d.ts +2 -2
- package/dist_ts/data/gatewayconnector.js +20 -1
- package/dist_ts/data/gatewayintent.d.ts +154 -0
- package/dist_ts/data/gatewayintent.js +61 -0
- package/dist_ts/data/index.d.ts +2 -0
- package/dist_ts/data/index.js +3 -1
- package/dist_ts/data/witness.js +4 -9
- package/dist_ts/private/bearerencoding.d.ts +9 -0
- package/dist_ts/private/bearerencoding.js +17 -0
- package/dist_ts/private/storagecontract.js +3 -3
- package/dist_ts/requests/cloudaccess.d.ts +125 -0
- package/dist_ts/requests/cloudaccess.js +2 -0
- package/dist_ts/requests/gatewayconnector.d.ts +33 -1
- package/dist_ts/requests/index.d.ts +2 -1
- package/dist_ts/requests/index.js +3 -2
- package/package.json +1 -1
- package/readme.md +146 -10
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/data/cloudaccess.ts +1133 -0
- package/ts/data/cloudlyconfig.ts +27 -0
- package/ts/data/gatewayareas.ts +82 -19
- package/ts/data/gatewayareas.validation.ts +192 -34
- package/ts/data/gatewayconnector.ts +19 -0
- package/ts/data/gatewayintent.ts +209 -0
- package/ts/data/index.ts +2 -0
- package/ts/data/witness.ts +3 -10
- package/ts/private/bearerencoding.ts +24 -0
- package/ts/private/storagecontract.ts +2 -2
- package/ts/requests/cloudaccess.ts +201 -0
- package/ts/requests/gatewayconnector.ts +41 -1
- package/ts/requests/index.ts +2 -0
package/ts/data/cloudlyconfig.ts
CHANGED
|
@@ -177,6 +177,33 @@ export const cloudlyHostOptionalEnvironment = Object.freeze([
|
|
|
177
177
|
/** One variable the Cloudly server reads but starts without. */
|
|
178
178
|
export type TCloudlyHostOptionalEnvironmentName = typeof cloudlyHostOptionalEnvironment[number];
|
|
179
179
|
|
|
180
|
+
/**
|
|
181
|
+
* The host extras a host can advertise to the Cloudly it runs (Linus ruling 13, amendment points
|
|
182
|
+
* 12 and 17): optional offers Cloudly uses only when the host advertises them, never a precondition
|
|
183
|
+
* for its start or run, and never inferred from the host type (`SERVEZONE_APP_HOST_TYPE`) or by
|
|
184
|
+
* probing the environment.
|
|
185
|
+
*
|
|
186
|
+
* `relayIngress` (Linus ruling 141 C7): the host serves `SERVEZONE_PUBLIC_ORIGIN`'s TLS on a second
|
|
187
|
+
* listener the Cloudly container can reach and forwards that listener only to Cloudly's relayed
|
|
188
|
+
* port, which serves the human surface only; a request accepted there is relayed. Cloud access can
|
|
189
|
+
* be started only on a host that advertises it.
|
|
190
|
+
*
|
|
191
|
+
* No carrier advertises an extra yet, so none can be advertised or read (amendment 141a): ruling 15
|
|
192
|
+
* point 4 names the carrier, `IHostedAppLifecycleState.hostExtras`, which this package does not
|
|
193
|
+
* declare yet, and no environment variable of either list names the relayed port yet.
|
|
194
|
+
*/
|
|
195
|
+
export const cloudlyHostExtras = Object.freeze([
|
|
196
|
+
'relayIngress',
|
|
197
|
+
] as const);
|
|
198
|
+
|
|
199
|
+
/** One host extra. */
|
|
200
|
+
export type TCloudlyHostExtra = typeof cloudlyHostExtras[number];
|
|
201
|
+
|
|
202
|
+
/** True for one of `cloudlyHostExtras`. */
|
|
203
|
+
export const isCloudlyHostExtra = (valueArg: unknown): valueArg is TCloudlyHostExtra => (
|
|
204
|
+
(cloudlyHostExtras as readonly unknown[]).includes(valueArg)
|
|
205
|
+
);
|
|
206
|
+
|
|
180
207
|
/**
|
|
181
208
|
* Cloudly's health path on its listen port (`GET` or `HEAD`). It answers 200 with
|
|
182
209
|
* `{ healthy: true, checks }` while Cloudly runs and 503 otherwise; it states no version. Cloudly
|
package/ts/data/gatewayareas.ts
CHANGED
|
@@ -449,16 +449,30 @@ export interface IGatewayDnsRecordRow {
|
|
|
449
449
|
/** A `dcrouter`-source row of `domains`. */
|
|
450
450
|
domainId: string;
|
|
451
451
|
/**
|
|
452
|
-
*
|
|
453
|
-
*
|
|
452
|
+
* At most 253 characters of lowercase labels (letters, digits, `_` and inner `-`, 1 to 63
|
|
453
|
+
* characters, as a zone's), no trailing dot; the leftmost label may instead be exactly `*`, with at
|
|
454
|
+
* least one label after it (Linus ruling 129). Inside its zone: the zone's `name` itself, or a name
|
|
455
|
+
* that ends in `.` and the zone's `name`, compared as written. A name outside the form is refused,
|
|
456
|
+
* never repaired; whether a gateway answers a `*` name as a wildcard is the gateway's to state.
|
|
454
457
|
*/
|
|
455
458
|
name: string;
|
|
456
459
|
type: TGatewayDnsRecordType;
|
|
457
460
|
/**
|
|
458
|
-
* The record value in
|
|
459
|
-
*
|
|
460
|
-
*
|
|
461
|
-
*
|
|
461
|
+
* The record value in its one spelling per type, the one the gateway's record value owner emits
|
|
462
|
+
* (Linus ruling 129):
|
|
463
|
+
*
|
|
464
|
+
* - `A`: one IPv4 address as a dotted quad without leading zeros. `AAAA`: one IPv6 address in its
|
|
465
|
+
* RFC 5952 text (lowercase hex groups without leading zeros, the longest run of two or more
|
|
466
|
+
* zero groups written `::`, the first run on a tie), no IPv4 tail and no zone id. The contract's
|
|
467
|
+
* canonical address text, with nothing around it (Linus ruling 143 B): another spelling of the
|
|
468
|
+
* same address is refused, and any address of the family is a value.
|
|
469
|
+
* - `CNAME`, `NS`: one domain name: lowercase, no trailing dot, no whitespace, no empty label,
|
|
470
|
+
* each label at most 63 octets and the name at most 253.
|
|
471
|
+
* - `MX`: `<preference> <exchange>` with one space between: the preference 0 to 65535 without a
|
|
472
|
+
* leading zero, the exchange such a name, or `0 .` for a null MX.
|
|
473
|
+
* - `SOA`: `<mname> <rname> <serial> <refresh> <retry> <expire> <minimum>` with one space between
|
|
474
|
+
* each: two such names and five numbers from 0 to 4294967295 without a leading zero.
|
|
475
|
+
* - `CAA`: a text without whitespace around it. `TXT`: the text itself.
|
|
462
476
|
*/
|
|
463
477
|
value: string;
|
|
464
478
|
/** Seconds, positive. */
|
|
@@ -472,9 +486,10 @@ export interface IGatewayDnsRecordRow {
|
|
|
472
486
|
export interface IGatewayDnsStaticRecordRow {
|
|
473
487
|
/** `static-` followed by 64 lowercase hex digits. */
|
|
474
488
|
id: string;
|
|
489
|
+
/** The name form of `IGatewayDnsRecordRow.name`; a static record belongs to no zone row. */
|
|
475
490
|
name: string;
|
|
476
491
|
type: TGatewayDnsStaticRecordType;
|
|
477
|
-
/** As `IGatewayDnsRecordRow.value
|
|
492
|
+
/** As `IGatewayDnsRecordRow.value`: the one spelling of its type. */
|
|
478
493
|
value: string;
|
|
479
494
|
/** Seconds; `null` for the gateway's default. */
|
|
480
495
|
ttl: number | null;
|
|
@@ -486,6 +501,7 @@ export interface IGatewayDnsStaticRecordRow {
|
|
|
486
501
|
export interface IGatewayDnsProtectedHostnameRow {
|
|
487
502
|
/** The exact hostname: lowercase, no trailing dot, no wildcard. */
|
|
488
503
|
id: string;
|
|
504
|
+
/** Without whitespace around it: the gateway stores a reason trimmed. */
|
|
489
505
|
reason: string;
|
|
490
506
|
}
|
|
491
507
|
|
|
@@ -529,7 +545,8 @@ export interface IGatewayDnsArea {
|
|
|
529
545
|
protectedHostnames: IGatewayDnsProtectedHostnameRow[];
|
|
530
546
|
/**
|
|
531
547
|
* Zones the gateway may answer for once it has proven their delegation itself, keyed by zone
|
|
532
|
-
* name
|
|
548
|
+
* name: at least two labels of letters, digits and inner hyphens (no `_`), the form a delegation
|
|
549
|
+
* names. The proof and its evidence stay on the gateway; it serves the proven ones.
|
|
533
550
|
*/
|
|
534
551
|
authorityZones: IGatewayAreaKeyRow[];
|
|
535
552
|
clientHostnames: IGatewayDnsClientHostnameRow[];
|
|
@@ -803,7 +820,8 @@ export interface IGatewayMailPortConfig {
|
|
|
803
820
|
|
|
804
821
|
/**
|
|
805
822
|
* The mail server settings singleton (the stored settings, never the run-time options).
|
|
806
|
-
* `emailConfig` is SmartMTA's server options
|
|
823
|
+
* `emailConfig` is SmartMTA's server options; while `enabled` it names a non-blank `hostname` and
|
|
824
|
+
* `ports`, a non-empty list of ports 1 to 65535 (a gateway starts no mail server without them). `auth.users` and `auth.accounts` are out; the rest of
|
|
807
825
|
* `auth` (`required`, `methods`) travels inside `emailConfig` (Linus ruling 126, which amends ruling
|
|
808
826
|
* 121). SMTP accounts are rows of `smtpAccounts`; plaintext `auth.users` logins have no table form,
|
|
809
827
|
* so a gateway that holds one refuses to export by name. Host paths stay out, and `tls.keyPem` is
|
|
@@ -816,7 +834,10 @@ export interface IGatewayMailServerSettings {
|
|
|
816
834
|
/** `emailConfig.tls.keyPem`; only with `emailConfig.tls`. */
|
|
817
835
|
tlsKey: IGatewaySealedValue | null;
|
|
818
836
|
emailPortConfig: IGatewayMailPortConfig;
|
|
819
|
-
/**
|
|
837
|
+
/**
|
|
838
|
+
* The effective source: what the gateway serves for settings stored without one.
|
|
839
|
+
* `configuredMaterial` only with material in the table: `tlsKey`, or `emailConfig.tls.certPem`.
|
|
840
|
+
*/
|
|
820
841
|
tlsSource: 'managedCertificate' | 'configuredMaterial';
|
|
821
842
|
}
|
|
822
843
|
|
|
@@ -948,11 +969,45 @@ export interface IGatewayMailArea {
|
|
|
948
969
|
// edges
|
|
949
970
|
// ---------------------------------------------------------------------------------------------
|
|
950
971
|
|
|
972
|
+
/**
|
|
973
|
+
* The ranges and bounds of an edge's settings (`IGatewayEdgePerformance`, `IGatewayEdgeEgress`), the
|
|
974
|
+
* ones a gateway's remote ingress engine takes; `validateGatewayAreaTables` refuses outside them: an
|
|
975
|
+
* integer outside its range as `invalid-value` (a wrong value), a list beyond its length as
|
|
976
|
+
* `bound-exceeded` (a document's size).
|
|
977
|
+
*/
|
|
978
|
+
export const gatewayEdgeSettingBounds = Object.freeze({
|
|
979
|
+
/** Each integer performance setting, inclusive. Only `maxHalfClosedStreams` may be 0 (it turns the retention off). */
|
|
980
|
+
performance: Object.freeze({
|
|
981
|
+
maxStreamsPerEdge: Object.freeze({ minimum: 1, maximum: 100_000 }),
|
|
982
|
+
totalWindowBudgetBytes: Object.freeze({ minimum: 1, maximum: 1_073_741_824 }),
|
|
983
|
+
minStreamWindowBytes: Object.freeze({ minimum: 1, maximum: 16_777_216 }),
|
|
984
|
+
maxStreamWindowBytes: Object.freeze({ minimum: 1, maximum: 134_217_728 }),
|
|
985
|
+
sustainedStreamWindowBytes: Object.freeze({ minimum: 1, maximum: 134_217_728 }),
|
|
986
|
+
quicDatagramReceiveBufferBytes: Object.freeze({ minimum: 1, maximum: 67_108_864 }),
|
|
987
|
+
streamFramePayloadBytes: Object.freeze({ minimum: 1, maximum: 16_777_216 }),
|
|
988
|
+
firstDataConnectTimeoutMs: Object.freeze({ minimum: 1, maximum: 3_600_000 }),
|
|
989
|
+
clientWriteTimeoutMs: Object.freeze({ minimum: 1, maximum: 3_600_000 }),
|
|
990
|
+
maxHalfClosedStreams: Object.freeze({ minimum: 0, maximum: 100_000 }),
|
|
991
|
+
halfCloseDrainTimeoutMs: Object.freeze({ minimum: 1, maximum: 3_600_000 }),
|
|
992
|
+
}),
|
|
993
|
+
/** Entries of `serverFirstPorts`. */
|
|
994
|
+
maximumServerFirstPorts: 128,
|
|
995
|
+
/** The client-first TLS port, which `serverFirstPorts` never names. */
|
|
996
|
+
clientFirstPort: 443,
|
|
997
|
+
/** The `allowedPorts` of every enabled egress policy, exactly (Linus ruling 129, Q3): outbound SMTP. */
|
|
998
|
+
egressAllowedPorts: Object.freeze([25] as const),
|
|
999
|
+
/** Entries of an egress policy's `deniedCidrs` and of its `allowedHostPatterns`. */
|
|
1000
|
+
maximumEgressListEntries: 128,
|
|
1001
|
+
/** An egress policy's `maxConcurrentStreams`, from 1. */
|
|
1002
|
+
maximumEgressConcurrentStreams: 100_000,
|
|
1003
|
+
} as const);
|
|
1004
|
+
|
|
951
1005
|
/**
|
|
952
1006
|
* dcrouter's `IRemoteIngressPerformanceConfig`, canonical; `null` members take the gateway default.
|
|
953
1007
|
* At least one member is set: settings that state nothing are the owner's `performance: null`, never
|
|
954
1008
|
* an object of `null` members (Linus ruling 125, Q-b7; the gateway stores and exports them as no
|
|
955
|
-
* setting).
|
|
1009
|
+
* setting). Every integer lies in its range of `gatewayEdgeSettingBounds.performance`, and neither
|
|
1010
|
+
* `minStreamWindowBytes` nor `sustainedStreamWindowBytes` is above a stated `maxStreamWindowBytes`.
|
|
956
1011
|
*/
|
|
957
1012
|
export interface IGatewayEdgePerformance {
|
|
958
1013
|
profile: 'balanced' | 'throughput' | 'highConcurrency' | null;
|
|
@@ -967,15 +1022,19 @@ export interface IGatewayEdgePerformance {
|
|
|
967
1022
|
clientWriteTimeoutMs: number | null;
|
|
968
1023
|
maxHalfClosedStreams: number | null;
|
|
969
1024
|
halfCloseDrainTimeoutMs: number | null;
|
|
970
|
-
/**
|
|
1025
|
+
/**
|
|
1026
|
+
* A non-empty set of at most `gatewayEdgeSettingBounds.maximumServerFirstPorts` ports, never 443
|
|
1027
|
+
* (client-first TLS); `null` for none (never `[]`).
|
|
1028
|
+
*/
|
|
971
1029
|
serverFirstPorts: number[] | null;
|
|
972
1030
|
}
|
|
973
1031
|
|
|
974
1032
|
/**
|
|
975
1033
|
* dcrouter's `IRemoteIngressEgressPolicyConfig`, canonical; `null` members take the gateway default.
|
|
976
|
-
* An enabled policy states its ports
|
|
977
|
-
*
|
|
978
|
-
*
|
|
1034
|
+
* An enabled policy states its ports, which are exactly `gatewayEdgeSettingBounds.egressAllowedPorts`
|
|
1035
|
+
* (`[25]`, never `null`; Linus ruling 129: a gateway opens no other egress port); a disabled one
|
|
1036
|
+
* states nothing else, every other member `null`, because the gateway keeps only `enabled` of it. A
|
|
1037
|
+
* list member is `null` or non-empty, never `[]` (Linus ruling 125, Q-b7).
|
|
979
1038
|
*
|
|
980
1039
|
* Always stated on an edge row (`IGatewayEdgeRow.egress`): the gateway reads an edge without a
|
|
981
1040
|
* policy and one with a disabled policy alike, so egress off has the one spelling
|
|
@@ -985,13 +1044,14 @@ export interface IGatewayEdgePerformance {
|
|
|
985
1044
|
*/
|
|
986
1045
|
export interface IGatewayEdgeEgress {
|
|
987
1046
|
enabled: boolean;
|
|
988
|
-
/**
|
|
1047
|
+
/** `[25]` exactly when `enabled`; `null` otherwise. */
|
|
989
1048
|
allowedPorts: number[] | null;
|
|
990
1049
|
allowPrivateRanges: boolean | null;
|
|
991
|
-
/** A non-empty set of CIDRs, or `null`. */
|
|
1050
|
+
/** A non-empty set of at most `gatewayEdgeSettingBounds.maximumEgressListEntries` CIDRs, each without whitespace around it, or `null`. */
|
|
992
1051
|
deniedCidrs: string[] | null;
|
|
993
|
-
/** A non-empty set of host patterns, or `null`. */
|
|
1052
|
+
/** A non-empty set of host patterns under the same bound and rule, or `null`. */
|
|
994
1053
|
allowedHostPatterns: string[] | null;
|
|
1054
|
+
/** 1 to `gatewayEdgeSettingBounds.maximumEgressConcurrentStreams`, or `null`. */
|
|
995
1055
|
maxConcurrentStreams: number | null;
|
|
996
1056
|
}
|
|
997
1057
|
|
|
@@ -1012,15 +1072,18 @@ export interface IGatewayEdgeRow {
|
|
|
1012
1072
|
egress: IGatewayEdgeEgress;
|
|
1013
1073
|
/** A set of tags (the gateway reads absent as empty). */
|
|
1014
1074
|
tags: string[];
|
|
1075
|
+
/** One IPv4 address in canonical text (a dotted quad without leading zeros). */
|
|
1015
1076
|
publicIp: string | null;
|
|
1016
|
-
/** dcrouter stores it as `publicIpV6`. */
|
|
1077
|
+
/** One IPv6 address in canonical text (RFC 5952). dcrouter stores it as `publicIpV6`. */
|
|
1017
1078
|
publicIpv6: string | null;
|
|
1079
|
+
/** A lowercase fully qualified name: two or more labels of letters, digits and inner hyphens, no trailing dot. */
|
|
1018
1080
|
mailHostname: string | null;
|
|
1019
1081
|
}
|
|
1020
1082
|
|
|
1021
1083
|
/** The tunnel hub singleton, without its listener port and TLS files. */
|
|
1022
1084
|
export interface IGatewayEdgeHubSettings {
|
|
1023
1085
|
enabled: boolean;
|
|
1086
|
+
/** Without whitespace around it. */
|
|
1024
1087
|
hubDomain: string | null;
|
|
1025
1088
|
performance: IGatewayEdgePerformance | null;
|
|
1026
1089
|
}
|
|
@@ -22,6 +22,7 @@ import {
|
|
|
22
22
|
import { isPlainRecord, readDataElements, readDataProperty, readExactDataRecord } from '../private/dataproperties.js';
|
|
23
23
|
import { matchesEngineKeyEntry, readEngineKeyEntries } from '../private/enginekeyentries.js';
|
|
24
24
|
import { isGatewayClientIdText } from '../private/gatewayclientid.js';
|
|
25
|
+
import { parseCanonicalIpAddress } from '../private/ipaddress.js';
|
|
25
26
|
import { normalizeCoreMailCredentialVerifier } from './coremail.runtime.js';
|
|
26
27
|
import {
|
|
27
28
|
isGatewayClientHostname,
|
|
@@ -35,6 +36,7 @@ import {
|
|
|
35
36
|
gatewayBlockRuleTypes,
|
|
36
37
|
gatewayDnsRecordTypes,
|
|
37
38
|
gatewayDnsStaticRecordTypes,
|
|
39
|
+
gatewayEdgeSettingBounds,
|
|
38
40
|
gatewayMailIdentityScramIterations,
|
|
39
41
|
gatewayRoutePathClasses,
|
|
40
42
|
isGatewayApiTokenScope,
|
|
@@ -926,36 +928,114 @@ const validateSecurity = (scopeArg: IScope, contentArg: Record<string, unknown>)
|
|
|
926
928
|
// ---------------------------------------------------------------------------------------------
|
|
927
929
|
|
|
928
930
|
/**
|
|
929
|
-
* The
|
|
930
|
-
* `
|
|
931
|
+
* The form of a record's `name` (Linus ruling 129, Q1): at most 253 characters, every label a
|
|
932
|
+
* `zoneLabel`, except that the leftmost label may be exactly `*` with at least one label after it.
|
|
933
|
+
* Lowercase, no trailing dot, nothing around it.
|
|
931
934
|
*/
|
|
932
|
-
const
|
|
933
|
-
|
|
934
|
-
|
|
935
|
+
const isDnsRecordName = (valueArg: unknown): valueArg is string => {
|
|
936
|
+
if (typeof valueArg !== 'string' || valueArg.length === 0 || valueArg.length > 253) {
|
|
937
|
+
return false;
|
|
938
|
+
}
|
|
939
|
+
const [first, ...rest] = valueArg.split('.');
|
|
940
|
+
return (first === '*' ? rest.length > 0 : zoneLabel.test(first)) && rest.every((labelArg) => zoneLabel.test(labelArg));
|
|
941
|
+
};
|
|
942
|
+
|
|
943
|
+
/** A record's `name`: beyond 253 characters `bound-exceeded`, outside the form `invalid-value`. */
|
|
944
|
+
const checkDnsRecordName = (scopeArg: IScope, valueArg: unknown): boolean => {
|
|
945
|
+
if (typeof valueArg === 'string' && valueArg.length > 253) {
|
|
946
|
+
refuse(scopeArg, 'name', 'bound-exceeded');
|
|
947
|
+
return false;
|
|
948
|
+
}
|
|
949
|
+
check(scopeArg, isDnsRecordName(valueArg), 'name');
|
|
950
|
+
return isDnsRecordName(valueArg);
|
|
935
951
|
};
|
|
936
952
|
|
|
953
|
+
const utf8Encoder = new TextEncoder();
|
|
954
|
+
const utf8Length = (textArg: string): number => utf8Encoder.encode(textArg).length;
|
|
955
|
+
const whitespace = /\s/;
|
|
956
|
+
|
|
937
957
|
/**
|
|
938
|
-
*
|
|
939
|
-
*
|
|
940
|
-
* most
|
|
941
|
-
*
|
|
958
|
+
* A domain name inside a record value, in the one spelling the gateway's record value owner emits
|
|
959
|
+
* (dcrouter's `canonicalDnsRecordValue`): lowercase as written, no trailing dot, no whitespace, no
|
|
960
|
+
* empty label, every label at most 63 octets and the name at most 253. The characters of a label are
|
|
961
|
+
* not restricted further, as the gateway's encoder does not restrict them; the root is no name here.
|
|
942
962
|
*/
|
|
943
|
-
const
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
963
|
+
const isDnsValueName = (valueArg: string): boolean => (
|
|
964
|
+
valueArg !== '' && !whitespace.test(valueArg) && valueArg === valueArg.toLowerCase() && !valueArg.endsWith('.')
|
|
965
|
+
&& utf8Length(valueArg) <= 253
|
|
966
|
+
&& valueArg.split('.').every((labelArg) => labelArg !== '' && utf8Length(labelArg) <= 63)
|
|
967
|
+
);
|
|
968
|
+
|
|
969
|
+
/** A decimal number from 0 to `maximumArg` without a leading zero, as the value owner writes one. */
|
|
970
|
+
const isDnsValueNumber = (valueArg: string, maximumArg: number): boolean => (
|
|
971
|
+
/^(?:0|[1-9][0-9]{0,9})$/.test(valueArg) && Number(valueArg) <= maximumArg
|
|
972
|
+
);
|
|
973
|
+
|
|
974
|
+
/**
|
|
975
|
+
* The one spelling of a record value per type (Linus ruling 129, Q3), which is what dcrouter's
|
|
976
|
+
* record value owner emits (`canonicalDnsRecordValue`): the validator judges that spelling and
|
|
977
|
+
* accepts no other, so one record has one digest.
|
|
978
|
+
*
|
|
979
|
+
* - `A`, `AAAA`: one address of the type's family in the contract's canonical address text
|
|
980
|
+
* (`parseCanonicalIpAddress`, Linus ruling 143 B): a dotted quad without leading zeros, or the
|
|
981
|
+
* RFC 5952 text (lowercase, no leading zeros, the longest run of zero groups compressed). Every
|
|
982
|
+
* other spelling of the same address, which the gateway's DNS encoder would serve alike, is
|
|
983
|
+
* refused: the gateway's exporter respells a stored value. Spelling only: any address of the
|
|
984
|
+
* family is a value (the unspecified and multicast addresses too).
|
|
985
|
+
* - `CNAME`, `NS`: one name (`isDnsValueName`).
|
|
986
|
+
* - `MX`: `<preference> <exchange>` with one space between: the preference 0 to 65535, the exchange
|
|
987
|
+
* a name, or `.` exactly with preference 0 (the null MX of RFC 7505).
|
|
988
|
+
* - `SOA`: `<mname> <rname> <serial> <refresh> <retry> <expire> <minimum>` with one space between
|
|
989
|
+
* each: two names and five numbers from 0 to 4294967295.
|
|
990
|
+
* - `CAA`: any text without whitespace around it (the gateway keeps it as it is).
|
|
991
|
+
* - `TXT`: the text itself.
|
|
992
|
+
*/
|
|
993
|
+
const isDnsRecordValue = (typeArg: unknown, valueArg: string): boolean => {
|
|
994
|
+
switch (typeArg) {
|
|
995
|
+
case 'A':
|
|
996
|
+
return parseCanonicalIpAddress(valueArg)?.family === 4;
|
|
997
|
+
case 'AAAA':
|
|
998
|
+
return parseCanonicalIpAddress(valueArg)?.family === 6;
|
|
999
|
+
case 'CNAME':
|
|
1000
|
+
case 'NS':
|
|
1001
|
+
return isDnsValueName(valueArg);
|
|
1002
|
+
case 'MX': {
|
|
1003
|
+
const fields = valueArg.split(' ');
|
|
1004
|
+
return fields.length === 2 && isDnsValueNumber(fields[0], 65_535)
|
|
1005
|
+
&& (fields[1] === '.' ? fields[0] === '0' : isDnsValueName(fields[1]));
|
|
1006
|
+
}
|
|
1007
|
+
case 'SOA': {
|
|
1008
|
+
const fields = valueArg.split(' ');
|
|
1009
|
+
return fields.length === 7 && isDnsValueName(fields[0]) && isDnsValueName(fields[1])
|
|
1010
|
+
&& fields.slice(2).every((fieldArg) => isDnsValueNumber(fieldArg, 4_294_967_295));
|
|
1011
|
+
}
|
|
1012
|
+
case 'CAA':
|
|
1013
|
+
return valueArg === valueArg.trim();
|
|
1014
|
+
default:
|
|
1015
|
+
// `TXT` is the text itself; a type outside the vocabulary is refused at `type`.
|
|
1016
|
+
return true;
|
|
947
1017
|
}
|
|
948
|
-
const groups = halves.flatMap((halfArg) => (halfArg === '' ? [] : halfArg.split(':')));
|
|
949
|
-
return groups.every((groupArg) => /^[0-9A-Fa-f]{1,4}$/.test(groupArg))
|
|
950
|
-
&& (halves.length === 2 ? groups.length <= 8 : groups.length === 8);
|
|
951
1018
|
};
|
|
952
1019
|
|
|
953
|
-
/** A record value: a bounded text
|
|
1020
|
+
/** A record value: a bounded text in the one spelling of its type (`isDnsRecordValue`). */
|
|
954
1021
|
const checkRecordValue = (scopeArg: IScope, typeArg: unknown, valueArg: unknown): void => {
|
|
955
1022
|
checkText(scopeArg, valueArg, 'value', contract.maximumRecordValueLength);
|
|
956
|
-
if (isText(valueArg, contract.maximumRecordValueLength)
|
|
957
|
-
check(scopeArg, typeArg
|
|
1023
|
+
if (isText(valueArg, contract.maximumRecordValueLength)) {
|
|
1024
|
+
check(scopeArg, isDnsRecordValue(typeArg, valueArg), 'value');
|
|
1025
|
+
}
|
|
1026
|
+
};
|
|
1027
|
+
|
|
1028
|
+
/**
|
|
1029
|
+
* A zone the gateway may answer for: a zone name of at least two labels whose labels are letters,
|
|
1030
|
+
* digits and inner hyphens (no underscore), the form a delegation can name.
|
|
1031
|
+
*/
|
|
1032
|
+
const authorityZoneLabel = /^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/;
|
|
1033
|
+
const isAuthorityZoneName = (valueArg: unknown): boolean => {
|
|
1034
|
+
if (!isZoneName(valueArg)) {
|
|
1035
|
+
return false;
|
|
958
1036
|
}
|
|
1037
|
+
const labels = valueArg.split('.');
|
|
1038
|
+
return labels.length >= 2 && labels.every((labelArg) => authorityZoneLabel.test(labelArg));
|
|
959
1039
|
};
|
|
960
1040
|
|
|
961
1041
|
const validateDns = (scopeArg: IScope, contentArg: Record<string, unknown>): void => {
|
|
@@ -1039,13 +1119,14 @@ const validateDns = (scopeArg: IScope, contentArg: Record<string, unknown>): voi
|
|
|
1039
1119
|
} else if (domainSources.get(row.domainId) !== 'dcrouter') {
|
|
1040
1120
|
refuse(rowScopeArg, 'domainId', 'reference-not-dcrouter-zone');
|
|
1041
1121
|
} else {
|
|
1042
|
-
// A record lies inside its zone: the zone's name itself or a name below it, as written.
|
|
1122
|
+
// A record lies inside its zone: the zone's name itself or a name below it, as written. A name
|
|
1123
|
+
// outside the name form is refused for that alone, below.
|
|
1043
1124
|
const zone = domainNames.get(row.domainId);
|
|
1044
|
-
if (
|
|
1125
|
+
if (isDnsRecordName(row.name) && isZoneName(zone)) {
|
|
1045
1126
|
check(rowScopeArg, row.name === zone || row.name.endsWith(`.${zone}`), 'name');
|
|
1046
1127
|
}
|
|
1047
1128
|
}
|
|
1048
|
-
|
|
1129
|
+
checkDnsRecordName(rowScopeArg, row.name);
|
|
1049
1130
|
checkOneOf(rowScopeArg, row.type, 'type', gatewayDnsRecordTypes);
|
|
1050
1131
|
checkRecordValue(rowScopeArg, row.type, row.value);
|
|
1051
1132
|
checkInteger(rowScopeArg, row.ttl, 'ttl', 1);
|
|
@@ -1058,7 +1139,7 @@ const validateDns = (scopeArg: IScope, contentArg: Record<string, unknown>): voi
|
|
|
1058
1139
|
if (rowScopeArg.rowId !== null) {
|
|
1059
1140
|
check(rowScopeArg, /^static-[a-f0-9]{64}$/.test(rowScopeArg.rowId), 'id', 'invalid-row-id');
|
|
1060
1141
|
}
|
|
1061
|
-
|
|
1142
|
+
checkDnsRecordName(rowScopeArg, row.name);
|
|
1062
1143
|
checkOneOf(rowScopeArg, row.type, 'type', gatewayDnsStaticRecordTypes);
|
|
1063
1144
|
checkRecordValue(rowScopeArg, row.type, row.value);
|
|
1064
1145
|
checkInteger(rowScopeArg, row.ttl, 'ttl', 1, true);
|
|
@@ -1079,10 +1160,14 @@ const validateDns = (scopeArg: IScope, contentArg: Record<string, unknown>): voi
|
|
|
1079
1160
|
check(rowScopeArg, isGatewayClientHostname(rowScopeArg.rowId), 'id', 'invalid-row-id');
|
|
1080
1161
|
}
|
|
1081
1162
|
checkText(rowScopeArg, row.reason, 'reason', contract.maximumTextLength);
|
|
1163
|
+
// The gateway stores a reason trimmed, so one with whitespace around it would not read back.
|
|
1164
|
+
if (isText(row.reason, contract.maximumTextLength)) {
|
|
1165
|
+
check(rowScopeArg, row.reason === row.reason.trim(), 'reason');
|
|
1166
|
+
}
|
|
1082
1167
|
});
|
|
1083
1168
|
rowList(scopeArg, 'authorityZones', contentArg.authorityZones, bounds.authorityZones, (rowScopeArg, rowArg) => {
|
|
1084
1169
|
if (exact(rowScopeArg, rowArg, ['id'], null) !== null && rowScopeArg.rowId !== null) {
|
|
1085
|
-
check(rowScopeArg,
|
|
1170
|
+
check(rowScopeArg, isAuthorityZoneName(rowScopeArg.rowId), 'id', 'invalid-row-id');
|
|
1086
1171
|
}
|
|
1087
1172
|
});
|
|
1088
1173
|
rowList(scopeArg, 'clientHostnames', contentArg.clientHostnames, bounds.clientHostnames, (rowScopeArg, rowArg) => {
|
|
@@ -1646,6 +1731,20 @@ const validateMail = (scopeArg: IScope, contentArg: Record<string, unknown>, dns
|
|
|
1646
1731
|
});
|
|
1647
1732
|
}
|
|
1648
1733
|
checkOneOf(memberScopeArg, server.tlsSource, 'tlsSource', ['managedCertificate', 'configuredMaterial']);
|
|
1734
|
+
// Enabled mail with server options names its hostname and at least one port: the gateway cannot
|
|
1735
|
+
// start a mail server without them.
|
|
1736
|
+
if (server.enabled === true && isPlainRecord(server.emailConfig)) {
|
|
1737
|
+
const hostname = engineValueAt(server.emailConfig, 'hostname');
|
|
1738
|
+
check(memberScopeArg, typeof hostname === 'string' && hostname.trim() !== '', 'emailConfig.hostname');
|
|
1739
|
+
const ports = readDataElements(engineValueAt(server.emailConfig, 'ports'), Number.MAX_SAFE_INTEGER);
|
|
1740
|
+
check(memberScopeArg, ports !== null && ports.length > 0 && ports.every(isPort), 'emailConfig.ports');
|
|
1741
|
+
}
|
|
1742
|
+
// `configuredMaterial` serves the table's own TLS material: the lifted key, or a certificate in
|
|
1743
|
+
// `emailConfig.tls` (every other material member is a refused engine key).
|
|
1744
|
+
if (server.tlsSource === 'configuredMaterial') {
|
|
1745
|
+
check(memberScopeArg, isPlainRecord(server.emailConfig)
|
|
1746
|
+
&& (server.tlsKey !== null || Boolean(engineValueAt(server.emailConfig, 'tls.certPem'))), 'tlsSource');
|
|
1747
|
+
}
|
|
1649
1748
|
});
|
|
1650
1749
|
rowList(scopeArg, 'domains', contentArg.domains, bounds.domains, (rowScopeArg, rowArg) => {
|
|
1651
1750
|
const row = exact(rowScopeArg, rowArg, [
|
|
@@ -1796,6 +1895,40 @@ const checkNullableNonEmptyList = (
|
|
|
1796
1895
|
checkListArg(scopeArg, valueArg, pathArg);
|
|
1797
1896
|
};
|
|
1798
1897
|
|
|
1898
|
+
const edgeBounds = gatewayEdgeSettingBounds;
|
|
1899
|
+
|
|
1900
|
+
/** A bounded set of ports that never names the client-first TLS port. */
|
|
1901
|
+
const checkServerFirstPorts = (scopeArg: IScope, valueArg: unknown, pathArg: string): void => {
|
|
1902
|
+
if (Array.isArray(valueArg) && valueArg.length > edgeBounds.maximumServerFirstPorts) {
|
|
1903
|
+
refuse(scopeArg, pathArg, 'bound-exceeded');
|
|
1904
|
+
return;
|
|
1905
|
+
}
|
|
1906
|
+
checkPortSet(scopeArg, valueArg, pathArg);
|
|
1907
|
+
const ports = readDataElements(valueArg, edgeBounds.maximumServerFirstPorts);
|
|
1908
|
+
check(scopeArg, ports === null || !ports.includes(edgeBounds.clientFirstPort), pathArg);
|
|
1909
|
+
};
|
|
1910
|
+
|
|
1911
|
+
/** A bounded set of texts without whitespace around them (the gateway stores each trimmed). */
|
|
1912
|
+
const checkEgressTextSet = (scopeArg: IScope, valueArg: unknown, pathArg: string): void => {
|
|
1913
|
+
if (Array.isArray(valueArg) && valueArg.length > edgeBounds.maximumEgressListEntries) {
|
|
1914
|
+
refuse(scopeArg, pathArg, 'bound-exceeded');
|
|
1915
|
+
return;
|
|
1916
|
+
}
|
|
1917
|
+
checkTextSet(scopeArg, valueArg, pathArg,
|
|
1918
|
+
(entryArg) => isText(entryArg, contract.maximumNameLength) && entryArg === entryArg.trim());
|
|
1919
|
+
};
|
|
1920
|
+
|
|
1921
|
+
/** An edge's mail hostname: lowercase letters, digits and inner hyphens in two or more labels, at most 253 characters. */
|
|
1922
|
+
const mailHostnamePattern = /^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)+$/;
|
|
1923
|
+
|
|
1924
|
+
/** `null`, or the contract's canonical address text of one family (dotted quad, RFC 5952). */
|
|
1925
|
+
const checkNullableAddress = (scopeArg: IScope, valueArg: unknown, pathArg: string, familyArg: 4 | 6): void => {
|
|
1926
|
+
checkNullableText(scopeArg, valueArg, pathArg, 64);
|
|
1927
|
+
if (isText(valueArg, 64)) {
|
|
1928
|
+
check(scopeArg, parseCanonicalIpAddress(valueArg)?.family === familyArg, pathArg);
|
|
1929
|
+
}
|
|
1930
|
+
};
|
|
1931
|
+
|
|
1799
1932
|
const checkPerformance = (scopeArg: IScope, valueArg: unknown, pathArg: string): void => {
|
|
1800
1933
|
if (valueArg === null) {
|
|
1801
1934
|
return;
|
|
@@ -1814,9 +1947,21 @@ const checkPerformance = (scopeArg: IScope, valueArg: unknown, pathArg: string):
|
|
|
1814
1947
|
if (key === 'profile') {
|
|
1815
1948
|
checkOneOf(inner, performance.profile, 'profile', ['balanced', 'throughput', 'highConcurrency'], true);
|
|
1816
1949
|
} else if (key === 'serverFirstPorts') {
|
|
1817
|
-
checkNullableNonEmptyList(inner, performance.serverFirstPorts, 'serverFirstPorts',
|
|
1950
|
+
checkNullableNonEmptyList(inner, performance.serverFirstPorts, 'serverFirstPorts', checkServerFirstPorts);
|
|
1818
1951
|
} else {
|
|
1819
|
-
|
|
1952
|
+
const range = edgeBounds.performance[key];
|
|
1953
|
+
const value = performance[key];
|
|
1954
|
+
check(inner, value === null || (isInteger(value, range.minimum) && value <= range.maximum), key);
|
|
1955
|
+
}
|
|
1956
|
+
}
|
|
1957
|
+
// A stream window never starts or settles above its maximum.
|
|
1958
|
+
const maximumWindow = performance.maxStreamWindowBytes;
|
|
1959
|
+
if (isInteger(maximumWindow, 1)) {
|
|
1960
|
+
for (const key of ['minStreamWindowBytes', 'sustainedStreamWindowBytes'] as const) {
|
|
1961
|
+
const value = performance[key];
|
|
1962
|
+
if (isInteger(value, 1)) {
|
|
1963
|
+
check(inner, value <= maximumWindow, key);
|
|
1964
|
+
}
|
|
1820
1965
|
}
|
|
1821
1966
|
}
|
|
1822
1967
|
};
|
|
@@ -1828,7 +1973,8 @@ const egressSettingKeys = [
|
|
|
1828
1973
|
/**
|
|
1829
1974
|
* An edge's egress policy in its one spelling (ruling 125, Q-b7): always the object, so `null` fails
|
|
1830
1975
|
* the shape check (the gateway reads no policy and a disabled one alike; ruling 128, B2's pattern);
|
|
1831
|
-
* enabled, it states its ports
|
|
1976
|
+
* enabled, it states its ports, which are exactly `gatewayEdgeSettingBounds.egressAllowedPorts`
|
|
1977
|
+
* (`[25]`, Linus ruling 129 Q3: the only ports a gateway opens for egress); disabled, every setting is
|
|
1832
1978
|
* `null`, because the gateway keeps only `enabled` of a disabled policy; a list is `null` or non-empty.
|
|
1833
1979
|
*/
|
|
1834
1980
|
const checkEgress = (scopeArg: IScope, valueArg: unknown): void => {
|
|
@@ -1845,13 +1991,19 @@ const checkEgress = (scopeArg: IScope, valueArg: unknown): void => {
|
|
|
1845
1991
|
return;
|
|
1846
1992
|
}
|
|
1847
1993
|
if (egress.enabled === true) {
|
|
1848
|
-
|
|
1994
|
+
const ports = readDataElements(egress.allowedPorts, contract.maximumListEntries);
|
|
1995
|
+
const allowed = edgeBounds.egressAllowedPorts;
|
|
1996
|
+
check(inner, ports !== null && ports.length === allowed.length
|
|
1997
|
+
&& ports.every((portArg, indexArg) => portArg === allowed[indexArg]), 'allowedPorts');
|
|
1998
|
+
} else {
|
|
1999
|
+
checkNullableNonEmptyList(inner, egress.allowedPorts, 'allowedPorts', checkPortSet);
|
|
1849
2000
|
}
|
|
1850
|
-
checkNullableNonEmptyList(inner, egress.allowedPorts, 'allowedPorts', checkPortSet);
|
|
1851
2001
|
checkNullableBoolean(inner, egress.allowPrivateRanges, 'allowPrivateRanges');
|
|
1852
|
-
checkNullableNonEmptyList(inner, egress.deniedCidrs, 'deniedCidrs',
|
|
1853
|
-
checkNullableNonEmptyList(inner, egress.allowedHostPatterns, 'allowedHostPatterns',
|
|
1854
|
-
|
|
2002
|
+
checkNullableNonEmptyList(inner, egress.deniedCidrs, 'deniedCidrs', checkEgressTextSet);
|
|
2003
|
+
checkNullableNonEmptyList(inner, egress.allowedHostPatterns, 'allowedHostPatterns', checkEgressTextSet);
|
|
2004
|
+
const streams = egress.maxConcurrentStreams;
|
|
2005
|
+
check(inner, streams === null || (isInteger(streams, 1) && streams <= edgeBounds.maximumEgressConcurrentStreams),
|
|
2006
|
+
'maxConcurrentStreams');
|
|
1855
2007
|
};
|
|
1856
2008
|
|
|
1857
2009
|
const validateEdges = (scopeArg: IScope, contentArg: Record<string, unknown>): void => {
|
|
@@ -1861,6 +2013,9 @@ const validateEdges = (scopeArg: IScope, contentArg: Record<string, unknown>): v
|
|
|
1861
2013
|
if (hub !== null) {
|
|
1862
2014
|
checkBoolean(memberScopeArg, hub.enabled, 'enabled');
|
|
1863
2015
|
checkNullableText(memberScopeArg, hub.hubDomain, 'hubDomain', 253);
|
|
2016
|
+
if (isText(hub.hubDomain, 253)) {
|
|
2017
|
+
check(memberScopeArg, hub.hubDomain === hub.hubDomain.trim(), 'hubDomain');
|
|
2018
|
+
}
|
|
1864
2019
|
checkPerformance(memberScopeArg, hub.performance, 'performance');
|
|
1865
2020
|
}
|
|
1866
2021
|
});
|
|
@@ -1881,9 +2036,12 @@ const validateEdges = (scopeArg: IScope, contentArg: Record<string, unknown>): v
|
|
|
1881
2036
|
checkPerformance(rowScopeArg, row.performance, 'performance');
|
|
1882
2037
|
checkEgress(rowScopeArg, row.egress);
|
|
1883
2038
|
checkTextSet(rowScopeArg, row.tags, 'tags');
|
|
1884
|
-
|
|
1885
|
-
|
|
2039
|
+
checkNullableAddress(rowScopeArg, row.publicIp, 'publicIp', 4);
|
|
2040
|
+
checkNullableAddress(rowScopeArg, row.publicIpv6, 'publicIpv6', 6);
|
|
1886
2041
|
checkNullableText(rowScopeArg, row.mailHostname, 'mailHostname', 253);
|
|
2042
|
+
if (isText(row.mailHostname, 253)) {
|
|
2043
|
+
check(rowScopeArg, mailHostnamePattern.test(row.mailHostname), 'mailHostname');
|
|
2044
|
+
}
|
|
1887
2045
|
});
|
|
1888
2046
|
};
|
|
1889
2047
|
|
|
@@ -360,6 +360,24 @@ export const gatewayConnectorRefusals = Object.freeze([
|
|
|
360
360
|
* export.
|
|
361
361
|
*/
|
|
362
362
|
'local-changing-during-export',
|
|
363
|
+
/**
|
|
364
|
+
* A local write to a configuration area the gateway's controller owns: an operator's or a gateway
|
|
365
|
+
* client's change on the gateway itself, whichever call carried it (the gateway's own API, a
|
|
366
|
+
* gateway-client token or a gateway-client call on the connector socket). Nothing was written; the
|
|
367
|
+
* error text names the area (the error data stays `{ code, retryable }` and carries none), and the
|
|
368
|
+
* change is made at the controller. A reader built on an earlier release of this package reads it
|
|
369
|
+
* as a failure without a named refusal.
|
|
370
|
+
*/
|
|
371
|
+
'area-controller-owned',
|
|
372
|
+
/**
|
|
373
|
+
* Momentary (`gatewayConnectorMomentaryRefusals`): a `getGatewayRouteDnsResults` while the gateway
|
|
374
|
+
* runs no route DNS reconciler (it has not started yet, or it failed), so no outcome can be read.
|
|
375
|
+
* It refuses the whole read only and is never one hostname's condition: those stay in the result
|
|
376
|
+
* rows (`IGatewayRouteDnsResult`). Nothing changed, and the controller asks again later. A reader
|
|
377
|
+
* built on an earlier release of this package reads it as a failure without a named refusal, never
|
|
378
|
+
* as an answer.
|
|
379
|
+
*/
|
|
380
|
+
'route-dns-unavailable',
|
|
363
381
|
] as const);
|
|
364
382
|
|
|
365
383
|
/** One of the reasons one side of the gateway connector answers instead of a request. */
|
|
@@ -386,6 +404,7 @@ export const isGatewayConnectorRefusal = (valueArg: unknown): valueArg is TGatew
|
|
|
386
404
|
*/
|
|
387
405
|
export const gatewayConnectorMomentaryRefusals = Object.freeze([
|
|
388
406
|
'local-changing-during-export',
|
|
407
|
+
'route-dns-unavailable',
|
|
389
408
|
] as const satisfies readonly TGatewayConnectorRefusal[]);
|
|
390
409
|
|
|
391
410
|
/** One of the momentary connector refusals. */
|