-
Notifications
You must be signed in to change notification settings - Fork 504
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updating s3 bucket policies for v4 aws provider (#1175)
- Loading branch information
1 parent
504aa1a
commit b909460
Showing
8 changed files
with
546 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
173 changes: 163 additions & 10 deletions
173
pkg/policies/opa/rego/aws/aws_s3_bucket/s3BucketAccessLoggingDisabled.rego
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,169 @@ | ||
|
||
package accurics | ||
|
||
{{.prefix}}s3BucketAccessLoggingDisabled[s3_bucket.id] { | ||
s3_bucket := input.aws_s3_bucket[_] | ||
object.get(s3_bucket.config, "logging", "undefined") == "undefined" | ||
{{.prefix}}s3BucketAccessLoggingDisabled[retVal] { | ||
cloudTrail := input.aws_cloudtrail[_] | ||
bucket := input.aws_s3_bucket[_] | ||
|
||
contains(cloudTrail.config.s3_bucket_name, "{") | ||
cleanId := cleanSSEBucketID(cloudTrail.config.s3_bucket_name) | ||
matchBucketName(bucket, cleanId) | ||
object.get(bucket.config, "logging", "undefined") == ["undefined", [], null][_] | ||
object.get(input, "aws_s3_bucket_logging", "undefined") == "undefined" | ||
|
||
decode_rc := `resource "aws_s3_bucket_logging" "{{.defaultValue}}" { | ||
bucket = aws_s3_bucket.##name##.id | ||
targetBucket = "{{.defaultValue1}}" | ||
}` | ||
|
||
replaced_rc := replace(decode_rc, "##name##", split(cleanId, ".")[1]) | ||
|
||
retVal := { | ||
"Id": bucket.id, | ||
"ReplaceType": "add", | ||
"CodeType": "resource", | ||
"Traverse": "", | ||
"Attribute": "", | ||
"AttributeDataType": "base64", | ||
"Expected": base64.encode(replaced_rc), | ||
"Actual": null, | ||
} | ||
} | ||
|
||
{{.prefix}}s3BucketAccessLoggingDisabled[retVal] { | ||
cloudTrail := input.aws_cloudtrail[_] | ||
bucket := input.aws_s3_bucket[_] | ||
|
||
not contains(cloudTrail.config.s3_bucket_name, "{") | ||
matchBucketName(bucket, cloudTrail.config.s3_bucket_name) | ||
object.get(bucket.config, "logging", "undefined") == ["undefined", [], null][_] | ||
object.get(input, "aws_s3_bucket_logging", "undefined") == "undefined" | ||
|
||
decode_rc := `resource "aws_s3_bucket_logging" "{{.defaultValue}}" { | ||
bucket = aws_s3_bucket.##name##.id | ||
targetBucket = "{{.defaultValue1}}" | ||
}` | ||
|
||
replaced_rc := replace(decode_rc, "##name##", bucket.name) | ||
|
||
retVal := { | ||
"Id": bucket.id, | ||
"ReplaceType": "add", | ||
"CodeType": "resource", | ||
"Traverse": "", | ||
"Attribute": "", | ||
"AttributeDataType": "base64", | ||
"Expected": base64.encode(replaced_rc), | ||
"Actual": null, | ||
} | ||
} | ||
|
||
{{.prefix}}s3BucketAccessLoggingDisabled[retVal] { | ||
bucket := input.aws_s3_bucket[_] | ||
object.get(bucket.config, "logging", "undefined") == ["undefined", [], null][_] | ||
|
||
cloudTrail := input.aws_cloudtrail[_] | ||
not contains(cloudTrail.config.s3_bucket_name, "{") | ||
matchBucketName(bucket, cloudTrail.config.s3_bucket_name) | ||
|
||
bucket_logged := [bl | bucketlogging := input.aws_s3_bucket_logging[_]; | ||
bl := bucketlogging.config.bucket] | ||
not matchBucketName(bucket_logged, bucket) | ||
|
||
decode_rc := `resource "aws_s3_bucket_logging" "{{.defaultValue}}" { | ||
bucket = aws_s3_bucket.##name##.id | ||
targetBucket = "{{.defaultValue1}}" | ||
}` | ||
|
||
replaced_rc := replace(decode_rc, "##name##", bucket.name) | ||
|
||
retVal := { | ||
"Id": bucket.id, | ||
"ReplaceType": "add", | ||
"CodeType": "resource", | ||
"Traverse": "", | ||
"Attribute": "", | ||
"AttributeDataType": "base64", | ||
"Expected": base64.encode(replaced_rc), | ||
"Actual": null, | ||
} | ||
} | ||
|
||
{{.prefix}}s3BucketAccessLoggingDisabled[retVal] { | ||
bucket := input.aws_s3_bucket[_] | ||
object.get(bucket.config, "logging", "undefined") == ["undefined", [], null][_] | ||
|
||
cloudTrail := input.aws_cloudtrail[_] | ||
contains(cloudTrail.config.s3_bucket_name, "{") | ||
|
||
cleanId := cleanSSEBucketID(cloudTrail.config.s3_bucket_name) | ||
matchBucketName(bucket, cleanId) | ||
|
||
bucket_logged := [bl | bucketlogging := input.aws_s3_bucket_logging[_]; | ||
bl := cleanSSEBucketID(bucketlogging.config.bucket)] | ||
not matchBucketName(bucket_logged, bucket) | ||
|
||
decode_rc := `resource "aws_s3_bucket_logging" "{{.defaultValue}}" { | ||
bucket = aws_s3_bucket.##name##.id | ||
targetBucket = "{{.defaultValue1}}" | ||
}` | ||
|
||
replaced_rc := replace(decode_rc, "##name##", bucket.name) | ||
|
||
retVal := { | ||
"Id": bucket.id, | ||
"ReplaceType": "add", | ||
"CodeType": "resource", | ||
"Traverse": "", | ||
"Attribute": "", | ||
"AttributeDataType": "base64", | ||
"Expected": base64.encode(replaced_rc), | ||
"Actual": null, | ||
} | ||
} | ||
|
||
matchBucketName(arg1, arg2){ | ||
arg1.id == arg2 | ||
} | ||
|
||
matchBucketName(arg1, arg2){ | ||
arg1[_] == arg2 | ||
} | ||
|
||
matchBucketName(arg1, arg2){ | ||
arg1[_] == arg2.id | ||
} | ||
|
||
matchBucketName(arg1, arg2){ | ||
arg1[_] == arg2.config.id | ||
} | ||
|
||
matchBucketName(arg1, arg2){ | ||
arg1[_] == arg2.config.bucket | ||
} | ||
|
||
{{.prefix}}s3BucketAccessLoggingDisabled[s3_bucket.id] { | ||
s3_bucket := input.aws_s3_bucket[_] | ||
s3_bucket.config.logging == [] | ||
matchBucketName(arg1, arg2){ | ||
arg1.config.id == arg2 | ||
} | ||
|
||
{{.prefix}}s3BucketAccessLoggingDisabled[s3_bucket.id] { | ||
s3_bucket := input.aws_s3_bucket[_] | ||
s3_bucket.config.logging == null | ||
} | ||
matchBucketName(arg1, arg2){ | ||
arg1.config.bucket == arg2 | ||
} | ||
|
||
|
||
cleanSSEBucketID(sseBucketID) = cleanID { | ||
v1 := trim_left(sseBucketID, "$") | ||
v2 := trim_left(v1, "{") | ||
v3 := trim_right(v2, "}") | ||
cleanID = cleanEnd(v3) | ||
} | ||
|
||
cleanEnd(sseBucketID_v3) = cleanID { | ||
endswith(sseBucketID_v3, ".id") | ||
cleanID = trim_right(sseBucketID_v3, ".id") | ||
} | ||
|
||
cleanEnd(sseBucketID_v3) = cleanID { | ||
endswith(sseBucketID_v3, ".bucket") | ||
cleanID = trim_right(sseBucketID_v3, ".bucket") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.