Skip to content

Commit a198a86

Browse files
Added SQS QUEUE POLICY check #6
1 parent 26f3994 commit a198a86

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Following services are integrated
1717
- S3 POLICY
1818
- ELASTICSEARCH
1919
- DOCUMENTDB
20+
- SQS QUEUE POLICY
2021

2122
### Requirements and Installation
2223

shared/awscommands.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from shared.internal.database import RDS, ELASTICACHE, DOCUMENTDB
66
from shared.internal.storage import EFS, S3POLICY
77
from shared.internal.analytics import ELASTICSEARCH
8+
from shared.internal.application import SQSPOLICY
89

910

1011
class AwsCommands(object):
@@ -24,3 +25,4 @@ def run(self):
2425
S3POLICY(self.vpc_options).run()
2526
ELASTICSEARCH(self.vpc_options).run()
2627
DOCUMENTDB(self.vpc_options).run()
28+
SQSPOLICY(self.vpc_options).run()

shared/internal/application.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
from shared.common import *
2+
import json
3+
4+
class SQSPOLICY(object):
5+
6+
def __init__(self, vpc_options: VpcOptions):
7+
self.vpc_options = vpc_options
8+
9+
def run(self):
10+
try:
11+
client = self.vpc_options.session.client('sqs', region_name=self.vpc_options.region_name)
12+
13+
response = client.list_queues()
14+
15+
message_handler("\nChecking SQS QUEUE POLICY...", "HEADER")
16+
17+
if not "QueueUrls" in response:
18+
message_handler("Found 0 SQS Queues in region {0}".format(self.vpc_options.region_name), "OKBLUE")
19+
else:
20+
found = 0
21+
message = ""
22+
23+
""" SQS Queue doesn't returns a dict"""
24+
for idx, queue in enumerate(response["QueueUrls"]):
25+
26+
sqs_queue_policy = client.get_queue_attributes(QueueUrl=queue,
27+
AttributeNames=['Policy'])
28+
29+
30+
if "Attributes" in sqs_queue_policy:
31+
32+
""" Not sure about boto3 return """
33+
try:
34+
documentpolicy = sqs_queue_policy['Attributes']['Policy']
35+
36+
document = json.dumps(documentpolicy, default=datetime_to_string)
37+
38+
if self.vpc_options.vpc_id in document:
39+
found += 1
40+
message = message + "\nQueueUrl: {0} - VpcId {1}".format(
41+
queue,
42+
self.vpc_options.vpc_id
43+
)
44+
except:
45+
pass
46+
47+
48+
message_handler("Found {0} SQS Queue Policy using VPC {1} {2}".format(str(found), self.vpc_options.vpc_id, message),'OKBLUE')
49+
50+
except Exception as e:
51+
message = "Can't list SQS Queue Policy\nError {0}".format(str(e))
52+
exit_critical(message)

0 commit comments

Comments
 (0)