Skip to content
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

Azure Linux Web App doesn't have callback route? #20989

Open
1 task done
ncook-hxgn opened this issue Mar 16, 2023 · 17 comments
Open
1 task done

Azure Linux Web App doesn't have callback route? #20989

ncook-hxgn opened this issue Mar 16, 2023 · 17 comments

Comments

@ncook-hxgn
Copy link

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.40.0

AzureRM Provider Version

3.47.0

Affected Resource(s)/Data Source(s)

azurerm_linux_web_app

Terraform Configuration Files

provider.tf
provider "azurerm" {
  features {}
}

terraform {
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "3.47.0"
    }
  }
}


backend.tf

terraform {
    backend "azurerm" {
        resource_group_name   = "tf_rg"
        storage_account_name  = "tf_sa"
        container_name        = "tfstate"
        key                   = "example.tfstate"
    }
}

main.tf
# Run the script to get the environment variables of interest.
# This is a data source, so it will run at plan time.
# this bit of code says a lot, imho.
data "external" "env" {
  program = ["sh", "-c", "jq -n 'env | {ARM_TENANT_ID,ARM_SUBSCRIPTION_ID,ARM_CLIENT_ID,ARM_CLIENT_SECRET}'"]
}

# Define a Resource Group for an Azure App
resource "azurerm_resource_group" "example_rg" {
  name     = "${var.app_name}-rg"
  location = "West Europe"
}

# Define an Azure App Service Plan for Linux
# https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/app_service_plan
resource "azurerm_service_plan" "example_service_plan" {
  name                = "${var.app_name}-serviceplan"
  location            = azurerm_resource_group.example_rg.location
  resource_group_name = azurerm_resource_group.example_rg.name
  os_type             = "Linux"
  sku_name            = "B1"
}

# Define an Azure Web App
# https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/azurerm_linux_web_app
resource "azurerm_linux_web_app" "example_wa" {
  name                = "${var.app_name}"
  resource_group_name = azurerm_resource_group.example_rg.name
  location            = azurerm_service_plan.example_service_plan.location
  service_plan_id     = azurerm_service_plan.example_service_plan.id


  # Enable a System Managed Identity for the Azure Web App
  identity {
    type = "SystemAssigned"
  }

  # iisnode
  site_config {
    application_stack {
      node_version = "16-lts"
    }
  }

  # Configure the Azure Web app with your AAD Auth Provider (see web.config)
  auth_settings_v2 {
    auth_enabled                  = true
    require_authentication        = true
    default_provider              = "AzureActiveDirectory"
    unauthenticated_action        = "RedirectToLoginPage"

    # our default_provider:
    active_directory_v2 {
      tenant_auth_endpoint        = "https://login.microsoftonline.com/${data.external.env.result["ARM_TENANT_ID"]}/v2.0"
      client_secret_setting_name  = "MICROSOFT_PROVIDER_AUTHENTICATION_SECRET" # should be used instead of ARM_CLIENT_SECRET
      client_id                   = data.external.env.result["ARM_CLIENT_ID"]
      allowed_groups              = var.app_allowed_groups
    }

    # use a store for tokens (az blob storage backed)
    login {
      token_store_enabled = true
    }
  }
}

# Output the Azure Web App URL
output "webapp_url" {
  value = "https://${azurerm_linux_web_app.example_wa.default_hostname}"
}


variables.tf
variable "app_name" {
  description = "The name of the Azure Web App to create."
  type        = string
}
variable "app_allowed_groups" {
  description = "The list of allowed Group Names for the Default Authorisation Policy."
  type        = list(string)
}

Debug Output/Panic Output

None, but expected some maybe?

Expected Behaviour

There should be a sensible callback url defined here in the portal in App Services > Example > Authentication > Identity Provider > Microsoft (click the link for the App Registration)
image

Actual Behaviour

Because there isn't the correct redirect URI in the app registration created by active_directory_v2, the Authentication provider doesn't work.

When I visit my deployed site, I consent to the app looking me up on Graph, and after that I am redirected to e.g. https://example.azurewebsites.net/.auth/login/aad/callback.

This results in the following screen:
image

