Skip to content

Commit e3452b4

Browse files
authored
feat: Add account ID to GuardDuty event notification (#187)
1 parent 8ca3317 commit e3452b4

File tree

8 files changed

+34
-18
lines changed

8 files changed

+34
-18
lines changed

.github/workflows/pre-commit.yml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ on:
88

99
env:
1010
TERRAFORM_DOCS_VERSION: v0.16.0
11+
TFLINT_VERSION: v0.44.1
1112

1213
jobs:
1314
collectInputs:
@@ -21,7 +22,7 @@ jobs:
2122

2223
- name: Get root directories
2324
id: dirs
24-
uses: clowdhaus/terraform-composite-actions/[email protected].0
25+
uses: clowdhaus/terraform-composite-actions/[email protected].3
2526

2627
preCommitMinVersions:
2728
name: Min TF pre-commit
@@ -36,24 +37,26 @@ jobs:
3637

3738
- name: Terraform min/max versions
3839
id: minMax
39-
uses: clowdhaus/[email protected].0
40+
uses: clowdhaus/[email protected].4
4041
with:
4142
directory: ${{ matrix.directory }}
4243

4344
- name: Pre-commit Terraform ${{ steps.minMax.outputs.minVersion }}
4445
# Run only validate pre-commit check on min version supported
4546
if: ${{ matrix.directory != '.' }}
46-
uses: clowdhaus/terraform-composite-actions/[email protected].0
47+
uses: clowdhaus/terraform-composite-actions/[email protected].3
4748
with:
4849
terraform-version: ${{ steps.minMax.outputs.minVersion }}
50+
tflint-version: ${{ env.TFLINT_VERSION }}
4951
args: 'terraform_validate --color=always --show-diff-on-failure --files ${{ matrix.directory }}/*'
5052

5153
- name: Pre-commit Terraform ${{ steps.minMax.outputs.minVersion }}
5254
# Run only validate pre-commit check on min version supported
5355
if: ${{ matrix.directory == '.' }}
54-
uses: clowdhaus/terraform-composite-actions/[email protected].0
56+
uses: clowdhaus/terraform-composite-actions/[email protected].3
5557
with:
5658
terraform-version: ${{ steps.minMax.outputs.minVersion }}
59+
tflint-version: ${{ env.TFLINT_VERSION }}
5760
args: 'terraform_validate --color=always --show-diff-on-failure --files $(ls *.tf)'
5861

5962
preCommitMaxVersion:
@@ -69,10 +72,12 @@ jobs:
6972

7073
- name: Terraform min/max versions
7174
id: minMax
72-
uses: clowdhaus/[email protected].0
75+
uses: clowdhaus/[email protected].4
7376

7477
- name: Pre-commit Terraform ${{ steps.minMax.outputs.maxVersion }}
75-
uses: clowdhaus/terraform-composite-actions/[email protected].0
78+
uses: clowdhaus/terraform-composite-actions/[email protected].3
7679
with:
7780
terraform-version: ${{ steps.minMax.outputs.maxVersion }}
81+
tflint-version: ${{ env.TFLINT_VERSION }}
7882
terraform-docs-version: ${{ env.TERRAFORM_DOCS_VERSION }}
83+
install-hcledit: true

functions/events/guardduty_finding_high.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"id": "sample-id-2",
66
"title": "SAMPLE Unprotected port on EC2 instance i-123123123 is being probed",
77
"severity": 9,
8+
"accountId": "123456789",
89
"description": "EC2 instance has an unprotected port which is being probed by a known malicious host.",
910
"type": "Recon:EC2 PortProbeUnprotectedPort",
1011
"service": {

functions/events/guardduty_finding_low.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"id": "sample-id-2",
66
"title": "SAMPLE Unprotected port on EC2 instance i-123123123 is being probed",
77
"severity": 2,
8+
"accountId": "123456789",
89
"description": "EC2 instance has an unprotected port which is being probed by a known malicious host.",
910
"type": "Recon:EC2 PortProbeUnprotectedPort",
1011
"service": {

functions/events/guardduty_finding_medium.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"id": "sample-id-2",
66
"title": "SAMPLE Unprotected port on EC2 instance i-123123123 is being probed",
77
"severity": 5,
8+
"accountId": "123456789",
89
"description": "EC2 instance has an unprotected port which is being probed by a known malicious host.",
910
"type": "Recon:EC2 PortProbeUnprotectedPort",
1011
"service": {

functions/messages/guardduty_finding.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"MessageId": "95df01b4-ee98-5cb9-9903-4c221d41eb5e",
99
"TopicArn": "arn:aws:sns:us-gov-east-1:123456789012:ExampleTopic",
1010
"Subject": "GuardDuty Finding",
11-
"Message": "{\"detail-type\": \"GuardDuty Finding\",\"region\": \"us-gov-east-1\",\"detail\": {\"id\": \"sample-id-2\",\"title\": \"SAMPLE Unprotected port on EC2 instance i-123123123 is being probed\",\"severity\": 9,\"description\": \"EC2 instance has an unprotected port which is being probed by a known malicious host.\",\"type\": \"Recon:EC2 PortProbeUnprotectedPort\",\"service\": {\"eventFirstSeen\": \"2020-01-02T01:02:03Z\",\"eventLastSeen\": \"2020-01-03T01:02:03Z\",\"count\": 1234}}}",
11+
"Message": "{\"detail-type\": \"GuardDuty Finding\",\"region\": \"us-gov-east-1\",\"detail\": {\"id\": \"sample-id-2\",\"title\": \"SAMPLE Unprotected port on EC2 instance i-123123123 is being probed\",\"severity\": 9,\"accountId\":\"123456789\",\"description\": \"EC2 instance has an unprotected port which is being probed by a known malicious host.\",\"type\": \"Recon:EC2 PortProbeUnprotectedPort\",\"service\": {\"eventFirstSeen\": \"2020-01-02T01:02:03Z\",\"eventLastSeen\": \"2020-01-03T01:02:03Z\",\"count\": 1234}}}",
1212
"Timestamp": "1970-01-01T00:00:00.000Z",
1313
"SignatureVersion": "1",
1414
"Signature": "EXAMPLE",

functions/mylambda.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
#!/usr/bin/python3.6
22
# CUSTOM LAMBDA FUNCTION
33

4-
import urllib3
54
import json
65
import os
6+
7+
import urllib3
8+
79
http = urllib3.PoolManager()
810

911

@@ -12,14 +14,16 @@ def lambda_handler(event, context):
1214
msg = {
1315
"channel": "#channel-name",
1416
"username": "Prometheus",
15-
"text": event['Records'][0]['Sns']['Message'],
16-
"icon_emoji": ""
17+
"text": event["Records"][0]["Sns"]["Message"],
18+
"icon_emoji": "",
1719
}
1820

19-
encoded_msg = json.dumps(msg).encode('utf-8')
20-
resp = http.request('POST', url, body=encoded_msg)
21-
print({
22-
"message": event['Records'][0]['Sns']['Message'],
23-
"status_code": resp.status,
24-
"response": resp.data
25-
})
21+
encoded_msg = json.dumps(msg).encode("utf-8")
22+
resp = http.request("POST", url, body=encoded_msg)
23+
print(
24+
{
25+
"message": event["Records"][0]["Sns"]["Message"],
26+
"status_code": resp.status,
27+
"response": resp.data,
28+
}
29+
)

functions/notify_slack.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ def format_guardduty_finding(message: Dict[str, Any], region: str) -> Dict[str,
176176
"short": True,
177177
},
178178
{"title": "Severity", "value": f"`{severity}`", "short": True},
179+
{"title": "Account ID", "value": f"`{detail['accountId']}`", "short": True},
179180
{
180181
"title": "Count",
181182
"value": f"`{service['count']}`",

functions/snapshots/snap_notify_slack_test.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
from snapshottest import Snapshot
66

7-
87
snapshots = Snapshot()
98

109
snapshots[
@@ -121,6 +120,7 @@
121120
"value": "`2020-01-03T01:02:03Z`",
122121
},
123122
{"short": True, "title": "Severity", "value": "`High`"},
123+
{"short": True, "title": "Account ID", "value": "`123456789`"},
124124
{"short": True, "title": "Count", "value": "`1234`"},
125125
{
126126
"short": False,
@@ -167,6 +167,7 @@
167167
"value": "`2020-01-03T01:02:03Z`",
168168
},
169169
{"short": True, "title": "Severity", "value": "`Low`"},
170+
{"short": True, "title": "Account ID", "value": "`123456789`"},
170171
{"short": True, "title": "Count", "value": "`1234`"},
171172
{
172173
"short": False,
@@ -213,6 +214,7 @@
213214
"value": "`2020-01-03T01:02:03Z`",
214215
},
215216
{"short": True, "title": "Severity", "value": "`Medium`"},
217+
{"short": True, "title": "Account ID", "value": "`123456789`"},
216218
{"short": True, "title": "Count", "value": "`1234`"},
217219
{
218220
"short": False,
@@ -387,6 +389,7 @@
387389
"value": "`2020-01-03T01:02:03Z`",
388390
},
389391
{"short": True, "title": "Severity", "value": "`High`"},
392+
{"short": True, "title": "Account ID", "value": "`123456789`"},
390393
{"short": True, "title": "Count", "value": "`1234`"},
391394
{
392395
"short": False,

0 commit comments

Comments
 (0)