Azure webapp安全组访问

Azure webapp安全组访问,azure,azure-web-app-service,terraform-provider-azure,Azure,Azure Web App Service,Terraform Provider Azure,我有一个azure web应用程序,我想限制对其URL的访问,并允许仅通过我的应用程序网关进行访问。其中一个选择是使用“访问限制”,但我希望使用安全组实现这一点,因为这将给我更多的自由和定制,因为我有很多应用程序服务 使用terraform,我将应用程序网关、应用程序网关子网和应用程序服务网关配置如下 resource "azurerm_virtual_network" "VNET" { address_space = ["VNE

我有一个azure web应用程序,我想限制对其URL的访问,并允许仅通过我的应用程序网关进行访问。其中一个选择是使用“访问限制”,但我希望使用安全组实现这一点,因为这将给我更多的自由和定制,因为我有很多应用程序服务

使用terraform,我将应用程序网关、应用程序网关子网和应用程序服务网关配置如下

resource "azurerm_virtual_network" "VNET" {
  address_space       = ["VNET-CIDR"]
  location            = var.location
  name                = "hri-prd-VNET"
  resource_group_name = azurerm_resource_group.rg-hri-prd-eur-app-gate.name
}

resource "azurerm_subnet" "app-gate" {
  name                 = "app-gateway-subnet"
  resource_group_name  = azurerm_resource_group.app-gate.name
  virtual_network_name = azurerm_virtual_network.VNET.name
  address_prefixes     = ["SUBNET-CIDR"]
}

resource "azurerm_subnet" "app-service" {
  name                 = "app-service-subnet"
  resource_group_name  = azurerm_resource_group.app-gate.name
  virtual_network_name = azurerm_virtual_network.hri-prd-VNET.name
  address_prefixes     = ["APP_CIDR"]
  delegation {
    name = "app-service-delegation"
    service_delegation {
      name    = "Microsoft.Web/serverFarms"
      actions = ["Microsoft.Network/virtualNetworks/subnets/action"]
    }
  }
}
在我的安全组中,我将映射配置为:

resource "azurerm_network_security_group" "app-service-sg" {
  location            = var.app-service-loc
  name                = "app-service-sg"
  resource_group_name = azurerm_resource_group.app-service.name
  security_rule {
    access = "Allow"
    direction = "Inbound"
    name = "application_gateway_access"
    priority = 100
    protocol = "Tcp"
    destination_port_range = "80"
    source_port_range = "*"
    source_address_prefixes = ["app-gate-CIDR"]
    destination_address_prefixes = ["app-service-CIDR"]

  }

}


resource "azurerm_subnet_network_security_group_association" "app-service-assoc" {
  network_security_group_id = azurerm_network_security_group.app-service-sg.id
  subnet_id                 = azurerm_subnet.app-service.id
}
terraform的配置运行时没有任何问题,但是当我直接点击web应用程序url时,我就能够访问它

在这个阶段我做错了什么?因为我希望只能通过我的应用程序网关访问web应用程序url


非常感谢您刚才创建的网络和安全组提供的帮助。您需要使用应用程序网关与服务端点集成

此外,您还需要进行进一步的配置。 下面是您的解决方案的示意图。

使用地形代码创建应用程序服务并添加IP限制。

将应用程序服务链接到您的网络

resource "azurerm_app_service_virtual_network_swift_connection" "example" {
  app_service_id = azurerm_app_service.example.id
  subnet_id      = azurerm_subnet.app-service.id
}
使用服务端点创建访问限制。

有没有一种方法可以在不使用访问限制的情况下执行此操作?要通过子网和azure安全组来完成这一切吗?不。实际上,在2019年引入服务端点之前,没有办法做到这一点。
resource "azurerm_app_service_virtual_network_swift_connection" "example" {
  app_service_id = azurerm_app_service.example.id
  subnet_id      = azurerm_subnet.app-service.id
}