forked from PaloAltoNetworks/Prisma-Enhanced-Remediation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAWS-SSS-014.py
66 lines (50 loc) · 1.18 KB
/
AWS-SSS-014.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
"""
Remediate Prisma Policy:
AWS:SSS-014 S3 Server Side Encryption Not Enabled
Description:
S3 buckets now require Server Side Encryption on creation of all objects via bucket policy.
Required Permissions:
- s3:PutEncryptionConfiguration
Sample IAM Policy:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "S3Permissions",
"Action": [
"s3:PutEncryptionConfiguration"
],
"Effect": "Allow",
"Resource": "*"
}
]
}
"""
import boto3
from botocore.exceptions import ClientError
def remediate(session, alert, lambda_context):
"""
Main Function invoked by index_prisma.py
"""
bucket = alert['resource_id']
region = alert['region']
s3 = session.client('s3', region_name=region)
try:
result = s3.put_bucket_encryption(
Bucket = bucket,
ServerSideEncryptionConfiguration = {
'Rules': [
{
'ApplyServerSideEncryptionByDefault': {
'SSEAlgorithm': 'AES256'
}
},
]
}
)
except ClientError as e:
print(e.response['Error']['Message'])
return
else:
print('Server Side Encryption enabled for S3 bucket: {}.'.format(bucket))
return