File tree Expand file tree Collapse file tree 2 files changed +36
-3
lines changed
pkg/iac/adapters/terraform/aws/s3 Expand file tree Collapse file tree 2 files changed +36
-3
lines changed Original file line number Diff line number Diff line change @@ -36,7 +36,7 @@ resource "aws_s3_bucket_public_access_block" "example_access_block"{
3636 hasPublicAccess : true ,
3737 },
3838 {
39- desc : "public access block is found when using the bucket name as the lookup" ,
39+ desc : "public access block is found when using the bucket id as the lookup" ,
4040 source : `
4141resource "aws_s3_bucket" "example" {
4242 bucket = "bucketname"
@@ -254,6 +254,33 @@ func Test_Adapt(t *testing.T) {
254254 },
255255 },
256256 },
257+ {
258+ name : "non-valid SSE algorithm" ,
259+ terraform : `
260+ resource "aws_s3_bucket" "this" {
261+ bucket = "test"
262+ }
263+
264+ resource "aws_s3_bucket_server_side_encryption_configuration" "this" {
265+ bucket = aws_s3_bucket.this.id
266+ rule {
267+ apply_server_side_encryption_by_default {
268+ sse_algorithm = ""
269+ }
270+ }
271+ }` ,
272+ expected : s3.S3 {
273+ Buckets : []s3.Bucket {
274+ {
275+ Name : iacTypes .String ("test" , iacTypes .NewTestMetadata ()),
276+ Encryption : s3.Encryption {
277+ Enabled : iacTypes .Bool (false , iacTypes .NewTestMetadata ()),
278+ },
279+ ACL : iacTypes .String ("private" , iacTypes .NewTestMetadata ()),
280+ },
281+ },
282+ },
283+ },
257284 }
258285
259286 for _ , test := range tests {
Original file line number Diff line number Diff line change 11package s3
22
33import (
4+ "slices"
5+
6+ s3types "github.com/aws/aws-sdk-go-v2/service/s3/types"
7+
48 "github.com/aquasecurity/trivy/pkg/iac/providers/aws/s3"
59 "github.com/aquasecurity/trivy/pkg/iac/terraform"
610 iacTypes "github.com/aquasecurity/trivy/pkg/iac/types"
@@ -194,11 +198,13 @@ func isEncrypted(sseConfgihuration *terraform.Block) iacTypes.BoolValue {
194198 sseConfgihuration ,
195199 "rule.apply_server_side_encryption_by_default.sse_algorithm" ,
196200 func (attr * terraform.Attribute , parent * terraform.Block ) iacTypes.BoolValue {
197- if attr .IsNil () {
201+ if attr .IsNil () || ! attr . IsString () {
198202 return iacTypes .BoolDefault (false , parent .GetMetadata ())
199203 }
204+ algoVal := attr .Value ().AsString ()
205+ isValidAlgo := slices .Contains (s3types .ServerSideEncryption ("" ).Values (), s3types .ServerSideEncryption (algoVal ))
200206 return iacTypes .Bool (
201- true ,
207+ isValidAlgo ,
202208 attr .GetMetadata (),
203209 )
204210 },
You can’t perform that action at this time.
0 commit comments