The redirect URL it is trying to send me to is correct (that is, I have ported this solution from auth_settings.active_directory, which worked, and that was the redirect URI. Now, I need the allowed_groups feature, so I'm upgrading to auth_settings_v2.active_directory_v2)

Steps to Reproduce

terraform apply with the code above and a suitable terraform.tfvars file (see provided variables.tf)

Important Factoids

No response

References

No response

@ncook-hxgn
Copy link
Author

So I tried a dumb workaround,

  1. Paste https://example.azurewebsites.net/.auth/login/aad/callback into the Redirect URI in the App Registration,
    image

  2. Restart the Web App, then in a private window, browse it it.
    image

it didn't work:

I managed to enter an email and a password and pass MFA (it didn't ask me to consent for graph API lookup, so presume that stuck).

The the redirect URI didn't exist.. I got the following in my browser:
This page isn’t working
example.azurewebsites.net is currently unable to handle this request.
HTTP ERROR 500

So, I went back to 1. and changed the link again to https://example.azurewebsites.net/, and got the error I had in the first place on OP.

So.. not sure if this is helpful.

Probably just bad code on my side, missing parameter or something?

@mikeam565
Copy link

I think (2) is closer to correct than (1). In (1), you didn't have the redirect URL registered in Azure AD. In (2), since it was registered, AD redirected you back to your app using that URL, but for some reason, that callback route doesn't seem to work. This is where I have been stuck and the documentation on easyauth or authn/authz (whatever they call the auth module) is very unclear.

@aristosvo
Copy link
Collaborator

@ncook-hxgn Did you apply this: https://learn.microsoft.com/en-us/azure/app-service/configure-authentication-provider-aad#-option-2-use-an-existing-registration-created-separately?

I saw you were using the Service Principal details to fill in the application details, which wont work/I wouldn't advise. Try to create a separate application accordingly to provided instructions on the link, that should probably solve most of your problems.

@ncook-hxgn
Copy link
Author

ncook-hxgn commented Mar 17, 2023

@aristosvo I'm not sure I follow what you're saying - I think you're referring to my workaround?

@mikeam565 I agree, the docs aren't always very helpful. I had to look at the PR for v3.45 to make sense of the structure of the doc file for azurerm_linux_web_app. There's no headings in it and the links in the docs don't work as I think was intended either. I digress.

I went back to the old auth_settings.active_directory, to see if I would get the redirect/callback uri set. (This Used To Work And Now It Doesn't)

data "external" "env" {
  program = ["sh", "-c", "jq -n 'env | {ARM_TENANT_ID,ARM_SUBSCRIPTION_ID,ARM_CLIENT_ID,ARM_CLIENT_SECRET}'"]
}

# Define a Resource Group for an Azure App
resource "azurerm_resource_group" "example_rg" {
  name     = "${var.app_name}-rg"
  location = "West Europe"
}

# Define an Azure App Service Plan for Linux
# https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/app_service_plan
resource "azurerm_service_plan" "example_service_plan" {
  name                = "${var.app_name}-serviceplan"
  location            = azurerm_resource_group.example_rg.location
  resource_group_name = azurerm_resource_group.example_rg.name
  os_type             = "Linux"
  sku_name            = "B1"
}

# Define an Azure Web App
# https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/azurerm_linux_web_app
resource "azurerm_linux_web_app" "example_wa" {
  name                = "${var.app_name}"
  resource_group_name = azurerm_resource_group.example_rg.name
  location            = azurerm_service_plan.example_service_plan.location
  service_plan_id     = azurerm_service_plan.example_service_plan.id


  # Enable a System Managed Identity for the Azure Web App
  identity {
    type = "SystemAssigned"
  }

  # iisnode
  site_config {
    application_stack {
      node_version = "16-lts"
    }
  }

  # Configure the Azure Web app with your AAD Auth Provider (see web.config)
  auth_settings {
    enabled                       = true
    issuer                        = "https://sts.windows.net/${data.external.env.result["ARM_TENANT_ID"]}"
    default_provider              = "AzureActiveDirectory"
    token_refresh_extension_hours = 24
    token_store_enabled           = true
    unauthenticated_client_action = "RedirectToLoginPage"

    active_directory {
      client_id     = data.external.env.result["ARM_CLIENT_ID"]
      client_secret = data.external.env.result["ARM_CLIENT_SECRET"]
    }
  }
}

# Output the Azure Web App URL
output "webapp_url" {
  value = "https://${azurerm_linux_web_app.example_wa.default_hostname}"
}

It set the redirect URI as the AAD Auth provider expects (and thus, as I tried in my workaround):
image

Something is wrong with active_directory_v2. It doesn't properly initialise the redirect uri as active_directory did, and upgrading to v2 therefore breaks my world.

@mikeam565
Copy link

For context, I am personally having this issue with the custom_oidc_v2 setting. Same issue. Redirect uris registered with my OP, I can get auth to work in curl commands using our client id and secret, but the easy auth/authz/authn module that this auth_settings_v2 corresponds to 500 errors on redirect to callback (and shows no trace of the error in the logs either).

@ncook-hxgn
Copy link
Author

@mikeam565 I see, OK I'm glad it's not just me 😄

@mikeam565
Copy link

@ncook-hxgn It's definitely not... I'm about to just implement auth myself, it's ridiculously easy with just minor modifications to code... You'd just think that a module called "easy auth" would be ... easy.

@ncook-hxgn
Copy link
Author

I tried 3.49, and the problem might be fixed but I can't tell because azurerm crashed.

Using the following terraform code (unchanged from before really)

# Run the script to get the environment variables of interest.
# This is a data source, so it will run at plan time.
data "external" "env" {
  program = ["sh", "-c", "jq -n 'env | {ARM_TENANT_ID,ARM_SUBSCRIPTION_ID,ARM_CLIENT_ID,ARM_CLIENT_SECRET}'"]
}

# Define a Resource Group for an Azure App
resource "azurerm_resource_group" "example_rg" {
  name     = "${var.app_name}-rg"
  location = "West Europe"
}

# Define an Azure App Service Plan for Linux
# https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/app_service_plan
resource "azurerm_service_plan" "example_service_plan" {
  name                = "${var.app_name}-serviceplan"
  location            = azurerm_resource_group.example_rg.location
  resource_group_name = azurerm_resource_group.example_rg.name
  os_type             = "Linux"
  sku_name            = "B1"
}

# Define an Azure Web App
# https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/azurerm_linux_web_app
resource "azurerm_linux_web_app" "example_wa" {
  name                = "${var.app_name}"
  resource_group_name = azurerm_resource_group.example_rg.name
  location            = azurerm_service_plan.example_service_plan.location
  service_plan_id     = azurerm_service_plan.example_service_plan.id


  # Enable a System Managed Identity for the Azure Web App
  identity {
    type = "SystemAssigned"
  }

  # iisnode
  site_config {
    application_stack {
      node_version = "16-lts"
    }
  }

  # Configure the Azure Web app with your AAD Auth Provider (see web.config)
  #auth_settings {
  #  enabled                       = true
  #  issuer                        = "https://sts.windows.net/${data.external.env.result["ARM_TENANT_ID"]}"
  #  default_provider              = "AzureActiveDirectory"
  #  token_refresh_extension_hours = 24
  #  token_store_enabled           = true
  #  unauthenticated_client_action = "RedirectToLoginPage"
  #
  #  active_directory {
  #    client_id     = data.external.env.result["ARM_CLIENT_ID"]
  #    client_secret = data.external.env.result["ARM_CLIENT_SECRET"]
  #  }
  #}
  # Configure the Azure Web app with your AAD Auth Provider (see web.config)
  auth_settings_v2 {
    auth_enabled                  = true
    require_authentication        = true
    default_provider              = "AzureActiveDirectory"
    unauthenticated_action        = "RedirectToLoginPage"
    # our default_provider:
    active_directory_v2 {
      tenant_auth_endpoint        = "https://login.microsoftonline.com/${data.external.env.result["ARM_TENANT_ID"]}/v2.0"
      client_secret_setting_name  = "MICROSOFT_PROVIDER_AUTHENTICATION_SECRET"  # should be used instead of ARM_CLIENT_SECRET
      client_id                   = data.external.env.result["ARM_CLIENT_ID"]
      # client_secret               = data.external.env.result["ARM_CLIENT_SECRET"]
      allowed_groups              = var.app_allowed_groups
    }
    # use a store for tokens (az blob storage backed)
    login {
      token_store_enabled = true
    }
  }
}

# Output the Azure Web App URL
output "webapp_url" {
  value = "https://${azurerm_linux_web_app.example_wa.default_hostname}"
}

This is the output I got:

azurerm_linux_web_app.example_wa: Creating...
azurerm_linux_web_app.example_wa: Still creating... [10s elapsed]
azurerm_linux_web_app.example_wa: Still creating... [20s elapsed]
azurerm_linux_web_app.example_wa: Still creating... [30s elapsed]
azurerm_linux_web_app.example_wa: Still creating... [40s elapsed]
╷
│ Error: Plugin did not respond
│ 
│   with azurerm_linux_web_app.example_wa,
│   on main.tf line 26, in resource "azurerm_linux_web_app" "example_wa":
│   26: resource "azurerm_linux_web_app" "example_wa" {
│ 
│ The plugin encountered an error, and failed to respond to the
│ plugin.(*GRPCProvider).ApplyResourceChange call. The plugin logs may
│ contain more details.
╵

Stack trace from the terraform-provider-azurerm_v3.49.0_x5 plugin:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x49a993b]

goroutine 140 [running]:
github.com/hashicorp/terraform-provider-azurerm/internal/services/appservice/helpers.expandAadAuthV2Settings({0xc00117d7a0, 0x1, 0x0?})
	github.com/hashicorp/terraform-provider-azurerm/internal/services/appservice/helpers/auth_v2_schema.go:981 +0x55b
github.com/hashicorp/terraform-provider-azurerm/internal/services/appservice/helpers.ExpandAuthV2Settings({0xc00149f6c0, 0x1, 0x75b6c00?})
	github.com/hashicorp/terraform-provider-azurerm/internal/services/appservice/helpers/auth_v2_schema.go:2059 +0x12a
github.com/hashicorp/terraform-provider-azurerm/internal/services/appservice.LinuxWebAppResource.Create.func1({0x75c4168, 0xc001d41da0}, {0xc0027f0000, {0x75c4c90, 0xc000453cf8}, 0xc000227e80, 0x0, {0x75c60b0, 0xbb25668}})
	github.com/hashicorp/terraform-provider-azurerm/internal/services/appservice/linux_web_app_resource.go:385 +0x1b0d
github.com/hashicorp/terraform-provider-azurerm/internal/sdk.(*ResourceWrapper).Resource.func2({0x75c4168, 0xc001d41da0}, 0x1a3185c431c?, {0x617f780?, 0xc0027f0000?})
	github.com/hashicorp/terraform-provider-azurerm/internal/sdk/wrapper_resource.go:52 +0x163
github.com/hashicorp/terraform-provider-azurerm/internal/sdk.diagnosticsWrapper.func1({0x75c4168, 0xc001d41da0}, 0x0?, {0x617f780, 0xc0027f0000})
	github.com/hashicorp/terraform-provider-azurerm/internal/sdk/wrapper_resource.go:185 +0xbe
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).create(0xc000176000, {0x75c41a0, 0xc001370990}, 0xd?, {0x617f780, 0xc0027f0000})
	github.com/hashicorp/terraform-plugin-sdk/v2@v2.24.1/helper/schema/resource.go:707 +0x12e
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(0xc000176000, {0x75c41a0, 0xc001370990}, 0xc000fc2b60, 0xc000227c80, {0x617f780, 0xc0027f0000})
	github.com/hashicorp/terraform-plugin-sdk/v2@v2.24.1/helper/schema/resource.go:837 +0xa85
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ApplyResourceChange(0xc0013ea2b8, {0x75c41a0?, 0xc001370870?}, 0xc00136e8c0)
	github.com/hashicorp/terraform-plugin-sdk/v2@v2.24.1/helper/schema/grpc_provider.go:1021 +0xe8d
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ApplyResourceChange(0xc0013d0500, {0x75c41a0?, 0xc001370240?}, 0xc0019647e0)
	github.com/hashicorp/terraform-plugin-go@v0.14.3/tfprotov5/tf5server/server.go:818 +0x574
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ApplyResourceChange_Handler({0x68d1600?, 0xc0013d0500}, {0x75c41a0, 0xc001370240}, 0xc001964770, 0x0)
	github.com/hashicorp/terraform-plugin-go@v0.14.3/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:385 +0x170
google.golang.org/grpc.(*Server).processUnaryRPC(0xc000468000, {0x75d43c0, 0xc001947380}, 0xc001b80480, 0xc001a76780, 0xbae4da0, 0x0)
	google.golang.org/grpc@v1.51.0/server.go:1340 +0xd23
google.golang.org/grpc.(*Server).handleStream(0xc000468000, {0x75d43c0, 0xc001947380}, 0xc001b80480, 0x0)
	google.golang.org/grpc@v1.51.0/server.go:1713 +0xa2f
google.golang.org/grpc.(*Server).serveStreams.func1.2()
	google.golang.org/grpc@v1.51.0/server.go:965 +0x98
created by google.golang.org/grpc.(*Server).serveStreams.func1
	google.golang.org/grpc@v1.51.0/server.go:963 +0x28a

Error: The terraform-provider-azurerm_v3.49.0_x5 plugin crashed!

This is always indicative of a bug within the plugin. It would be immensely
helpful if you could report the crash with the plugin's maintainers so that it
can be fixed. The output above should help diagnose the issue.

##[debug]Exit code 1 received from tool '/opt/hostedtoolcache/terraform/1.4.2/x64/terraform'

@aristosvo
Copy link
Collaborator

Hopefully fixed in #21113 /next release!!🤞

@ncook-hxgn
Copy link
Author

azurerm_linux_web_app.docs_portal_wa: Still creating... [50s elapsed]
╷
│ Error: Plugin did not respond
│ 
│   with azurerm_linux_web_app.docs_portal_wa,
│   on main.tf line 26, in resource "azurerm_linux_web_app" "docs_portal_wa":
│   26: resource "azurerm_linux_web_app" "docs_portal_wa" {
│ 
│ The plugin encountered an error, and failed to respond to the
│ plugin.(*GRPCProvider).ApplyResourceChange call. The plugin logs may
│ contain more details.
╵

Stack trace from the terraform-provider-azurerm_v3.50.0_x5 plugin:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x49b087b]

goroutine 149 [running]:
github.com/hashicorp/terraform-provider-azurerm/internal/services/appservice/helpers.expandAadAuthV2Settings({0xc0017416c0, 0x1, 0x0?})
	github.com/hashicorp/terraform-provider-azurerm/internal/services/appservice/helpers/auth_v2_schema.go:981 +0x55b
github.com/hashicorp/terraform-provider-azurerm/internal/services/appservice/helpers.ExpandAuthV2Settings({0xc001ef2680, 0x1, 0x75cc920?})
	github.com/hashicorp/terraform-provider-azurerm/internal/services/appservice/helpers/auth_v2_schema.go:2059 +0x12a
github.com/hashicorp/terraform-provider-azurerm/internal/services/appservice.LinuxWebAppResource.Create.func1({0x75d9ee8, 0xc001772600}, {0xc001d36000, {0x75daa10, 0xc00011dce0}, 0xc0019b8980, 0x0, {0x75dbe30, 0xbb457e8}})
	github.com/hashicorp/terraform-provider-azurerm/internal/services/appservice/linux_web_app_resource.go:385 +0x1b0d
github.com/hashicorp/terraform-provider-azurerm/internal/sdk.(*ResourceWrapper).Resource.func2({0x75d9ee8, 0xc001772600}, 0x1a3185c41f0?, {0x61914e0?, 0xc001d36000?})

@ncook-hxgn
Copy link
Author

#21113

@rocketmonkeys
Copy link

@mikeam565 - FYI, I'm not sure if it's related to what you experienced with custom_oidc_v2, but I just noticed that if I don't set "default_provider" in terraform, then the "Redirect to" setting is left blank and I get a warning in azure portal:

Unauthenticated traffic is blocked, and requests will receive an HTTP 401 Unauthorized. This is because the app is configured to redirect unauthenticated traffic to an invalid target. You should update the authentication settings either to redirect to a configured provider or to handle unauthenticated requests in a different way.

Setting default_provider = "{name of custom oidc method}" fixes this error. It may be unrelated to what you saw.

@ncook-hxgn
Copy link
Author

@aristosvo still broken in v3.51.0 I'm afraid..

╷
│ Error: Plugin did not respond
│ 
│   with azurerm_linux_web_app.docs_portal_wa,
│   on main.tf line 26, in resource "azurerm_linux_web_app" "docs_portal_wa":
│   26: resource "azurerm_linux_web_app" "docs_portal_wa" {
│ 
│ The plugin encountered an error, and failed to respond to the
│ plugin.(*GRPCProvider).ApplyResourceChange call. The plugin logs may
│ contain more details.
╵

Stack trace from the terraform-provider-azurerm_v3.51.0_x5 plugin:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x49cdf3b]

goroutine 140 [running]:
github.com/hashicorp/terraform-provider-azurerm/internal/services/appservice/helpers.expandAadAuthV2Settings({0xc001a41340, 0x1, 0x0?})
	github.com/hashicorp/terraform-provider-azurerm/internal/services/appservice/helpers/auth_v2_schema.go:981 +0x55b
github.com/hashicorp/terraform-provider-azurerm/internal/services/appservice/helpers.ExpandAuthV2Settings({0xc0010456c0, 0x1, 0x761da40?})
	github.com/hashicorp/terraform-provider-azurerm/internal/services/appservice/helpers/auth_v2_schema.go:2062 +0x12a
github.com/hashicorp/terraform-provider-azurerm/internal/services/appservice.LinuxWebAppResource.Create.func1({0x762b188, 0xc0021ef980}, {0xc0016a9c00, {0x762bcb0, 0xc00011dd28}, 0xc000573700, 0x0, {0x762d0d0, 0xbbcdbe8}})
	github.com/hashicorp/terraform-provider-azurerm/internal/services/appservice/linux_web_app_resource.go:385 +0x1b0d
github.com/hashicorp/terraform-provider-azurerm/internal/sdk.(*ResourceWrapper).Resource.func2({0x762b188, 0xc0021ef980}, 0x1a3185c44ac?, {0x61d4be0?, 0xc0016a9c00?})
	github.com/hashicorp/terraform-provider-azurerm/internal/sdk/wrapper_resource.go:52 +0x163
github.com/hashicorp/terraform-provider-azurerm/internal/sdk.diagnosticsWrapper.func1({0x762b188, 0xc0021ef980}, 0x0?, {0x61d4be0, 0xc0016a9c00})
	github.com/hashicorp/terraform-provider-azurerm/internal/sdk/wrapper_resource.go:185 +0xbe
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).create(0xc0001c6000, {0x762b1c0, 0xc0016421b0}, 0xd?, {0x61d4be0, 0xc0016a9c00})
	github.com/hashicorp/terraform-plugin-sdk/v2@v2.24.1/helper/schema/resource.go:707 +0x12e
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(0xc0001c6000, {0x762b1c0, 0xc0016421b0}, 0xc0021481a0, 0xc000573580, {0x61d4be0, 0xc0016a9c00})
	github.com/hashicorp/terraform-plugin-sdk/v2@v2.24.1/helper/schema/resource.go:837 +0xa85
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ApplyResourceChange(0xc001ade540, {0x762b1c0?, 0xc001642090?}, 0xc00136a820)
	github.com/hashicorp/terraform-plugin-sdk/v2@v2.24.1/helper/schema/grpc_provider.go:1021 +0xe8d
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ApplyResourceChange(0xc00136dcc0, {0x762b1c0?, 0xc000bc1680?}, 0xc001198700)
	github.com/hashicorp/terraform-plugin-go@v0.14.3/tfprotov5/tf5server/server.go:818 +0x574
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ApplyResourceChange_Handler({0x69311c0?, 0xc00136dcc0}, {0x762b1c0, 0xc000bc1680}, 0xc001198620, 0x0)
	github.com/hashicorp/terraform-plugin-go@v0.14.3/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:385 +0x170
google.golang.org/grpc.(*Server).processUnaryRPC(0xc00045e000, {0x763b6e0, 0xc0018de000}, 0xc001d73320, 0xc001bbad20, 0xbb8d320, 0x0)
	google.golang.org/grpc@v1.51.0/server.go:1340 +0xd23
google.golang.org/grpc.(*Server).handleStream(0xc00045e000, {0x763b6e0, 0xc0018de000}, 0xc001d73320, 0x0)
	google.golang.org/grpc@v1.51.0/server.go:1713 +0xa2f
google.golang.org/grpc.(*Server).serveStreams.func1.2()
	google.golang.org/grpc@v1.51.0/server.go:965 +0x98
created by google.golang.org/grpc.(*Server).serveStreams.func1
	google.golang.org/grpc@v1.51.0/server.go:963 +0x28a

Error: The terraform-provider-azurerm_v3.51.0_x5 plugin crashed!

This is always indicative of a bug within the plugin. It would be immensely
helpful if you could report the crash with the plugin's maintainers so that it
can be fixed. The output above should help diagnose the issue.

##[debug]Exit code 1 received from tool '/opt/hostedtoolcache/terraform/1.4.5/x64/terraform'
##[debug]STDIO streams have closed for tool '/opt/hostedtoolcache/terraform/1.4.5/x64/terraform'
##[debug]task result: Failed
##[error]Error: The process '/opt/hostedtoolcache/terraform/1.4.5/x64/terraform' failed with exit code 1
##[debug]Processed: ##vso[task.issue type=error;]Error: The process '/opt/hostedtoolcache/terraform/1.4.5/x64/terraform' failed with exit code 1
##[debug]Processed: ##vso[task.complete result=Failed;]Error: The process '/opt/hostedtoolcache/terraform/1.4.5/x64/terraform' failed with exit code 1
Finishing: Terraform Apply

@ncook-hxgn
Copy link
Author

@aristosvo so I tried 3.52 and didn't get a crash this time, but I still get an error in my browser when browsing to my web app url.

AADSTS700054: response_type 'id_token' is not enabled for the application.


Circumstantially, the role assignment I do in the IRL code that birthed the repro code in the OP has stopped working. Not sure if because new azurerm provider or because a service principle has changed whilst I was away.. I will dig deeper.. (it's probably the latter tbh)

@aristosvo
Copy link
Collaborator

@ncook-hxgn Seems like the AD Application configuration is lacking the proper config for ID Token. Let me know if anything with regard to the Terraform part has to be adapted or seems to be not functioning👍🏽

@ncook-hxgn
Copy link
Author

ncook-hxgn commented Apr 19, 2023

Seems like the AD Application configuration is lacking the proper config for ID Token.

@aristosvo that's encouraging, something I can maybe fix :)
What do you mean by AD Application configuration though?

The managed identity of the deployed Web App, or the App Registration (service principle) that I pass to the terraform tasks in my pipeline (that ultimately runs this code), or some global policy..?

Let me know if anything with regard to the Terraform part has to be adapted or seems to be not functioning👍🏽

When I deployed my app with v1, everything worked? As in OP: I ported from v1 to v2 for a feature and v2 doesn't work. The error has changed flavour now, so, do I log a new issue? How can we prove that this one is resolved?

@ncook-hxgn
Copy link
Author

@ncook-hxgn Seems like the AD Application configuration is lacking the proper config for ID Token. Let me know if anything with regard to the Terraform part has to be adapted or seems to be not functioning👍🏽

OK I think I understand this a little better now.

I created a new service connection / service principal / AD Application specifically to run terraform in our pipelines, as I don't want to share my roleAssignment/write with other (azure devops) projects.

Did I really configure the callback uri on my service principal/authentication/AD Application manually, when I deployed with auth_settings v1?

(I was sure terraform had done that, hence raising this originally..? Is it the expectation that I should need to do this with v2, too?)

Looking into it on my side, hoping to come back and confirm the fixes once I understand what's different with my new AD Application..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants