Share via


방법: 엔터프라이즈에서 엔드포인트 잠그기

대형 엔터프라이즈에서는 애플리케이션을 엔터프라이즈 보안 정책에 따라 개발해야 하는 경우가 종종 있습니다. 다음 항목에서는 컴퓨터에 설치된 모든 WCF(Windows Communication Foundation) 클라이언트 애플리케이션의 유효성을 검사하는 데 사용할 수 있는 클라이언트 엔드포인트 유효성 검사기를 개발하고 설치하는 방법에 대해 설명합니다.

이 경우 이 엔드포인트 동작이 machine.config 파일의 클라이언트 <commonBehaviors> 섹션에 추가되므로 유효성 검사기는 클라이언트 유효성 검사기입니다. WCF는 클라이언트 애플리케이션 전용의 공통 엔드포인트 동작을 로드하고 서비스 애플리케이션 전용의 공통 서비스 동작을 로드합니다. 서비스 애플리케이션에 동일한 유효성 검사기를 설치하려면 유효성 검사기가 서비스 동작이어야 합니다. 자세한 내용은 <commonBehaviors> 섹션을 참조하세요.

Important

구성 파일의 <commonBehaviors> 섹션에 추가된, AllowPartiallyTrustedCallersAttribute 특성(APTCA)으로 표시되지 않은 서비스 또는 엔드포인트 동작은 애플리케이션이 부분 신뢰 환경에서 실행될 때 실행되지 않으며, 이러한 경우 예외가 throw되지 않습니다. 유효성 검사기와 같은 일반 동작을 실행하려면 다음을 수행해야 합니다.

  • 부분 신뢰 애플리케이션으로 배포될 때 실행될 수 있도록 일반 동작을 AllowPartiallyTrustedCallersAttribute 특성으로 표시합니다. APTCA로 표시된 어셈블리가 실행되지 않도록 컴퓨터에 레지스트리 항목을 설정할 수 있습니다.

  • 부분 신뢰 환경에서 애플리케이션을 실행하기 위해 사용자가 코드 액세스 보안 설정을 수정할 수 없는 완전 신뢰 애플리케이션으로서 애플리케이션이 배포되는지 확인합니다. 사용자가 보안 설정을 수정할 수 있는 경우 사용자 지정 유효성 검사기가 실행되지 않고 예외가 throw되지 않습니다. 이를 보장하는 한 가지 방법을 알아보려면 코드 액세스 보안 정책 도구(Caspol.exe)를 사용한 levelfinal 옵션을 참조하세요.

자세한 내용은 부분 신뢰를 위한 최선의 방법지원되는 배포 시나리오를 참조하세요.

엔드포인트 유효성 검사기를 만들려면

  1. IEndpointBehavior 메서드의 원하는 유효성 검사 단계를 사용하여 Validate를 만듭니다. 다음 코드에 예가 나와 있습니다. InternetClientValidatorBehaviorSecurity Validation 샘플에서 가져온 것입니다.

    public class InternetClientValidatorBehavior : IEndpointBehavior
    {
        public void AddBindingParameters(ServiceEndpoint serviceEndpoint, System.ServiceModel.Channels.BindingParameterCollection bindingParameters) { }
        public void ApplyClientBehavior(ServiceEndpoint serviceEndpoint, System.ServiceModel.Dispatcher.ClientRuntime behavior) { }
        public void ApplyDispatchBehavior(ServiceEndpoint serviceEndpoint, System.ServiceModel.Dispatcher.EndpointDispatcher endpointDispatcher) { }
    
        public void Validate(ServiceEndpoint endpoint)
        {
            BindingElementCollection elements = endpoint.Binding.CreateBindingElements();
    
            if (EndpointIsDual(endpoint, elements))
                throw new InvalidOperationException("InternetClientValidator: endpoint uses 'dual' mode. This mode is disallowed for use with untrusted services.");
    
            if (EndpointAllowsNtlm(endpoint, elements))
                throw new InvalidOperationException("InternetClientValidator: endpoint allows NTLM. This mode is disallowed for use with untrusted services.");
    
            if (EndpointAllowsTransactionFlow(endpoint, elements))
                throw new InvalidOperationException("InternetClientValidator: endpoint flows transaction ids. This mode is disallowed for use with untrusted services.");
        }
    
  2. 1단계에서 만든 엔드포인트 유효성 검사기를 등록할 새 BehaviorExtensionElement를 만듭니다. 다음 코드 예제에서는 이를 보여 줍니다. 이 예의 원본 코드는 Security Validation 샘플에 있습니다.

    public class InternetClientValidatorElement : BehaviorExtensionElement
    {
        public override Type BehaviorType
        {
            get { return typeof(InternetClientValidatorBehavior); }
        }
    
        protected override object CreateBehavior()
        {
            return new InternetClientValidatorBehavior();
        }
    }
    
  3. 컴파일된 어셈블리가 강력한 이름으로 서명되어 있는지 확인합니다. 자세한 내용은 강력한 이름 도구(SN.EXE) 및 사용하는 해당 언어에 대한 컴파일러 명령을 참조하세요.

대상 컴퓨터에 유효성 검사기를 설치하려면

  1. 적절한 메커니즘을 사용하여 엔드포인트 유효성 검사기를 설치합니다. 엔터프라이즈에서는 그룹 정책 및 SMS(Systems Management Server)를 사용해 수행할 수 있습니다.

  2. Gacutil.exe(전역 어셈블리 캐시 도구)를 사용하여 전역 어셈블리 캐시에 강력한 이름의 어셈블리를 설치합니다.

  3. 다음 작업에 System.Configuration 네임스페이스 형식을 사용합니다.

    1. 정규화된 형식 이름을 사용하여 확장을 <behaviorExtensions> 섹션에 추가하고 요소를 잠급니다.

      // Register our validator configuration element.
      ExtensionsSection extensions
        = machine.GetSection(@"system.serviceModel/extensions") as ExtensionsSection;
      if (extensions == null)
        throw new Exception("not extensions section.");
      ExtensionElement validator
        = new ExtensionElement(
          "internetClientValidator",
          "Microsoft.ServiceModel.Samples.InternetClientValidatorElement, InternetClientValidator, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"
        );
      validator.LockItem = true;
      if (extensions.BehaviorExtensions.IndexOf(validator) < 0)
        extensions.BehaviorExtensions.Add(validator);
      
    2. 동작 요소를 <commonBehaviors> 섹션의 EndpointBehaviors 속성에 추가하고 요소를 잠급니다. (서비스에 유효성 검사기를 설치하려면 유효성 검사기가 IServiceBehavior여야 하고 ServiceBehaviors 속성에 추가되어야 합니다.) 다음 코드 예는 강력한 이름이 없다는 유일한 예외를 제외한 모든 경우에서 a단계와 b단계 이후의 적절한 구성을 보여 줍니다.

      // Add a new section for our validator and lock it down.
      // Behaviors for client applications must be endpoint behaviors.
      // Behaviors for service applications must be service behaviors.
      CommonBehaviorsSection commonBehaviors
        = machine.GetSection(@"system.serviceModel/commonBehaviors") as CommonBehaviorsSection;
      InternetClientValidatorElement internetValidator = new InternetClientValidatorElement();
      internetValidator.LockItem = true;
      commonBehaviors.EndpointBehaviors.Add(internetValidator);
      
    3. machine.config 파일을 저장합니다. 다음 코드 예제에서는 3단계의 모든 작업을 수행하며 수정된 machine.config 파일의 복사본을 로컬에 저장합니다.

      // Write to disk.
      machine.SaveAs("newMachine.config");
      
      // Write our new information.
      SectionInformation cBInfo = commonBehaviors.SectionInformation;
      Console.WriteLine(cBInfo.GetRawXml());
      Console.WriteLine(extensions.SectionInformation.GetRawXml());
      Console.Read();
      

예시

다음 코드 예제에서는 일반 동작을 machine.config 파일에 추가하고 복사본을 디스크에 저장하는 방법을 보여 줍니다. InternetClientValidatorBehaviorSecurity Validation 샘플에서 가져온 것입니다.

Configuration machine = ConfigurationManager.OpenMachineConfiguration();
// Register our validator configuration element.
ExtensionsSection extensions
  = machine.GetSection(@"system.serviceModel/extensions") as ExtensionsSection;
if (extensions == null)
  throw new Exception("not extensions section.");
ExtensionElement validator
  = new ExtensionElement(
    "internetClientValidator",
    "Microsoft.ServiceModel.Samples.InternetClientValidatorElement, InternetClientValidator, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"
  );
validator.LockItem = true;
if (extensions.BehaviorExtensions.IndexOf(validator) < 0)
  extensions.BehaviorExtensions.Add(validator);

// Add a new section for our validator and lock it down.
// Behaviors for client applications must be endpoint behaviors.
// Behaviors for service applications must be service behaviors.
CommonBehaviorsSection commonBehaviors
  = machine.GetSection(@"system.serviceModel/commonBehaviors") as CommonBehaviorsSection;
InternetClientValidatorElement internetValidator = new InternetClientValidatorElement();
internetValidator.LockItem = true;
commonBehaviors.EndpointBehaviors.Add(internetValidator);
// Write to disk.
machine.SaveAs("newMachine.config");

// Write our new information.
SectionInformation cBInfo = commonBehaviors.SectionInformation;
Console.WriteLine(cBInfo.GetRawXml());
Console.WriteLine(extensions.SectionInformation.GetRawXml());
Console.Read();

.NET Framework 보안

구성 파일 요소를 암호화할 수도 있습니다. 자세한 내용은 참고 항목 단원을 참조하세요.

참고 항목