Open achave11-ucsc opened 1 year ago
I found two notifications for the same finding (matched by the findingArn
), posted to our SNS topic about 15 hours apart.
The only differences found between the two JSON are the event ID and date related fields:
(.venv) daniel@Crispin ~/Library/Application Support/JetBrains/PyCharm2023.1/scratches $ diff scratch_96.json scratch_97.json
5c5
< "id": "41f4792e-e860-8666-6dd7-a15742fdcf0b",
---
> "id": "eec1bcd1-91b3-7b34-cd5a-d14142589a30",
9c9
< "time": "2023-10-13T09:43:50Z",
---
> "time": "2023-10-14T01:01:52Z",
35c35
< "lastObservedAt": "Oct 13, 2023, 9:43:50 AM",
---
> "lastObservedAt": "Oct 14, 2023, 1:01:52 AM",
59c59
< "vendorCreatedAt": "Jan 10, 2022, 2:12:00 PM",
---
> "vendorCreatedAt": "Jan 10, 2022, 2:12:56 PM",
61c61
< "vendorUpdatedAt": "Oct 6, 2022, 3:29:00 PM",
---
> "vendorUpdatedAt": "Oct 6, 2022, 3:29:48 PM",
107c107
< "updatedAt": "Oct 13, 2023, 9:43:50 AM"
---
> "updatedAt": "Oct 14, 2023, 1:01:52 AM"
(.venv) daniel@Crispin ~/Library/Application Support/JetBrains/PyCharm2023.1/scratches $
From AWS documentation, it appears that the vendorCreatedAt
and vendorUpdatedAt
differences caused the re-notification about this finding.
https://docs.aws.amazon.com/inspector/latest/user/findings-managing-automating-responses.html
Amazon Inspector creates an event for Amazon EventBridge for newly generated findings, newly aggregated findings, and changes in the state of findings. Anything other than a change to the updatedAt and lastObservedAt fields will publish a new event. This means new events for a finding are generated when you take actions such as restarting a resource or changing the tags associated with a resource. However, the finding ID in the id field remains the same. Events are emitted on a best-effort basis.
From the Inspector documentation I do not see a way to configure Inspector so that only new findings are sent to EventBridge.
One possibility I can think of is to filter out events when firstObservedAt
and updatedAt
do not have the same value, however EventBridge would have to send the event to a Lambda to accomplish this.
Note: We are using an EventBridge event pattern to filter the events sent to our SNS (severity in ['CRITICAL', 'HIGH'] and status == 'ACTIVE'), however the comparison operations for use in event patterns don't allow checking if two field values equal each other.
@hannes-ucsc: "During standup, @dsotirho-ucsc proposed a strategy to detect genuinely new findings. I'd like to ask him to formulate it here and use the inspector API to collect examples of findings that would be detected by his strategy."
Inspector findings contain a few date properties, including firstObservedAt
, lastObservedAt
, and updatedAt
. In newly created findings these three properties have the same value, and in updated findings the firstObservedAt
property retains its original value while updatedAt
is updated.
Once https://github.com/DataBiosphere/azul/issues/5246 (Route SNS notifications through a Lambda function) is in place, we can use the Lambda to distinguish new findings from updated findings by comparing a finding's firstObservedAt
to updatedAt
value.
Alternatively, the Lambda could compare the updatedAt
date to the current time (using a reasonable buffer window) to determine if the finding is new.
(.venv) daniel@Crispin ~/repo/azul3 $ _select
lrwxr-xr-x 1 daniel staff 9 Oct 17 14:32 .active -> anvilprod
(.venv) daniel@Crispin ~/repo/azul3 $
(.venv) daniel@Crispin ~/repo/azul3 $ aws inspector2 list-findings --filter-criteria '{"findingStatus" : [{"comparison" : "EQUALS", "value": "ACTIVE"}]}' | jq '[.findings[] | {"findingArn": .findingArn, "firstObservedAt": .firstObservedAt, "lastObservedAt": .lastObservedAt, "updatedAt": .updatedAt}]' > findings.json
(.venv) daniel@Crispin ~/repo/azul3 $
(.venv) daniel@Crispin ~/repo/azul3 $ head -n 13 findings.json
[
{
"findingArn": "arn:aws:inspector2:us-east-1:465330168186:finding/006cd9b8758d2a97e34b4dff5bba7d57",
"firstObservedAt": 1696873676.504,
"lastObservedAt": 1696873676.504,
"updatedAt": 1696873676.504
},
{
"findingArn": "arn:aws:inspector2:us-east-1:465330168186:finding/008f61cda1c49ca0c36b21a4eecb7ef3",
"firstObservedAt": 1683271917.184,
"lastObservedAt": 1697242916.251,
"updatedAt": 1697242916.251
},
(.venv) daniel@Crispin ~/repo/azul3 $
(.venv) daniel@Crispin ~/repo/azul3 $ grep "findingArn" findings.json | wc -l
580
(.venv) daniel@Crispin ~/repo/azul3 $
(.venv) daniel@Crispin ~/repo/azul3 $ cat findings.json | jq '.[] | select(.firstObservedAt == .updatedAt)' | grep "findingArn" | wc -l
217
(.venv) daniel@Crispin ~/repo/azul3 $
(.venv) daniel@Crispin ~/repo/azul3 $ cat findings.json | jq '.[] | select(.firstObservedAt != .updatedAt)' | grep "findingArn" | wc -l
363
(.venv) daniel@Crispin ~/repo/azul3 $
@hannes-ucsc: "Sounds good. Let's tackle this once the blocker is resolved."
We just got hundreds of alarm messages for an image (kibana/kibana-oss) that we didn't touch. It's a lot of work to triage. Ideally, we would only want to be notify on newly discovered vulnerabilities on existing images and all vulnerabilities for new version of an images.