Skip to content

Commit c8d5ab7

Browse files
authored
feat(misconf): support https_traffic_only_enabled in Az storage account (#9784)
Signed-off-by: nikpivkin <[email protected]>
1 parent 9da33b5 commit c8d5ab7

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

pkg/iac/adapters/terraform/azure/storage/adapt.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,10 @@ func adaptAccount(resource *terraform.Block) storage.Account {
176176
account.NetworkRules = append(account.NetworkRules, adaptNetworkRule(networkBlock))
177177
}
178178

179-
httpsOnlyAttr := resource.GetAttribute("enable_https_traffic_only")
180-
account.EnforceHTTPS = httpsOnlyAttr.AsBoolValueOrDefault(true, resource)
179+
account.EnforceHTTPS = resource.GetFirstAttributeOf(
180+
"enable_https_traffic_only",
181+
"https_traffic_only_enabled", // provider above version 4
182+
).AsBoolValueOrDefault(true, resource)
181183

182184
// Adapt blob properties
183185
blobPropertiesBlock := resource.GetBlock("blob_properties")

pkg/iac/terraform/block.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616

1717
"github.com/aquasecurity/trivy/pkg/iac/terraform/context"
1818
iacTypes "github.com/aquasecurity/trivy/pkg/iac/types"
19+
"github.com/aquasecurity/trivy/pkg/set"
1920
)
2021

2122
type Block struct {
@@ -303,11 +304,18 @@ func (b *Block) GetAttributes() []*Attribute {
303304
}
304305

305306
func (b *Block) GetAttribute(name string) *Attribute {
306-
if b == nil || b.hclBlock == nil {
307+
return b.GetFirstAttributeOf(name)
308+
}
309+
310+
func (b *Block) GetFirstAttributeOf(names ...string) *Attribute {
311+
if b == nil || b.hclBlock == nil || len(names) == 0 {
307312
return nil
308313
}
314+
315+
nameSet := set.New(names...)
316+
309317
for _, attr := range b.attributes {
310-
if attr.Name() == name {
318+
if ok := nameSet.Contains(attr.Name()); ok {
311319
return attr
312320
}
313321
}

0 commit comments

Comments
 (0)