How to restrict/stop public (internet) access to Azure function? - azure

I have several Azure Functions (Premium plan) which do some stuff and load the results to the storage blob. The connection to the storage account is restricted by a v-net so no public access to the storage account, however, I check and found that my (HTTP) azure functions can be triggered on the public internet.
How can I restrict this in the azure function, is there a way to do it through configuration?
Is this the way it's done?
Please help if there're other ways

You can set access restrictions in the portal through the networking blade. Click on Networking, then Configure Access Restrictions, and you can set access rules in there based on various options.

Instead of allowing specific IPS, i would request you to look at access restrictions to an Azure Function.
Add-AzWebAppAccessRestrictionRule -ResourceGroupName "ResourceGroup" -WebAppName "AppName" `-Name "Multi-source rule" -IpAddress "192.168.1.0/24,192.168.10.0/24,192.168.100.0/24" `
-Priority 100 -Action Allow

Related

Unable to get storage account container details

Is there a way to get the storage account container details in Azure when private endpoint is enabled?
When i am trying to use get-azcontainer -name -context
I get an error saying this is not an authorised operation. However when i remove the private endpoint and enable public access. I am able to do so.
Hence, unable to figure out if there is any other way to achieve this
Tried using get-azcontainer. It didn't work as expected.
Request your help
Private endpoint means it is created with the help of VNet-Subnet.
So, you have to access the Storage account from the Virtual Machines connected to that Subnet added in your Storage Account > Networking > Vnet - Subnet which is linked with that Private Endpoint.
Reference: Microsoft Documentation of Azure Storage Account using Private Link

Azure Web App: Cannot add a VNET Restriction Rule using PowerShell when VNET is on a different subscription

I have a web application in azure and I want to make sure that only my build server (or any other VM on the same subnet) are the only ones which are able to access the SCM site. I thought the most obvious thing would be to create an access restriction rule and in fact that works, I am able to create it from the portal with no issue whatsoever.
The problem, however, happens when I try to automate this using powershell. My build server subnet is located on a subscription different from the one where my web application is.
I am executing the following powershell script:
$subnetId = "/subscriptions/$VNETSubscriptionId/resourceGroups/$VNETResourceGroup/providers/Microsoft.Network/virtualNetworks/$buildServerVNET/subnets/$buildServerSubNet"
Add-AzWebAppAccessRestrictionRule -ResourceGroup $webAppRg -WebAppName $webAppname -Name VNETAccess -Priority 1000 -Action Allow -SubnetId $subnetId
And I get the following error:
Add-AzWebAppAccessRestrictionRule : The client '{{my user credential}}' with object id '81fa4eb1-5553-4daa-af44-3c717b19eda2' does not have authorization to perform action 'Microsoft.Network/virtualNetworks/subnets/read' over scope '/subscriptions/{{websiteSubscriptionId}}/resour
ceGroups/{{VNETResourceGroup}}/providers/Microsoft.Network/virtualNetworks/{{buildServerVNET}}/subnets/{{buildServerSubNet}}' or
the scope is invalid. If access was recently granted, please refresh your credentials.
The error seems to indicate that the cmdlet is searching for the subnet on the same subscription id than the website instead of the subscription where the subnet is located, since the resourceId string that is being returned on the error messsage has the wrong subscription Id. It is using the one where the website is instead of using the one where the build server is.
What else needs to be done in order to create this rule through powershell?
The error message is confused.
In fact, after my validation, you need to add the -IgnoreMissingServiceEndpoint parameter when adding a subnet from a different subscription. Read this GitHub case WebApp:Add-AzWebAppAccessRestrictionRule.md - incorrect use of subscription context over SubnetId param
When using a subnet from a different subscription, we cannot validate
the subnet to see if the correct service endpoint (Microsoft.Web) has
been set. If you use -IgnoreMissingServiceEndpoint the rule can be
added.

How to get the azure VMUUID of azure VM?

I am creating an ARM template for the Azure Log Analytics workspace.it has some queries which use azure VM's VMUUID. Is there is any way to fetch the azure VM's VMUUID inside the ARM template or any other way to fetch azure VMUUID?
ARM Template I just need to get the values of VMUUID of all VM's in that subscription.
You can also get this information programmatically from the Azure Instance Metadata Service (IMDS). It provides information about currently running virtual machine instances. You can use IMDS to manage and configure your virtual machines. This information includes the SKU, storage, network configurations, and upcoming maintenance events. For a complete list of the data available, see the Endpoint Categories Summary.
IMDS is a REST API that's available at a well-known, non-routable IP address 169.254.169.254. You can only access it from within the VM. Communication between the VM and IMDS never leaves the host.
https://learn.microsoft.com/en-us/azure/virtual-machines/windows/instance-metadata-service
Try Azure Resource Explorer
You could easily find it in the Azure Resource Explorer.
//One more extra reference: What is Azure Resource Explorer?
Just navigate to the Microsoft.Compute => virtualMachines view:
There is one more way to find it, but for me seems more complicated as you need to connect to the VM:
https://azure.microsoft.com/en-us/blog/accessing-and-using-azure-vm-unique-id/
Update: Try PowerShell
The simple PowerShell script below returns a list of all VMUUIDs in the specified subscription:
Get-AzSubscription
Select-AzSubscription -SubscriptionId "Olga's Subscription"
$GetVM = Get-AzVM
Foreach ($vm in $GetVM)
{
$vmId =""
$vmId = $vm.vmid
$vmIdList +=$vmId + "`r`n"
}
Write-Output $vmIdList
Please let me know if above answers your question.

AppService access restrictions and access from Release Pipelines

As part of my deployment I would like to call some endpoint in my application to smoke test it.
But we are using Access Restrictions and calls from Azure Devops Release Pipeline are rejected.
Is there a way around this?
Right after asking question I noticed there is new option in Preview in Access Restrictions page in Azure portal.
With this rule Azure Devops will be able to reach application endpoints.
Or using Powershell
Add-AzWebAppAccessRestrictionRule
-ResourceGroupName "resourcegroup"
-WebAppName "webapi"
-Priority 65000
-ServiceTag Azurecloud
-Action Allow
In future you should be able to use AzureDevOps service tag, but looks like it's not supported in Preview - Set a service tag-based rule (preview)

Make Azure Functions not publicly accessible?

Currently my functions are accessible publicly. Is there a way to make it so that they can only be accessed via something else, like an API gateway, and not directly? I tried adding a VNET via the "networking" blade but I don't think that did anything (I could still call the functions publicly)...I think that just makes it so the functions could access resources on a private network. I didn't see any options in the settings to make the IP private. I'm not very well versed in networking related issues, so apologies if I'm being unclear.
The built-in keys support is meant to provide an option for this. You can require all requests to include an API key which is only shared with resources you care about. In fact, all HTTP-triggered functions require a key by default. You would have to explicitly choose to remove this requirement.
Keys aren't a networking solution though, and if you leak the keys, someone could access your APIs (until you roll the keys). You are correct that the VNet support is point-to-site, meaning it can access resources, but the function app is not protected itself. An App Service Environment would solve that, although Kai's comment on the original question is correct - ASE is not yet available for Functions.
In addition to keys, you could look at using App Service Authentication / Authorization to require an AAD service principal. This is effectively like a key, but has additional benefits if you are modeling other entities in AAD. Unless you know you need this, though, I would stick with keys.
With CORS functionnality you can restrict access to your Azure Function. To configure this, check the following link : Azure Function Settings, at the CORS section.
You can apply access restrictions to an Azure Function. The documentation can be found here.
You can use PowerShell AZ module to create a rule (or the portal if you prefer).
Add-AzWebAppAccessRestrictionRule `
-ResourceGroupName "ResourceGroup" `
-WebAppName "AppName" `
-Name "Ip example rule" `
-Priority 100 `
-Action Allow `
-IpAddress 122.133.144.0/24
Docs for Add-AzWebAppAccessRestrictionRule can be found here.
IP restrictions can be used to restrict access to whitelisted IPs. You can do it via the the Portal -
https://learn.microsoft.com/en-gb/azure/app-service/app-service-ip-restrictions
or in the web.config with ipSecurity

Resources