How to set up an Azure alert for inbound port rule changes

Phil Arnfield 0 Reputation points
2023-10-24T12:09:33.7566667+00:00

Is there a way to create an alert in Azure that can notify us when an inbound port rule is changed from "Deny" to "Allow" for port 3389 (RDP)? We have several virtual machines with their own virtual network, and we want to be notified whenever the inbound port rule is not set back to "Deny" after it has been changed for RDP access. Can we schedule something to alert us so that we can switch the status back to "Deny"?

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
8,713 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  2. Thomas Meads 1,586 Reputation points
    2023-10-24T17:19:18.6666667+00:00

    Hi,

    A couple of options here I can think of:

    1. Diagnostic settings streaming to log analytics (from the network security group). The Network Security Group Event category logs the VM and security rule applied when changes are made to a NSG. Hence getting the latest log will tell you if there is an allow rule with the port 3389.
    2. Using the in Preview Azure Resource Graph. This allows ARG queries to be used in log analytic queries. More info here: https://azure.microsoft.com/en-us/updates/public-preview-azure-log-alerts-support-for-azure-resource-graph-arg/
      Using this you could write a query like:
    arg("").Resources
    | where type == "microsoft.network/networksecuritygroups"
    | mv-expand properties["securityRules"]
    | where properties['securityRules'] contains "Allow" and properties['securityRules'] contains "3389"
    

    This code works within Azure Resource Graph Explorer but doesn't seem to work in log analytics which maybe a bug?

    Please note the usage of preview features https://azure.microsoft.com/en-gb/support/legal/preview-supplemental-terms

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.