Skip to content

Commit ad91412

Browse files
authored
feat(misconf): public network support for Azure Storage Account (#7601)
Signed-off-by: nikpivkin <[email protected]>
1 parent 633a7ab commit ad91412

File tree

6 files changed

+54
-23
lines changed

6 files changed

+54
-23
lines changed

pkg/iac/adapters/arm/storage/adapt.go

+6
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ func adaptAccounts(deployment azure.Deployment) []storage.Account {
6262
MinimumTLSVersion: resource.Properties.GetMapValue("minimumTlsVersion").AsStringValue("", resource.Properties.GetMetadata()),
6363
Queues: queues,
6464
}
65+
66+
publicNetworkAccess := resource.Properties.GetMapValue("publicNetworkAccess")
67+
account.PublicNetworkAccess = types.Bool(
68+
publicNetworkAccess.AsStringValue("Enabled", publicNetworkAccess.Metadata).EqualTo("Enabled"),
69+
publicNetworkAccess.Metadata,
70+
)
6571
accounts = append(accounts, account)
6672
}
6773
return accounts

pkg/iac/adapters/arm/storage/adapt_test.go

+15-12
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@ import (
66
"github.com/stretchr/testify/assert"
77
"github.com/stretchr/testify/require"
88

9-
azure2 "github.com/aquasecurity/trivy/pkg/iac/scanners/azure"
9+
"github.com/aquasecurity/trivy/pkg/iac/scanners/azure"
1010
"github.com/aquasecurity/trivy/pkg/iac/types"
1111
)
1212

