azureazure-eventgrid

How to programmatically add ip addresses to Azure Event grid namespace


In Azure we have provisioned an MQTT broker through the event grid namespace functionality. We need to access this broker from the internet so public access is allowed. To make it a bit more secure I want to restrict access from a list of known IP addresses. In the UI I can do this one by one (IP or CIDR) but I would like to add these programmatically. (I have a list of 180 slowly changing addresses)

After going through the docs in the azure docs I can't seem to find a way to set these values.

How can I achieve this through the azure cli or some other way?

Thanks!


Solution

  • To add IP addresses to an Azure Event Grid namespace for restricting access, you can use the Azure CLI.

    If you want to add multiple IP address , you can add all IP address in JSON file,as follows.

    code inbound-ip-rules.json

    [
      { "ipMask": "10.1.56.1" },
      { "ipMask": "10.1.56.2" },
      { "ipMask": "10.1.56.3" },
      { "ipMask": "10.1.56.4" },
      { "ipMask": "10.1.56.5" },
      { "ipMask": "10.1.56.6" },
      { "ipMask": "10.1.56.7" },
      { "ipMask": "10.1.56.8" },
      { "ipMask": "10.1.56.9" },
      { "ipMask": "10.1.56.10" }
    ]
    
    

    I have referred this MSDOC for Azure CLI commands.

    az eventgrid namespace update  --resource-group "yourResourceGroup"  --name "yourEventGridNamespace"   --public-network-access "Enabled" --inbound-ip-rules @inbound-ip-rules.json
    
    

    After executing the command, The IP address has been added in azure event grid namespace firewall section.

    enter image description here