@hardkeel/benthic 0.0.0-stage → 1.0.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 +121 -0
- package/LICENSE +92 -0
- package/NOTICE +16 -0
- package/README.md +424 -2
- package/action.yml +54 -0
- package/dist/agility.js +80 -0
- package/dist/badge.js +62 -0
- package/dist/baseline.js +81 -0
- package/dist/cbom-diff.js +273 -0
- package/dist/cbom.js +418 -0
- package/dist/cli.js +834 -0
- package/dist/cloud-aws-services.js +375 -0
- package/dist/cloud-aws.js +354 -0
- package/dist/cloud-azure-services.js +73 -0
- package/dist/cloud-azure.js +144 -0
- package/dist/cloud-common.js +242 -0
- package/dist/cloud-gcp-services.js +90 -0
- package/dist/cloud-gcp.js +150 -0
- package/dist/comments.js +138 -0
- package/dist/community-rules.js +37 -0
- package/dist/community.js +30 -0
- package/dist/deps.js +406 -0
- package/dist/der.js +571 -0
- package/dist/evidence-cli.js +235 -0
- package/dist/evidence-live.js +109 -0
- package/dist/evidence.js +512 -0
- package/dist/ignore.js +90 -0
- package/dist/image.js +1224 -0
- package/dist/infra.js +635 -0
- package/dist/inventory.js +277 -0
- package/dist/map-activity.js +24 -0
- package/dist/map-areas.js +60 -0
- package/dist/map-cloud-keys.js +110 -0
- package/dist/map-cloud.js +34 -0
- package/dist/map-ct.js +107 -0
- package/dist/map-host.js +335 -0
- package/dist/map-network.js +520 -0
- package/dist/map-people.js +79 -0
- package/dist/map-rank.js +70 -0
- package/dist/map-report.js +304 -0
- package/dist/map-run.js +327 -0
- package/dist/map-sarif.js +61 -0
- package/dist/map-signin.js +247 -0
- package/dist/map-types.js +19 -0
- package/dist/map-web.js +666 -0
- package/dist/native.js +168 -0
- package/dist/policy.js +221 -0
- package/dist/pqc.js +46 -0
- package/dist/profile.js +65 -0
- package/dist/project.js +928 -0
- package/dist/prose.js +159 -0
- package/dist/protocols.js +207 -0
- package/dist/registry.js +326 -0
- package/dist/report.js +190 -0
- package/dist/rules.js +230 -0
- package/dist/sarif-common.js +30 -0
- package/dist/sarif.js +114 -0
- package/dist/scan.js +601 -0
- package/dist/score.js +124 -0
- package/dist/secrets.js +192 -0
- package/dist/share-config.js +129 -0
- package/dist/share-lists.js +19 -0
- package/dist/share.js +125 -0
- package/dist/sonar.js +83 -0
- package/dist/structure.js +218 -0
- package/dist/suites.js +402 -0
- package/dist/tls-check.js +122 -0
- package/dist/types.js +4 -0
- package/dist/walk.js +78 -0
- package/dist/yaml.js +173 -0
- package/package.json +73 -4
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
// SPDX-License-Identifier: PolyForm-Shield-1.0.0
|
|
2
|
+
// Copyright 2026 Hard Keel (https://hardkeel.com)
|
|
3
|
+
// AWS beyond keys and load balancers: API Gateway, OpenSearch, ElastiCache, RDS, Redshift, EFS, MSK,
|
|
4
|
+
// EC2 key pairs and default disk encryption, Private CA, uploaded IAM certificates, Transfer Family
|
|
5
|
+
// (SFTP and FTP) servers and S3 bucket TLS rules. Every call lists, describes or gets settings.
|
|
6
|
+
import { X509Certificate } from "node:crypto";
|
|
7
|
+
import { ALGORITHMS } from "./rules.js";
|
|
8
|
+
import { pool, SAFE_ARG, SIG_FIX, KEX_FIX } from "./cloud-common.js";
|
|
9
|
+
/** The API Gateway policy for REST API custom domains with hybrid ML-KEM key exchange (November 2025). */
|
|
10
|
+
export const APIGW_PQ_POLICY = "SecurityPolicy_TLS13_1_2_PQ_2025_09";
|
|
11
|
+
export const OPENSEARCH_POLICY = "Policy-Min-TLS-1-2-PFS-2023-10";
|
|
12
|
+
export const TRANSFER_PQ_POLICY = "TransferSecurityPolicy-2025-03";
|
|
13
|
+
const list = (v) => (Array.isArray(v) ? v : []);
|
|
14
|
+
const TLS = ALGORITHMS["TLS 1.0/1.1"];
|
|
15
|
+
const TRANSIT_FIX = "Require TLS for every connection.";
|
|
16
|
+
const AT_REST_FIX = "Turn on encryption at rest, ideally with a customer-managed KMS key. For most services this means making an encrypted copy and switching over.";
|
|
17
|
+
export const oldTls = (target, title, fix, internetFacing, severity = TLS.severity) => ({
|
|
18
|
+
target, ruleId: "cloud-tls-old", title, algorithm: "TLS 1.0/1.1", primitive: TLS.primitive, risk: TLS.risk, severity, fix, internetFacing,
|
|
19
|
+
});
|
|
20
|
+
export const plainTraffic = (target, title, fix, internetFacing, severity = "medium") => ({
|
|
21
|
+
target, ruleId: "cloud-unencrypted-traffic", title, algorithm: "Unencrypted traffic allowed", primitive: "setting", risk: "exposed", severity, fix, internetFacing,
|
|
22
|
+
});
|
|
23
|
+
export const atRestOff = (target, title, fix = AT_REST_FIX, severity = "medium") => ({
|
|
24
|
+
target, ruleId: "cloud-at-rest-off", title, algorithm: "Encryption at rest off", primitive: "setting", risk: "exposed", severity, fix, internetFacing: false,
|
|
25
|
+
});
|
|
26
|
+
const noPqKex = (target, title, fix, internetFacing) => ({
|
|
27
|
+
target, ruleId: "cloud-tls-kex", title, algorithm: "TLS key exchange", primitive: "key-agreement", risk: "quantum-vulnerable", severity: "high", fix, internetFacing,
|
|
28
|
+
});
|
|
29
|
+
const pqStrength = (target, title) => ({ target, algorithm: "Hybrid ML-KEM key exchange", title });
|
|
30
|
+
// ---------- API Gateway ----------
|
|
31
|
+
/** What an API Gateway security policy allows. TLS_1_0 and TLS_1_2 are the legacy names. */
|
|
32
|
+
export function apigwPolicy(name) {
|
|
33
|
+
const n = String(name ?? "");
|
|
34
|
+
if (n === "TLS_1_0")
|
|
35
|
+
return { min: "1.0", pq: false };
|
|
36
|
+
if (n === "TLS_1_2")
|
|
37
|
+
return { min: "1.2", pq: false };
|
|
38
|
+
const m = n.match(/^SecurityPolicy_TLS1[23]_1_([0-3])/);
|
|
39
|
+
return { min: m ? `1.${m[1]}` : undefined, pq: /_PQ_/.test(n) };
|
|
40
|
+
}
|
|
41
|
+
export function apigwFindings(policy, target, internetFacing, what) {
|
|
42
|
+
const p = apigwPolicy(policy);
|
|
43
|
+
const findings = [];
|
|
44
|
+
if (p.min === "1.0" || p.min === "1.1")
|
|
45
|
+
findings.push(oldTls(target, `${what} accepts TLS ${p.min} (security policy ${policy})`, `Switch to ${APIGW_PQ_POLICY}, which allows TLS 1.2 and 1.3 and adds hybrid ML-KEM key exchange.`, internetFacing));
|
|
46
|
+
if (p.pq)
|
|
47
|
+
return { findings, strength: pqStrength(target, `${what} offers hybrid ML-KEM key exchange`) };
|
|
48
|
+
if (internetFacing)
|
|
49
|
+
findings.push(noPqKex(target, `${what} has no quantum-safe key exchange`, `Switch to ${APIGW_PQ_POLICY} for hybrid ML-KEM key exchange. It still serves TLS 1.2 clients.`, true));
|
|
50
|
+
return { findings };
|
|
51
|
+
}
|
|
52
|
+
// ---------- OpenSearch ----------
|
|
53
|
+
export function openSearch(d, target) {
|
|
54
|
+
const out = [];
|
|
55
|
+
const ep = d?.DomainEndpointOptions ?? {};
|
|
56
|
+
const internetFacing = !d?.VPCOptions?.VPCId;
|
|
57
|
+
if (String(ep.TLSSecurityPolicy ?? "") === "Policy-Min-TLS-1-0-2019-07")
|
|
58
|
+
out.push(oldTls(target, "Search domain accepts TLS 1.0 and 1.1", `Set the domain's TLS security policy to ${OPENSEARCH_POLICY}.`, internetFacing));
|
|
59
|
+
if (ep.EnforceHTTPS === false)
|
|
60
|
+
out.push(plainTraffic(target, "Search domain accepts plain HTTP", "Turn on Require HTTPS for all traffic to the domain.", internetFacing));
|
|
61
|
+
if (d?.NodeToNodeEncryptionOptions?.Enabled === false)
|
|
62
|
+
out.push(plainTraffic(target, "Search domain's nodes talk to each other without encryption", "Turn on node-to-node encryption.", false, "low"));
|
|
63
|
+
if (d?.EncryptionAtRestOptions?.Enabled === false)
|
|
64
|
+
out.push(atRestOff(target, "Search domain's data is not encrypted at rest"));
|
|
65
|
+
return out;
|
|
66
|
+
}
|
|
67
|
+
// ---------- ElastiCache ----------
|
|
68
|
+
export function cache(c, target, replicationGroup) {
|
|
69
|
+
const out = [];
|
|
70
|
+
const engine = String(c?.Engine ?? "").toLowerCase();
|
|
71
|
+
if (c?.TransitEncryptionEnabled === false || c?.TransitEncryptionEnabled === undefined && !replicationGroup) {
|
|
72
|
+
out.push(plainTraffic(target, "Cache accepts connections without encryption", "Turn on encryption in transit. Recent Valkey, Redis OSS and Memcached versions can switch over without a new cluster.", false));
|
|
73
|
+
}
|
|
74
|
+
else if (String(c?.TransitEncryptionMode ?? "") === "preferred") {
|
|
75
|
+
out.push(plainTraffic(target, "Cache still accepts unencrypted connections alongside encrypted ones", "Change the transit encryption mode from preferred to required once every client uses TLS.", false, "low"));
|
|
76
|
+
}
|
|
77
|
+
if (c?.AtRestEncryptionEnabled === false && engine !== "memcached")
|
|
78
|
+
out.push(atRestOff(target, "Cache data is not encrypted at rest"));
|
|
79
|
+
return out;
|
|
80
|
+
}
|
|
81
|
+
// ---------- RDS ----------
|
|
82
|
+
const RDS_CA = {
|
|
83
|
+
"rds-ca-rsa2048-g1": { algorithm: "RSA-2048", family: "RSA", primitive: "signature", functions: ["sign", "verify"], keySize: 2048, note: "RDS server certificate authority" },
|
|
84
|
+
"rds-ca-rsa4096-g1": { algorithm: "RSA-4096", family: "RSA", primitive: "signature", functions: ["sign", "verify"], keySize: 4096, note: "RDS server certificate authority" },
|
|
85
|
+
"rds-ca-ecc384-g1": { algorithm: "ECDSA-P384", family: "ECDSA", primitive: "signature", functions: ["sign", "verify"], keySize: 384, note: "RDS server certificate authority" },
|
|
86
|
+
};
|
|
87
|
+
export function rdsInstance(d, target, now) {
|
|
88
|
+
const out = [];
|
|
89
|
+
const ca = String(d?.CACertificateIdentifier ?? d?.CertificateDetails?.CAIdentifier ?? "");
|
|
90
|
+
const till = Date.parse(String(d?.CertificateDetails?.ValidTill ?? ""));
|
|
91
|
+
const caFix = "Switch the database to the rds-ca-rsa2048-g1 or rds-ca-ecc384-g1 certificate authority, and update the CA bundle your apps trust.";
|
|
92
|
+
if (ca === "rds-ca-2019" || (!Number.isNaN(till) && till < now.getTime())) {
|
|
93
|
+
out.push({ target, ruleId: "cloud-cert-expired", title: ca === "rds-ca-2019" ? "Database uses the rds-ca-2019 certificate authority, which expired in August 2024" : "Database's server certificate has expired", algorithm: "Expired certificate", primitive: "protocol", risk: "weak-now", severity: "high", fix: caFix, internetFacing: d?.PubliclyAccessible === true });
|
|
94
|
+
}
|
|
95
|
+
else if (!Number.isNaN(till) && till - now.getTime() < 60 * 86_400_000) {
|
|
96
|
+
out.push({ target, ruleId: "cloud-cert-expiring", title: `Database's server certificate expires on ${new Date(till).toISOString().slice(0, 10)}`, algorithm: "Expiring certificate", primitive: "protocol", risk: "weak-now", severity: "medium", fix: "Rotate the certificate before then (Modify, then the certificate authority), and check the CA bundle your apps trust.", internetFacing: d?.PubliclyAccessible === true });
|
|
97
|
+
}
|
|
98
|
+
if (d?.StorageEncrypted === false && !d?.DBClusterIdentifier)
|
|
99
|
+
out.push(atRestOff(target, "Database storage is not encrypted", "Take a snapshot, copy it with encryption turned on, and restore from the encrypted copy."));
|
|
100
|
+
return { findings: out, inventory: RDS_CA[ca] };
|
|
101
|
+
}
|
|
102
|
+
// ---------- Private CA ----------
|
|
103
|
+
export function privateCa(c, target) {
|
|
104
|
+
if (c?.Status !== "ACTIVE")
|
|
105
|
+
return {};
|
|
106
|
+
const conf = c?.CertificateAuthorityConfiguration ?? {};
|
|
107
|
+
const key = String(conf.KeyAlgorithm ?? "");
|
|
108
|
+
const root = c?.Type === "ROOT";
|
|
109
|
+
const what = root ? "Root certificate authority" : "Certificate authority";
|
|
110
|
+
const ml = key.match(/^ML_DSA_(44|65|87)$/);
|
|
111
|
+
if (ml)
|
|
112
|
+
return { strength: { target, algorithm: "ML-DSA", title: `${what} signs with ML-DSA-${ml[1]}` }, inventory: { algorithm: `ML-DSA-${ml[1]}`, family: "ML-DSA", primitive: "signature", functions: ["sign", "verify"], nistQuantumLevel: { "44": 2, "65": 3, "87": 5 }[ml[1]], note: "AWS Private CA" } };
|
|
113
|
+
const rsa = key.match(/^RSA_(\d{4})$/);
|
|
114
|
+
const ec = key.match(/^EC_(\w+)$/);
|
|
115
|
+
if (!rsa && !ec)
|
|
116
|
+
return {};
|
|
117
|
+
const label = rsa ? `RSA-${rsa[1]}` : `ECDSA ${ec[1]}`;
|
|
118
|
+
const bits = rsa ? Number(rsa[1]) : { prime256v1: 256, secp384r1: 384, secp521r1: 521 }[ec[1]];
|
|
119
|
+
return {
|
|
120
|
+
finding: { target, ruleId: "cloud-ca-quantum", title: `${what} signs with ${label}`, algorithm: rsa ? "RSA signature" : "ECDSA", primitive: "signature", risk: "quantum-vulnerable", severity: root ? "high" : "medium", fix: "Plan an ML-DSA certificate authority. AWS Private CA offers ML-DSA-44, 65 and 87: start a new ML-DSA hierarchy for internal services that can use it, and keep this one for the rest until they can.", internetFacing: false, longLived: true, keySize: bits },
|
|
121
|
+
inventory: { algorithm: rsa ? `RSA-${rsa[1]}` : `ECDSA-${ec[1]}`, family: rsa ? "RSA" : "ECDSA", primitive: "signature", functions: ["sign", "verify"], keySize: bits, note: "AWS Private CA" },
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
// ---------- uploaded certificates ----------
|
|
125
|
+
/** Key type and size from a certificate in PEM form, read with Node's own X.509 parser. */
|
|
126
|
+
export function pemKey(pem) {
|
|
127
|
+
try {
|
|
128
|
+
const x = new X509Certificate(pem);
|
|
129
|
+
const k = x.publicKey;
|
|
130
|
+
const d = (k.asymmetricKeyDetails ?? {});
|
|
131
|
+
const curveBits = { prime256v1: 256, secp384r1: 384, secp521r1: 521 };
|
|
132
|
+
return { type: k.asymmetricKeyType, bits: d.modulusLength ?? (d.namedCurve ? curveBits[d.namedCurve] : undefined), curve: d.namedCurve, notAfter: Date.parse(x.validTo) };
|
|
133
|
+
}
|
|
134
|
+
catch {
|
|
135
|
+
return {};
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
const CURVE_NAME = { prime256v1: "P-256", secp384r1: "P-384", secp521r1: "P-521" };
|
|
139
|
+
export function certFromPem(pem, target, now, internetFacing, what = "Certificate") {
|
|
140
|
+
const k = pemKey(pem);
|
|
141
|
+
if (k.notAfter !== undefined && !Number.isNaN(k.notAfter) && k.notAfter < now.getTime())
|
|
142
|
+
return { target, ruleId: "cloud-cert-expired", title: `${what} has expired`, algorithm: "Expired certificate", primitive: "protocol", risk: "weak-now", severity: "medium", fix: "Delete it if nothing uses it, or replace it.", internetFacing };
|
|
143
|
+
if (k.type === "rsa" && k.bits && k.bits < 2048)
|
|
144
|
+
return { target, ruleId: "cloud-cert-small-rsa", title: `${what} uses a ${k.bits}-bit RSA key`, algorithm: "RSA", primitive: "signature", risk: "weak-now", severity: "high", keySize: k.bits, fix: "Reissue with at least a 2048-bit RSA key, or ECDSA P-256.", internetFacing };
|
|
145
|
+
if (k.type === "rsa" || k.type === "ec" || k.type === "ed25519")
|
|
146
|
+
return { target, ruleId: "cloud-cert-quantum", title: `${what} uses ${k.type === "rsa" ? `${k.bits}-bit RSA` : k.type === "ec" ? `ECDSA ${CURVE_NAME[k.curve ?? ""] ?? k.curve ?? ""}`.trim() : "Ed25519"}`, algorithm: k.type === "rsa" ? "RSA signature" : k.type === "ec" ? "ECDSA" : "Ed25519", primitive: "signature", risk: "quantum-vulnerable", severity: "medium", keySize: k.bits, fix: "Plan to move to ML-DSA certificates once your certificate authority offers them. Short-lived certificates make the switch easy.", internetFacing };
|
|
147
|
+
return null;
|
|
148
|
+
}
|
|
149
|
+
// ---------- Transfer Family ----------
|
|
150
|
+
const SSH_WEAK = /sha1$|-sha1-|^diffie-hellman-group1-|md5|-cbc$|3des|arcfour/i;
|
|
151
|
+
export function transferServer(server, policy, target) {
|
|
152
|
+
const out = [];
|
|
153
|
+
const protocols = list(server?.Protocols).map(String);
|
|
154
|
+
const internetFacing = server?.EndpointType !== "VPC_ENDPOINT";
|
|
155
|
+
const name = String(server?.SecurityPolicyName ?? "");
|
|
156
|
+
if (protocols.includes("FTP"))
|
|
157
|
+
out.push(plainTraffic(target, "File transfer server accepts plain FTP, with no encryption", "Turn off FTP and use SFTP or FTPS.", internetFacing, "high"));
|
|
158
|
+
if (!protocols.length || protocols.includes("SFTP")) {
|
|
159
|
+
const kex = list(policy?.SshKexs).map(String);
|
|
160
|
+
const weak = [...kex, ...list(policy?.SshMacs).map(String), ...list(policy?.SshCiphers).map(String)].filter((a) => SSH_WEAK.test(a));
|
|
161
|
+
if (weak.length)
|
|
162
|
+
out.push({ target, ruleId: "cloud-ssh-weak", title: `SFTP policy ${name} allows ${weak.slice(0, 2).join(" and ")}${weak.length > 2 ? ` and ${weak.length - 2} more` : ""}`, algorithm: "SSH weak settings", primitive: "protocol", risk: "weak-now", severity: "medium", fix: `Switch the server to ${TRANSFER_PQ_POLICY}, which drops SHA-1 and adds hybrid ML-KEM key exchange.`, internetFacing });
|
|
163
|
+
if (kex.some((k) => /^mlkem/i.test(k)))
|
|
164
|
+
return { findings: out, strength: { target, algorithm: "Hybrid ML-KEM key exchange", title: `SFTP policy ${name} offers hybrid ML-KEM key exchange` } };
|
|
165
|
+
if (kex.length || name)
|
|
166
|
+
out.push({ target, ruleId: "cloud-ssh-kex", title: `SFTP policy ${name || "in use"} has no quantum-safe key exchange`, algorithm: "SSH key exchange", primitive: "key-agreement", risk: "quantum-vulnerable", severity: "high", fix: `Switch the server to ${TRANSFER_PQ_POLICY} for hybrid ML-KEM key exchange. OpenSSH 9.9 and later, PuTTY and JSch support it, and older clients still connect.`, internetFacing });
|
|
167
|
+
}
|
|
168
|
+
return { findings: out };
|
|
169
|
+
}
|
|
170
|
+
// ---------- S3 ----------
|
|
171
|
+
/** Does a bucket policy refuse requests that don't use TLS? */
|
|
172
|
+
export function requiresTls(policyJson) {
|
|
173
|
+
let p = policyJson;
|
|
174
|
+
if (typeof p === "string") {
|
|
175
|
+
try {
|
|
176
|
+
p = JSON.parse(p);
|
|
177
|
+
}
|
|
178
|
+
catch {
|
|
179
|
+
return false;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
return list(Array.isArray(p?.Statement) ? p.Statement : [p?.Statement]).some((s) => {
|
|
183
|
+
if (String(s?.Effect) !== "Deny")
|
|
184
|
+
return false;
|
|
185
|
+
const c = s?.Condition ?? {};
|
|
186
|
+
const secure = c.Bool?.["aws:SecureTransport"];
|
|
187
|
+
const tlsVersion = c.NumericLessThan?.["s3:TlsVersion"];
|
|
188
|
+
return String(secure).toLowerCase() === "false" || [secure].flat().map(String).includes("false") || tlsVersion !== undefined;
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
const BUCKET = /^[a-z0-9][a-z0-9.-]{1,61}[a-z0-9]$/;
|
|
192
|
+
const NAME = /^[A-Za-z0-9._-]{1,255}$/;
|
|
193
|
+
const SERVER_ID = /^s-[0-9a-f]{17}$/;
|
|
194
|
+
/** Region by region. Each part is skipped quietly when the service isn't offered there. */
|
|
195
|
+
export async function awsRegional(ctx, where, region) {
|
|
196
|
+
const { svc, push, inv, now } = ctx;
|
|
197
|
+
const r = ["--region", region];
|
|
198
|
+
const counted = [];
|
|
199
|
+
// API Gateway REST APIs: custom domains, and the default endpoint of each API where its policy is reported.
|
|
200
|
+
const domains = await svc("API Gateway", where, ["apigateway", "get-domain-names", ...r], "list API custom domains and their TLS policies");
|
|
201
|
+
let apis = 0;
|
|
202
|
+
for (const d of list(domains?.items)) {
|
|
203
|
+
apis++;
|
|
204
|
+
const types = list(d?.endpointConfiguration?.types);
|
|
205
|
+
const res = apigwFindings(String(d?.securityPolicy ?? "TLS_1_2"), `${where} API domain ${String(d?.domainName ?? "")}`, !types.includes("PRIVATE"), "API custom domain");
|
|
206
|
+
for (const f of res.findings)
|
|
207
|
+
push(f);
|
|
208
|
+
push(undefined, res.strength);
|
|
209
|
+
}
|
|
210
|
+
const rest = await svc("API Gateway", where, ["apigateway", "get-rest-apis", ...r], "list REST APIs and their TLS policies");
|
|
211
|
+
for (const a of list(rest?.items)) {
|
|
212
|
+
if (!a?.securityPolicy || a?.disableExecuteApiEndpoint === true)
|
|
213
|
+
continue;
|
|
214
|
+
apis++;
|
|
215
|
+
const types = list(a?.endpointConfiguration?.types);
|
|
216
|
+
const res = apigwFindings(String(a.securityPolicy), `${where} REST API ${String(a?.name ?? a?.id ?? "")}`, !types.includes("PRIVATE"), "REST API");
|
|
217
|
+
for (const f of res.findings)
|
|
218
|
+
push(f);
|
|
219
|
+
push(undefined, res.strength);
|
|
220
|
+
}
|
|
221
|
+
if (apis)
|
|
222
|
+
counted.push(`${apis} API endpoint${apis === 1 ? "" : "s"}`);
|
|
223
|
+
// OpenSearch domains, five per describe call.
|
|
224
|
+
const os = await svc("OpenSearch", where, ["opensearch", "list-domain-names", ...r], "list search domains");
|
|
225
|
+
const osNames = list(os?.DomainNames).map((d) => String(d?.DomainName ?? "")).filter((n) => /^[a-z][a-z0-9-]{2,27}$/.test(n));
|
|
226
|
+
for (let i = 0; i < osNames.length; i += 5) {
|
|
227
|
+
const d = await svc("OpenSearch", where, ["opensearch", "describe-domains", "--domain-names", ...osNames.slice(i, i + 5), ...r], "read the search domains' encryption settings");
|
|
228
|
+
for (const s of list(d?.DomainStatusList))
|
|
229
|
+
for (const f of openSearch(s, `${where} search domain ${String(s?.DomainName ?? "")}`))
|
|
230
|
+
push(f);
|
|
231
|
+
}
|
|
232
|
+
if (osNames.length)
|
|
233
|
+
counted.push(`${osNames.length} search domain${osNames.length === 1 ? "" : "s"}`);
|
|
234
|
+
// ElastiCache: replication groups, then clusters that aren't part of one.
|
|
235
|
+
const rgs = await svc("ElastiCache", where, ["elasticache", "describe-replication-groups", ...r], "read cache encryption settings");
|
|
236
|
+
let caches = 0;
|
|
237
|
+
for (const g of list(rgs?.ReplicationGroups)) {
|
|
238
|
+
caches++;
|
|
239
|
+
for (const f of cache(g, `${where} cache ${String(g?.ReplicationGroupId ?? "")}`, true))
|
|
240
|
+
push(f);
|
|
241
|
+
}
|
|
242
|
+
const ccs = await svc("ElastiCache", where, ["elasticache", "describe-cache-clusters", ...r], "read cache encryption settings");
|
|
243
|
+
for (const c of list(ccs?.CacheClusters)) {
|
|
244
|
+
if (c?.ReplicationGroupId)
|
|
245
|
+
continue;
|
|
246
|
+
caches++;
|
|
247
|
+
for (const f of cache(c, `${where} cache ${String(c?.CacheClusterId ?? "")}`, false))
|
|
248
|
+
push(f);
|
|
249
|
+
}
|
|
250
|
+
if (caches)
|
|
251
|
+
counted.push(`${caches} cache${caches === 1 ? "" : "s"}`);
|
|
252
|
+
// RDS, Aurora, DocumentDB and Neptune.
|
|
253
|
+
const dbs = await svc("RDS", where, ["rds", "describe-db-instances", ...r], "read database certificates and encryption");
|
|
254
|
+
let dbCount = 0;
|
|
255
|
+
for (const d of list(dbs?.DBInstances)) {
|
|
256
|
+
dbCount++;
|
|
257
|
+
const target = `${where} database ${String(d?.DBInstanceIdentifier ?? "")}`;
|
|
258
|
+
const res = rdsInstance(d, target, now);
|
|
259
|
+
for (const f of res.findings)
|
|
260
|
+
push(f);
|
|
261
|
+
if (res.inventory)
|
|
262
|
+
inv(res.inventory, target);
|
|
263
|
+
}
|
|
264
|
+
const clusters = await svc("RDS", where, ["rds", "describe-db-clusters", ...r], "read database cluster encryption");
|
|
265
|
+
for (const c of list(clusters?.DBClusters))
|
|
266
|
+
if (c?.StorageEncrypted === false)
|
|
267
|
+
push(atRestOff(`${where} database cluster ${String(c?.DBClusterIdentifier ?? "")}`, "Database cluster storage is not encrypted", "Take a snapshot, copy it with encryption turned on, and restore from the encrypted copy."));
|
|
268
|
+
const rs = await svc("Redshift", where, ["redshift", "describe-clusters", ...r], "read data warehouse encryption");
|
|
269
|
+
for (const c of list(rs?.Clusters)) {
|
|
270
|
+
dbCount++;
|
|
271
|
+
if (c?.Encrypted === false)
|
|
272
|
+
push(atRestOff(`${where} data warehouse ${String(c?.ClusterIdentifier ?? "")}`, "Data warehouse is not encrypted", "Turn on encryption for the cluster. Redshift can encrypt an existing cluster in place."));
|
|
273
|
+
}
|
|
274
|
+
if (dbCount)
|
|
275
|
+
counted.push(`${dbCount} database${dbCount === 1 ? "" : "s"}`);
|
|
276
|
+
// EFS file systems.
|
|
277
|
+
const efs = await svc("EFS", where, ["efs", "describe-file-systems", ...r], "read file system encryption");
|
|
278
|
+
for (const fs of list(efs?.FileSystems))
|
|
279
|
+
if (fs?.Encrypted === false)
|
|
280
|
+
push(atRestOff(`${where} file system ${String(fs?.Name || fs?.FileSystemId || "")}`, "File system is not encrypted", "Create an encrypted file system and copy the data across with DataSync."));
|
|
281
|
+
// MSK (Kafka) clusters.
|
|
282
|
+
const msk = await svc("MSK", where, ["kafka", "list-clusters-v2", ...r], "read Kafka cluster encryption");
|
|
283
|
+
for (const c of list(msk?.ClusterInfoList)) {
|
|
284
|
+
const t = c?.Provisioned?.EncryptionInfo?.EncryptionInTransit;
|
|
285
|
+
if (!t)
|
|
286
|
+
continue;
|
|
287
|
+
const target = `${where} Kafka cluster ${String(c?.ClusterName ?? "")}`;
|
|
288
|
+
if (t.ClientBroker === "PLAINTEXT" || t.ClientBroker === "TLS_PLAINTEXT")
|
|
289
|
+
push(plainTraffic(target, t.ClientBroker === "PLAINTEXT" ? "Kafka cluster accepts only unencrypted client connections" : "Kafka cluster accepts unencrypted client connections alongside TLS", "Set client-broker encryption to TLS only once every client uses it.", false));
|
|
290
|
+
if (t.InCluster === false)
|
|
291
|
+
push(plainTraffic(target, "Kafka brokers talk to each other without encryption", "Turn on encryption within the cluster (needs a new cluster).", false, "low"));
|
|
292
|
+
}
|
|
293
|
+
// EC2: default disk encryption, and the SSH key pairs people log in with.
|
|
294
|
+
const ebs = await svc("EC2", where, ["ec2", "get-ebs-encryption-by-default", ...r], "read whether new disks are encrypted by default");
|
|
295
|
+
if (ebs && ebs.EbsEncryptionByDefault === false)
|
|
296
|
+
push(atRestOff(`${where} EC2`, "New disks in this region aren't encrypted by default", "Turn on EBS encryption by default for the region (EC2 settings, Data protection and security). It applies to new disks and costs nothing extra.", "low"));
|
|
297
|
+
const kp = await svc("EC2", where, ["ec2", "describe-key-pairs", ...r], "list SSH key pair types");
|
|
298
|
+
const pairs = list(kp?.KeyPairs);
|
|
299
|
+
for (const p of pairs) {
|
|
300
|
+
const t = String(p?.KeyType ?? "rsa");
|
|
301
|
+
inv(t === "ed25519" ? { algorithm: "Ed25519", family: "EdDSA", primitive: "signature", functions: ["sign", "verify"], note: "EC2 SSH key pair" } : { algorithm: "RSA", family: "RSA", primitive: "signature", functions: ["sign", "verify"], note: "EC2 SSH key pair" }, `${where} EC2 key pair ${String(p?.KeyName ?? "")}`);
|
|
302
|
+
}
|
|
303
|
+
if (pairs.length)
|
|
304
|
+
counted.push(`${pairs.length} SSH key pair${pairs.length === 1 ? "" : "s"}`);
|
|
305
|
+
// Private CA.
|
|
306
|
+
const pca = await svc("Private CA", where, ["acm-pca", "list-certificate-authorities", ...r], "list private certificate authorities and their key types");
|
|
307
|
+
for (const c of list(pca?.CertificateAuthorities)) {
|
|
308
|
+
const cn = String(c?.CertificateAuthorityConfiguration?.Subject?.CommonName ?? String(c?.Arn ?? "").split("/").pop() ?? "");
|
|
309
|
+
const target = `${where} private CA ${cn}`;
|
|
310
|
+
const res = privateCa(c, target);
|
|
311
|
+
push(res.finding, res.strength);
|
|
312
|
+
if (res.inventory)
|
|
313
|
+
inv(res.inventory, target);
|
|
314
|
+
}
|
|
315
|
+
// Transfer Family servers, with each security policy read once.
|
|
316
|
+
const tf = await svc("Transfer Family", where, ["transfer", "list-servers", ...r], "list file transfer servers");
|
|
317
|
+
const ids = list(tf?.Servers).map((s) => String(s?.ServerId ?? "")).filter((s) => SERVER_ID.test(s));
|
|
318
|
+
const policies = new Map();
|
|
319
|
+
for (const id of ids) {
|
|
320
|
+
const d = await svc("Transfer Family", `${where} file transfer server ${id}`, ["transfer", "describe-server", "--server-id", id, ...r], "read the server's protocols and security policy", true);
|
|
321
|
+
const server = d?.Server;
|
|
322
|
+
if (!server)
|
|
323
|
+
continue;
|
|
324
|
+
const pn = String(server.SecurityPolicyName ?? "");
|
|
325
|
+
if (pn && NAME.test(pn) && !policies.has(pn)) {
|
|
326
|
+
const p = await svc("Transfer Family", where, ["transfer", "describe-security-policy", "--security-policy-name", pn, ...r], "read the security policy's algorithms");
|
|
327
|
+
policies.set(pn, p?.SecurityPolicy ?? null);
|
|
328
|
+
}
|
|
329
|
+
const res = transferServer(server, policies.get(pn), `${where} file transfer server ${id}`);
|
|
330
|
+
for (const f of res.findings)
|
|
331
|
+
push(f);
|
|
332
|
+
push(undefined, res.strength);
|
|
333
|
+
}
|
|
334
|
+
if (ids.length)
|
|
335
|
+
counted.push(`${ids.length} file transfer server${ids.length === 1 ? "" : "s"}`);
|
|
336
|
+
return counted;
|
|
337
|
+
}
|
|
338
|
+
/** Account-wide: uploaded IAM server certificates and S3 bucket TLS rules. */
|
|
339
|
+
export async function awsGlobal(ctx, tag, buckets = 100) {
|
|
340
|
+
const { svc, push, now } = ctx;
|
|
341
|
+
const counted = [];
|
|
342
|
+
const certs = await svc("IAM certificates", `${tag} IAM`, ["iam", "list-server-certificates"], "list uploaded server certificates");
|
|
343
|
+
const meta = list(certs?.ServerCertificateMetadataList).filter((m) => NAME.test(String(m?.ServerCertificateName ?? "")));
|
|
344
|
+
await pool(meta, 2, async (m) => {
|
|
345
|
+
const name = String(m.ServerCertificateName);
|
|
346
|
+
const target = `${tag} IAM server certificate ${name}`;
|
|
347
|
+
const d = await svc("IAM certificates", target, ["iam", "get-server-certificate", "--server-certificate-name", name], "read the certificate's key type (the public certificate only)", true);
|
|
348
|
+
const pem = String(d?.ServerCertificate?.CertificateBody ?? "");
|
|
349
|
+
const f = pem ? certFromPem(pem, target, now, true, "Uploaded server certificate") : Date.parse(String(m.Expiration ?? "")) < now.getTime() ? certFromPem("", target, now, true) : null;
|
|
350
|
+
if (f)
|
|
351
|
+
push(f);
|
|
352
|
+
});
|
|
353
|
+
if (meta.length)
|
|
354
|
+
counted.push(`${meta.length} uploaded certificate${meta.length === 1 ? "" : "s"}`);
|
|
355
|
+
const b = await svc("S3", `${tag} S3`, ["s3api", "list-buckets"], "list storage buckets");
|
|
356
|
+
const names = list(b?.Buckets).map((x) => String(x?.Name ?? "")).filter((n) => BUCKET.test(n) && SAFE_ARG.test(n));
|
|
357
|
+
const open = [];
|
|
358
|
+
const checked = names.slice(0, buckets);
|
|
359
|
+
await pool(checked, 4, async (name) => {
|
|
360
|
+
const p = await svc("S3", `${tag} S3 bucket ${name}`, ["s3api", "get-bucket-policy", "--bucket", name], "read whether the bucket requires TLS", true, /NoSuchBucketPolicy|bucket policy does not exist/i);
|
|
361
|
+
if (p === null)
|
|
362
|
+
return;
|
|
363
|
+
if (p.absent || !requiresTls(p?.Policy))
|
|
364
|
+
open.push(name);
|
|
365
|
+
});
|
|
366
|
+
if (open.length) {
|
|
367
|
+
open.sort();
|
|
368
|
+
const shown = open.slice(0, 3).join(", ");
|
|
369
|
+
push(plainTraffic(`${tag} S3`, `${open.length === checked.length ? (open.length === 1 ? "The bucket accepts" : `All ${open.length} buckets accept`) : `${open.length} of ${checked.length} buckets accept`} requests without TLS: ${shown}${open.length > 3 ? ` and ${open.length - 3} more` : ""}`, "Add a bucket policy statement that denies requests where aws:SecureTransport is false. AWS's own clients already use TLS, so this only stops plain-HTTP requests.", false, "low"));
|
|
370
|
+
}
|
|
371
|
+
if (names.length)
|
|
372
|
+
counted.push(`${Math.min(names.length, buckets)} bucket${names.length === 1 ? "" : "s"}${names.length > buckets ? ` of ${names.length}` : ""}`);
|
|
373
|
+
return counted;
|
|
374
|
+
}
|
|
375
|
+
export { KEX_FIX, SIG_FIX };
|