@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,354 @@
|
|
|
1
|
+
// SPDX-License-Identifier: PolyForm-Shield-1.0.0
|
|
2
|
+
// Copyright 2026 Hard Keel (https://hardkeel.com)
|
|
3
|
+
// AWS: KMS keys, ACM certificates, load balancer TLS policies and CloudFront distributions here,
|
|
4
|
+
// and the rest of the services in cloud-aws-services.ts.
|
|
5
|
+
// Read-only: list, describe and get calls through the AWS CLI, with the profile and sign-in it already has.
|
|
6
|
+
import { ALGORITHMS } from "./rules.js";
|
|
7
|
+
import { awsGlobal, awsRegional, oldTls, plainTraffic } from "./cloud-aws-services.js";
|
|
8
|
+
import { CERT_FIX, emptyCloud, failure, KEX_FIX, PKE_FIX, pool, PROFILE, REGION, SAFE_ARG, SIG_FIX } from "./cloud-common.js";
|
|
9
|
+
/** The recommended post-quantum policy for Application and Network Load Balancers (hybrid ML-KEM, TLS 1.2 and 1.3). */
|
|
10
|
+
export const ELB_PQ_POLICY = "ELBSecurityPolicy-TLS13-1-2-Res-PQ-2025-09";
|
|
11
|
+
const OLD_TLS = new Set(["SSLv3", "TLSv1", "TLSv1.1"]);
|
|
12
|
+
const PROTOCOL_WORD = { SSLv3: "SSL 3.0", TLSv1: "TLS 1.0", "TLSv1.1": "TLS 1.1" };
|
|
13
|
+
const WEAK_CIPHER = /DES-CBC3|3DES|RC4|NULL|EXPORT|(^|-)DES-CBC-|ADH|anon/i;
|
|
14
|
+
const CF_OLD = new Set(["SSLv3", "TLSv1", "TLSv1_2016", "TLSv1.1_2016"]);
|
|
15
|
+
const EC_BITS = { prime256v1: 256, secp384r1: 384, secp521r1: 521, P256: 256, P384: 384, P521: 521, SECG_P256K1: 256 };
|
|
16
|
+
const ACM_KEY_TYPES = "keyTypes=RSA_1024,RSA_2048,RSA_3072,RSA_4096,EC_prime256v1,EC_secp384r1,EC_secp521r1";
|
|
17
|
+
/** What svc returns when the call said the thing simply isn't there, like a bucket with no policy. */
|
|
18
|
+
export const ABSENT = Object.freeze({ absent: true });
|
|
19
|
+
const list = (v) => (Array.isArray(v) ? v : []);
|
|
20
|
+
/** One KMS key, from describe-key's KeyMetadata. */
|
|
21
|
+
export function kmsKey(meta, target) {
|
|
22
|
+
const spec = String(meta?.KeySpec ?? meta?.CustomerMasterKeySpec ?? "");
|
|
23
|
+
const usage = String(meta?.KeyUsage ?? "");
|
|
24
|
+
const off = meta?.KeyState && meta.KeyState !== "Enabled" ? ` (${String(meta.KeyState).toLowerCase()})` : "";
|
|
25
|
+
if (spec === "SYMMETRIC_DEFAULT" || spec === "")
|
|
26
|
+
return { inventory: { algorithm: "AES-256-GCM", family: "AES", primitive: "ae", functions: ["encrypt", "decrypt"], keySize: 256, mode: "gcm", nistQuantumLevel: 5, note: "AWS KMS symmetric key" } };
|
|
27
|
+
const hmac = spec.match(/^HMAC_(224|256|384|512)$/);
|
|
28
|
+
if (hmac)
|
|
29
|
+
return { inventory: { algorithm: `HMAC-SHA${hmac[1]}`, family: "HMAC", primitive: "mac", functions: ["tag"], note: "AWS KMS HMAC key" } };
|
|
30
|
+
const mldsa = spec.match(/^ML_DSA_(44|65|87)$/);
|
|
31
|
+
if (mldsa)
|
|
32
|
+
return { strength: { target, algorithm: "ML-DSA", title: `KMS signing key uses ML-DSA-${mldsa[1]}` }, inventory: { algorithm: `ML-DSA-${mldsa[1]}`, family: "ML-DSA", primitive: "signature", functions: ["sign", "verify"], nistQuantumLevel: { "44": 2, "65": 3, "87": 5 }[mldsa[1]] } };
|
|
33
|
+
const rsa = spec.match(/^RSA_(\d{4})$/);
|
|
34
|
+
const sign = usage === "SIGN_VERIFY";
|
|
35
|
+
if (rsa) {
|
|
36
|
+
const bits = Number(rsa[1]);
|
|
37
|
+
if (sign)
|
|
38
|
+
return { finding: { target, ruleId: "cloud-kms-rsa-sign", title: `KMS signing key uses RSA-${bits}${off}`, algorithm: "RSA signature", primitive: "signature", risk: "quantum-vulnerable", severity: "medium", fix: SIG_FIX, internetFacing: false, longLived: true, keySize: bits } };
|
|
39
|
+
return { finding: { target, ruleId: "cloud-kms-rsa-encrypt", title: `KMS encryption key uses RSA-${bits}${off}`, algorithm: "RSA encryption", primitive: "public-key-encryption", risk: "quantum-vulnerable", severity: "high", fix: PKE_FIX, internetFacing: false, keySize: bits } };
|
|
40
|
+
}
|
|
41
|
+
if (/^ECC_|^SM2$/.test(spec)) {
|
|
42
|
+
const curve = spec.replace(/^ECC_(NIST_)?/, "");
|
|
43
|
+
const label = spec === "SM2" ? "SM2" : curve === "EDWARDS25519" ? "Ed25519" : curve.replace("SECG_", "");
|
|
44
|
+
if (usage === "KEY_AGREEMENT")
|
|
45
|
+
return { finding: { target, ruleId: "cloud-kms-ecdh", title: `KMS key agreement key uses ${label}${off}`, algorithm: "ECDH", primitive: "key-agreement", risk: "quantum-vulnerable", severity: "high", fix: KEX_FIX, internetFacing: false, keySize: EC_BITS[curve] } };
|
|
46
|
+
const alg = label === "Ed25519" ? "Ed25519" : "ECDSA";
|
|
47
|
+
if (sign)
|
|
48
|
+
return { finding: { target, ruleId: "cloud-kms-ec-sign", title: `KMS signing key uses ${label}${off}`, algorithm: alg, primitive: "signature", risk: "quantum-vulnerable", severity: "medium", fix: SIG_FIX, internetFacing: false, longLived: true, keySize: EC_BITS[curve] } };
|
|
49
|
+
return { finding: { target, ruleId: "cloud-kms-ec-encrypt", title: `KMS encryption key uses ${label}${off}`, algorithm: "EC", primitive: "public-key-encryption", risk: "quantum-vulnerable", severity: "high", fix: PKE_FIX, internetFacing: false, keySize: EC_BITS[curve] } };
|
|
50
|
+
}
|
|
51
|
+
return {};
|
|
52
|
+
}
|
|
53
|
+
/** One ACM certificate, from list-certificates' summary. */
|
|
54
|
+
export function acmCert(c, target) {
|
|
55
|
+
const status = String(c?.Status ?? "");
|
|
56
|
+
const inUse = c?.InUse === true;
|
|
57
|
+
const internetFacing = inUse && c?.Type !== "PRIVATE";
|
|
58
|
+
if (status === "EXPIRED") {
|
|
59
|
+
if (!inUse)
|
|
60
|
+
return {};
|
|
61
|
+
return { finding: { target, ruleId: "cloud-cert-expired", title: "Certificate in use has expired", algorithm: "Expired certificate", primitive: "protocol", risk: "weak-now", severity: "high", fix: "Renew or replace the certificate. Clients refuse expired ones.", internetFacing } };
|
|
62
|
+
}
|
|
63
|
+
if (status !== "ISSUED")
|
|
64
|
+
return {};
|
|
65
|
+
const alg = String(c?.KeyAlgorithm ?? "");
|
|
66
|
+
const note = inUse ? "" : " (not in use)";
|
|
67
|
+
if (/ML[-_]?DSA/i.test(alg))
|
|
68
|
+
return { strength: { target, algorithm: "ML-DSA", title: "Certificate uses ML-DSA" } };
|
|
69
|
+
const rsa = alg.match(/^RSA[-_](\d{4})$/);
|
|
70
|
+
if (rsa) {
|
|
71
|
+
const bits = Number(rsa[1]);
|
|
72
|
+
if (bits < 2048)
|
|
73
|
+
return { finding: { target, ruleId: "cloud-cert-small-rsa", title: `Certificate uses a ${bits}-bit RSA key${note}`, algorithm: "RSA", primitive: "signature", risk: "weak-now", severity: "high", keySize: bits, fix: "Reissue with at least a 2048-bit RSA key, or ECDSA P-256.", internetFacing } };
|
|
74
|
+
return { finding: { target, ruleId: "cloud-cert-quantum", title: `Certificate uses ${bits}-bit RSA${note}`, algorithm: "RSA signature", primitive: "signature", risk: "quantum-vulnerable", severity: "medium", keySize: bits, fix: CERT_FIX, internetFacing } };
|
|
75
|
+
}
|
|
76
|
+
const ec = alg.match(/^EC[-_](\w+)$/);
|
|
77
|
+
if (ec)
|
|
78
|
+
return { finding: { target, ruleId: "cloud-cert-quantum", title: `Certificate uses ECDSA ${ec[1]}${note}`, algorithm: "ECDSA", primitive: "signature", risk: "quantum-vulnerable", severity: "medium", keySize: EC_BITS[ec[1]], fix: CERT_FIX, internetFacing } };
|
|
79
|
+
return {};
|
|
80
|
+
}
|
|
81
|
+
export function policyFindings(p, target, internetFacing, kind) {
|
|
82
|
+
const out = [];
|
|
83
|
+
const switchTo = kind === "classic" ? "Move to an Application or Network Load Balancer with" : "Switch the listener to";
|
|
84
|
+
const old = p.protocols.filter((x) => OLD_TLS.has(x));
|
|
85
|
+
if (old.length) {
|
|
86
|
+
const a = ALGORITHMS["TLS 1.0/1.1"];
|
|
87
|
+
out.push({ target, ruleId: "cloud-tls-old", title: `TLS policy ${p.name} accepts ${old.map((x) => PROTOCOL_WORD[x]).join(" and ")}`, algorithm: "TLS 1.0/1.1", primitive: a.primitive, risk: a.risk, severity: a.severity, fix: `${switchTo} ${ELB_PQ_POLICY}, which allows only TLS 1.2 and 1.3.`, internetFacing });
|
|
88
|
+
}
|
|
89
|
+
const weak = p.ciphers.filter((c) => WEAK_CIPHER.test(c));
|
|
90
|
+
if (weak.length)
|
|
91
|
+
out.push({ target, ruleId: "cloud-tls-weak-cipher", title: `TLS policy ${p.name} allows ${weak.slice(0, 2).join(" and ")}${weak.length > 2 ? ` and ${weak.length - 2} more weak ciphers` : ""}`, algorithm: "Weak TLS ciphers", primitive: "protocol", risk: "weak-now", severity: "high", fix: `${switchTo} ${ELB_PQ_POLICY}, which allows only AES-GCM cipher suites.`, internetFacing });
|
|
92
|
+
if (p.pq)
|
|
93
|
+
return { findings: out, strength: { target, algorithm: "Hybrid ML-KEM key exchange", title: `TLS policy ${p.name} offers hybrid ML-KEM key exchange` } };
|
|
94
|
+
out.push({
|
|
95
|
+
target,
|
|
96
|
+
ruleId: "cloud-tls-kex",
|
|
97
|
+
title: `TLS policy ${p.name} has no quantum-safe key exchange`,
|
|
98
|
+
algorithm: "TLS key exchange",
|
|
99
|
+
primitive: "key-agreement",
|
|
100
|
+
risk: "quantum-vulnerable",
|
|
101
|
+
severity: "high",
|
|
102
|
+
fix: kind === "classic" ? `Classic Load Balancers have no quantum-safe option. Move to an Application or Network Load Balancer with ${ELB_PQ_POLICY}.` : `Switch the listener to ${ELB_PQ_POLICY} for hybrid ML-KEM key exchange. It costs nothing extra and still serves older clients.`,
|
|
103
|
+
internetFacing,
|
|
104
|
+
});
|
|
105
|
+
return { findings: out };
|
|
106
|
+
}
|
|
107
|
+
/** A predefined ELBv2 policy from describe-ssl-policies, or what its name says when AWS didn't list it. */
|
|
108
|
+
export function elbv2Policy(name, listed) {
|
|
109
|
+
const p = listed.get(name);
|
|
110
|
+
const pq = /-PQ-/i.test(name);
|
|
111
|
+
if (!p) {
|
|
112
|
+
// Not in the list (a newer policy): judge by the name. Policies named TLS13-1-2 or newer allow 1.2 and up.
|
|
113
|
+
const protocols = /TLS13-1-[23]|TLS-1-2|FS-1-2/.test(name) ? ["TLSv1.2"] : /TLS-1-1|FS-1-1/.test(name) ? ["TLSv1.1", "TLSv1.2"] : /TLS13-1-1/.test(name) ? ["TLSv1.1", "TLSv1.2"] : /TLS13-1-0|2016-08|2015-05|TLS-1-0|FS-2018-06/.test(name) ? ["TLSv1", "TLSv1.1", "TLSv1.2"] : [];
|
|
114
|
+
return { name, protocols, ciphers: [], pq };
|
|
115
|
+
}
|
|
116
|
+
return { name, protocols: list(p.SslProtocols), ciphers: list(p.Ciphers).map((c) => String(c?.Name ?? "")), pq };
|
|
117
|
+
}
|
|
118
|
+
/** A Classic Load Balancer's SSL negotiation policy, from describe-load-balancer-policies. */
|
|
119
|
+
export function classicPolicy(desc) {
|
|
120
|
+
if (!desc || desc.PolicyTypeName !== "SSLNegotiationPolicyType")
|
|
121
|
+
return null;
|
|
122
|
+
const attrs = list(desc.PolicyAttributeDescriptions);
|
|
123
|
+
const on = attrs.filter((a) => a?.AttributeValue === "true").map((a) => String(a.AttributeName));
|
|
124
|
+
const ref = attrs.find((a) => a?.AttributeName === "Reference-Security-Policy")?.AttributeValue;
|
|
125
|
+
const protocols = on.filter((a) => a.startsWith("Protocol-")).map((a) => a.slice("Protocol-".length));
|
|
126
|
+
const ciphers = on.filter((a) => !a.startsWith("Protocol-") && a !== "Server-Defined-Cipher-Order");
|
|
127
|
+
return { name: String(ref ?? desc.PolicyName ?? "custom"), protocols, ciphers, pq: false };
|
|
128
|
+
}
|
|
129
|
+
/** Plain HTTP to viewers or origins, and old TLS to origins, for one CloudFront distribution. */
|
|
130
|
+
export function cloudFrontTransport(d, target) {
|
|
131
|
+
const out = [];
|
|
132
|
+
const behaviors = [d?.DefaultCacheBehavior, ...list(d?.CacheBehaviors?.Items)].filter(Boolean);
|
|
133
|
+
const plain = behaviors.filter((b) => b?.ViewerProtocolPolicy === "allow-all");
|
|
134
|
+
if (plain.length)
|
|
135
|
+
out.push(plainTraffic(target, plain.length === behaviors.length ? "Distribution serves viewers over plain HTTP as well as HTTPS" : `Distribution serves plain HTTP on ${plain.length === 1 ? "one path" : `${plain.length} paths`}`, "Set the viewer protocol policy to Redirect HTTP to HTTPS on every behavior.", true));
|
|
136
|
+
for (const origin of list(d?.Origins?.Items)) {
|
|
137
|
+
const c = origin?.CustomOriginConfig;
|
|
138
|
+
if (!c)
|
|
139
|
+
continue;
|
|
140
|
+
const name = String(origin?.DomainName ?? origin?.Id ?? "");
|
|
141
|
+
if (c.OriginProtocolPolicy === "http-only") {
|
|
142
|
+
out.push(plainTraffic(target, `Distribution fetches from origin ${name} over plain HTTP`, "Set the origin protocol policy to HTTPS only, with a certificate on the origin.", true));
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
const oldOrigin = list(c.OriginSslProtocols?.Items).filter((x) => x === "SSLv3" || x === "TLSv1" || x === "TLSv1.1");
|
|
146
|
+
if (oldOrigin.length)
|
|
147
|
+
out.push(oldTls(target, `Distribution allows ${oldOrigin.map((x) => (x === "SSLv3" ? "SSL 3.0" : x === "TLSv1" ? "TLS 1.0" : "TLS 1.1")).join(" and ")} to origin ${name}`, "Allow only TLSv1.2 in the origin's SSL protocols.", false, "low"));
|
|
148
|
+
}
|
|
149
|
+
return out;
|
|
150
|
+
}
|
|
151
|
+
/** One CloudFront distribution, from list-distributions. */
|
|
152
|
+
export function cloudFront(d, target) {
|
|
153
|
+
const out = [];
|
|
154
|
+
const vc = d?.ViewerCertificate ?? {};
|
|
155
|
+
const min = String(vc.MinimumProtocolVersion ?? "");
|
|
156
|
+
const a = ALGORITHMS["TLS 1.0/1.1"];
|
|
157
|
+
if (vc.CloudFrontDefaultCertificate === true) {
|
|
158
|
+
out.push({ target, ruleId: "cloud-tls-old", title: "Uses the default cloudfront.net certificate, which accepts TLS 1.0 and 1.1", algorithm: "TLS 1.0/1.1", primitive: a.primitive, risk: a.risk, severity: "medium", fix: "Serve it on your own domain with an ACM certificate and the TLSv1.2_2021 security policy or newer.", internetFacing: true });
|
|
159
|
+
}
|
|
160
|
+
else if (CF_OLD.has(min)) {
|
|
161
|
+
out.push({ target, ruleId: "cloud-tls-old", title: `Security policy ${min} accepts ${min === "SSLv3" ? "SSL 3.0 and TLS 1.0" : min.startsWith("TLSv1.1") ? "TLS 1.1" : "TLS 1.0 and 1.1"}`, algorithm: "TLS 1.0/1.1", primitive: a.primitive, risk: a.risk, severity: a.severity, fix: "Change the distribution's security policy to TLSv1.2_2021 or newer.", internetFacing: true });
|
|
162
|
+
}
|
|
163
|
+
out.push(...cloudFrontTransport(d, target));
|
|
164
|
+
// CloudFront has offered hybrid ML-KEM key exchange to viewers on every security policy since September 2025.
|
|
165
|
+
return { findings: out, strength: d?.Enabled === false ? undefined : { target, algorithm: "Hybrid ML-KEM key exchange", title: "CloudFront offers hybrid ML-KEM key exchange to viewers" } };
|
|
166
|
+
}
|
|
167
|
+
/** Does an HTTP listener send everyone to HTTPS? */
|
|
168
|
+
export function redirectsToHttps(l) {
|
|
169
|
+
return list(l?.DefaultActions).some((a) => a?.Type === "redirect" && String(a?.RedirectConfig?.Protocol ?? "").toUpperCase() === "HTTPS");
|
|
170
|
+
}
|
|
171
|
+
const ELB_ARN = /^arn:aws[a-z-]*:elasticloadbalancing:[a-z0-9-]+:\d{12}:loadbalancer\/[A-Za-z0-9/_.-]+$/;
|
|
172
|
+
const KEY_ID = /^[A-Za-z0-9-]{1,128}$|^mrk-[a-f0-9]{32}$/;
|
|
173
|
+
const ELB_NAME = /^[A-Za-z0-9-]{1,32}$/;
|
|
174
|
+
const POLICY_NAME = /^[A-Za-z0-9._-]{1,128}$/;
|
|
175
|
+
export async function runAws(scope, log, o) {
|
|
176
|
+
const res = emptyCloud();
|
|
177
|
+
const base = scope.profile && PROFILE.test(scope.profile) ? ["--profile", scope.profile] : [];
|
|
178
|
+
const call = (args) => o.runner("aws", [...args, "--output", "json", ...base]);
|
|
179
|
+
const who = scope.profile ? `AWS profile ${scope.profile}` : "AWS";
|
|
180
|
+
log.record("cloud", who, "aws sts get-caller-identity: which account is signed in");
|
|
181
|
+
const id = await call(["sts", "get-caller-identity"]);
|
|
182
|
+
if (!id.ok) {
|
|
183
|
+
failure(res, "aws", who, id, "read the signed-in AWS account");
|
|
184
|
+
return res;
|
|
185
|
+
}
|
|
186
|
+
const account = String(id.data?.Account ?? "unknown");
|
|
187
|
+
const tag = `AWS ${account}`;
|
|
188
|
+
res.notes.push(`AWS account ${account}${scope.profile ? ` (profile ${scope.profile})` : ""}, signed in as ${String(id.data?.Arn ?? "unknown").split(":").pop()}`);
|
|
189
|
+
let regions = (scope.regions ?? []).filter((r) => REGION.test(r));
|
|
190
|
+
if (!regions.length) {
|
|
191
|
+
const conf = await o.runner("aws", ["configure", "get", "region", ...base]);
|
|
192
|
+
const home = conf.ok && typeof conf.data === "string" && REGION.test(conf.data.trim()) ? conf.data.trim() : "us-east-1";
|
|
193
|
+
log.record("cloud", tag, "aws ec2 describe-regions: list the regions turned on for this account");
|
|
194
|
+
const r = await call(["ec2", "describe-regions", "--region", home]);
|
|
195
|
+
if (r.ok)
|
|
196
|
+
regions = list(r.data?.Regions).map((x) => String(x?.RegionName ?? "")).filter((x) => REGION.test(x));
|
|
197
|
+
if (!regions.length) {
|
|
198
|
+
regions = [...new Set([home, "us-east-1"])];
|
|
199
|
+
res.result.skipped.push({ target: tag, reason: `couldn't list this account's regions, so only ${regions.join(" and ")} ${regions.length === 1 ? "was" : "were"} checked. Use --region to name others` });
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
// A service the identity can't read in one region usually can't be read in any. Report it once.
|
|
203
|
+
const denied = new Set();
|
|
204
|
+
// A key's own key policy can refuse one key while allowing the rest, so describe-key failures stay with that key.
|
|
205
|
+
// A service AWS doesn't offer in a region is listed once, with the regions, instead of once per region.
|
|
206
|
+
const unoffered = new Map();
|
|
207
|
+
const svc = async (service, target, args, what, perItem = false, absent) => {
|
|
208
|
+
if (denied.has(service))
|
|
209
|
+
return null;
|
|
210
|
+
log.record("cloud", target, `aws ${args[0]} ${args[1]}: ${what}`);
|
|
211
|
+
const r = await call(args);
|
|
212
|
+
if (r.ok)
|
|
213
|
+
return r.data ?? {};
|
|
214
|
+
if (absent?.test(r.message))
|
|
215
|
+
return ABSENT;
|
|
216
|
+
const region = args.includes("--region") ? args[args.indexOf("--region") + 1] : "";
|
|
217
|
+
if (r.kind === "unsupported" && region && regions.length > 1) {
|
|
218
|
+
unoffered.set(service, [...(unoffered.get(service) ?? []), region]);
|
|
219
|
+
return null;
|
|
220
|
+
}
|
|
221
|
+
if (!perItem && (r.kind === "denied" || r.kind === "signin")) {
|
|
222
|
+
// Regions run side by side, so another region may have reported it while this call ran.
|
|
223
|
+
if (denied.has(service))
|
|
224
|
+
return null;
|
|
225
|
+
denied.add(service);
|
|
226
|
+
failure(res, "aws", `${tag} ${service}`, r, what);
|
|
227
|
+
}
|
|
228
|
+
else
|
|
229
|
+
failure(res, "aws", target, r, what);
|
|
230
|
+
return null;
|
|
231
|
+
};
|
|
232
|
+
const push = (f, s) => {
|
|
233
|
+
if (f)
|
|
234
|
+
res.result.findings.push({ area: "cloud", ...f });
|
|
235
|
+
if (s)
|
|
236
|
+
res.result.strengths.push({ area: "cloud", ...s });
|
|
237
|
+
};
|
|
238
|
+
const sslPolicies = async (region) => {
|
|
239
|
+
const d = await svc("load balancer TLS policies", `${tag} ${region}`, ["elbv2", "describe-ssl-policies", "--region", region], "read the TLS policies load balancers can use");
|
|
240
|
+
return new Map(list(d?.SslPolicies).map((p) => [String(p?.Name), p]));
|
|
241
|
+
};
|
|
242
|
+
const ctx = { svc, push, inv: (item, target) => res.inventory.push({ ...item, file: target, line: 0 }), now: o.now };
|
|
243
|
+
await pool(regions, o.concurrency, async (region) => {
|
|
244
|
+
const where = `${tag} ${region}`;
|
|
245
|
+
const counts = { keys: 0, certs: 0, listeners: 0 };
|
|
246
|
+
// KMS keys. Keys whose only aliases are alias/aws/... are AWS-managed and always symmetric.
|
|
247
|
+
const aliases = await svc("KMS", where, ["kms", "list-aliases", "--region", region], "list KMS key names");
|
|
248
|
+
const names = new Map();
|
|
249
|
+
for (const a of list(aliases?.Aliases))
|
|
250
|
+
if (a?.TargetKeyId)
|
|
251
|
+
names.set(a.TargetKeyId, [...(names.get(a.TargetKeyId) ?? []), String(a.AliasName)]);
|
|
252
|
+
const keys = await svc("KMS", where, ["kms", "list-keys", "--region", region], "list KMS keys");
|
|
253
|
+
const ids = list(keys?.Keys).map((k) => String(k?.KeyId ?? "")).filter((k) => KEY_ID.test(k) && SAFE_ARG.test(k));
|
|
254
|
+
await pool(ids, 2, async (keyId) => {
|
|
255
|
+
const label = names.get(keyId)?.find((n) => !n.startsWith("alias/aws/")) ?? names.get(keyId)?.[0] ?? keyId;
|
|
256
|
+
const target = `${where} KMS key ${label === keyId ? keyId : `${label} (${keyId})`}`;
|
|
257
|
+
counts.keys++;
|
|
258
|
+
if (names.get(keyId)?.every((n) => n.startsWith("alias/aws/"))) {
|
|
259
|
+
res.inventory.push({ ...kmsKey({ KeySpec: "SYMMETRIC_DEFAULT" }, target).inventory, file: target, line: 0 });
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
const d = await svc("KMS", target, ["kms", "describe-key", "--key-id", keyId, "--region", region], "read the key's type and size", true);
|
|
263
|
+
const meta = d?.KeyMetadata;
|
|
264
|
+
if (!meta || /^Pending/.test(String(meta.KeyState ?? "")))
|
|
265
|
+
return;
|
|
266
|
+
const r = kmsKey(meta, target);
|
|
267
|
+
push(r.finding, r.strength);
|
|
268
|
+
if (r.inventory)
|
|
269
|
+
res.inventory.push({ ...r.inventory, file: target, line: 0 });
|
|
270
|
+
});
|
|
271
|
+
// ACM certificates. By default ACM lists only RSA 1024 and 2048, so ask for every key type.
|
|
272
|
+
const certs = await svc("ACM", where, ["acm", "list-certificates", "--includes", ACM_KEY_TYPES, "--region", region], "list certificates and their key types");
|
|
273
|
+
for (const c of list(certs?.CertificateSummaryList)) {
|
|
274
|
+
counts.certs++;
|
|
275
|
+
const r = acmCert(c, `${where} certificate ${String(c?.DomainName ?? "unnamed")}`);
|
|
276
|
+
push(r.finding, r.strength);
|
|
277
|
+
}
|
|
278
|
+
// Application and Network Load Balancers.
|
|
279
|
+
const lbs = await svc("load balancers", where, ["elbv2", "describe-load-balancers", "--region", region], "list load balancers");
|
|
280
|
+
let policies = null;
|
|
281
|
+
for (const lb of list(lbs?.LoadBalancers)) {
|
|
282
|
+
const arn = String(lb?.LoadBalancerArn ?? "");
|
|
283
|
+
if (!ELB_ARN.test(arn) || !SAFE_ARG.test(arn))
|
|
284
|
+
continue;
|
|
285
|
+
const ls = await svc("load balancers", `${where} load balancer ${lb.LoadBalancerName}`, ["elbv2", "describe-listeners", "--load-balancer-arn", arn, "--region", region], "read the listeners' TLS policies");
|
|
286
|
+
for (const l of list(ls?.Listeners)) {
|
|
287
|
+
if (l?.Protocol === "HTTP") {
|
|
288
|
+
if (lb.Scheme === "internet-facing" && !redirectsToHttps(l))
|
|
289
|
+
push(plainTraffic(`${where} load balancer ${lb.LoadBalancerName}:${l.Port}`, `Load balancer serves plain HTTP on port ${l.Port}`, "Make the HTTP listener redirect to HTTPS, or remove it.", true));
|
|
290
|
+
continue;
|
|
291
|
+
}
|
|
292
|
+
if (!l?.SslPolicy || !/^(HTTPS|TLS)$/.test(String(l.Protocol)))
|
|
293
|
+
continue;
|
|
294
|
+
counts.listeners++;
|
|
295
|
+
policies ??= await sslPolicies(region);
|
|
296
|
+
const r = policyFindings(elbv2Policy(String(l.SslPolicy), policies), `${where} load balancer ${lb.LoadBalancerName}:${l.Port}`, lb.Scheme === "internet-facing", "alb");
|
|
297
|
+
for (const f of r.findings)
|
|
298
|
+
push(f);
|
|
299
|
+
push(undefined, r.strength);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
// Classic Load Balancers.
|
|
303
|
+
const classic = await svc("classic load balancers", where, ["elb", "describe-load-balancers", "--region", region], "list Classic Load Balancers");
|
|
304
|
+
for (const lb of list(classic?.LoadBalancerDescriptions)) {
|
|
305
|
+
const name = String(lb?.LoadBalancerName ?? "");
|
|
306
|
+
if (!ELB_NAME.test(name))
|
|
307
|
+
continue;
|
|
308
|
+
for (const ld of list(lb.ListenerDescriptions)) {
|
|
309
|
+
const l = ld?.Listener;
|
|
310
|
+
if (/^HTTP$/i.test(String(l?.Protocol ?? ""))) {
|
|
311
|
+
if (lb.Scheme !== "internal")
|
|
312
|
+
push(plainTraffic(`${where} classic load balancer ${name}:${l.LoadBalancerPort}`, `Classic Load Balancer serves plain HTTP on port ${l.LoadBalancerPort}`, "Serve HTTPS only. Classic Load Balancers can't redirect, so move to an Application Load Balancer with an HTTP-to-HTTPS redirect if you need port 80.", true));
|
|
313
|
+
continue;
|
|
314
|
+
}
|
|
315
|
+
if (!/^(HTTPS|SSL)$/i.test(String(l?.Protocol ?? "")))
|
|
316
|
+
continue;
|
|
317
|
+
counts.listeners++;
|
|
318
|
+
const target = `${where} classic load balancer ${name}:${l.LoadBalancerPort}`;
|
|
319
|
+
const pn = list(ld.PolicyNames).filter((p) => POLICY_NAME.test(p));
|
|
320
|
+
let policy = null;
|
|
321
|
+
if (pn.length) {
|
|
322
|
+
const d = await svc("classic load balancers", target, ["elb", "describe-load-balancer-policies", "--load-balancer-name", name, "--policy-names", ...pn, "--region", region], "read the listener's TLS settings");
|
|
323
|
+
for (const p of list(d?.PolicyDescriptions))
|
|
324
|
+
policy ??= classicPolicy(p);
|
|
325
|
+
}
|
|
326
|
+
// With no policy set, a Classic Load Balancer uses its old default, which accepts TLS 1.0 and 1.1.
|
|
327
|
+
const r = policyFindings(policy ?? { name: "the default policy", protocols: ["TLSv1", "TLSv1.1", "TLSv1.2"], ciphers: [], pq: false }, target, lb.Scheme !== "internal", "classic");
|
|
328
|
+
for (const f of r.findings)
|
|
329
|
+
push(f);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
const more = await awsRegional(ctx, where, region);
|
|
333
|
+
res.result.checked.push(`${where}: ${[`${counts.keys} KMS key${counts.keys === 1 ? "" : "s"}`, `${counts.certs} certificate${counts.certs === 1 ? "" : "s"}`, `${counts.listeners} TLS listener${counts.listeners === 1 ? "" : "s"}`, ...more].join(", ")}`);
|
|
334
|
+
});
|
|
335
|
+
// CloudFront is global: one call.
|
|
336
|
+
const cf = await svc("CloudFront", `${tag} CloudFront`, ["cloudfront", "list-distributions"], "list CloudFront distributions and their TLS settings");
|
|
337
|
+
if (cf) {
|
|
338
|
+
const items = list(cf?.DistributionList?.Items);
|
|
339
|
+
for (const d of items) {
|
|
340
|
+
const name = list(d?.Aliases?.Items)[0] ?? String(d?.DomainName ?? "");
|
|
341
|
+
const r = cloudFront(d, `${tag} CloudFront ${String(d?.Id ?? "")} (${name})`);
|
|
342
|
+
for (const f of r.findings)
|
|
343
|
+
push(f);
|
|
344
|
+
push(undefined, r.strength);
|
|
345
|
+
}
|
|
346
|
+
res.result.checked.push(`${tag} CloudFront: ${items.length} distribution${items.length === 1 ? "" : "s"}`);
|
|
347
|
+
}
|
|
348
|
+
const global = await awsGlobal(ctx, tag);
|
|
349
|
+
if (global.length)
|
|
350
|
+
res.result.checked.push(`${tag} account-wide: ${global.join(", ")}`);
|
|
351
|
+
for (const [service, where] of unoffered)
|
|
352
|
+
res.result.skipped.push({ target: `${tag} ${service}`, reason: `not offered in ${where.length === 1 ? where[0] : `${where.length} regions (${where.sort().join(", ")})`}` });
|
|
353
|
+
return res;
|
|
354
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// SPDX-License-Identifier: PolyForm-Shield-1.0.0
|
|
2
|
+
// Copyright 2026 Hard Keel (https://hardkeel.com)
|
|
3
|
+
// Azure beyond Key Vault: storage accounts, App Service and Functions apps, and Azure Cache for Redis.
|
|
4
|
+
// Every call lists or shows settings. Checks that Azure itself now enforces (TLS 1.2 on Storage and SQL)
|
|
5
|
+
// are left out, so nothing is reported that the platform already fixed.
|
|
6
|
+
import { pool, SAFE_ARG } from "./cloud-common.js";
|
|
7
|
+
import { oldTls, plainTraffic } from "./cloud-aws-services.js";
|
|
8
|
+
const list = (v) => (Array.isArray(v) ? v : []);
|
|
9
|
+
/** The day Azure stops accepting TLS 1.0 and 1.1 for App Service, Functions and Logic Apps. */
|
|
10
|
+
export const APP_SERVICE_TLS_CUTOFF = "May 31, 2027";
|
|
11
|
+
/** Is a storage account reachable from the internet? */
|
|
12
|
+
function storagePublic(a) {
|
|
13
|
+
if (String(a?.publicNetworkAccess ?? "") === "Disabled")
|
|
14
|
+
return false;
|
|
15
|
+
return String(a?.networkRuleSet?.defaultAction ?? "Allow") !== "Deny";
|
|
16
|
+
}
|
|
17
|
+
export function storageAccount(a, target) {
|
|
18
|
+
if (a?.enableHttpsTrafficOnly !== false)
|
|
19
|
+
return [];
|
|
20
|
+
return [plainTraffic(target, "Storage account accepts plain HTTP", "Turn on Secure transfer required for the storage account.", storagePublic(a))];
|
|
21
|
+
}
|
|
22
|
+
/** One web or Functions app: the app itself from `webapp list`, and its settings from `webapp config show`. */
|
|
23
|
+
export function webApp(app, config, target) {
|
|
24
|
+
const out = [];
|
|
25
|
+
const kind = /functionapp/i.test(String(app?.kind ?? "")) ? "Functions app" : "Web app";
|
|
26
|
+
const internetFacing = String(app?.publicNetworkAccess ?? "Enabled") !== "Disabled";
|
|
27
|
+
if (app?.httpsOnly === false)
|
|
28
|
+
out.push(plainTraffic(target, `${kind} answers on plain HTTP`, "Turn on HTTPS Only for the app, so HTTP requests are redirected to HTTPS.", internetFacing));
|
|
29
|
+
const min = String(config?.minTlsVersion ?? "");
|
|
30
|
+
const tlsFix = `Set the app's minimum TLS version to 1.2 or 1.3. Azure stops accepting TLS 1.0 and 1.1 for App Service on ${APP_SERVICE_TLS_CUTOFF}, so clients that still use them will stop working then anyway.`;
|
|
31
|
+
if (min === "1.0" || min === "1.1")
|
|
32
|
+
out.push(oldTls(target, `${kind} accepts TLS ${min}`, tlsFix, internetFacing));
|
|
33
|
+
const scm = String(config?.scmMinTlsVersion ?? "");
|
|
34
|
+
if (scm === "1.0" || scm === "1.1")
|
|
35
|
+
out.push(oldTls(target, `${kind}'s deployment site accepts TLS ${scm}`, tlsFix.replace("the app's minimum", "the deployment (SCM) site's minimum"), internetFacing, "low"));
|
|
36
|
+
if (String(config?.ftpsState ?? "") === "AllAllowed")
|
|
37
|
+
out.push(plainTraffic(target, `${kind} accepts plain FTP for deployments`, "Set FTP state to FTPS only, or Disabled if nobody deploys over FTP.", internetFacing));
|
|
38
|
+
return out;
|
|
39
|
+
}
|
|
40
|
+
export function redisCache(c, target) {
|
|
41
|
+
if (c?.enableNonSslPort !== true)
|
|
42
|
+
return [];
|
|
43
|
+
return [plainTraffic(target, "Cache has its unencrypted port (6379) open", "Turn off the non-TLS port once every client connects on 6380 with TLS.", String(c?.publicNetworkAccess ?? "Enabled") !== "Disabled")];
|
|
44
|
+
}
|
|
45
|
+
const SITE_ID = /^\/subscriptions\/[A-Za-z0-9-]+\/resourceGroups\/[A-Za-z0-9._-]+\/providers\/Microsoft\.Web\/sites\/[A-Za-z0-9-]+$/i;
|
|
46
|
+
/** The extra services for one subscription. Returns what was counted, for the checked line. */
|
|
47
|
+
export async function azureServices(ctx, tag, subArgs, concurrency, maxApps = 200) {
|
|
48
|
+
const { az, push } = ctx;
|
|
49
|
+
const counted = [];
|
|
50
|
+
const accounts = await az(tag, ["storage", "account", "list", ...subArgs], "list storage accounts and their transfer settings");
|
|
51
|
+
for (const a of list(accounts))
|
|
52
|
+
for (const f of storageAccount(a, `${tag} storage account ${String(a?.name ?? "")}`))
|
|
53
|
+
push(f);
|
|
54
|
+
if (list(accounts).length)
|
|
55
|
+
counted.push(`${list(accounts).length} storage account${list(accounts).length === 1 ? "" : "s"}`);
|
|
56
|
+
const apps = list(await az(tag, ["webapp", "list", ...subArgs], "list web and Functions apps"));
|
|
57
|
+
const ids = apps.filter((a) => SITE_ID.test(String(a?.id ?? "")) && SAFE_ARG.test(String(a.id))).slice(0, maxApps);
|
|
58
|
+
await pool(ids, Math.max(1, Math.min(concurrency, 4)), async (app) => {
|
|
59
|
+
const target = `${tag} app ${String(app?.name ?? "")}`;
|
|
60
|
+
const config = await az(target, ["webapp", "config", "show", "--ids", String(app.id)], "read the app's TLS and FTP settings");
|
|
61
|
+
for (const f of webApp(app, config ?? {}, target))
|
|
62
|
+
push(f);
|
|
63
|
+
});
|
|
64
|
+
if (apps.length)
|
|
65
|
+
counted.push(`${ids.length} app${ids.length === 1 ? "" : "s"}${apps.length > ids.length ? ` of ${apps.length}` : ""}`);
|
|
66
|
+
const caches = list(await az(tag, ["redis", "list", ...subArgs], "list Azure Cache for Redis instances"));
|
|
67
|
+
for (const c of caches)
|
|
68
|
+
for (const f of redisCache(c, `${tag} cache ${String(c?.name ?? "")}`))
|
|
69
|
+
push(f);
|
|
70
|
+
if (caches.length)
|
|
71
|
+
counted.push(`${caches.length} cache${caches.length === 1 ? "" : "s"}`);
|
|
72
|
+
return counted;
|
|
73
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
// SPDX-License-Identifier: PolyForm-Shield-1.0.0
|
|
2
|
+
// Copyright 2026 Hard Keel (https://hardkeel.com)
|
|
3
|
+
// Azure Key Vault: the type and size of each key and certificate. Storage, apps and caches are in
|
|
4
|
+
// cloud-azure-services.ts. Read-only: list and show calls through the Azure CLI, with the sign-in it already has.
|
|
5
|
+
// Reads public key parts, certificate policies and settings only. Never reads a secret or a private key.
|
|
6
|
+
import { azureServices } from "./cloud-azure-services.js";
|
|
7
|
+
import { CERT_FIX, commandOf, emptyCloud, failure, modulusBits, PKE_FIX, pool, SIG_FIX, SUBSCRIPTION } from "./cloud-common.js";
|
|
8
|
+
const list = (v) => (Array.isArray(v) ? v : []);
|
|
9
|
+
const NAME = /^[A-Za-z0-9-]{1,127}$/;
|
|
10
|
+
const CURVE_BITS = { "P-256": 256, "P-256K": 256, "P-384": 384, "P-521": 521 };
|
|
11
|
+
/** One Key Vault key, from `az keyvault key show`. */
|
|
12
|
+
export function vaultKey(k, target) {
|
|
13
|
+
const key = k?.key ?? {};
|
|
14
|
+
const kty = String(key.kty ?? "");
|
|
15
|
+
const ops = list(key.keyOps ?? key.key_ops).map((o) => String(o).toLowerCase());
|
|
16
|
+
const off = k?.attributes?.enabled === false ? " (disabled)" : "";
|
|
17
|
+
const signs = ops.includes("sign") || ops.includes("verify");
|
|
18
|
+
if (/^oct/.test(kty))
|
|
19
|
+
return { inventory: { algorithm: "AES-256", family: "AES", primitive: "block-cipher", functions: ["encrypt", "decrypt"], keySize: 256, nistQuantumLevel: 5, note: "Azure Key Vault symmetric key" } };
|
|
20
|
+
if (/^RSA/.test(kty)) {
|
|
21
|
+
const bits = modulusBits(key.n);
|
|
22
|
+
if (bits !== undefined && bits < 2048)
|
|
23
|
+
return { finding: { target, ruleId: "cloud-keyvault-small-rsa", title: `Key Vault key uses a ${bits}-bit RSA key${off}`, algorithm: "RSA", primitive: signs ? "signature" : "public-key-encryption", risk: "weak-now", severity: "high", keySize: bits, fix: "Replace it with a 3072-bit or larger RSA key now, and plan the move to ML-KEM or ML-DSA.", internetFacing: false } };
|
|
24
|
+
if (signs && !ops.some((o) => /encrypt|wrap/.test(o)))
|
|
25
|
+
return { finding: { target, ruleId: "cloud-keyvault-rsa-sign", title: `Key Vault signing key uses RSA${bits ? `-${bits}` : ""}${off}`, algorithm: "RSA signature", primitive: "signature", risk: "quantum-vulnerable", severity: "medium", keySize: bits, fix: SIG_FIX, internetFacing: false, longLived: true } };
|
|
26
|
+
return { finding: { target, ruleId: "cloud-keyvault-rsa-encrypt", title: `Key Vault key uses RSA${bits ? `-${bits}` : ""} to encrypt or wrap keys${off}`, algorithm: "RSA encryption", primitive: "public-key-encryption", risk: "quantum-vulnerable", severity: "high", keySize: bits, fix: PKE_FIX, internetFacing: false } };
|
|
27
|
+
}
|
|
28
|
+
if (/^EC/.test(kty)) {
|
|
29
|
+
const crv = String(key.crv ?? "");
|
|
30
|
+
return { finding: { target, ruleId: "cloud-keyvault-ec-sign", title: `Key Vault signing key uses ECDSA${crv ? ` ${crv}` : ""}${off}`, algorithm: "ECDSA", primitive: "signature", risk: "quantum-vulnerable", severity: "medium", keySize: CURVE_BITS[crv], fix: SIG_FIX, internetFacing: false, longLived: true } };
|
|
31
|
+
}
|
|
32
|
+
if (/ML-?DSA/i.test(kty))
|
|
33
|
+
return { strength: { target, algorithm: "ML-DSA", title: "Key Vault key uses ML-DSA" } };
|
|
34
|
+
return {};
|
|
35
|
+
}
|
|
36
|
+
/** One Key Vault certificate, from `az keyvault certificate show`. */
|
|
37
|
+
export function vaultCert(c, target) {
|
|
38
|
+
const kp = c?.policy?.keyProperties ?? c?.policy?.key_properties ?? {};
|
|
39
|
+
const type = String(kp.keyType ?? kp.kty ?? "");
|
|
40
|
+
const off = c?.attributes?.enabled === false ? " (disabled)" : "";
|
|
41
|
+
if (/^RSA/.test(type)) {
|
|
42
|
+
const bits = Number(kp.keySize ?? kp.key_size) || undefined;
|
|
43
|
+
if (bits !== undefined && bits < 2048)
|
|
44
|
+
return { finding: { target, ruleId: "cloud-cert-small-rsa", title: `Certificate uses a ${bits}-bit RSA key${off}`, algorithm: "RSA", primitive: "signature", risk: "weak-now", severity: "high", keySize: bits, fix: "Reissue with at least a 2048-bit RSA key, or ECDSA P-256.", internetFacing: false } };
|
|
45
|
+
return { finding: { target, ruleId: "cloud-cert-quantum", title: `Certificate uses${bits ? ` ${bits}-bit` : ""} RSA${off}`, algorithm: "RSA signature", primitive: "signature", risk: "quantum-vulnerable", severity: "medium", keySize: bits, fix: CERT_FIX, internetFacing: false } };
|
|
46
|
+
}
|
|
47
|
+
if (/^EC/.test(type)) {
|
|
48
|
+
const crv = String(kp.curve ?? kp.crv ?? "");
|
|
49
|
+
return { finding: { target, ruleId: "cloud-cert-quantum", title: `Certificate uses ECDSA${crv ? ` ${crv}` : ""}${off}`, algorithm: "ECDSA", primitive: "signature", risk: "quantum-vulnerable", severity: "medium", keySize: CURVE_BITS[crv], fix: CERT_FIX, internetFacing: false } };
|
|
50
|
+
}
|
|
51
|
+
return {};
|
|
52
|
+
}
|
|
53
|
+
export async function runAzure(scope, log, o) {
|
|
54
|
+
const res = emptyCloud();
|
|
55
|
+
const az = (args) => o.runner("az", [...args, "--output", "json", "--only-show-errors"]);
|
|
56
|
+
const subs = (scope.subscriptions ?? []).filter((s) => SUBSCRIPTION.test(s));
|
|
57
|
+
const push = (f, s) => {
|
|
58
|
+
if (f)
|
|
59
|
+
res.result.findings.push({ area: "cloud", ...f });
|
|
60
|
+
if (s)
|
|
61
|
+
res.result.strengths.push({ area: "cloud", ...s });
|
|
62
|
+
};
|
|
63
|
+
for (const sub of subs.length ? subs : [null]) {
|
|
64
|
+
const subArgs = sub ? ["--subscription", sub] : [];
|
|
65
|
+
log.record("cloud", sub ? `Azure subscription ${sub}` : "Azure", "az account show: which subscription is signed in");
|
|
66
|
+
const acct = await az(["account", "show", ...subArgs]);
|
|
67
|
+
if (!acct.ok) {
|
|
68
|
+
failure(res, "az", sub ? `Azure subscription ${sub}` : "Azure", acct, "read the signed-in Azure subscription");
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
const subName = String(acct.data?.name ?? acct.data?.id ?? sub ?? "current");
|
|
72
|
+
const tag = `Azure ${subName}`;
|
|
73
|
+
res.notes.push(`Azure subscription ${subName} (${String(acct.data?.id ?? "")}), signed in as ${String(acct.data?.user?.name ?? "unknown")}`);
|
|
74
|
+
log.record("cloud", tag, "az keyvault list: list key vaults");
|
|
75
|
+
const vaults = await az(["keyvault", "list", ...subArgs]);
|
|
76
|
+
if (!vaults.ok)
|
|
77
|
+
failure(res, "az", tag, vaults, "list key vaults");
|
|
78
|
+
let keyCount = 0;
|
|
79
|
+
let certCount = 0;
|
|
80
|
+
const names = list(vaults.ok ? vaults.data : []).map((v) => String(v?.name ?? "")).filter((n) => NAME.test(n));
|
|
81
|
+
await pool(names, o.concurrency, async (vault) => {
|
|
82
|
+
const where = `${tag} key vault ${vault}`;
|
|
83
|
+
log.record("cloud", where, "az keyvault key list: list keys");
|
|
84
|
+
const keys = await az(["keyvault", "key", "list", "--vault-name", vault]);
|
|
85
|
+
if (!keys.ok)
|
|
86
|
+
failure(res, "az", where, keys, "list keys");
|
|
87
|
+
// Keys that back a certificate are listed as managed; the certificate covers them.
|
|
88
|
+
const own = keys.ok ? list(keys.data).filter((k) => k?.managed !== true).map((k) => String(k?.name ?? "")).filter((n) => NAME.test(n)) : [];
|
|
89
|
+
await pool(own, 2, async (name) => {
|
|
90
|
+
const target = `${where} key ${name}`;
|
|
91
|
+
log.record("cloud", target, "az keyvault key show: read the key type and size (public part only)");
|
|
92
|
+
const k = await az(["keyvault", "key", "show", "--vault-name", vault, "--name", name]);
|
|
93
|
+
if (!k.ok)
|
|
94
|
+
return failure(res, "az", target, k, "read the key");
|
|
95
|
+
keyCount++;
|
|
96
|
+
const r = vaultKey(k.data, target);
|
|
97
|
+
push(r.finding, r.strength);
|
|
98
|
+
if (r.inventory)
|
|
99
|
+
res.inventory.push({ ...r.inventory, file: target, line: 0 });
|
|
100
|
+
});
|
|
101
|
+
log.record("cloud", where, "az keyvault certificate list: list certificates");
|
|
102
|
+
const certs = await az(["keyvault", "certificate", "list", "--vault-name", vault]);
|
|
103
|
+
if (!certs.ok)
|
|
104
|
+
return failure(res, "az", where, certs, "list certificates");
|
|
105
|
+
const cnames = list(certs.data).map((c) => String(c?.name ?? "")).filter((n) => NAME.test(n));
|
|
106
|
+
await pool(cnames, 2, async (name) => {
|
|
107
|
+
const target = `${where} certificate ${name}`;
|
|
108
|
+
log.record("cloud", target, "az keyvault certificate show: read the certificate's key type and size");
|
|
109
|
+
const c = await az(["keyvault", "certificate", "show", "--vault-name", vault, "--name", name]);
|
|
110
|
+
if (!c.ok)
|
|
111
|
+
return failure(res, "az", target, c, "read the certificate");
|
|
112
|
+
certCount++;
|
|
113
|
+
push(vaultCert(c.data, target).finding);
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
// A permission problem with one service is reported once for the subscription.
|
|
117
|
+
const denied = new Set();
|
|
118
|
+
const more = await azureServices({
|
|
119
|
+
az: async (target, args, what) => {
|
|
120
|
+
const service = args[0];
|
|
121
|
+
if (denied.has(service))
|
|
122
|
+
return null;
|
|
123
|
+
log.record("cloud", target, `az ${commandOf(args)}: ${what}`);
|
|
124
|
+
const r = await az(args);
|
|
125
|
+
if (r.ok)
|
|
126
|
+
return r.data ?? {};
|
|
127
|
+
if (r.kind === "denied" || r.kind === "signin" || r.kind === "unsupported") {
|
|
128
|
+
if (denied.has(service))
|
|
129
|
+
return null;
|
|
130
|
+
denied.add(service);
|
|
131
|
+
failure(res, "az", `${tag} ${service}`, r, what);
|
|
132
|
+
}
|
|
133
|
+
else
|
|
134
|
+
failure(res, "az", target, r, what);
|
|
135
|
+
return null;
|
|
136
|
+
},
|
|
137
|
+
push: (f) => push(f),
|
|
138
|
+
}, tag, subArgs, o.concurrency);
|
|
139
|
+
const parts = vaults.ok ? [`${names.length} key vault${names.length === 1 ? "" : "s"}`, `${keyCount} key${keyCount === 1 ? "" : "s"}`, `${certCount} certificate${certCount === 1 ? "" : "s"}`] : [];
|
|
140
|
+
if (parts.length || more.length)
|
|
141
|
+
res.result.checked.push(`${tag}: ${[...parts, ...more].join(", ")}`);
|
|
142
|
+
}
|
|
143
|
+
return res;
|
|
144
|
+
}
|