Microsoft MVP성태의 닷넷 이야기
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 
(연관된 글이 1개 있습니다.)

IIS - appcmd.exe를 이용해 특정 페이지에 클라이언트 측 인증서를 제출하도록 설정하는 방법

제 홈페이지의 경우, 특정 페이지를 방문했을 때 클라이언트 측 인증서를 제출하도록 했습니다.

IIS 7에서 클라이언트 측 인증서 사용 시 주의점
; https://www.sysnet.pe.kr/2/0/418

위의 글에서처럼, IIS 관리자에서는 "SSL Settings"를 통해 손쉽게 설정할 수 있습니다. 문제는, 이것이 Azure에 배포되는 PaaS 형식의 웹 사이트인 경우 바람직하지 않다는 점입니다. 즉, Azure로 웹 사이트를 배포하는 시점에 자동으로 "SSL Settings"를 할 수 있는 방법이 있어야 합니다.

이를 위해 이전에 설명했던 ServiceDefinition.csdef 파일의 Task 설정을 사용할 수 있습니다.

Azure Cloud Service 배포시 사용자 정의 작업을 추가하는 방법
; https://www.sysnet.pe.kr/2/0/11022

Azure - 네트워크 포트 여는 방법
; https://www.sysnet.pe.kr/2/0/1319

이제 수행할 명령어가 필요한데요, 이는 다음의 문서에 나와 있습니다.

Specify Whether to Use Client Certificates (IIS 7)
; https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2008-R2-and-2008/cc753983(v=ws.10)

위의 문서에 따라 가령 test.aspx를 방문할 때 클라이언트 인증서를 요구하고 싶다면 다음과 같이 실행하면 됩니다.

%windir%\System32\inetsrv\appcmd set config "https://localhost/test.aspx" /section:access /sslFlags:SslNegotiateCert /commit:APPHOST

그런데, 실제로 이런 식으로 명령을 내리면 경우에 따라 다음과 같은 오류가 발생합니다.

D:\>%windir%\System32\inetsrv\appcmd set config "http://localhost/test.aspx" /section:access /sslFlags:SslNegotiateCert /commit:APPHOST
ERROR ( message:Cannot find SITE object with identifier "localhost/test.aspx". )

왜냐하면, Azure의 웹 사이트는 사이트 바인딩 설정에 IP 주소가 설정되어 있기 때문입니다.

client_cert_on_azure_1.png

위와 같이 바인딩이 명시되어 버리면 appcmd set config http://.... 와 같은 형식의 대상 지정은 오류가 발생합니다. 대신, 이런 경우 사이트 이름을 지정하는 방식으로 바꿔야 합니다. 이렇게!

%windir%\System32\inetsrv\appcmd set config "Default Web Site/test.aspx" /section:access /sslFlags:SslNegotiateCert /commit:APPHOST

사이트 이름은 IIS 관리자에서도 확인할 수 있지만 appcmd.exe로도 확인이 가능합니다.

D:\>%windir%\System32\inetsrv\appcmd list site
SITE "Default Web Site" (id:1,bindings:http/192.168.0.88:80:,https/192.168.0.88:443:,state:Started)

이 방식대로 실행해주면, 정상적으로 반영되었다는 메시지를 다음과 같이 확인할 수 있습니다.

D:\>%windir%\System32\inetsrv\appcmd set config "Default Web Site/test.aspx" /section:access /sslFlags:SslNegotiateCert /commit:APPHOST
Applied configuration changes to section "system.webServer/security/access" for "MACHINE/WEBROOT/APPHOST/Default Web Site/test.aspx" at configuration commit path "MACHINE/WEBROOT/APPHOST"

그리고 이 결과는 "%windir%\System32\inetsrv\config\applicationHost.config" 파일에 다음의 내용을 포함하는 것으로 반영됩니다.

<location path="Default Web Site/test.aspx">
    <system.webServer>
        <security>
            <access sslFlags="SslNegotiateCert" />
        </security>
    </system.webServer>
</location>

(참고로, 저 설정은 web.config에도 넣을 수는 있지만 적용이 안 됩니다.)




그런데, 문제가 여기서 끝이 아닙니다. 위의 작업을 Azure의 Task에 명시된 Startup.cmd에 다음과 같이 추가할 수 있을 텐데요.

%windir%\System32\inetsrv\appcmd set config "...[사이트이름].../test.aspx" /section:access /sslFlags:SslNegotiateCert /commit:APPHOST

웬일인지, 이렇게 추가하고 배포해도 여전히 test.aspx에 대한 설정이 applicationHost.config 파일에 적용되지 않습니다. 예측하기로는, 아마도 Startup.cmd가 실행되는 시점이 너무 이른 것이 아닌가 하는 건데요. 이런 경우 Task 작업을 다소 지연시키기 위해 별도의 실행 파일을 만들어서 taskType을 "background"로 설정할 수 있습니다.

<?xml version="1.0" encoding="utf-8"?>
<ServiceDefinition name="SysnetWebApp9.Azure" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition" schemaVersion="2015-04.2.6">
    <WebRole name="SysnetWebApp9" vmsize="Small">
        <Startup>
            <Task commandLine="Startup.cmd" executionContext="elevated" taskType="simple" />
            <Task commandLine="SslSettings.exe" executionContext="elevated" taskType="background">
            </Task>
        </Startup>
        ...[생략]...
    </WebRole>
</ServiceDefinition>

위와 같이 해주면, Azure는 배포 시 SslSettings.exe를 실행하고 그 결과를 기다리지 않은 체 배포 작업을 진행하게 됩니다. 따라서, SslSettings.exe에서는 내부에 단순히 Thread.Sleep과 같은 일정 시간 지연을 한 다음 Process.Start를 이용해 appcmd.exe 작업을 처리해 줄 수 있습니다.

일단, 5초 지연을 주고 appcmd.exe를 실행하니 정상적으로 applicationHost.config에 반영되는 것을 확인했습니다. ^^

휴~~~ 환경이 바뀌니 이렇게 부가 작업이 많아지는군요.




엎어진 김에 쉬어간다고... ^^ 이참에 Azure에 구성하는 VM의 종류를 기존 Windows Server 2012 R2에서 Windows Server 2016으로 변경했습니다. 방법은, 단순히 ServiceConfiguration.Cloud.cscfg 파일의 osFamily를 5로 지정하면 됩니다.

<?xml version="1.0" encoding="utf-8"?>
<ServiceConfiguration serviceName="..." xmlns="..." osFamily="5" osVersion="*" schemaVersion="2015-04.2.6">
    <Role name="SysnetWebApp9">
        <Instances count="1" />
        ...[생략]...
    </Role>
</ServiceConfiguration>

그런데, 웬일인지 배포가 실패하고 다음과 같은 오류 메시지가 나왔습니다.

The OS family 5 you are trying to deploy is not supported by the SDK package. The SDK package supported OS families:3,4,1,2,98. Please try to deploy to a different operating system. To do this specify a different osFamily and/or osVersion in your .cscfg file.


원인은, Visual Studio에서 사용 중인 Azure SDK를 업데이트하지 않아서 그런 것입니다. "Tools" / "Extensions and Updates"에 가면 신규 버전의 Azure SDK가 있다는 알림이 있을 텐데 그것을 설치하신 후 다시 배포를 하시면 됩니다.

그러고 보니... 예전에 썼던 글이 하나 생각납니다.

Azure 구독 후 PaaS 서비스 만들어 보기
; https://www.sysnet.pe.kr/2/0/11023

위의 글에서, 다음과 같은 이야기를 했었는데요.

Azure Cloud Service로 배포되는 WebRole은 현재 지원되는 .NET 버전이 4.0/4.5입니다. 만약 4.6이 포함된 웹 프로젝트를 배포하는 경우 다음과 같은 식의 빌드 경고가 발생합니다. 

2>------ Rebuild All started: Project: AzureCloudService1, Configuration: Debug Any CPU ------
2>..\WebApplication1\WebApplication1.csproj(0,0): warning WAT210: Microsoft Azure Cloud Service projects only support roles that run on .NET Framework versions 4.0 and 4.5.  Please set the Target Framework property in the project settings for project 'WebApplication1' to .NET Framework 4.0, or .NET Framework 4.5.
2>WebApplication1(0,0): warning WAT190: The project 'WebApplication1' targets .NET Framework 4.6. To make sure that the role starts, this version of the .NET Framework must be installed on the virtual machine for this role. You can use a startup task to install the required version, if it is not already installed as part of the Microsoft Azure guest OS. For more details, see http://go.microsoft.com/fwlink/?LinkId=309796.

osFamily를 5로 설정해 Windows Server 2016을 사용하게 되면, WebRole 프로젝트도 4.6을 지정할 수 있게 됩니다. 이러한 호환 정보는 다음의 문서로 정리되어 있으니 참고하세요.

Azure Guest OS releases and SDK compatibility matrix
; https://docs.microsoft.com/en-us/azure/cloud-services/cloud-services-guestos-update-matrix

아래는 Windows Server 2016과 2012 R2의 닷넷 프레임워크 지원 정보를 나타냅니다.

client_cert_on_azure_2.png

그러니까, "Azure 구독 후 PaaS 서비스 만들어 보기" 글을 쓸 당시에 지정한 osFamily가 4이므로 Windows Server 2012 R2가 지정된 것이고, .NET 4.6을 사용할 수는 없었던 것입니다.




[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]

[연관 글]






[최초 등록일: ]
[최종 수정일: 3/26/2021]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 




... 46  47  48  49  50  51  52  [53]  54  55  56  57  58  59  60  ...
NoWriterDateCnt.TitleFile(s)
12307정성태9/2/202012112오류 유형: 643. curl - json_parse_exception / Invalid UTF-8 start byte
12306정성태9/1/202010295오류 유형: 642. SQL Server 시작 오류 - error code 10013
12305정성태9/1/202011148Windows: 172. "Administered port exclusions"이 아닌 포트 범위 항목을 삭제하는 방법
12304정성태8/31/202010122개발 환경 구성: 505. 윈도우 - (네트워크 어댑터의 우선순위로 인한) 열거되는 IP 주소 순서를 조정하는 방법
12303정성태8/30/202010289개발 환경 구성: 504. ETW - 닷넷 프레임워크 기반의 응용 프로그램을 위한 명령행 도구 etrace 소개
12302정성태8/30/202010213.NET Framework: 936. C# - ETW 관련 Win32 API 사용 예제 코드 (5) - Private Logger파일 다운로드1
12301정성태8/30/202010487오류 유형: 641. error MSB4044: The "Fody.WeavingTask" task was not given a value for the required parameter "IntermediateDir".
12300정성태8/29/20209919.NET Framework: 935. C# - ETW 관련 Win32 API 사용 예제 코드 (4) CLR ETW Consumer파일 다운로드1
12299정성태8/27/202010841.NET Framework: 934. C# - ETW 관련 Win32 API 사용 예제 코드 (3) ETW Consumer 구현파일 다운로드1
12298정성태8/27/202010561오류 유형: 640. livekd - Could not resolve symbols for ntoskrnl.exe: MmPfnDatabase
12297정성태8/25/20209777개발 환경 구성: 503. SHA256 테스트 인증서 생성 방법
12296정성태8/24/202010198.NET Framework: 933. C# - ETW 관련 Win32 API 사용 예제 코드 (2) NT Kernel Logger파일 다운로드1
12295정성태8/24/20209635오류 유형: 639. Bitvise - Address is already in use; bind() in ListeningSocket::StartListening() failed: Windows error 10013: An attempt was made to access a socket ,,,
12293정성태8/24/202010964Windows: 171. "Administered port exclusions" 설명
12292정성태8/20/202012226.NET Framework: 932. C# - ETW 관련 Win32 API 사용 예제 코드 (1)파일 다운로드2
12291정성태8/15/202011142오류 유형: 638. error 1297: Device driver does not install on any devices, use primitive driver if this is intended.
12290정성태8/11/202011838.NET Framework: 931. C# - IP 주소에 따른 국가별 위치 확인 [8]파일 다운로드1
12289정성태8/6/20209372개발 환경 구성: 502. Portainer에 윈도우 컨테이너를 등록하는 방법
12288정성태8/5/20209370오류 유형: 637. WCF - The protocol 'net.tcp' does not have an implementation of HostedTransportConfiguration type registered.
12287정성태8/5/20209833오류 유형: 636. C# - libdl.so를 DllImport로 연결 시 docker container 내에서 System.DllNotFoundException 예외 발생
12286정성태8/5/202010692개발 환경 구성: 501. .NET Core 용 container 이미지 만들 때 unzip이 필요한 경우
12285정성태8/4/202011095오류 유형: 635. 윈도우 10 업데이트 - 0xc1900209 [2]
12284정성태8/4/202010377디버깅 기술: 169. Hyper-V의 VM에 대한 메모리 덤프를 뜨는 방법
12283정성태8/3/202010875디버깅 기술: 168. windbg - 필터 드라이버 확인하는 확장 명령어(!fltkd) [2]
12282정성태8/2/20209630디버깅 기술: 167. windbg 디버깅 사례: AppDomain 간의 static 변수 사용으로 인한 crash (2)
12281정성태8/2/202012155개발 환경 구성: 500. (PDB 연결이 없는) DLL의 소스 코드 디버깅을 dotPeek 도구로 해결하는 방법
... 46  47  48  49  50  51  52  [53]  54  55  56  57  58  59  60  ...