@stacksjs/ts-cloud 0.7.105 → 0.7.109
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/dist/alerts/delivery.d.ts +10 -0
- package/dist/alerts/model.d.ts +1 -1
- package/dist/api/client.d.ts +53 -0
- package/dist/api/handler.d.ts +10 -0
- package/dist/api/service.d.ts +1 -0
- package/dist/aws/index.js +10 -10
- package/dist/aws/lambda.d.ts +19 -0
- package/dist/bin/cli.js +1677 -1370
- package/dist/bin/dashboard-server.js +926 -620
- package/dist/{chunk-fmt40tpw.js → chunk-53jatzaw.js} +2 -2
- package/dist/{chunk-ef2dwfrg.js → chunk-8kh577qh.js} +5 -5
- package/dist/{chunk-s9c2x5jv.js → chunk-9v2pwxv9.js} +2 -2
- package/dist/chunk-aa2dkn7b.js +205 -0
- package/dist/{chunk-vkd2y0fs.js → chunk-cktwk9hy.js} +7169 -14800
- package/dist/{chunk-dmzez5f8.js → chunk-d3vx2ekv.js} +123 -28
- package/dist/chunk-grx1rp09.js +12163 -0
- package/dist/{chunk-c6db5m63.js → chunk-t2s3gdq6.js} +253 -8
- package/dist/chunk-va2yd85b.js +200 -0
- package/dist/{chunk-3g4r09dd.js → chunk-wmbep3b5.js} +1 -1
- package/dist/{chunk-ybcz6sxc.js → chunk-x6yzgv7y.js} +33 -0
- package/dist/chunk-xrtwv3v2.js +420 -0
- package/dist/control-plane/types.d.ts +1 -1
- package/dist/deploy/dashboard-bundle-encoding.test.d.ts +1 -0
- package/dist/deploy/dashboard-payload.d.ts +20 -0
- package/dist/deploy/dashboard-payload.test.d.ts +1 -0
- package/dist/deploy/dashboard-protection.test.d.ts +1 -0
- package/dist/deploy/dashboard-spend.test.d.ts +1 -0
- package/dist/deploy/dashboard-topology.d.ts +85 -0
- package/dist/deploy/dashboard-topology.test.d.ts +1 -0
- package/dist/deploy/egress-collection.d.ts +60 -0
- package/dist/deploy/index.d.ts +2 -0
- package/dist/deploy/index.js +23 -8
- package/dist/deploy/local-dashboard-server.d.ts +2 -0
- package/dist/drivers/index.js +4 -2
- package/dist/drivers/shared/protection.d.ts +43 -0
- package/dist/drivers/shared/protection.test.d.ts +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +364 -102
- package/dist/protection/controls.d.ts +113 -0
- package/dist/protection/controls.test.d.ts +1 -0
- package/dist/protection/ddos.d.ts +130 -0
- package/dist/protection/ddos.test.d.ts +1 -0
- package/dist/protection/index.d.ts +11 -0
- package/dist/protection/index.js +87 -0
- package/dist/protection/ratelimit.d.ts +154 -0
- package/dist/protection/ratelimit.test.d.ts +1 -0
- package/dist/protection/waf.d.ts +143 -0
- package/dist/protection/waf.test.d.ts +1 -0
- package/dist/spend/anomaly-config.d.ts +130 -0
- package/dist/spend/anomaly-config.test.d.ts +1 -0
- package/dist/spend/anomaly.d.ts +114 -0
- package/dist/spend/anomaly.test.d.ts +1 -0
- package/dist/spend/api.d.ts +42 -0
- package/dist/spend/api.test.d.ts +1 -0
- package/dist/spend/appliers.d.ts +126 -0
- package/dist/spend/docs.test.d.ts +1 -0
- package/dist/spend/enforcement.d.ts +111 -0
- package/dist/spend/enforcement.integration.test.d.ts +1 -0
- package/dist/spend/evaluator.d.ts +70 -0
- package/dist/spend/evaluator.test.d.ts +1 -0
- package/dist/spend/focus.d.ts +93 -0
- package/dist/spend/focus.test.d.ts +1 -0
- package/dist/spend/gate.d.ts +96 -0
- package/dist/spend/index.d.ts +20 -0
- package/dist/spend/index.js +173 -0
- package/dist/spend/lease.d.ts +54 -0
- package/dist/spend/lease.test.d.ts +1 -0
- package/dist/spend/meter.d.ts +70 -0
- package/dist/spend/meter.test.d.ts +1 -0
- package/dist/spend/model.d.ts +228 -0
- package/dist/spend/notifications.d.ts +58 -0
- package/dist/spend/pricing.d.ts +109 -0
- package/dist/spend/pricing.test.d.ts +1 -0
- package/dist/spend/projection.d.ts +36 -0
- package/dist/spend/runner.d.ts +130 -0
- package/dist/spend/service.d.ts +129 -0
- package/dist/spend/signals.d.ts +110 -0
- package/dist/spend/signals.test.d.ts +1 -0
- package/dist/spend/sms-sdk.test.d.ts +1 -0
- package/dist/spend/spend.integration.test.d.ts +1 -0
- package/dist/spend/store.d.ts +166 -0
- package/dist/spend/transports.d.ts +169 -0
- package/dist/spend/transports.test.d.ts +1 -0
- package/dist/spend/window.d.ts +52 -0
- package/dist/spend/window.test.d.ts +1 -0
- package/dist/ui/404.html +2 -0
- package/dist/ui/access-denied.html +2 -2
- package/dist/ui/account/automation.html +4 -4
- package/dist/ui/account/security.html +2 -2
- package/dist/ui/applications/compose.html +4 -4
- package/dist/ui/applications/new.html +2 -2
- package/dist/ui/data/backups.html +22 -9
- package/dist/ui/data/services.html +22 -9
- package/dist/ui/data/volumes.html +22 -9
- package/dist/ui/index.html +22 -9
- package/dist/ui/infrastructure/topology.html +2223 -0
- package/dist/ui/integrations.html +2 -2
- package/dist/ui/operations/alerts.html +22 -9
- package/dist/ui/operations/configuration.html +4 -4
- package/dist/ui/operations/jobs.html +22 -9
- package/dist/ui/operations/maintenance.html +4 -4
- package/dist/ui/operations/observability.html +22 -9
- package/dist/ui/operations/previews.html +4 -4
- package/dist/ui/operations/queue.html +4 -4
- package/dist/ui/operations/regions.html +3 -3
- package/dist/ui/operations/releases.html +3 -3
- package/dist/ui/operations/spend.html +1634 -0
- package/dist/ui/operations/workloads.html +22 -9
- package/dist/ui/security.html +2 -2
- package/dist/ui/server/actions.html +4 -4
- package/dist/ui/server/activity.html +2 -2
- package/dist/ui/server/capacity.html +4 -4
- package/dist/ui/server/database.html +4 -4
- package/dist/ui/server/deployments.html +4 -4
- package/dist/ui/server/diagnostics.html +2 -2
- package/dist/ui/server/firewall.html +100 -161
- package/dist/ui/server/fleet.html +22 -9
- package/dist/ui/server/logs.html +22 -9
- package/dist/ui/server/metrics.html +130 -14
- package/dist/ui/server/security.html +2 -2
- package/dist/ui/server/services.html +1 -1
- package/dist/ui/server/sites.html +22 -9
- package/dist/ui/server/ssh-keys.html +3 -3
- package/dist/ui/server/team.html +4 -4
- package/dist/ui/server/terminal.html +2 -2
- package/dist/ui/serverless/alarms.html +4 -4
- package/dist/ui/serverless/assets.html +2 -2
- package/dist/ui/serverless/cost.html +2 -2
- package/dist/ui/serverless/data.html +4 -4
- package/dist/ui/serverless/deployments.html +2 -2
- package/dist/ui/serverless/firewall.html +2 -2
- package/dist/ui/serverless/functions.html +4 -4
- package/dist/ui/serverless/logs.html +22 -9
- package/dist/ui/serverless/metrics.html +2 -2
- package/dist/ui/serverless/queues.html +4 -4
- package/dist/ui/serverless/secrets.html +4 -4
- package/dist/ui/serverless/traces.html +4 -4
- package/dist/ui/serverless.html +4 -4
- package/dist/ui-src/functions/requestJson.ts +41 -0
- package/dist/ui-src/functions/useOpConfirm.ts +132 -0
- package/dist/ui-src/functions/usePolling.ts +98 -0
- package/dist/ui-src/functions/useTerminal.ts +79 -0
- package/dist/ui-src/pages/infrastructure/topology.stx +517 -0
- package/dist/ui-src/pages/operations/spend.stx +225 -0
- package/dist/ui-src/pages/partials/nav.stx +4 -0
- package/dist/ui-src/pages/server/firewall.stx +89 -0
- package/dist/ui-src/pages/server/metrics.stx +140 -6
- package/dist/ui-src/src/topology.ts +485 -0
- package/package.json +11 -3
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
buildAndPushServerlessImage
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-wmbep3b5.js";
|
|
4
4
|
import"./chunk-50jpda9q.js";
|
|
5
|
-
import"./chunk-c6db5m63.js";
|
|
6
5
|
import"./chunk-zqtpg06c.js";
|
|
6
|
+
import"./chunk-t2s3gdq6.js";
|
|
7
7
|
import"./chunk-v0bahtg2.js";
|
|
8
8
|
export {
|
|
9
9
|
buildAndPushServerlessImage
|
|
@@ -8,12 +8,12 @@ import {
|
|
|
8
8
|
UnifiedDnsValidator,
|
|
9
9
|
createDnsProvider
|
|
10
10
|
} from "./chunk-gttvakpv.js";
|
|
11
|
-
import {
|
|
12
|
-
CloudFormationClient
|
|
13
|
-
} from "./chunk-4cjrg98a.js";
|
|
14
11
|
import {
|
|
15
12
|
Route53Client
|
|
16
13
|
} from "./chunk-32e7ya18.js";
|
|
14
|
+
import {
|
|
15
|
+
CloudFormationClient
|
|
16
|
+
} from "./chunk-4cjrg98a.js";
|
|
17
17
|
import {
|
|
18
18
|
S3Client
|
|
19
19
|
} from "./chunk-wj3s95p9.js";
|
|
@@ -815,7 +815,7 @@ async function deployStaticSiteWithExternalDnsFull(config) {
|
|
|
815
815
|
}
|
|
816
816
|
}
|
|
817
817
|
onProgress?.("upload", "Uploading files to S3...");
|
|
818
|
-
const { uploadStaticFiles } = await import("./chunk-
|
|
818
|
+
const { uploadStaticFiles } = await import("./chunk-9v2pwxv9.js");
|
|
819
819
|
const uploadResult = await uploadStaticFiles({
|
|
820
820
|
sourceDir,
|
|
821
821
|
bucket: infraResult.bucket,
|
|
@@ -835,7 +835,7 @@ async function deployStaticSiteWithExternalDnsFull(config) {
|
|
|
835
835
|
}
|
|
836
836
|
if (infraResult.distributionId && uploadResult.uploaded > 0) {
|
|
837
837
|
onProgress?.("invalidate", "Invalidating CloudFront cache...");
|
|
838
|
-
const { invalidateCache } = await import("./chunk-
|
|
838
|
+
const { invalidateCache } = await import("./chunk-9v2pwxv9.js");
|
|
839
839
|
await invalidateCache(infraResult.distributionId);
|
|
840
840
|
}
|
|
841
841
|
onProgress?.("complete", "Deployment complete!");
|
|
@@ -5,11 +5,11 @@ import {
|
|
|
5
5
|
generateStaticSiteTemplate,
|
|
6
6
|
invalidateCache,
|
|
7
7
|
uploadStaticFiles
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-8kh577qh.js";
|
|
9
9
|
import"./chunk-01d86gt1.js";
|
|
10
10
|
import"./chunk-gttvakpv.js";
|
|
11
|
-
import"./chunk-4cjrg98a.js";
|
|
12
11
|
import"./chunk-32e7ya18.js";
|
|
12
|
+
import"./chunk-4cjrg98a.js";
|
|
13
13
|
import"./chunk-wj3s95p9.js";
|
|
14
14
|
import"./chunk-zqtpg06c.js";
|
|
15
15
|
import"./chunk-v0bahtg2.js";
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
// src/protection/ddos.ts
|
|
2
|
+
var DEFAULT_DDOS_THRESHOLDS = {
|
|
3
|
+
newConnectionsPerSecond: 50,
|
|
4
|
+
concurrentPerSource: 100,
|
|
5
|
+
synPerSecond: 2000,
|
|
6
|
+
burst: 100,
|
|
7
|
+
icmpPerSecond: 5,
|
|
8
|
+
banSeconds: 600
|
|
9
|
+
};
|
|
10
|
+
function resolveThresholds(config) {
|
|
11
|
+
return { ...DEFAULT_DDOS_THRESHOLDS, ...config.thresholds };
|
|
12
|
+
}
|
|
13
|
+
var CIDR_PATTERN = /^(?:\d{1,3}\.){3}\d{1,3}(?:\/\d{1,2})?$|^[0-9a-f:]+(?:\/\d{1,3})?$/i;
|
|
14
|
+
function isValidCidr(value) {
|
|
15
|
+
if (!CIDR_PATTERN.test(value))
|
|
16
|
+
return false;
|
|
17
|
+
const [address, prefix] = value.split("/");
|
|
18
|
+
if (address.includes(":"))
|
|
19
|
+
return prefix == null || Number(prefix) >= 0 && Number(prefix) <= 128;
|
|
20
|
+
const octets = address.split(".");
|
|
21
|
+
if (octets.length !== 4 || octets.some((octet) => Number(octet) > 255 || octet === ""))
|
|
22
|
+
return false;
|
|
23
|
+
return prefix == null || Number(prefix) >= 0 && Number(prefix) <= 32;
|
|
24
|
+
}
|
|
25
|
+
function validCidrs(values) {
|
|
26
|
+
return [...new Set((values ?? []).map((value) => value.trim()).filter(isValidCidr))];
|
|
27
|
+
}
|
|
28
|
+
function validPorts(values) {
|
|
29
|
+
const ports = (values ?? [80, 443]).filter((port) => Number.isInteger(port) && port >= 1 && port <= 65535);
|
|
30
|
+
return [...new Set(ports)].sort((a, b) => a - b);
|
|
31
|
+
}
|
|
32
|
+
function sysctlHardening(config = {}) {
|
|
33
|
+
const thresholds = resolveThresholds(config);
|
|
34
|
+
return {
|
|
35
|
+
"net.ipv4.tcp_syncookies": "1",
|
|
36
|
+
"net.ipv4.tcp_max_syn_backlog": String(Math.max(4096, thresholds.synPerSecond * 4)),
|
|
37
|
+
"net.ipv4.tcp_synack_retries": "2",
|
|
38
|
+
"net.ipv4.tcp_abort_on_overflow": "1",
|
|
39
|
+
"net.ipv4.tcp_fin_timeout": "15",
|
|
40
|
+
"net.ipv4.tcp_keepalive_time": "300",
|
|
41
|
+
"net.ipv4.tcp_keepalive_intvl": "30",
|
|
42
|
+
"net.ipv4.tcp_keepalive_probes": "3",
|
|
43
|
+
"net.core.somaxconn": "4096",
|
|
44
|
+
"net.core.netdev_max_backlog": "16384",
|
|
45
|
+
"net.ipv4.conf.all.rp_filter": "1",
|
|
46
|
+
"net.ipv4.conf.default.rp_filter": "1",
|
|
47
|
+
"net.ipv4.conf.all.accept_source_route": "0",
|
|
48
|
+
"net.ipv4.conf.all.accept_redirects": "0",
|
|
49
|
+
"net.ipv4.conf.all.send_redirects": "0",
|
|
50
|
+
"net.ipv6.conf.all.accept_redirects": "0",
|
|
51
|
+
"net.ipv6.conf.all.accept_source_route": "0",
|
|
52
|
+
"net.ipv4.icmp_echo_ignore_broadcasts": "1",
|
|
53
|
+
"net.ipv4.icmp_ignore_bogus_error_responses": "1",
|
|
54
|
+
"net.netfilter.nf_conntrack_max": "262144",
|
|
55
|
+
"net.netfilter.nf_conntrack_tcp_timeout_established": "3600"
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
function renderSysctlFile(config = {}) {
|
|
59
|
+
const lines = [
|
|
60
|
+
"# Managed by ts-cloud. Edits are overwritten on the next deploy.",
|
|
61
|
+
"# Network hardening against L3/L4 floods.",
|
|
62
|
+
""
|
|
63
|
+
];
|
|
64
|
+
for (const [key, value] of Object.entries(sysctlHardening(config)))
|
|
65
|
+
lines.push(`${key} = ${value}`);
|
|
66
|
+
return `${lines.join(`
|
|
67
|
+
`)}
|
|
68
|
+
`;
|
|
69
|
+
}
|
|
70
|
+
function renderNftablesRuleset(config = {}) {
|
|
71
|
+
const thresholds = resolveThresholds(config);
|
|
72
|
+
const ports = validPorts(config.ports);
|
|
73
|
+
const allowlist = validCidrs(config.allowlist);
|
|
74
|
+
const blocklist = validCidrs(config.blocklist);
|
|
75
|
+
const verdict = config.monitorOnly ? "counter" : "counter drop";
|
|
76
|
+
const cdnRanges = config.originProtection?.enabled ? validCidrs(config.originProtection.cdnRanges) : [];
|
|
77
|
+
const ipv4Allow = allowlist.filter((cidr) => !cidr.includes(":"));
|
|
78
|
+
const ipv6Allow = allowlist.filter((cidr) => cidr.includes(":"));
|
|
79
|
+
const ipv4Block = blocklist.filter((cidr) => !cidr.includes(":"));
|
|
80
|
+
const lines = [
|
|
81
|
+
"#!/usr/sbin/nft -f",
|
|
82
|
+
"# Managed by ts-cloud. Edits are overwritten on the next deploy.",
|
|
83
|
+
"",
|
|
84
|
+
"table inet ts_cloud_ddos",
|
|
85
|
+
"delete table inet ts_cloud_ddos",
|
|
86
|
+
"",
|
|
87
|
+
"table inet ts_cloud_ddos {",
|
|
88
|
+
" # Sources that tripped a limit, with a timeout so a ban self-expires.",
|
|
89
|
+
` set banned4 { type ipv4_addr; flags timeout; timeout ${thresholds.banSeconds}s; }`,
|
|
90
|
+
` set banned6 { type ipv6_addr; flags timeout; timeout ${thresholds.banSeconds}s; }`
|
|
91
|
+
];
|
|
92
|
+
if (ipv4Allow.length > 0)
|
|
93
|
+
lines.push(` set allow4 { type ipv4_addr; flags interval; elements = { ${ipv4Allow.join(", ")} } }`);
|
|
94
|
+
if (ipv6Allow.length > 0)
|
|
95
|
+
lines.push(` set allow6 { type ipv6_addr; flags interval; elements = { ${ipv6Allow.join(", ")} } }`);
|
|
96
|
+
if (ipv4Block.length > 0)
|
|
97
|
+
lines.push(` set block4 { type ipv4_addr; flags interval; elements = { ${ipv4Block.join(", ")} } }`);
|
|
98
|
+
if (cdnRanges.length > 0)
|
|
99
|
+
lines.push(` set cdn4 { type ipv4_addr; flags interval; elements = { ${cdnRanges.filter((cidr) => !cidr.includes(":")).join(", ")} } }`);
|
|
100
|
+
lines.push("", " chain input {", " type filter hook input priority -150; policy accept;", "", " # Established traffic is already paid for; never re-inspect it.", " ct state established,related accept", " iif lo accept", "", " # Invalid packets are never legitimate and are cheap to drop early.", " ct state invalid counter drop");
|
|
101
|
+
if (ipv4Allow.length > 0)
|
|
102
|
+
lines.push(" ip saddr @allow4 accept");
|
|
103
|
+
if (ipv6Allow.length > 0)
|
|
104
|
+
lines.push(" ip6 saddr @allow6 accept");
|
|
105
|
+
if (ipv4Block.length > 0)
|
|
106
|
+
lines.push(" ip saddr @block4 counter drop");
|
|
107
|
+
lines.push(" ip saddr @banned4 counter drop", " ip6 saddr @banned6 counter drop", "");
|
|
108
|
+
lines.push(" # Nonsense TCP flag combinations: scanners and stack fingerprinting.", " tcp flags & (fin|syn) == (fin|syn) counter drop", " tcp flags & (syn|rst) == (syn|rst) counter drop", " tcp flags & (fin|rst) == (fin|rst) counter drop", " tcp flags & (fin|ack) == fin counter drop", " tcp flags & (syn|fin|ack|rst|psh|urg) == 0x0 counter drop", "", ` # Ping stays usable, ping floods do not.`, ` ip protocol icmp icmp type echo-request limit rate ${thresholds.icmpPerSecond}/second burst ${thresholds.burst} packets accept`, " ip protocol icmp icmp type echo-request counter drop", "");
|
|
109
|
+
if (ports.length > 0) {
|
|
110
|
+
const portSet = ports.join(", ");
|
|
111
|
+
lines.push(` # Platform-wide SYN ceiling. Above it the kernel falls back to cookies.`, ` tcp dport { ${portSet} } ct state new limit rate ${thresholds.synPerSecond}/second burst ${thresholds.burst} packets accept`, "", ` # Per-source new-connection rate. This is what stops one host hammering.`, ` tcp dport { ${portSet} } ct state new meter conn_rate4 { ip saddr limit rate over ${thresholds.newConnectionsPerSecond}/second burst ${thresholds.burst} packets } add @banned4 { ip saddr } ${verdict}`, ` tcp dport { ${portSet} } ct state new meter conn_rate6 { ip6 saddr limit rate over ${thresholds.newConnectionsPerSecond}/second burst ${thresholds.burst} packets } add @banned6 { ip6 saddr } ${verdict}`, "", ` # Concurrency ceiling per source: the slow-loris defence.`, ` tcp dport { ${portSet} } ct state new meter conn_count4 { ip saddr ct count over ${thresholds.concurrentPerSource} } ${verdict}`, ` tcp dport { ${portSet} } ct state new meter conn_count6 { ip6 saddr ct count over ${thresholds.concurrentPerSource} } ${verdict}`, "");
|
|
112
|
+
if (cdnRanges.length > 0)
|
|
113
|
+
lines.push(" # Origin protection: reject traffic that skipped the CDN and came", " # straight to the box, which is how an attacker bypasses the edge.", ` tcp dport { ${portSet} } ip saddr != @cdn4 counter drop`, "");
|
|
114
|
+
}
|
|
115
|
+
lines.push(" }", "}", "");
|
|
116
|
+
return lines.join(`
|
|
117
|
+
`);
|
|
118
|
+
}
|
|
119
|
+
function renderDdosInstallScript(config = {}) {
|
|
120
|
+
return `#!/usr/bin/env bash
|
|
121
|
+
# Managed by ts-cloud. Installs L3/L4 flood mitigation.
|
|
122
|
+
set -euo pipefail
|
|
123
|
+
|
|
124
|
+
if ! command -v nft >/dev/null 2>&1; then
|
|
125
|
+
export DEBIAN_FRONTEND=noninteractive
|
|
126
|
+
apt-get update -qq
|
|
127
|
+
apt-get install -y -qq nftables
|
|
128
|
+
fi
|
|
129
|
+
|
|
130
|
+
install -d -m 0755 /etc/ts-cloud /etc/nftables.d
|
|
131
|
+
cat > /etc/sysctl.d/90-ts-cloud-ddos.conf <<'SYSCTL_EOF'
|
|
132
|
+
${renderSysctlFile(config)}SYSCTL_EOF
|
|
133
|
+
sysctl --system >/dev/null
|
|
134
|
+
|
|
135
|
+
cat > /etc/nftables.d/ts-cloud-ddos.nft.new <<'NFT_EOF'
|
|
136
|
+
${renderNftablesRuleset(config)}NFT_EOF
|
|
137
|
+
|
|
138
|
+
# Syntax-check before applying: a bad ruleset would leave the box unprotected.
|
|
139
|
+
if ! nft -c -f /etc/nftables.d/ts-cloud-ddos.nft.new; then
|
|
140
|
+
echo "ts-cloud: generated nftables ruleset failed validation, keeping the previous one" >&2
|
|
141
|
+
rm -f /etc/nftables.d/ts-cloud-ddos.nft.new
|
|
142
|
+
exit 1
|
|
143
|
+
fi
|
|
144
|
+
|
|
145
|
+
mv /etc/nftables.d/ts-cloud-ddos.nft.new /etc/nftables.d/ts-cloud-ddos.nft
|
|
146
|
+
nft -f /etc/nftables.d/ts-cloud-ddos.nft
|
|
147
|
+
|
|
148
|
+
# Applying the ruleset does not survive a reboot on its own: nftables.service
|
|
149
|
+
# loads /etc/nftables.conf, so the file has to be included from there or the box
|
|
150
|
+
# comes back up unprotected and nothing says so.
|
|
151
|
+
touch /etc/nftables.conf
|
|
152
|
+
if ! grep -q 'ts-cloud-ddos.nft' /etc/nftables.conf; then
|
|
153
|
+
printf '
|
|
154
|
+
include "/etc/nftables.d/ts-cloud-ddos.nft"
|
|
155
|
+
' >> /etc/nftables.conf
|
|
156
|
+
fi
|
|
157
|
+
systemctl enable nftables >/dev/null 2>&1 || true
|
|
158
|
+
echo "ts-cloud: L3/L4 mitigation active"
|
|
159
|
+
`;
|
|
160
|
+
}
|
|
161
|
+
var LEVEL_ORDER = ["off", "monitor", "rate_limit", "challenge", "lockdown"];
|
|
162
|
+
function planMitigation(signals, topSources = []) {
|
|
163
|
+
const reasons = [];
|
|
164
|
+
const baseline = Math.max(1, signals.baselineRequestsPerSecond);
|
|
165
|
+
const ratio = signals.requestsPerSecond / baseline;
|
|
166
|
+
let levelIndex = 0;
|
|
167
|
+
const escalate = (next, reason) => {
|
|
168
|
+
reasons.push(reason);
|
|
169
|
+
levelIndex = Math.max(levelIndex, LEVEL_ORDER.indexOf(next));
|
|
170
|
+
};
|
|
171
|
+
const surging = ratio >= 3;
|
|
172
|
+
if (surging)
|
|
173
|
+
escalate("monitor", `Traffic is ${ratio.toFixed(1)}x the baseline.`);
|
|
174
|
+
const concentrated = signals.topSourceShare >= 0.25;
|
|
175
|
+
const failing = signals.errorRate >= 0.25;
|
|
176
|
+
const scripted = (signals.suspiciousAgentShare ?? 0) >= 0.5;
|
|
177
|
+
const thinlySpread = signals.uniqueSources > 0 && signals.requestsPerSecond / signals.uniqueSources >= 50;
|
|
178
|
+
if (surging && concentrated)
|
|
179
|
+
escalate("rate_limit", `One source accounts for ${(signals.topSourceShare * 100).toFixed(0)}% of traffic.`);
|
|
180
|
+
if (surging && thinlySpread)
|
|
181
|
+
escalate("rate_limit", "Request rate per unique source is far above what a browser produces.");
|
|
182
|
+
if (surging && failing)
|
|
183
|
+
escalate("challenge", `Error rate is ${(signals.errorRate * 100).toFixed(0)}% under load.`);
|
|
184
|
+
if (surging && scripted)
|
|
185
|
+
escalate("challenge", "Most requests carry no recognisable browser agent.");
|
|
186
|
+
if (ratio >= 20 && (concentrated || failing || scripted || thinlySpread))
|
|
187
|
+
escalate("lockdown", `Traffic is ${ratio.toFixed(0)}x the baseline with attack-shaped characteristics.`);
|
|
188
|
+
if (!surging && signals.topSourceShare >= 0.6 && signals.requestsPerSecond > baseline)
|
|
189
|
+
escalate("rate_limit", "A single source dominates traffic without an overall surge.");
|
|
190
|
+
const level = LEVEL_ORDER[levelIndex];
|
|
191
|
+
const factor = { off: 1, monitor: 1, rate_limit: 0.5, challenge: 0.25, lockdown: 0.1 }[level];
|
|
192
|
+
return {
|
|
193
|
+
level,
|
|
194
|
+
reasons,
|
|
195
|
+
rateLimitFactor: factor,
|
|
196
|
+
challengeEnabled: level === "challenge" || level === "lockdown",
|
|
197
|
+
staticOnly: level === "lockdown",
|
|
198
|
+
banCandidates: level === "off" || level === "monitor" ? [] : validCidrs(topSources)
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
function applyMitigationFactor(limit, plan) {
|
|
202
|
+
return Math.max(1, Math.floor(limit * plan.rateLimitFactor));
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export { DEFAULT_DDOS_THRESHOLDS, isValidCidr, sysctlHardening, renderSysctlFile, renderNftablesRuleset, renderDdosInstallScript, planMitigation, applyMitigationFactor };
|