terraform-provider-azurerm: Authentication not working with `auth_settings_v2` because of not-omitted empty validation checks
Is there an existing issue for this?
- I have searched the existing issues
Community Note
- Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
- Please do not leave “+1” or “me too” comments, they generate extra noise for issue followers and do not help prioritize the request
- If you are interested in working on this issue or have submitted a pull request, please leave a comment
Terraform Version
1.3.9
AzureRM Provider Version
3.45.0
Affected Resource(s)/Data Source(s)
azurerm_linux_web_app
Terraform Configuration Files
resource "azurerm_linux_web_app" "api" {
name = "app-test"
location = "westeurope"
resource_group_name = "rg-test"
auth_settings_v2 {
auth_enabled = true
default_provider = "aad"
forward_proxy_convention = "NoProxy"
require_authentication = true
require_https = true
unauthenticated_action = "RedirectToLoginPage"
active_directory_v2 {
client_id = "---"
tenant_auth_endpoint = "---"
client_secret_setting_name = "MICROSOFT_PROVIDER_AUTHENTICATION_SECRET"
}
}
}
Debug Output/Panic Output
no relevance
Expected Behaviour
Expected resource json in authsettingsV2
.
"azureActiveDirectory": {
"enabled": true,
"registration": {
"openIdIssuer": "https://sts.windows.net/---/v2.0",
"clientId": "---",
"clientSecretSettingName": "MICROSOFT_PROVIDER_AUTHENTICATION_SECRET"
},
"login": {
"loginParameters": [],
"disableWWWAuthenticate": false
},
"validation": {
"jwtClaimChecks": {},
"defaultAuthorizationPolicy": {
"allowedPrincipals": {}
}
}
}
Actual Behaviour
Actual resource json in authsettingsV2
.
"azureActiveDirectory": {
"enabled": true,
"registration": {
"openIdIssuer": "https://sts.windows.net/---/v2.0",
"clientId": "---",
"clientSecretSettingName": "MICROSOFT_PROVIDER_AUTHENTICATION_SECRET",
"clientSecretCertificateThumbprint": ""
},
"login": {
"loginParameters": [],
"disableWWWAuthenticate": false
},
"validation": {
"jwtClaimChecks": {
"allowedGroups": [],
"allowedClientApplications": []
},
"allowedAudiences": [],
"defaultAuthorizationPolicy": {
"allowedPrincipals": {
"groups": [],
"identities": []
},
"allowedApplications": []
}
}
}
Steps to Reproduce
No response
Important Factoids
No response
References
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 25
- Comments: 19 (2 by maintainers)
Can confirm the issue when trying to configure App Service authentication with
auth_settings_v2
. For me the issue emerged when trying to provide pre-created app registration, after first testing it by toggling/auto-generating the auth and app registration directly from Portal.I used hours to debug the issue, but only difference I found (comparing first the manual and auto-generated app registrations, then the actual
/providers/Microsoft.Web/sites/xxx/config/authsettingsV2
resources as well.) was just what described by @mickare about the empty list stuff.Examples of the differences in settings (
az webapp auth microsoft show
) when autogenerated vs. when created with Terraform:Autogenerated (auth working):
Created with Terraform (auth not working, HTTP 500 with no other details):
auth_settings_v2
block used in TerraformThis makes the
auth_settings_v2
currently unusable.Fix is already merged in #21113 and will be in next release 😃
Hi @xiaxyi, there is a HUGE difference between an “empty list” and a “missing list”.
Showing the problem with code is much faster.
Output:
The difference between cases a,b,c show that it does matter if an empty pointer or an empty list is provided to any model that is serialized with json.
Case C is the problematic one when
terraform-provider-azurerm
models are transformed toazure-sdk-for-go
models. E.g.:AllowedClientApplications: &aad.JWTAllowedClientApps
(here)I tried 3.49, and the problem might be fixed but I can’t tell because it crashed.
Using the following terraform code (unchanged from before really)
This is the output I got:
Created a PR in hashicorp/go-azure-helpers to add a new pointer method
FromSliceOrOmitEmpty
.This could be used to replace all the problematic
pointer.To
calls when creating theazure-sdk-for-go
data structureI’ve hit the same issue and resorted to using azapi as a workaround until this bug is resolved.
It is not quite as nice as the azurerm way, but it works for now.
For everyone who have this authentication issue:
Removing the lists
jwtClaimChecks.allowedGroups
,jwtClaimChecks.allowedClientApplications
,allowedPrincipals.groups
,allowedPrincipals.identities
,allowedApplications
to tempoary fix the issue.You can use the Azure Resource Explorer to temporary fix the issue (until the next Terraform deployment): https://resources.azure.com