簡體   English   中英

Ubuntu上的ASP.NET Core 2.2 Web應用程序 - 如何實現數據保護

[英]ASP.NET Core 2.2 web app on Ubuntu - how to implement Data Protection

我已經開始使用Ubuntu(18.04)來托管一些簡單的.NET Core 2.2網站。 部署並啟動站點后,我會看到以下內容:

警告:Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager [59]用戶配置文件和HKLM注冊表都不可用。 使用臨時密鑰存儲庫。 應用程序退出時,受保護的數據將不可用。 警告:Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager [35]未配置XML加密器。 密鑰{c45288a6-63f8-4408-abdb-7894fb6d4e45}可以以未加密的形式保存到存儲中。 托管環境:生產內容根路徑:/ var / www / mysite現在正在偵聽: http:// localhost:5010應用程序已啟動。 按Ctrl + C關閉。 警告:Microsoft.AspNetCore.HttpsPolicy.HttpsRedirectionMiddleware [3]無法確定重定向的https端口。

那么,為Linux實現密鑰存儲提供程序的最佳和最安全的方式是什么(也可能是針對Windows的,通用的)? 有現成的嗎? 有什么例子嗎?

PS。 是的,我已經看過這個文檔 - ASP.NET Core中的密鑰存儲提供程序

我們實現這一點的方式,也支持負載平衡方案是使用Azure ATS作為密鑰存儲庫。

配置看起來像這樣:

  string storageUrl = "https://[your account here].blob.core.windows.net";
  string sasToken = "?sv=20XX-XX-XX&ss=x&srt=xxx&sp=xxxx&...";
  string containerName = "data-protection-XXXX-XXXX-container";
  string blobName = "data-protection-XXXX-XXXX-blob";

   // Create the new Storage URI
   Uri storageUri = new Uri($"{storageUrl}{sasToken}");

   //Create the blob client object.
   CloudBlobClient blobClient = new CloudBlobClient(storageUri);

   //Get a reference to a container. Create it if it does not exist.
   CloudBlobContainer container = blobClient.GetContainerReference(containerName);

   // (NOTE: internal library, do not use in your code)
   AsyncHelper.Guarded<bool>(() => { return container.CreateIfNotExistsAsync();  });


   services.AddDataProtection()
        .SetApplicationName("[your application name here]")
        .PersistKeysToAzureBlobStorage(container, blobName)
        .SetDefaultKeyLifetime(new TimeSpan(365 * 10, 0, 0, 0, 0));

注意:配置Data Protection以獲得額外的安全性時,請查看加密選項。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM