이 문서에서는 PowerShell을 사용하여 Application Gateway에서 상호 인증을 구성하는 방법을 설명합니다. 상호 인증은 Application Gateway가 Application Gateway에 업로드한 클라이언트 인증서를 사용하여 요청을 보내는 클라이언트를 인증한다는 것을 의미합니다.
Azure 구독이 없으신 경우 시작하기 전에 무료 계정을 만드세요.
비고
Azure Az PowerShell 모듈을 사용하여 Azure와 상호 작용하는 것이 좋습니다. 시작하려면 Azure PowerShell 설치를 참조하세요. Az PowerShell 모듈로 마이그레이션하는 방법에 대한 자세한 내용은 Azure PowerShell을 AzureRM에서 Azure로 마이그레이션을 참조하세요.
이 문서에는 Azure PowerShell 모듈 버전 1.0.0 이상이 필요합니다.
Get-Module -ListAvailable Az
을 실행하여 버전을 찾습니다. 업그레이드해야 하는 경우 Azure PowerShell 모듈 설치를 참조하세요. 또한 PowerShell을 로컬로 실행하는 경우 Login-AzAccount
를 실행하여 Azure와 연결해야 합니다.
시작하기 전 주의 사항:
Application Gateway를 사용하여 상호 인증을 구성하려면 게이트웨이에 업로드할 클라이언트 인증서가 필요합니다. 클라이언트 인증서는 클라이언트가 Application Gateway에 표시할 인증서의 유효성을 검사하는 데 사용됩니다. 테스트를 위해 자체 서명된 인증서를 사용할 수 있습니다. 그러나 관리가 더 어렵고 완전히 안전하지 않기 때문에 프로덕션 워크로드에는 권장되지 않습니다.
특히 업로드할 수 있는 클라이언트 인증서 종류에 대한 자세한 내용은 Application Gateway와의 상호 인증 개요를 참조하세요.
리소스 그룹 만들기
먼저 구독에서 새 리소스 그룹을 만듭니다.
$resourceGroup = New-AzResourceGroup -Name $rgname -Location $___location -Tags @{ testtag = "APPGw tag"}
가상 네트워크 만들기
배포할 Application Gateway에 대한 가상 네트워크를 배포합니다.
$gwSubnet = New-AzVirtualNetworkSubnetConfig -Name $gwSubnetName -AddressPrefix 10.0.0.0/24
$vnet = New-AzVirtualNetwork -Name $vnetName -ResourceGroupName $rgname -Location $___location -AddressPrefix 10.0.0.0/16 -Subnet $gwSubnet
$vnet = Get-AzVirtualNetwork -Name $vnetName -ResourceGroupName $rgname
$gwSubnet = Get-AzVirtualNetworkSubnetConfig -Name $gwSubnetName -VirtualNetwork $vnet
공용 IP 만들기
Application Gateway와 함께 사용할 공용 IP를 만듭니다.
$publicip = New-AzPublicIpAddress -ResourceGroupName $rgname -name $publicIpName -___location $___location -AllocationMethod Static -sku Standard
Application Gateway IP 구성 만들기
IP 구성 및 프런트 엔드 포트를 만듭니다.
$gipconfig = New-AzApplicationGatewayIPConfiguration -Name $gipconfigname -Subnet $gwSubnet
$fipconfig = New-AzApplicationGatewayFrontendIPConfig -Name $fipconfigName -PublicIPAddress $publicip
$port = New-AzApplicationGatewayFrontendPort -Name $frontendPortName -Port 443
프런트 엔드 SSL 구성
Application Gateway에 대한 SSL 인증서를 구성합니다.
$password = ConvertTo-SecureString "P@ssw0rd" -AsPlainText -Force
$sslCertPath = $basedir + "/ScenarioTests/Data/ApplicationGatewaySslCert1.pfx"
$sslCert = New-AzApplicationGatewaySslCertificate -Name $sslCertName -CertificateFile $sslCertPath -Password $password
클라이언트 인증 구성
Application Gateway에서 클라이언트 인증을 구성합니다. 여기에서 사용할 신뢰할 수 있는 클라이언트 CA 인증서 체인을 추출하는 방법에 대한 자세한 내용은 신뢰할 수 있는 클라이언트 CA 인증서 체인을 추출하는 방법을 참조하세요.
중요합니다
전체 클라이언트 CA 인증서 체인을 하나의 파일에 업로드하고 파일당 하나의 체인만 업로드해야 합니다.
비고
TLS 1.2는 나중에 위임될 것이므로 상호 인증과 함께 TLS 1.2를 사용하는 것이 좋습니다.
$clientCertFilePath = $basedir + "/ScenarioTests/Data/TrustedClientCertificate.cer"
$trustedClient01 = New-AzApplicationGatewayTrustedClientCertificate -Name $trustedClientCert01Name -CertificateFile $clientCertFilePath
$sslPolicy = New-AzApplicationGatewaySslPolicy -PolicyType Predefined -PolicyName "AppGwSslPolicy20170401S"
$clientAuthConfig = New-AzApplicationGatewayClientAuthConfiguration -VerifyClientCertIssuerDN
$sslProfile01 = New-AzApplicationGatewaySslProfile -Name $sslProfile01Name -SslPolicy $sslPolicy -ClientAuthConfiguration $clientAuthConfig -TrustedClientCertificates $trustedClient01
$listener = New-AzApplicationGatewayHttpListener -Name $listenerName -Protocol Https -SslCertificate $sslCert -FrontendIPConfiguration $fipconfig -FrontendPort $port -SslProfile $sslProfile01
백 엔드 풀 및 설정 구성
Application Gateway에 대한 백 엔드 풀 및 설정을 설정합니다. 필요에 따라 엔드투엔드 SSL 암호화를 위해 백 엔드 신뢰할 수 있는 루트 인증서를 설정합니다.
$certFilePath = $basedir + "/ScenarioTests/Data/ApplicationGatewayAuthCert.cer"
$trustedRoot = New-AzApplicationGatewayTrustedRootCertificate -Name $trustedRootCertName -CertificateFile $certFilePath
$pool = New-AzApplicationGatewayBackendAddressPool -Name $poolName -BackendIPAddresses www.microsoft.com, www.bing.com
$poolSetting = New-AzApplicationGatewayBackendHttpSettings -Name $poolSettingName -Port 443 -Protocol Https -CookieBasedAffinity Enabled -PickHostNameFromBackendAddress -TrustedRootCertificate $trustedRoot
규칙을 구성하십시오
Application Gateway에서 규칙을 설정합니다.
$rule = New-AzApplicationGatewayRequestRoutingRule -Name $ruleName -RuleType basic -BackendHttpSettings $poolSetting -HttpListener $listener -BackendAddressPool $pool
이후 수신기에 대한 기본 SSL 정책 설정
상호 인증을 설정하는 동안 수신기 특정 SSL 정책을 설정했습니다. 이 단계에서는 필요에 따라 만든 이후 수신기에 대한 기본 SSL 정책을 설정할 수 있습니다.
$sslPolicyGlobal = New-AzApplicationGatewaySslPolicy -PolicyType Predefined -PolicyName "AppGwSslPolicy20170401"
Application Gateway 만들기
위에서 만든 모든 항목을 사용하여 Application Gateway를 배포합니다.
$sku = New-AzApplicationGatewaySku -Name Standard_v2 -Tier Standard_v2
$appgw = New-AzApplicationGateway -Name $appgwName -ResourceGroupName $rgname -Zone 1,2 -Location $___location -BackendAddressPools $pool -BackendHttpSettingsCollection $poolSetting -FrontendIpConfigurations $fipconfig -GatewayIpConfigurations $gipconfig -FrontendPorts $port -HttpListeners $listener -RequestRoutingRules $rule -Sku $sku -SslPolicy $sslPolicyGlobal -TrustedRootCertificate $trustedRoot -AutoscaleConfiguration $autoscaleConfig -TrustedClientCertificates $trustedClient01 -SslProfiles $sslProfile01 -SslCertificates $sslCert
리소스 정리
더 이상 필요하지 않은 경우 Remove-AzResourceGroup 명령을 사용하여 리소스 그룹, 애플리케이션 게이트웨이 및 모든 관련 리소스를 제거합니다.
Remove-AzResourceGroup -Name $rgname
만료된 클라이언트 CA 인증서 갱신
클라이언트 CA 인증서가 만료된 경우 다음 단계를 통해 게이트웨이에서 인증서를 업데이트할 수 있습니다.
- Azure에 로그인
Connect-AzAccount Select-AzSubscription -Subscription "<sub name>"
- Application Gateway 구성 가져오기
$gateway = Get-AzApplicationGateway -Name "<gateway-name>" -ResourceGroupName "<resource-group-name>"
- 게이트웨이에서 신뢰할 수 있는 클라이언트 인증서 제거
Remove-AzApplicationGatewayTrustedClientCertificate -Name "<name-of-client-certificate>" -ApplicationGateway $gateway
- 게이트웨이에 새 인증서 추가
Add-AzApplicationGatewayTrustedClientCertificate -ApplicationGateway $gateway -Name "<name-of-new-cert>" -CertificateFile "<path-to-certificate-file>"
- 새 인증서로 게이트웨이 업데이트
Set-AzApplicationGateway -ApplicationGateway $gateway