Hello @VELASCO Alan M. TENARIS !
My policy which is Tested does not allow to create an Inbound Rule other than 22, or 3389 to the Destination IPs that are included in the Policy or any other IP
Remember the Policy has to appear as "Started" to take effect it needs 5-10 minutes
If you try to create an Ibound rule other than 3389 or 22 it wll deny it
Be aware this is the exact defiition ,the code above was the whole policy !
{
"mode": "All",
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.Network/networkSecurityGroups/securityRules"
},
{
"field": "Microsoft.Network/networkSecurityGroups/securityRules/access",
"equals": "Allow"
},
{
"field": "Microsoft.Network/networkSecurityGroups/securityRules/direction",
"equals": "Inbound"
},
{
"not": {
"anyOf": [
{
"field": "Microsoft.Network/networkSecurityGroups/securityRules/destinationPortRange",
"in": [
"22",
"3389"
]
},
{
"field": "Microsoft.Network/networkSecurityGroups/securityRules/sourceAddressPrefix",
"in": [
"10.0.0.0/8",
"172.16.0.0/12",
"192.168.0.0/16"
]
}
]
}
}
]
},
"then": {
"effect": "deny"
}
},
"parameters": {}
}
Maybe i dont undertand what you want ...since your policy does block already the Inbound Rules what else do you need ?
You said : So far my policy blocks the creation of an NSG with RDP and SSH ports and allows the creation of an NSG from only these 3 private IP addresses which are (10.0.0.0/8,172.16.0.0/12,192.168.0.0/16) with RDP ports and SSH.
So it does it already? saying from you mean source ? And then you add : My objetive is to allow you to create an NSG of a private IP on ports 22 and 3389 and have the policy block everything else.
Now i have created a new policy and let me remind you the Steps:
Azure Policy - New Definition to the Subsctption Scope
Add the Code
Save , and then Assign the Definition to the Subscription ,
Wait to become Started !
Here is a new one that does exaclty that : Allows only Inbound Rules on 22 and 3389 FROM only the IPs shown , (Source IP Control )
Everything else is denied - Tested and Validated
{
"mode": "All",
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.Network/networkSecurityGroups/securityRules"
},
{
"field": "Microsoft.Network/networkSecurityGroups/securityRules/access",
"equals": "Allow"
},
{
"field": "Microsoft.Network/networkSecurityGroups/securityRules/direction",
"equals": "Inbound"
},
{
"not": {
"allOf": [
{
"field": "Microsoft.Network/networkSecurityGroups/securityRules/destinationPortRange",
"in": ["22", "3389"]
},
{
"field": "Microsoft.Network/networkSecurityGroups/securityRules/sourceAddressPrefix",
"in": ["10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16"]
}
]
}
}
]
},
"then": {
"effect": "deny"
}
},
"parameters": {}
}
THis is the definition , follow the steps above to make it Active !
If this is not what you want lets clear it Out :
Source IP :................... Please select which sources do you want to control
Soure Port : ............... Please select if you need specific SOURCE ports
Destination IPs :..............Please Select Destination IPs to control
Destination Ports :...........Please select destination ports
I hope this helps!
Kindly mark the answer as Accepted and Upvote in case it helped!
Regards