복붙노트

[HADOOP] HttpClient를 사용한 .NET Core SPNEGO 인증

HADOOP

HttpClient를 사용한 .NET Core SPNEGO 인증

현재 WebHCat를 통해 Hadoop 클러스터와 상호 작용하기 위해 간단한 .NET Core 기반 클라이언트를 작성 중이며 curl 또는 Powershell Core와 같이 SPNEGO로 인증하는 방법을 알아 내려고 노력 중입니다.

Curl을 사용하여 WebHCat의 상태 끝점을 다음과 같이 쿼리 할 수 ​​있습니다.

curl "http://10.2.0.9:50111/templeton/v1/status" --negotiate -k -u :

Powershell Core에서도 동일한 요청을 실행할 수 있습니다.

$client = New-Object System.Net.WebClient;
$client.UseDefaultCredentials = $true;
$client.DownloadString("http://10.2.0.9:50111/templeton/v1/status");

그러나 클러스터와 동일한 서버에있는 .NET Core 프로젝트에서 다음을 실행하는 경우 :

using System;
using System.Net;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;

namespace testauth
{
    class Program
    {
        static async Task Main(string[] args)
        {
            var host = "http://10.2.0.9:50111/templeton/v1/status";
            var handler = new HttpClientHandler
            {
                UseDefaultCredentials = true,
                AllowAutoRedirect = true,
            };
            using (var client = new HttpClient(new LoggingHandler(handler)))
            {
                var res = await client.SendAsync(new HttpRequestMessage(HttpMethod.Get, host));
            }
        }
    }

}

다음과 같은 오류가 발생합니다.

Unhandled Exception: System.ComponentModel.Win32Exception: GSSAPI operation failed with error - An invalid status code was supplied (Server not found in Kerberos database).
   at System.Net.NTAuthentication.GetOutgoingBlob(Byte[] incomingBlob, Boolean throwOnError, SecurityStatusPal& statusCode)

클라이언트는 .NET Core 2.1을 실행 중이므로이 문제에서 언급 한 것처럼 기본 자격 증명을 처리기에 전달하면 예상대로 작동합니다.

C #의 PowerShell Core에서 사용한 것과 동일한 코드를 작성하려고 시도했지만 동일한 코드에도 불구하고 여전히 동일한 오류가 발생합니까?

내가 제공 할 수있는 유일한 다른 세부 사항은 Kerberos가 한 명의 사용자만으로 Active Directory 인스턴스에 연결되어 있으며 이러한 모든 요청이 kinit로 해당 사용자에 대한 티켓을 만든 후에 실행된다는 것입니다.

해결법

  1. ==============================

    1.나는 픽스를 찾았다. ASP.NET Core 2.1에서는 요청에 기본적으로 사용되는 새로운 SocketsHttpHandler를 도입했습니다. 이것은 일부 플랫폼에서 내 요청에 제공된 HttpHandler를 재정의 할 수 있으므로 기본적으로 소켓 처리기를 사용해야합니다.

    나는 픽스를 찾았다. ASP.NET Core 2.1에서는 요청에 기본적으로 사용되는 새로운 SocketsHttpHandler를 도입했습니다. 이것은 일부 플랫폼에서 내 요청에 제공된 HttpHandler를 재정의 할 수 있으므로 기본적으로 소켓 처리기를 사용해야합니다.

    AppContext.SetSwitch("System.Net.Http.UseSocketsHttpHandler", false);
    

    이것은 내 요청을 수정했습니다.

  2. from https://stackoverflow.com/questions/52266659/net-core-spnego-auth-with-httpclient by cc-by-sa and MIT license