1313
func Test_AdaptStorageDefaults(t *testing.T) {
1414

15-
input := azure2.Deployment{
16-
Resources: []azure2.Resource{
15+
input := azure.Deployment{
16+
Resources: []azure.Resource{
1717
{
18-
Type: azure2.NewValue("Microsoft.Storage/storageAccounts", types.NewTestMetadata()),
19-
Properties: azure2.NewValue(make(map[string]azure2.Value), types.NewTestMetadata()),
18+
Type: azure.NewValue("Microsoft.Storage/storageAccounts", types.NewTestMetadata()),
19+
Properties: azure.NewValue(make(map[string]azure.Value), types.NewTestMetadata()),
2020
},
2121
},
2222
}
@@ -28,19 +28,21 @@ func Test_AdaptStorageDefaults(t *testing.T) {
2828
account := output.Accounts[0]
2929
assert.Equal(t, "", account.MinimumTLSVersion.Value())
3030
assert.False(t, account.EnforceHTTPS.Value())
31+
assert.True(t, account.PublicNetworkAccess.Value())
3132

3233
}
3334

3435
func Test_AdaptStorage(t *testing.T) {
3536

36-
input := azure2.Deployment{
37-
Resources: []azure2.Resource{
37+
input := azure.Deployment{
38+
Resources: []azure.Resource{
3839
{
39-
Type: azure2.NewValue("Microsoft.Storage/storageAccounts", types.NewTestMetadata()),
40-
Name: azure2.Value{},
41-
Properties: azure2.NewValue(map[string]azure2.Value{
42-
"minimumTlsVersion": azure2.NewValue("TLS1_2", types.NewTestMetadata()),
43-
"supportsHttpsTrafficOnly": azure2.NewValue(true, types.NewTestMetadata()),
40+
Type: azure.NewValue("Microsoft.Storage/storageAccounts", types.NewTestMetadata()),
41+
Name: azure.Value{},
42+
Properties: azure.NewValue(map[string]azure.Value{
43+
"minimumTlsVersion": azure.NewValue("TLS1_2", types.NewTestMetadata()),
44+
"supportsHttpsTrafficOnly": azure.NewValue(true, types.NewTestMetadata()),
45+
"publicNetworkAccess": azure.NewValue("Disabled", types.NewTestMetadata()),
4446
}, types.NewTestMetadata()),
4547
},
4648
},
@@ -53,5 +55,6 @@ func Test_AdaptStorage(t *testing.T) {
5355
account := output.Accounts[0]
5456
assert.Equal(t, "TLS1_2", account.MinimumTLSVersion.Value())
5557
assert.True(t, account.EnforceHTTPS.Value())
58+
assert.False(t, account.PublicNetworkAccess.Value())
5659

5760
}

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ func adaptAccount(resource *terraform.Block) storage.Account {
108108
Metadata: resource.GetMetadata(),
109109
EnableLogging: iacTypes.BoolDefault(false, resource.GetMetadata()),
110110
},
111-
MinimumTLSVersion: iacTypes.StringDefault(minimumTlsVersionOneTwo, resource.GetMetadata()),
111+
MinimumTLSVersion: iacTypes.StringDefault(minimumTlsVersionOneTwo, resource.GetMetadata()),
112+
PublicNetworkAccess: resource.GetAttribute("public_network_access_enabled").AsBoolValueOrDefault(true, resource),
112113
}
113114

114115
networkRulesBlocks := resource.GetBlocks("network_rules")

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

+19-3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,20 @@ func Test_Adapt(t *testing.T) {
1818
terraform string
1919
expected storage.Storage
2020
}{
21+
{
22+
name: "default",
23+
terraform: `resource "azurerm_storage_account" "example" {}`,
24+
expected: storage.Storage{
25+
Accounts: []storage.Account{
26+
{
27+
PublicNetworkAccess: iacTypes.BoolTest(true),
28+
MinimumTLSVersion: iacTypes.StringTest(minimumTlsVersionOneTwo),
29+
EnforceHTTPS: iacTypes.BoolTest(true),
30+
},
31+
{},
32+
},
33+
},
34+
},
2135
{
2236
name: "defined",
2337
terraform: `
@@ -45,6 +59,7 @@ func Test_Adapt(t *testing.T) {
4559
}
4660
}
4761
min_tls_version = "TLS1_2"
62+
public_network_access_enabled = false
4863
}
4964
5065
resource "azurerm_storage_account_network_rules" "test" {
@@ -65,9 +80,10 @@ func Test_Adapt(t *testing.T) {
6580
Accounts: []storage.Account{
6681

6782
{
68-
Metadata: iacTypes.NewTestMetadata(),
69-
EnforceHTTPS: iacTypes.Bool(true, iacTypes.NewTestMetadata()),
70-
MinimumTLSVersion: iacTypes.String("TLS1_2", iacTypes.NewTestMetadata()),
83+
Metadata: iacTypes.NewTestMetadata(),
84+
EnforceHTTPS: iacTypes.Bool(true, iacTypes.NewTestMetadata()),
85+
MinimumTLSVersion: iacTypes.String("TLS1_2", iacTypes.NewTestMetadata()),
86+
PublicNetworkAccess: iacTypes.BoolTest(false),
7187
NetworkRules: []storage.NetworkRule{
7288
{
7389
Metadata: iacTypes.NewTestMetadata(),

pkg/iac/providers/azure/storage/storage.go

+8-7
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ type Storage struct {
99
}
1010

1111
type Account struct {
12-
Metadata iacTypes.Metadata
13-
NetworkRules []NetworkRule
14-
EnforceHTTPS iacTypes.BoolValue
15-
Containers []Container
16-
QueueProperties QueueProperties
17-
MinimumTLSVersion iacTypes.StringValue
18-
Queues []Queue
12+
Metadata iacTypes.Metadata
13+
NetworkRules []NetworkRule
14+
EnforceHTTPS iacTypes.BoolValue
15+
Containers []Container
16+
QueueProperties QueueProperties
17+
MinimumTLSVersion iacTypes.StringValue
18+
Queues []Queue
19+
PublicNetworkAccess iacTypes.BoolValue
1920
}
2021

2122
type Queue struct {

pkg/iac/rego/schemas/cloud.json

+4
Original file line numberDiff line numberDiff line change
@@ -5396,6 +5396,10 @@
53965396
"$ref": "#/definitions/github.com.aquasecurity.trivy.pkg.iac.providers.azure.storage.NetworkRule"
53975397
}
53985398
},
5399+
"publicnetworkaccess": {
5400+
"type": "object",
5401+
"$ref": "#/definitions/github.com.aquasecurity.trivy.pkg.iac.types.BoolValue"
5402+
},
53995403
"queueproperties": {
54005404
"type": "object",
54015405
"$ref": "#/definitions/github.com.aquasecurity.trivy.pkg.iac.providers.azure.storage.QueueProperties"

0 commit comments

Comments
 (0)