@intentius/chant-lexicon-aws 0.0.14 → 0.0.15

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.
@@ -10,6 +10,8 @@
10
10
  * - API Gateway V2 Deployment with no DependsOn on any Route
11
11
  * - DynamoDB ScalableTarget with no DependsOn on the Table
12
12
  * - ECS ScalableTarget with no DependsOn on the ECS Service
13
+ * - EKS Addon with hardcoded ClusterName but no DependsOn on the Cluster or Nodegroup
14
+ * - EKS Nodegroup with hardcoded ClusterName but no DependsOn on the Cluster
13
15
  */
14
16
 
15
17
  import type { PostSynthCheck, PostSynthContext, PostSynthDiagnostic } from "@intentius/chant/lint/post-synth";
@@ -34,6 +36,9 @@ export function checkMissingDependsOn(ctx: PostSynthContext): PostSynthDiagnosti
34
36
  const dynamoTableIds: string[] = [];
35
37
  const ecsServiceIds: string[] = [];
36
38
  const scalableTargetEntries: { logicalId: string; namespace: string }[] = [];
39
+ const eksClusterIds: string[] = [];
40
+ const eksNodegroupIds: string[] = [];
41
+ const eksAddonIds: string[] = [];
37
42
 
38
43
  for (const [logicalId, resource] of Object.entries(resources)) {
39
44
  if (resource.Type === "AWS::ElasticLoadBalancingV2::Listener") {
@@ -60,6 +65,15 @@ export function checkMissingDependsOn(ctx: PostSynthContext): PostSynthDiagnosti
60
65
  if (resource.Type === "AWS::ECS::Service") {
61
66
  ecsServiceIds.push(logicalId);
62
67
  }
68
+ if (resource.Type === "AWS::EKS::Cluster") {
69
+ eksClusterIds.push(logicalId);
70
+ }
71
+ if (resource.Type === "AWS::EKS::Nodegroup") {
72
+ eksNodegroupIds.push(logicalId);
73
+ }
74
+ if (resource.Type === "AWS::EKS::Addon") {
75
+ eksAddonIds.push(logicalId);
76
+ }
63
77
  if (resource.Type === "AWS::ApplicationAutoScaling::ScalableTarget") {
64
78
  const props = resource.Properties ?? {};
65
79
  const ns = inferScalingNamespace(props);
@@ -144,6 +158,47 @@ export function checkMissingDependsOn(ctx: PostSynthContext): PostSynthDiagnosti
144
158
  }
145
159
  }
146
160
 
161
+ // Pattern 7: EKS Addon with hardcoded ClusterName but no dependency on Cluster or Nodegroup
162
+ for (const addonId of eksAddonIds) {
163
+ const resource = resources[addonId];
164
+ const deps = getDependsOnSet(resource);
165
+ const propRefs = collectPropertyRefs(resource);
166
+ const allClusterAndNodeDeps = [...eksClusterIds, ...eksNodegroupIds];
167
+
168
+ const hasClusterDep = allClusterAndNodeDeps.some((id) => deps.has(id));
169
+ const hasClusterRef = allClusterAndNodeDeps.some((id) => propRefs.has(id));
170
+
171
+ if (!hasClusterDep && !hasClusterRef && eksClusterIds.length > 0) {
172
+ diagnostics.push({
173
+ checkId: "WAW030",
174
+ severity: "warning",
175
+ message: `EKS Addon "${addonId}" has no dependency on the Cluster or Nodegroup — the addon may fail if the cluster or nodes aren't ready yet. Add DependsOn.`,
176
+ entity: addonId,
177
+ lexicon: "aws",
178
+ });
179
+ }
180
+ }
181
+
182
+ // Pattern 8: EKS Nodegroup with hardcoded ClusterName but no dependency on Cluster
183
+ for (const ngId of eksNodegroupIds) {
184
+ const resource = resources[ngId];
185
+ const deps = getDependsOnSet(resource);
186
+ const propRefs = collectPropertyRefs(resource);
187
+
188
+ const hasClusterDep = eksClusterIds.some((id) => deps.has(id));
189
+ const hasClusterRef = eksClusterIds.some((id) => propRefs.has(id));
190
+
191
+ if (!hasClusterDep && !hasClusterRef && eksClusterIds.length > 0) {
192
+ diagnostics.push({
193
+ checkId: "WAW030",
194
+ severity: "warning",
195
+ message: `EKS Nodegroup "${ngId}" has no dependency on the Cluster — the node group may fail if the cluster isn't ready yet. Add DependsOn.`,
196
+ entity: ngId,
197
+ lexicon: "aws",
198
+ });
199
+ }
200
+ }
201
+
147
202
  // Pattern 5 & 6: ScalableTarget with no DependsOn on the target resource
148
203
  for (const entry of scalableTargetEntries) {
149
204
  const resource = resources[entry.logicalId];
@@ -0,0 +1,66 @@
1
+ /**
2
+ * WAW031: EKS Addon Missing ServiceAccountRoleArn
3
+ *
4
+ * Certain EKS addons require a ServiceAccountRoleArn (IRSA role) to function.
5
+ * Without one, the addon pods can't authenticate to AWS APIs and the addon
6
+ * hangs in CREATING status indefinitely.
7
+ *
8
+ * Known addons that require IRSA:
9
+ * - aws-ebs-csi-driver (needs EBS API access)
10
+ * - aws-efs-csi-driver (needs EFS API access)
11
+ * - adot (needs CloudWatch/X-Ray access)
12
+ * - amazon-cloudwatch-observability (needs CloudWatch access)
13
+ */
14
+
15
+ import type { PostSynthCheck, PostSynthContext, PostSynthDiagnostic } from "@intentius/chant/lint/post-synth";
16
+ import { parseCFTemplate } from "./cf-refs";
17
+
18
+ /** Addons that are known to require a ServiceAccountRoleArn to function. */
19
+ const ADDONS_REQUIRING_IRSA: Record<string, string> = {
20
+ "aws-ebs-csi-driver": "EBS API access to manage volumes",
21
+ "aws-efs-csi-driver": "EFS API access to manage file systems",
22
+ "adot": "CloudWatch/X-Ray access for metrics and traces",
23
+ "amazon-cloudwatch-observability": "CloudWatch access for logs and metrics",
24
+ };
25
+
26
+ export function checkAddonMissingRole(ctx: PostSynthContext): PostSynthDiagnostic[] {
27
+ const diagnostics: PostSynthDiagnostic[] = [];
28
+
29
+ for (const [_lexicon, output] of ctx.outputs) {
30
+ const template = parseCFTemplate(output);
31
+ if (!template?.Resources) continue;
32
+
33
+ for (const [logicalId, resource] of Object.entries(template.Resources)) {
34
+ if (resource.Type !== "AWS::EKS::Addon") continue;
35
+
36
+ const props = resource.Properties ?? {};
37
+ const addonName = typeof props.AddonName === "string" ? props.AddonName : null;
38
+ if (!addonName) continue;
39
+
40
+ const reason = ADDONS_REQUIRING_IRSA[addonName];
41
+ if (!reason) continue;
42
+
43
+ // Check if ServiceAccountRoleArn is set (could be a string, Ref, or GetAtt)
44
+ if (!props.ServiceAccountRoleArn) {
45
+ diagnostics.push({
46
+ checkId: "WAW031",
47
+ severity: "warning",
48
+ message: `EKS Addon "${logicalId}" (${addonName}) has no ServiceAccountRoleArn — it needs an IRSA role for ${reason}. Without it, the addon will hang in CREATING status.`,
49
+ entity: logicalId,
50
+ lexicon: "aws",
51
+ });
52
+ }
53
+ }
54
+ }
55
+
56
+ return diagnostics;
57
+ }
58
+
59
+ export const waw031: PostSynthCheck = {
60
+ id: "WAW031",
61
+ description: "EKS Addon missing ServiceAccountRoleArn for addons that require IRSA",
62
+
63
+ check(ctx: PostSynthContext): PostSynthDiagnostic[] {
64
+ return checkAddonMissingRole(ctx);
65
+ },
66
+ };