2016-11-15 7 views
0

サービスファブリックのステートレスサービスでは、クレームベースの認可がサポートされていますか?要求/ JWTをサービスファブリックのステートレスサービスに渡すにはどうすればよいですか?

ヘッダーにJWTを受け取るWeb APIがあるとします。 JWTまたはクレームをサービスファブリックのステートレスサービスに渡して、機密性の高い操作を実行する前にクレームをチェックすることはできますか?私たちはClaimsCredentialsを使用して、サービスへの特許請求の範囲に渡すことができていることがわかります

var serviceProxyFactory = new ServiceProxyFactory(
    (callbackClient) => new FabricTransportServiceRemotingClientFactory(
     new FabricTransportSettings 
     { 
      SecurityCredentials = new ClaimsCredentials 
      { 
       LocalClaims = "[JWT HERE? or just Claims JSON?]" 
      } 
     })); 

IMyService service = serviceProxyFactory.CreateServiceProxy<IMyService>(new Uri("fabric:/MyThing/MyService")); 

https://msdn.microsoft.com/en-us/library/azure/system.fabric.claimscredentials.localclaims.aspxはLocalClaimsがあると言う「クレームの文字列表現は、STS(セキュリティトークンサービス)から取得したトークンです。」また

:値のプロパティ:

  • が実際にClaimsCredentials JWT base64エンコード、または請求項キーのちょうどJSONペイロードですか?

  • ステートレスサービスで実行する必要のある特定の設定やコードはありますか?

  • ステートレスサービスからクレームへのアクセス方法を教えてください。

    System.Fabric.FabricCannotConnectException: Error in Connection during ServiceCommunication 
    ---> System.Runtime.InteropServices.COMException: Exception from HRESULT: 0x80071C4C\r\n 
    at Microsoft.ServiceFabric.Services.Communication.FabricTransport.Common.NativeServiceCommunication.IFabricServiceCommunicationClient2.EndRequest(IFabricAsyncOperationContext context)\r\n 
    at Microsoft.ServiceFabric.Services.Communication.FabricTransport.Client.NativeServiceCommunicationClient.EndRequest(IFabricAsyncOperationContext context)\r\n at System.Fabric.Interop.AsyncCallOutAdapter2`1.Finish(IFabricAsyncOperationContext context, Boolean expectedCompletedSynchronously)\r\n --- End of inner exception stack trace ---\r\n 
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n 
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n 
    at Microsoft.ServiceFabric.Services.Communication.FabricTransport.Client.NativeServiceCommunicationClient.<RequestResponseAsync>d__8.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.ServiceFabric.Services.Communication.Client.ServicePartitionClient`1.<InvokeWithRetryAsync>d__7`1.MoveNext() 
    

    ありがとう:

    現時点で

は、私がサービスを呼び出すときに、私は次のエラーを取得する、どんな値IはにLocalClaimsを設定していません!

答えて

1

私はClaimsCredentialsクラスがJWTトークンを運ぶことを意図しているのではなく、何らかの証明書に基づいてService Fabric自身によって生成されたセキュリティトークンを考えています。クラスClaimsCredentialsを調べると、それは主張情報を運ぶネイティブクラスに密接に関連していることがわかります。

[StructLayout(LayoutKind.Sequential, Pack = 8)] 
internal struct FABRIC_CLAIMS_CREDENTIALS 
{ 
    public uint ServerCommonNameCount; 
    public IntPtr ServerCommonNames; 
    public uint IssuerThumbprintCount; 
    public IntPtr IssuerThumbprints; 
    public IntPtr LocalClaims; 
    public NativeTypes.FABRIC_PROTECTION_LEVEL ProtectionLevel; 
    public IntPtr Reserved; 
} 

[StructLayout(LayoutKind.Sequential, Pack = 8)] 
internal struct FABRIC_CLAIMS_CREDENTIALS_EX1 
{ 
    public uint ServerThumbprintCount; 
    public IntPtr ServerThumbprints; 
    public IntPtr Reserved; 
} 

いずれかに関連し、またはJWTsの理解を示し、この内部悲鳴クラスと何について多くがあります:より深いものに掘ることは情報を渡すために使用される構造体を明らかにする。

HTTPエンドポイントに何らかのセキュリティを追加する場合は、System.IdentityModel.Tokens.JwtSecurityTokenHandlerを使用できるようになります。開始のためにこれを見てください:Decoding and verifying JWT token using System.IdentityModel.Tokens.Jwt

Fabric TransportエンドポイントにJWTベースのセキュリティを追加する場合は、クライアントのカスタムヘッダーとしてServiceRemotingMessageHeadersを使用してJWTを追加し、そのヘッダーを解析して検証する必要があります。 X509証明書を使用したサービスリモーティングに付属のセキュリティモデルを使用することは、このトランスポートの考え方にとってはより良い選択です。

関連する問題