Skip to content

Commit a546067

Browse files
committed
Accept freeform tags, exit early on snooze, use cluster name instead of ARN
1 parent 489ac6e commit a546067

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed
-4 Bytes
Binary file not shown.

maintenance-calendar/modules/ecs_scans/lambda/src/ignore.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ const clusterSnoozed = async (
129129
const snoozeDate = LocalDate.parse(snooze.snoozeUntil)
130130
.atStartOfDay()
131131
.atZone(ZoneId.of("UTC"));
132-
if (snooze.cluster === cluster && snoozeDate.isAfter(today)) {
132+
if (cluster.includes(snooze.cluster) && snoozeDate.isAfter(today)) {
133133
logger.debug(
134134
`Cluster: ${snooze.cluster} is snoozed until: ${snoozeDate}. It is now: ${today}`,
135135
);

maintenance-calendar/modules/ecs_scans/lambda/src/index.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,7 @@ const parseImageURI = async (
164164
logger: pino.Logger,
165165
uri: string,
166166
): Promise<ImageDescriptor> => {
167-
const match = uri.match(
168-
/\/([A-Za-z0-9_-]+).(sha256:[A-Fa-f0-9]{64}|[A-Fa-f0-9]{40})$/,
169-
);
167+
const match = uri.match(/\.amazonaws\.com\/([A-Za-z0-9_-]+):(.+)$/);
170168

171169
if (
172170
match === null ||
@@ -175,13 +173,14 @@ const parseImageURI = async (
175173
) {
176174
// If match is an array, 1 and 2 will always be strings, but typescript
177175
// doesn't know that.
176+
logger.fatal(`Attempted to parse URI: ${uri}`);
178177
throw new Error("Unable to parse ECR Image URI.");
179178
}
180179
const repo = match[1];
181180
const imageID = match[2];
182181

183182
// 64 character hash + 'sha256: = 71'
184-
if (imageID.length === 71) {
183+
if (imageID.length === 71 && imageID.includes("sha256:")) {
185184
logger.debug(`We got a digest in the image URI: ${imageID}`);
186185

187186
return {
@@ -190,7 +189,7 @@ const parseImageURI = async (
190189
imageDigest: imageID,
191190
},
192191
};
193-
} else if (imageID.length === 40) {
192+
} else {
194193
logger.debug(`We got a tag in the image URI: ${imageID}`);
195194

196195
const input = {
@@ -217,8 +216,6 @@ const parseImageURI = async (
217216
imageTag: imageID,
218217
},
219218
};
220-
} else {
221-
throw new Error("Something went wrong with our regex");
222219
}
223220
};
224221

@@ -315,12 +312,9 @@ const scanNeedsAlert = async (
315312

316313
if (await isFindingIgnored(finding)) {
317314
logger.debug(`Ignoring vulnerability '${finding.name}'`);
318-
} else if (await isClusterSnoozed(cluster)) {
319-
logger.debug(`Cluster '${cluster}' has been snoozed. Skipping alert`);
320315
} else {
321316
// There was a vulnerability >= our alert level that was not ignored.
322317
logger.debug(`Found open vulnerability '${finding.name}'.`);
323-
324318
return true;
325319
}
326320
}
@@ -400,6 +394,12 @@ const handler: Handler<Input, void> = async (
400394
});
401395
const { ERROR_TOPIC_ARN, ALERT_SEVERITY_LEVEL } = getEnv();
402396

397+
// Check if the cluster is snoozed before doing anything else
398+
if (await isClusterSnoozed(cluster)) {
399+
logger.debug(`Cluster '${cluster}' has been snoozed. Skipping it`);
400+
return;
401+
}
402+
403403
const now = new Date();
404404
const alertLevel = ALERT_SEVERITY_LEVEL;
405405
const images = await getContainerImages(ecs, cluster, logger);

0 commit comments

Comments
 (0)