@intentius/chant-lexicon-aws 0.1.1 → 0.1.8
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/integrity.json +40 -34
- package/dist/manifest.json +1 -1
- package/dist/meta.json +3755 -690
- package/dist/rules/waw032.ts +52 -0
- package/dist/rules/waw033.ts +86 -0
- package/dist/rules/waw034.ts +63 -0
- package/dist/rules/waw035.ts +71 -0
- package/dist/rules/waw036.ts +88 -0
- package/dist/rules/waw037.ts +81 -0
- package/dist/types/index.d.ts +5043 -483
- package/package.json +7 -7
- package/src/actions/actions.test.ts +1 -1
- package/src/codegen/__snapshots__/snapshot.test.ts.snap +45 -45
- package/src/codegen/docs-links.test.ts +3 -3
- package/src/codegen/docs.ts +15 -10
- package/src/codegen/generate-cli.ts +2 -2
- package/src/codegen/generate.test.ts +1 -1
- package/src/codegen/idempotency.test.ts +1 -1
- package/src/codegen/package.test.ts +1 -1
- package/src/codegen/package.ts +2 -7
- package/src/codegen/snapshot.test.ts +1 -1
- package/src/codegen/typecheck.test.ts +1 -1
- package/src/composites/composites.test.ts +66 -1
- package/src/composites/ec2-instance-role.ts +39 -0
- package/src/composites/fargate-service.ts +9 -0
- package/src/composites/index.ts +6 -0
- package/src/composites/lambda-function.ts +2 -1
- package/src/composites/minimal-vpc.ts +71 -0
- package/src/composites/solr-fargate-service.ts +42 -0
- package/src/coverage.test.ts +1 -1
- package/src/default-tags.test.ts +1 -1
- package/src/generated/index.d.ts +5043 -483
- package/src/generated/index.ts +392 -46
- package/src/generated/lexicon-aws.json +3755 -690
- package/src/import/generator.test.ts +1 -1
- package/src/import/generator.ts +1 -1
- package/src/import/parser.test.ts +1 -1
- package/src/import/roundtrip-fixtures.test.ts +4 -4
- package/src/import/roundtrip.test.ts +1 -1
- package/src/index.ts +2 -0
- package/src/integration.test.ts +1 -1
- package/src/intrinsics.test.ts +1 -1
- package/src/lint/post-synth/ext001.test.ts +1 -1
- package/src/lint/post-synth/post-synth.test.ts +1 -1
- package/src/lint/post-synth/waw013.test.ts +1 -1
- package/src/lint/post-synth/waw014.test.ts +1 -1
- package/src/lint/post-synth/waw015.test.ts +1 -1
- package/src/lint/post-synth/waw016.test.ts +1 -1
- package/src/lint/post-synth/waw017.test.ts +1 -1
- package/src/lint/post-synth/waw018.test.ts +1 -1
- package/src/lint/post-synth/waw019.test.ts +1 -1
- package/src/lint/post-synth/waw020.test.ts +1 -1
- package/src/lint/post-synth/waw021.test.ts +1 -1
- package/src/lint/post-synth/waw022.test.ts +1 -1
- package/src/lint/post-synth/waw023.test.ts +1 -1
- package/src/lint/post-synth/waw024.test.ts +1 -1
- package/src/lint/post-synth/waw025.test.ts +1 -1
- package/src/lint/post-synth/waw026.test.ts +1 -1
- package/src/lint/post-synth/waw027.test.ts +1 -1
- package/src/lint/post-synth/waw028.test.ts +1 -1
- package/src/lint/post-synth/waw029.test.ts +1 -1
- package/src/lint/post-synth/waw030.test.ts +1 -1
- package/src/lint/post-synth/waw031.test.ts +1 -1
- package/src/lint/post-synth/waw032.test.ts +83 -0
- package/src/lint/post-synth/waw032.ts +52 -0
- package/src/lint/post-synth/waw033.test.ts +68 -0
- package/src/lint/post-synth/waw033.ts +86 -0
- package/src/lint/post-synth/waw034.test.ts +54 -0
- package/src/lint/post-synth/waw034.ts +63 -0
- package/src/lint/post-synth/waw035.test.ts +74 -0
- package/src/lint/post-synth/waw035.ts +71 -0
- package/src/lint/post-synth/waw036.test.ts +217 -0
- package/src/lint/post-synth/waw036.ts +88 -0
- package/src/lint/post-synth/waw037.test.ts +155 -0
- package/src/lint/post-synth/waw037.ts +81 -0
- package/src/lint/rules/rules.test.ts +1 -1
- package/src/lsp/completions.test.ts +1 -1
- package/src/lsp/hover.test.ts +1 -1
- package/src/nested-stack-integration.test.ts +2 -2
- package/src/nested-stack.test.ts +1 -1
- package/src/package-cli.ts +3 -3
- package/src/plugin.test.ts +5 -5
- package/src/plugin.ts +6 -6
- package/src/pseudo.test.ts +1 -1
- package/src/serializer.test.ts +1 -1
- package/src/spec/fetch.test.ts +1 -1
- package/src/spec/parse.test.ts +1 -1
- package/src/spec/parse.ts +6 -0
- package/src/validate-cli.ts +2 -2
- package/src/validate.test.ts +1 -1
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WAW032: EFS Transit Encryption Disabled
|
|
3
|
+
*
|
|
4
|
+
* Flags EFS volume configurations on Fargate task definitions where transit
|
|
5
|
+
* encryption has been explicitly disabled. FargateService defaults to ENABLED;
|
|
6
|
+
* this rule catches intentional opt-outs.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import type { PostSynthCheck, PostSynthContext, PostSynthDiagnostic } from "@intentius/chant/lint/post-synth";
|
|
10
|
+
import { parseCFTemplate } from "./cf-refs";
|
|
11
|
+
|
|
12
|
+
export function checkEfsTransitEncryption(ctx: PostSynthContext): PostSynthDiagnostic[] {
|
|
13
|
+
const diagnostics: PostSynthDiagnostic[] = [];
|
|
14
|
+
|
|
15
|
+
for (const [_lexicon, output] of ctx.outputs) {
|
|
16
|
+
const template = parseCFTemplate(output);
|
|
17
|
+
if (!template?.Resources) continue;
|
|
18
|
+
|
|
19
|
+
for (const [logicalId, resource] of Object.entries(template.Resources)) {
|
|
20
|
+
if (resource.Type !== "AWS::ECS::TaskDefinition") continue;
|
|
21
|
+
|
|
22
|
+
const volumes = resource.Properties?.Volumes;
|
|
23
|
+
if (!Array.isArray(volumes)) continue;
|
|
24
|
+
|
|
25
|
+
for (const volume of volumes) {
|
|
26
|
+
const efsConfig = volume?.EFSVolumeConfiguration;
|
|
27
|
+
if (!efsConfig) continue;
|
|
28
|
+
|
|
29
|
+
if (efsConfig.TransitEncryption === "DISABLED") {
|
|
30
|
+
diagnostics.push({
|
|
31
|
+
checkId: "WAW032",
|
|
32
|
+
severity: "warning",
|
|
33
|
+
message: `EFS volume "${volume.Name ?? "unnamed"}" in task "${logicalId}" has transit encryption disabled — set TransitEncryption: ENABLED to protect data in transit`,
|
|
34
|
+
entity: logicalId,
|
|
35
|
+
lexicon: "aws",
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return diagnostics;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export const waw032: PostSynthCheck = {
|
|
46
|
+
id: "WAW032",
|
|
47
|
+
description: "EFS volume on Fargate task has transit encryption disabled",
|
|
48
|
+
|
|
49
|
+
check(ctx: PostSynthContext): PostSynthDiagnostic[] {
|
|
50
|
+
return checkEfsTransitEncryption(ctx);
|
|
51
|
+
},
|
|
52
|
+
};
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WAW033: Solr Heap Exceeds 50% of Container Memory
|
|
3
|
+
*
|
|
4
|
+
* When SOLR_HEAP is set on a Fargate task running a Solr image, validates that
|
|
5
|
+
* the heap does not exceed 50% of the task's allocated memory. Exceeding this
|
|
6
|
+
* leaves insufficient headroom for the OS file cache that Lucene MMap relies on,
|
|
7
|
+
* causing the OOM killer to terminate the container.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { PostSynthCheck, PostSynthContext, PostSynthDiagnostic } from "@intentius/chant/lint/post-synth";
|
|
11
|
+
import { parseCFTemplate } from "./cf-refs";
|
|
12
|
+
|
|
13
|
+
/** Parse heap strings like "4g", "2048m", "2048" → megabytes */
|
|
14
|
+
function parseHeapMb(value: string): number | null {
|
|
15
|
+
const lower = value.trim().toLowerCase();
|
|
16
|
+
const gMatch = lower.match(/^(\d+(?:\.\d+)?)g$/);
|
|
17
|
+
if (gMatch) return Math.round(parseFloat(gMatch[1]) * 1024);
|
|
18
|
+
const mMatch = lower.match(/^(\d+(?:\.\d+)?)m?$/);
|
|
19
|
+
if (mMatch) return Math.round(parseFloat(mMatch[1]));
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function isSolrImage(image: unknown): boolean {
|
|
24
|
+
return typeof image === "string" && image.toLowerCase().includes("solr");
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function checkSolrHeapRatio(ctx: PostSynthContext): PostSynthDiagnostic[] {
|
|
28
|
+
const diagnostics: PostSynthDiagnostic[] = [];
|
|
29
|
+
|
|
30
|
+
for (const [_lexicon, output] of ctx.outputs) {
|
|
31
|
+
const template = parseCFTemplate(output);
|
|
32
|
+
if (!template?.Resources) continue;
|
|
33
|
+
|
|
34
|
+
for (const [logicalId, resource] of Object.entries(template.Resources)) {
|
|
35
|
+
if (resource.Type !== "AWS::ECS::TaskDefinition") continue;
|
|
36
|
+
|
|
37
|
+
const props = resource.Properties ?? {};
|
|
38
|
+
if (typeof props.Memory !== "string") continue;
|
|
39
|
+
const taskMemoryMb = parseInt(props.Memory);
|
|
40
|
+
if (!taskMemoryMb) continue;
|
|
41
|
+
|
|
42
|
+
const containers: unknown[] = Array.isArray(props.ContainerDefinitions)
|
|
43
|
+
? props.ContainerDefinitions
|
|
44
|
+
: [];
|
|
45
|
+
|
|
46
|
+
for (const container of containers) {
|
|
47
|
+
if (typeof container !== "object" || container === null) continue;
|
|
48
|
+
const c = container as Record<string, unknown>;
|
|
49
|
+
|
|
50
|
+
if (!isSolrImage(c.Image)) continue;
|
|
51
|
+
|
|
52
|
+
const envVars: unknown[] = Array.isArray(c.Environment) ? c.Environment : [];
|
|
53
|
+
const heapEntry = envVars.find(
|
|
54
|
+
(e): e is Record<string, unknown> =>
|
|
55
|
+
typeof e === "object" && e !== null && (e as Record<string, unknown>).Name === "SOLR_HEAP",
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
if (!heapEntry) continue; // WAW034 covers missing heap
|
|
59
|
+
|
|
60
|
+
const heapMb = parseHeapMb(String(heapEntry.Value ?? ""));
|
|
61
|
+
if (heapMb === null) continue;
|
|
62
|
+
|
|
63
|
+
if (heapMb > taskMemoryMb * 0.5) {
|
|
64
|
+
diagnostics.push({
|
|
65
|
+
checkId: "WAW033",
|
|
66
|
+
severity: "error",
|
|
67
|
+
message: `Solr container "${c.Name ?? "app"}" SOLR_HEAP (${heapMb}MB) exceeds 50% of task memory (${taskMemoryMb}MB) — risk of OOM kill; set SOLR_HEAP <= ${Math.floor(taskMemoryMb * 0.45)}m`,
|
|
68
|
+
entity: logicalId,
|
|
69
|
+
lexicon: "aws",
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return diagnostics;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export const waw033: PostSynthCheck = {
|
|
80
|
+
id: "WAW033",
|
|
81
|
+
description: "Solr SOLR_HEAP exceeds 50% of Fargate task memory",
|
|
82
|
+
|
|
83
|
+
check(ctx: PostSynthContext): PostSynthDiagnostic[] {
|
|
84
|
+
return checkSolrHeapRatio(ctx);
|
|
85
|
+
},
|
|
86
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WAW034: Solr Container Undersized
|
|
3
|
+
*
|
|
4
|
+
* Fargate tasks running a Solr image with less than 2048MB of memory will
|
|
5
|
+
* fail under any real load — the JVM alone needs headroom for the heap plus
|
|
6
|
+
* OS file cache for Lucene MMap. 4096MB is the practical production minimum.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import type { PostSynthCheck, PostSynthContext, PostSynthDiagnostic } from "@intentius/chant/lint/post-synth";
|
|
10
|
+
import { parseCFTemplate } from "./cf-refs";
|
|
11
|
+
|
|
12
|
+
function isSolrImage(image: unknown): boolean {
|
|
13
|
+
return typeof image === "string" && image.toLowerCase().includes("solr");
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function checkSolrMemoryMinimum(ctx: PostSynthContext): PostSynthDiagnostic[] {
|
|
17
|
+
const diagnostics: PostSynthDiagnostic[] = [];
|
|
18
|
+
|
|
19
|
+
for (const [_lexicon, output] of ctx.outputs) {
|
|
20
|
+
const template = parseCFTemplate(output);
|
|
21
|
+
if (!template?.Resources) continue;
|
|
22
|
+
|
|
23
|
+
for (const [logicalId, resource] of Object.entries(template.Resources)) {
|
|
24
|
+
if (resource.Type !== "AWS::ECS::TaskDefinition") continue;
|
|
25
|
+
|
|
26
|
+
const props = resource.Properties ?? {};
|
|
27
|
+
if (typeof props.Memory !== "string") continue;
|
|
28
|
+
const taskMemoryMb = parseInt(props.Memory);
|
|
29
|
+
if (!taskMemoryMb) continue;
|
|
30
|
+
|
|
31
|
+
const containers: unknown[] = Array.isArray(props.ContainerDefinitions)
|
|
32
|
+
? props.ContainerDefinitions
|
|
33
|
+
: [];
|
|
34
|
+
|
|
35
|
+
const hasSolr = containers.some(
|
|
36
|
+
(c) => typeof c === "object" && c !== null && isSolrImage((c as Record<string, unknown>).Image),
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
if (!hasSolr) continue;
|
|
40
|
+
|
|
41
|
+
if (taskMemoryMb < 2048) {
|
|
42
|
+
diagnostics.push({
|
|
43
|
+
checkId: "WAW034",
|
|
44
|
+
severity: "warning",
|
|
45
|
+
message: `Solr task "${logicalId}" has only ${taskMemoryMb}MB memory — Solr requires at least 2048MB; 4096MB recommended for production`,
|
|
46
|
+
entity: logicalId,
|
|
47
|
+
lexicon: "aws",
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return diagnostics;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export const waw034: PostSynthCheck = {
|
|
57
|
+
id: "WAW034",
|
|
58
|
+
description: "Fargate task running Solr has insufficient memory (< 2048MB)",
|
|
59
|
+
|
|
60
|
+
check(ctx: PostSynthContext): PostSynthDiagnostic[] {
|
|
61
|
+
return checkSolrMemoryMinimum(ctx);
|
|
62
|
+
},
|
|
63
|
+
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WAW035: Solr Container Missing nofile Ulimit
|
|
3
|
+
*
|
|
4
|
+
* Solr opens a file descriptor for every shard replica, index file, log, and
|
|
5
|
+
* connection. Without a raised nofile limit the process hits the default kernel
|
|
6
|
+
* limit (~1024) under moderate load, causing "Too many open files" errors that
|
|
7
|
+
* bring the node down. The production minimum is 65535.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { PostSynthCheck, PostSynthContext, PostSynthDiagnostic } from "@intentius/chant/lint/post-synth";
|
|
11
|
+
import { parseCFTemplate } from "./cf-refs";
|
|
12
|
+
|
|
13
|
+
const NOFILE_MIN = 65535;
|
|
14
|
+
|
|
15
|
+
function isSolrImage(image: unknown): boolean {
|
|
16
|
+
return typeof image === "string" && image.toLowerCase().includes("solr");
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function checkSolrUlimits(ctx: PostSynthContext): PostSynthDiagnostic[] {
|
|
20
|
+
const diagnostics: PostSynthDiagnostic[] = [];
|
|
21
|
+
|
|
22
|
+
for (const [_lexicon, output] of ctx.outputs) {
|
|
23
|
+
const template = parseCFTemplate(output);
|
|
24
|
+
if (!template?.Resources) continue;
|
|
25
|
+
|
|
26
|
+
for (const [logicalId, resource] of Object.entries(template.Resources)) {
|
|
27
|
+
if (resource.Type !== "AWS::ECS::TaskDefinition") continue;
|
|
28
|
+
|
|
29
|
+
const containers: unknown[] = Array.isArray(resource.Properties?.ContainerDefinitions)
|
|
30
|
+
? resource.Properties.ContainerDefinitions
|
|
31
|
+
: [];
|
|
32
|
+
|
|
33
|
+
for (const container of containers) {
|
|
34
|
+
if (typeof container !== "object" || container === null) continue;
|
|
35
|
+
const c = container as Record<string, unknown>;
|
|
36
|
+
|
|
37
|
+
if (!isSolrImage(c.Image)) continue;
|
|
38
|
+
|
|
39
|
+
const ulimits: unknown[] = Array.isArray(c.Ulimits) ? c.Ulimits : [];
|
|
40
|
+
const nofile = ulimits.find(
|
|
41
|
+
(u): u is Record<string, unknown> =>
|
|
42
|
+
typeof u === "object" && u !== null && (u as Record<string, unknown>).Name === "nofile",
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
const hardLimit = nofile ? Number(nofile.HardLimit ?? 0) : 0;
|
|
46
|
+
|
|
47
|
+
if (!nofile || hardLimit < NOFILE_MIN) {
|
|
48
|
+
const current = nofile ? ` (current HardLimit: ${hardLimit})` : " (not set)";
|
|
49
|
+
diagnostics.push({
|
|
50
|
+
checkId: "WAW035",
|
|
51
|
+
severity: "warning",
|
|
52
|
+
message: `Solr container "${c.Name ?? "app"}" in task "${logicalId}" nofile ulimit${current} — set HardLimit >= ${NOFILE_MIN} to prevent "Too many open files" under load`,
|
|
53
|
+
entity: logicalId,
|
|
54
|
+
lexicon: "aws",
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return diagnostics;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export const waw035: PostSynthCheck = {
|
|
65
|
+
id: "WAW035",
|
|
66
|
+
description: "Solr container missing nofile ulimit >= 65535",
|
|
67
|
+
|
|
68
|
+
check(ctx: PostSynthContext): PostSynthDiagnostic[] {
|
|
69
|
+
return checkSolrUlimits(ctx);
|
|
70
|
+
},
|
|
71
|
+
};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WAW036: Non-ASCII Characters in EC2/IAM String Properties
|
|
3
|
+
*
|
|
4
|
+
* EC2, IAM, CloudWatch, and other AWS services only accept ASCII 0x20–0x7E in
|
|
5
|
+
* description, name, and label fields. Non-ASCII characters (em-dashes, curly
|
|
6
|
+
* quotes, accented letters, etc.) cause the changeset to fail at EarlyValidation
|
|
7
|
+
* with an opaque "Invalid parameter" error that doesn't name the offending property.
|
|
8
|
+
*
|
|
9
|
+
* Properties checked (all must be plain ASCII strings):
|
|
10
|
+
* - AWS::EC2::SecurityGroup GroupDescription
|
|
11
|
+
* - AWS::EC2::LaunchTemplate LaunchTemplateName
|
|
12
|
+
* - AWS::IAM::Role RoleName
|
|
13
|
+
* - AWS::Lambda::Function FunctionName
|
|
14
|
+
* - AWS::RDS::DBSubnetGroup DBSubnetGroupDescription
|
|
15
|
+
* - AWS::CloudWatch::Alarm AlarmDescription, AlarmName
|
|
16
|
+
* - AWS::AutoScaling::AutoScalingGroup AutoScalingGroupName
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import type { PostSynthCheck, PostSynthContext, PostSynthDiagnostic } from "@intentius/chant/lint/post-synth";
|
|
20
|
+
import { parseCFTemplate } from "./cf-refs";
|
|
21
|
+
|
|
22
|
+
/** Map of CFN resource type → list of property names that must be ASCII-only. */
|
|
23
|
+
const ASCII_REQUIRED: Record<string, string[]> = {
|
|
24
|
+
"AWS::EC2::SecurityGroup": ["GroupDescription"],
|
|
25
|
+
"AWS::EC2::LaunchTemplate": ["LaunchTemplateName"],
|
|
26
|
+
"AWS::IAM::Role": ["RoleName"],
|
|
27
|
+
"AWS::Lambda::Function": ["FunctionName"],
|
|
28
|
+
"AWS::RDS::DBSubnetGroup": ["DBSubnetGroupDescription"],
|
|
29
|
+
"AWS::CloudWatch::Alarm": ["AlarmDescription", "AlarmName"],
|
|
30
|
+
"AWS::AutoScaling::AutoScalingGroup": ["AutoScalingGroupName"],
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/** Return true if the string contains any character outside ASCII printable range (0x20–0x7E). */
|
|
34
|
+
function hasNonAscii(s: string): boolean {
|
|
35
|
+
for (let i = 0; i < s.length; i++) {
|
|
36
|
+
const code = s.charCodeAt(i);
|
|
37
|
+
if (code < 0x20 || code > 0x7e) return true;
|
|
38
|
+
}
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function checkNonAsciiProps(ctx: PostSynthContext): PostSynthDiagnostic[] {
|
|
43
|
+
const diagnostics: PostSynthDiagnostic[] = [];
|
|
44
|
+
|
|
45
|
+
for (const [_lexicon, output] of ctx.outputs) {
|
|
46
|
+
const template = parseCFTemplate(output);
|
|
47
|
+
if (!template?.Resources) continue;
|
|
48
|
+
|
|
49
|
+
for (const [logicalId, resource] of Object.entries(template.Resources)) {
|
|
50
|
+
const propsToCheck = ASCII_REQUIRED[resource.Type];
|
|
51
|
+
if (!propsToCheck) continue;
|
|
52
|
+
|
|
53
|
+
const props = resource.Properties ?? {};
|
|
54
|
+
|
|
55
|
+
for (const propName of propsToCheck) {
|
|
56
|
+
const value = props[propName];
|
|
57
|
+
if (typeof value !== "string") continue;
|
|
58
|
+
if (!hasNonAscii(value)) continue;
|
|
59
|
+
|
|
60
|
+
// Find the specific offending characters for the message.
|
|
61
|
+
const badChars = [...new Set([...value].filter((c) => {
|
|
62
|
+
const code = c.charCodeAt(0);
|
|
63
|
+
return code < 0x20 || code > 0x7e;
|
|
64
|
+
}))];
|
|
65
|
+
const charList = badChars.map((c) => `U+${c.charCodeAt(0).toString(16).toUpperCase().padStart(4, "0")}`).join(", ");
|
|
66
|
+
|
|
67
|
+
diagnostics.push({
|
|
68
|
+
checkId: "WAW036",
|
|
69
|
+
severity: "error",
|
|
70
|
+
message: `${resource.Type} "${logicalId}" property "${propName}" contains non-ASCII characters (${charList}) — AWS rejects these at changeset validation time`,
|
|
71
|
+
entity: logicalId,
|
|
72
|
+
lexicon: "aws",
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return diagnostics;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export const waw036: PostSynthCheck = {
|
|
82
|
+
id: "WAW036",
|
|
83
|
+
description: "Non-ASCII characters in EC2/IAM/CW string properties — rejected at changeset time",
|
|
84
|
+
|
|
85
|
+
check(ctx: PostSynthContext): PostSynthDiagnostic[] {
|
|
86
|
+
return checkNonAsciiProps(ctx);
|
|
87
|
+
},
|
|
88
|
+
};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WAW037: Null Values in CloudFormation Resource Properties
|
|
3
|
+
*
|
|
4
|
+
* `resource.PropName` where PropName is not a real GetAtt attribute returns null
|
|
5
|
+
* silently in chant's AttrRef system — the TypeScript types say `string` but the
|
|
6
|
+
* runtime value is null. This produces a template with literal null values that
|
|
7
|
+
* CloudFormation rejects at changeset time with an unhelpful "Invalid template"
|
|
8
|
+
* error.
|
|
9
|
+
*
|
|
10
|
+
* Common causes:
|
|
11
|
+
* - `resource.SomeId` instead of `Ref(resource)` (use Ref for the primary identifier)
|
|
12
|
+
* - `resource.SomeProp` where SomeProp is not listed in AWS CloudFormation GetAtt docs
|
|
13
|
+
* - Typo in an attribute name (e.g. `resource.GroupName` vs `resource.GroupId`)
|
|
14
|
+
*
|
|
15
|
+
* This check scans every resource's Properties for null values at any depth and
|
|
16
|
+
* reports the logical resource ID and dotted property path.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import type { PostSynthCheck, PostSynthContext, PostSynthDiagnostic } from "@intentius/chant/lint/post-synth";
|
|
20
|
+
import { parseCFTemplate } from "./cf-refs";
|
|
21
|
+
|
|
22
|
+
interface NullLocation {
|
|
23
|
+
logicalId: string;
|
|
24
|
+
path: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Recursively collect all paths where the value is null. */
|
|
28
|
+
function collectNullPaths(value: unknown, path: string, results: NullLocation[], logicalId: string): void {
|
|
29
|
+
if (value === null) {
|
|
30
|
+
results.push({ logicalId, path });
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
if (Array.isArray(value)) {
|
|
34
|
+
for (let i = 0; i < value.length; i++) {
|
|
35
|
+
collectNullPaths(value[i], `${path}[${i}]`, results, logicalId);
|
|
36
|
+
}
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
if (typeof value === "object") {
|
|
40
|
+
for (const [k, v] of Object.entries(value as Record<string, unknown>)) {
|
|
41
|
+
collectNullPaths(v, path ? `${path}.${k}` : k, results, logicalId);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function checkNullProperties(ctx: PostSynthContext): PostSynthDiagnostic[] {
|
|
47
|
+
const diagnostics: PostSynthDiagnostic[] = [];
|
|
48
|
+
|
|
49
|
+
for (const [_lexicon, output] of ctx.outputs) {
|
|
50
|
+
const template = parseCFTemplate(output);
|
|
51
|
+
if (!template?.Resources) continue;
|
|
52
|
+
|
|
53
|
+
for (const [logicalId, resource] of Object.entries(template.Resources)) {
|
|
54
|
+
if (!resource.Properties) continue;
|
|
55
|
+
|
|
56
|
+
const nullLocations: NullLocation[] = [];
|
|
57
|
+
collectNullPaths(resource.Properties, "", nullLocations, logicalId);
|
|
58
|
+
|
|
59
|
+
for (const loc of nullLocations) {
|
|
60
|
+
diagnostics.push({
|
|
61
|
+
checkId: "WAW037",
|
|
62
|
+
severity: "error",
|
|
63
|
+
message: `${resource.Type} "${logicalId}" has a null value at Properties.${loc.path} — likely a .PropName AttrRef on a non-existent GetAtt attribute. Use Ref(resource) for the primary identifier, or check the attribute name.`,
|
|
64
|
+
entity: logicalId,
|
|
65
|
+
lexicon: "aws",
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return diagnostics;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export const waw037: PostSynthCheck = {
|
|
75
|
+
id: "WAW037",
|
|
76
|
+
description: "Null values in CFN resource properties — caused by invalid AttrRef (.PropName) usage",
|
|
77
|
+
|
|
78
|
+
check(ctx: PostSynthContext): PostSynthDiagnostic[] {
|
|
79
|
+
return checkNullProperties(ctx);
|
|
80
|
+
},
|
|
81
|
+
};
|