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"{
36
36
hasPublicAccess : true ,
37
37
},
38
38
{
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" ,
40
40
source : `
41
41
resource "aws_s3_bucket" "example" {
42
42
bucket = "bucketname"
@@ -254,6 +254,33 @@ func Test_Adapt(t *testing.T) {
254
254
},
255
255
},
256
256
},
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
+ },
257
284
}
258
285
259
286
for _ , test := range tests {
Original file line number Diff line number Diff line change 1
1
package s3
2
2
3
3
import (
4
+ "slices"
5
+
6
+ s3types "github.com/aws/aws-sdk-go-v2/service/s3/types"
7
+
4
8
"github.com/aquasecurity/trivy/pkg/iac/providers/aws/s3"
5
9
"github.com/aquasecurity/trivy/pkg/iac/terraform"
6
10
iacTypes "github.com/aquasecurity/trivy/pkg/iac/types"
@@ -194,11 +198,13 @@ func isEncrypted(sseConfgihuration *terraform.Block) iacTypes.BoolValue {
194
198
sseConfgihuration ,
195
199
"rule.apply_server_side_encryption_by_default.sse_algorithm" ,
196
200
func (attr * terraform.Attribute , parent * terraform.Block ) iacTypes.BoolValue {
197
- if attr .IsNil () {
201
+ if attr .IsNil () || ! attr . IsString () {
198
202
return iacTypes .BoolDefault (false , parent .GetMetadata ())
199
203
}
204
+ algoVal := attr .Value ().AsString ()
205
+ isValidAlgo := slices .Contains (s3types .ServerSideEncryption ("" ).Values (), s3types .ServerSideEncryption (algoVal ))
200
206
return iacTypes .Bool (
201
- true ,
207
+ isValidAlgo ,
202
208
attr .GetMetadata (),
203
209
)
204
210
},
You can’t perform that action at this time.
0 commit comments