2017-04-27 97 views
0

在我當前的ASP.NET核心項目中,我使用Azure Active Directory身份驗證和X509Certificate來訪問密鑰保管庫。需要在機器上安裝證書以允許應用程序訪問它並最終從Key Vault讀取值。現在我正在將此應用程序遷移到Azure Service Fabric。我上傳的證書修飾手臂模板庫的關鍵,通過添加:從Azure服務結構中託管的ASP.NET核心應用程序訪問Azure密鑰保管庫

"osProfile": { 
    "secrets": [ 
     { 
      "sourceVault": { 
      "id": "{KeyVaultIdHere}" 
      }, 
      "vaultCertificates": [ 
      { 
       "certificateUrl": "{CertificateUrlHere}", 
       "certificateStore": "My" 
      } 
      ] 
     } 
     ] 
}, 

但是當我部署我的應用程序Azure的服務織物好像它沒有獲得證書。我是否正確理解當我使用此類ARM模板創建羣集時,正在安裝證書LocalMachine\My存儲?如果是,是否有可能,在哪個應用程序運行的操作系統用戶沒有權限訪問私鑰?當我在本地計算機上運行集羣時,我必須給予ASF本地集羣用戶特殊權限才能讀取私鑰。也許Azure上的ASF需要完成相同的工作?怎麼辦?提前致謝。

+0

我已經遠程從ASF集羣虛擬機,事實證明,這個證書上缺少私鑰許可。但我無法手動設置它,因爲「管理員」對此證書只具有「讀取」權限。出於這個原因,我將嘗試修改ARM模板,以便「解除」運行ASF羣集的NETWORK_SERVICE的私鑰。 –

+0

「NETWORK_SERVICE」的ACL應該在配置證書時自動完成。訪問KeyVault的代碼如何?也許你的方法是默認查看'cert:\ currentuser \ my',這對SF來說當然是不正確的! – Mardoxx

+0

我的方法確實在看'localmachine/my'商店。當我運行ASF本地集羣時,它工作正常。有趣的是,你提到的是,NETWORK_SERVICE應該可以訪問使用ARM模板安裝的這種證書的私鑰。顯然,它沒有。只有'System'完全可以訪問它。還提到了'Administrators'組,但只有'Read'權限。 –

回答

1

好的,所以解決方法是修改ARM模板,使其能夠訪問NETWORK SERVICE用戶的證書私鑰。爲此,需要編寫適當的PowerShell(如:https://social.technet.microsoft.com/Forums/windowsserver/en-US/1557e379-26a8-46d0-bf26-d32176395085/how-to-grant-permission-to-private-key-from-powershell?forum=winserverpowershell),並在ARM模板(virtualMachineProfile/extensionProfile/extensions)中附加CustomScriptExtension。它只能在ARM部署期間完成,因爲由於某些原因,Administrators只有通過ARM模板安裝的證書才能訪問Read

0

這是我的一個應用程序的應用程序清單之一。

<?xml version="1.0" encoding="utf-8"?> 
<ApplicationManifest xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ApplicationTypeName="S-Innovations.ServiceFabric.GatewayApplicationType" ApplicationTypeVersion="1.0.0" xmlns="http://schemas.microsoft.com/2011/01/fabric"> 
    <Parameters> 
    <Parameter Name="GatewayService_InstanceCount" DefaultValue="-1" /> 
    <Parameter Name="AzureADServicePrincipal" DefaultValue="" /> 
    <Parameter Name="TenantId" DefaultValue="" /> 
    <Parameter Name="ApplicationStorageAccountId" DefaultValue="" /> 
    <Parameter Name="AzureResourceManagerCertThumbrint" DefaultValue="C03BB5A6410741CDD2927B4FF88C3E67215A393B" /> 
    <Parameter Name="Azure.KeyVault.Uri" DefaultValue="https://earthml-core-k3ci.vault.azure.net/" /> 
    <Parameter Name="ASPNETCORE_ENVIRONMENT" DefaultValue="Development" /> 
    </Parameters> 
    <!-- Import the ServiceManifest from the ServicePackage. The ServiceManifestName and ServiceManifestVersion 
     should match the Name and Version attributes of the ServiceManifest element defined in the 
     ServiceManifest.xml file. --> 
    <ServiceManifestImport> 
    <ServiceManifestRef ServiceManifestName="S-Innovations.ServiceFabric.GatewayServicePkg" ServiceManifestVersion="1.0.0" /> 
    <ConfigOverrides> 
     <ConfigOverride Name="Config"> 
     <Settings> 
      <Section Name="AzureResourceManager"> 
      <Parameter Name="AzureADServicePrincipal" Value="[AzureADServicePrincipal]" IsEncrypted="true" /> 
      <Parameter Name="TenantId" Value="[TenantId]" /> 
      <Parameter Name="ApplicationStorageAccountId" Value="[ApplicationStorageAccountId]" /> 
      <Parameter Name="Azure.KeyVault.Uri" Value="[Azure.KeyVault.Uri]" /> 
      </Section> 
     </Settings> 
     </ConfigOverride> 
    </ConfigOverrides> 
    <EnvironmentOverrides CodePackageRef="Code"> 
     <EnvironmentVariable Name="ASPNETCORE_ENVIRONMENT" Value="[ASPNETCORE_ENVIRONMENT]" /> 
    </EnvironmentOverrides> 
    <Policies> 
     <RunAsPolicy CodePackageRef="Code" UserRef="Admin" EntryPointType="All" /> 
    </Policies> 
    </ServiceManifestImport> 
    <DefaultServices> 
    <!-- The section below creates instances of service types, when an instance of this 
     application type is created. You can also create one or more instances of service type using the 
     ServiceFabric PowerShell module. 

     The attribute ServiceTypeName below must match the name defined in the imported ServiceManifest.xml file. --> 
    <Service Name="GatewayService"> 
     <StatelessService ServiceTypeName="GatewayServiceType" InstanceCount="[GatewayService_InstanceCount]"> 
     <SingletonPartition /> 
     </StatelessService> 
    </Service> 
    <Service Name="GatewayServiceManagerActorService" GeneratedIdRef="ef5ab963-c061-486e-bb1c-84bf1c2fc7e1|Persisted"> 
     <StatefulService ServiceTypeName="GatewayServiceManagerActorServiceType"> 
     <UniformInt64Partition PartitionCount="2" LowKey="-9223372036854775808" HighKey="9223372036854775807" /> 
     </StatefulService> 
    </Service> 
    </DefaultServices> 
    <Principals> 
    <Users> 
     <User Name="Service1" AccountType="NetworkService" /> 
     <User Name="Admin"> 
     <MemberOf> 
      <SystemGroup Name="Administrators" /> 
     </MemberOf> 
     </User> 
    </Users> 
    </Principals> 
    <Policies> 
    <SecurityAccessPolicies> 
     <SecurityAccessPolicy ResourceRef="MyCert" PrincipalRef="Service1" ResourceType="Certificate" /> 
    </SecurityAccessPolicies> 
    </Policies> 
    <Certificates> 
    <SecretsCertificate X509FindValue="[AzureResourceManagerCertThumbrint]" Name="MyCert" /> 
    </Certificates> 
</ApplicationManifest> 

我一直在使用那個沒有任何你提到應用程序沒有訪問證書的問題。也許這可以幫助你使你的手臂腳本更簡單:)

相關問題