-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
azurerm_windows_web_app
, azurerm_windows_web_app_slot
, azurerm_linux_web_app
, azurerm_linux_web_app_slot
- add the default ip action
#24519
Conversation
Thanks @xiaxyi for opening the PR! |
Thanks @TrueSvenpai for the comment, would you mind be more specific about the update part? Do you mean the azure policy may change the status of the property |
Hi @xiaxyi , |
Thanks @TrueSvenpai for the explanation, if my understanding is correct, the property I tested the behavior, firstly not include the public ip access as :
then update leaving the default ip unchanged and added the public access:
The network setting remains the same: (API GET response)
It seems to me that the property remains what it was if no changes in the TF config. Please correct me if there is any misunderstanding, or it would be better if you can share some simple config with me for testing. |
@TrueSvenpai Good day! Any comments on my last response would be appreciated! :) |
@xiaxyi Good Day! |
@TrueSvenpai No worries about the delay response. Let me know once you have any updates |
Hi @xiaxyi, thanks a lot for implementing this. I originally reported the issue in #22593 and my colleagues made me aware of this PR. The way we originally noticed that these properties are missing is because we have deny-mode Azure Policies in place that prevent customers from deploying App Service Web Apps with public network access enabled in case no IP security restrictions are configured. Our policy needs to evaluate the properties "ipSecurityRestrictionsDefaultAction" and "scmIpSecurityRestrictionsDefaultAction", because we cannot allow deployment of Web Apps that allow all Internet traffic by default. The way deny-mode Azure policies work is that they only can evaluate deployment requests (meaning: API request payloads). They do not know what the corresponding Azure resource provider decides to do with that deployment request after it passed policy validation. Because of that it is crucial that API clients always perform proper PUT requests and always send all the attributes of the resource, even if they did not change. I'm not too familiar with how the Terraform provider works internally, but as far as I can tell from the resulting API requests, this is how other resources are implemented as well. Also the Azure CLI and Portal usually do this. |
Another suggestion: Maybe the property name in Terraform could be something along "ip_restriction_allow_by_default" if it has to be a bool. The name "ip_access_enabled" could be somewhat misleading because the property does not enable or disable IP access (that's what "public_network_access" does), but rather configures the firewall action in case no more specific rules apply. I think users would have a hard time understanding why they need to set |
Hi @xiaxyi, In my PR, both scmIpAccessEnabled and ipAccessEnabled are set to the update regardless of any changes:
Then the policy can check in the update for both attributes and allow the update. This is the only difference between our code for the linuxwebapp |
Thanks @TrueSvenpai and @andaryjo for your comment, if my understanding is correct, are you suggesting that your azure policy is checking the request body and then decide whether to accept/ reject the request? In my tests result, the value won't be changed even if it's not included in the request payload and does that mean if the create action is allowed by Azure policy at first place, the web app should be allowed if the property is not included in the request body when doing the update? I don't think it's a good idea of removing the hasChange check for it as the |
@andaryjo I will consider changing the name foir these two properties, but now we need to hold the change as we are migrating the app service SDK to Hashicorp azure go sdk, after the sdk change, we need to rebase the code, so any changes will need be waited after that... |
@TrueSvenpai good day! Do you have any questions to my last comment about the update part? let me know if you have any concern. |
@xiaxyi Sorry for my late response.
Unfortunately the policy framework has no access to the resource's current state. It can only evaluate what is present in the API request. So when an Azure policy evaluates a resource deployment (either create or update), it does not know whether the resource already exists and gets updated or whether it gets newly created. It also cannot access current properties of a potential already existing resource. To not allow constellations which should normally get denied, when you author Azure policies and a property gets omitted from a request, you need to suppose that in the worst case the resource does not yet exist. This means that always all properties of a resource must end up in the deployment request. Even if you only update the resource and the properties did not change, they must be included in the request. The Azure REST API handles it like this:
I'm not familar enough with the Terraform provider to say how it should handle this. All I know is, if it performs a PUT request, it must supply all resource properties for policy evaluations to work correctly. If it performs a PATCH request, it should be sufficient to only provide the properties that changed. But there is a catch. I noticed PATCH API requests not passing our custom Azure policy when they don't explicitly provide the To see a confirmation of what I'm talking about, simply deploy an App Service Web App through the Azure Portal and look into the HTTP requests your browser sends. You will see the Azure Portal performing PUT requests to the Azure Management API which always include the To reproduce:
|
Thanks @andaryjo for the explanation, let me involve our PR reviewer @jackofallops here for a discussion. @jackofallops Do you have any comment about removing the Besides of the hasChange check, I updated the property naming from |
I've ran some tests to confirm what @TrueSvenpai said. I've created a azurerm_linux_web_app resource like this:
Using trace logging mode on the provider reveals the API requests that the provider makes to the Azure REST API. For initial creation, the provider performs a PUT request which contains the new
If I now update the resource (for example change the IP address in the ip_restriction block, the Terraform provider now still performs a PUT request, but omits the
You can see that the Terraform provider fetched all the properties of the resource (even those that have been assigned server-side) and supplies them in the PUT request. Which makes sense, since with a PUT request, the server expects you to provide the whole resource. But the My understanding is, if the Terraform provider is only supplying some resource properties to the request, it should perform PATCH requests. But if it performs PUT requests, it needs to supply all properties of the resource for policy evaluatio to work properly. |
Hi @xiaxyi - As discussed offline, I'm going to close this in favour of a different approach that also covers all the supporting resources in one go. Thanks again! |
@jackofallops could you please give some more insights into what that approach is, whether there's already a new pull request or what the rough timeline here is? After spending so much time and effort discussing this issue, it's really frustrating to me when you guys simply close it without any real explanation. Hope you can understand that. |
Nevermind, just found the follow-up PR. For future visitors of this thread: #25131 |
I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions. |
For windows and linux web app, there is a switch to turn on/ off the network access from the site level called:
ipSecurityRestrictionsDefaultAction
for the main site andscmIpSecurityRestrictionsDefaultAction
for the scm site.referfence:https://learn.microsoft.com/en-us/azure/app-service/app-service-ip-restrictions?tabs=azurecli
User can't deny all access based on current Terraform provider as we have the ip address validation when specifying the
ip_address
inip_restriction
block.Acc test failure doesn't relate to the added property:
fix #22593
Partially duplicate to PR #24464 as it only covered Linux web app which the feature is also available to windows web app as well.