/
append-nsg-rule.json
206 lines (206 loc) · 8.42 KB
/
append-nsg-rule.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
{
"mode": "All",
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.Network/networkSecurityGroups"
},
{
"field": "name",
"like": "[concat(parameters('targetPrefix'), '*')]"
},
{
"count": {
"field": "Microsoft.Network/networkSecurityGroups/securityRules[*]",
"where": {
"allOf": [
{
"field": "Microsoft.Network/networkSecurityGroups/securityRules[*].name",
"equals": "[parameters('name')]"
},
{
"field": "Microsoft.Network/networkSecurityGroups/securityRules[*].protocol",
"equals": "[parameters('protocol')]"
},
{
"anyOf": [
{
"value": "[equals(field('Microsoft.Network/networkSecurityGroups/securityRules[*].sourcePortRange'), parameters('sourcePortRange'))]",
"equals": true
},
{
"value": "[equals(field('Microsoft.Network/networkSecurityGroups/securityRules[*].sourcePortRanges'), parameters('sourcePortRange'))]",
"equals": true
}
]
},
{
"anyOf": [
{
"value": "[equals(field('Microsoft.Network/networkSecurityGroups/securityRules[*].destinationPortRange'), parameters('destinationPortRange'))]",
"equals": true
},
{
"value": "[equals(field('Microsoft.Network/networkSecurityGroups/securityRules[*].destinationPortRanges'), parameters('destinationPortRange'))]",
"equals": true
}
]
},
{
"anyOf": [
{
"value": "[equals(field('Microsoft.Network/networkSecurityGroups/securityRules[*].sourceAddressPrefix'), parameters('sourceAddressPrefix'))]",
"equals": true
},
{
"value": "[equals(field('Microsoft.Network/networkSecurityGroups/securityRules[*].sourceAddressPrefixes'), parameters('sourceAddressPrefix'))]",
"equals": true
}
]
},
{
"anyOf": [
{
"value": "[equals(field('Microsoft.Network/networkSecurityGroups/securityRules[*].destinationAddressPrefix'), parameters('destinationAddressPrefix'))]",
"equals": true
},
{
"value": "[equals(field('Microsoft.Network/networkSecurityGroups/securityRules[*].destinationAddressPrefixes'), parameters('destinationAddressPrefix'))]",
"equals": true
}
]
},
{
"field": "Microsoft.Network/networkSecurityGroups/securityRules[*].access",
"equals": "[parameters('access')]"
},
{
"field": "Microsoft.Network/networkSecurityGroups/securityRules[*].priority",
"equals": "[parameters('priority')]"
},
{
"field": "Microsoft.Network/networkSecurityGroups/securityRules[*].direction",
"equals": "[parameters('direction')]"
}
]
}
},
"equals": 0
}
]
},
"then": {
"effect": "[parameters('effect')]",
"details": [
{
"field": "Microsoft.Network/networkSecurityGroups/securityRules[*]",
"value": {
"name": "[parameters('name')]",
"properties": {
"protocol": "[parameters('protocol')]",
"sourcePortRange": "[if(equals(length(parameters('sourcePortRange')), 1), parameters('sourcePortRange')[0], json('null'))]",
"sourcePortRanges": "[if(greater(length(parameters('sourcePortRange')), 1), parameters('sourcePortRange'), json('null'))]",
"destinationPortRange": "[if(equals(length(parameters('destinationPortRange')), 1), parameters('destinationPortRange')[0], json('null'))]",
"destinationPortRanges": "[if(greater(length(parameters('destinationPortRange')), 1), parameters('destinationPortRange'), json('null'))]",
"sourceAddressPrefix": "[if(equals(length(parameters('sourceAddressPrefix')), 1), parameters('sourceAddressPrefix')[0], json('null'))]",
"sourceAddressPrefixes": "[if(greater(length(parameters('sourceAddressPrefix')), 1), parameters('sourceAddressPrefix'), json('null'))]",
"destinationAddressPrefix": "[if(equals(length(parameters('destinationAddressPrefix')), 1), parameters('destinationAddressPrefix')[0], json('null'))]",
"destinationAddressPrefixes": "[if(greater(length(parameters('destinationAddressPrefix')), 1), parameters('destinationAddressPrefix'), json('null'))]",
"access": "[parameters('access')]",
"priority": "[parameters('priority')]",
"direction": "[parameters('direction')]"
}
}
}
]
}
},
"parameters": {
"name": {
"type": "String",
"metadata": {
"displayName": "Rule Name",
"description": "This is the name of the security rule itself."
}
},
"protocol": {
"type": "String",
"metadata": {
"displayName": "protocol",
"description": "Network protocol this rule applies to. - Tcp, Udp, Icmp, Esp, *, Ah"
}
},
"sourcePortRange": {
"type": "Array",
"metadata": {
"displayName": "sourcePortRange",
"description": "The source port or range. Integer or range between 0 and 65535. Asterisk '*' can also be used to match all ports."
}
},
"destinationPortRange": {
"type": "Array",
"metadata": {
"displayName": "destinationPortRange",
"description": "The destination port or range. Integer or range between 0 and 65535. Asterisk '*' can also be used to match all ports."
}
},
"sourceAddressPrefix": {
"type": "Array",
"metadata": {
"displayName": "sourceAddressPrefix",
"description": "The CIDR or source IP range. Asterisk '*' can also be used to match all source IPs. Default tags such as 'VirtualNetwork', 'AzureLoadBalancer' and 'Internet' can also be used. If this is an ingress rule, specifies where network traffic originates from."
}
},
"destinationAddressPrefix": {
"type": "Array",
"metadata": {
"displayName": "destinationAddressPrefix",
"description": "The destination address prefix. CIDR or destination IP range. Asterisk '*' can also be used to match all source IPs. Default tags such as 'VirtualNetwork', 'AzureLoadBalancer' and 'Internet' can also be used."
}
},
"access": {
"type": "String",
"metadata": {
"displayName": "access",
"description": "The network traffic is allowed or denied. - Allow or Deny"
}
},
"priority": {
"type": "Integer",
"metadata": {
"displayName": "priority",
"description": "The priority of the rule. The value can be between 100 and 4096. The priority number must be unique for each rule in the collection. The lower the priority number, the higher the priority of the rule."
}
},
"direction": {
"type": "String",
"metadata": {
"displayName": "direction",
"description": "The direction of the rule. The direction specifies if rule will be evaluated on incoming or outgoing traffic. - Inbound or Outbound"
}
},
"targetPrefix": {
"type": "String",
"metadata": {
"displayName": "Targeted Prefix",
"description": "NSG's containing this prefix will have this policy applied to them."
}
},
"effect": {
"type": "String",
"metadata": {
"displayName": "Effect",
"description": "Append, Deny, Audit or Disable the execution of the Policy"
},
"allowedValues": [
"Append",
"Deny",
"Audit",
"Disabled"
],
"defaultValue": "Append"
}
}
}