加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – DataProtection – 在多个应用程序之间共享机器密钥

发布时间:2020-12-15 23:41:26 所属栏目:百科 来源:网络整理
导读:假设我们有两个API,一个用于UserManagement,一个用于Auth. UserManagement API负责初始邀请电子邮件(我需要一个ResetPasswordToken,因为这是我当前的应用流程),Auth API负责密码恢复(我需要一个ResetPasswordToken). 当然,我需要为两个应用程序指定相同的机
假设我们有两个API,一个用于UserManagement,一个用于Auth.

UserManagement API负责初始邀请电子邮件(我需要一个ResetPasswordToken,因为这是我当前的应用流程),Auth API负责密码恢复(我需要一个ResetPasswordToken).

当然,我需要为两个应用程序指定相同的机器密钥.

我们还假设这两个应用程序将部署在负载均衡器后面. 2个应用程序x 3个实例.

在两个API中保持密钥(Redis等)的共享位置是否足够?

services.AddDataProtection().PersistKeysToRedis(/* */);

我认为如果它适用于一个应用程序,多个实例场景,它将适用于多个应用程序,多个实例场景.

P.S:我无法找到任何关于任何锁定机制的东西(似乎只有一个看看它的行为)

我关心的另一件事:竞争条件?!

Duc_Thuan_Nguy Jun 9,2017

Out of curiosity,how does key rolling
handle concurrency? For example,let’s say we have a web-farm with 2
machines and a shared network directory. There may be a race condition
in which both machines want to roll a new key at the same time. How is
this situation handled? Or the two machines can roll their own new
keys and as long as they can have access to both new keys,they can
unprotect data smoothly?

评论参考:https://docs.microsoft.com/en-us/aspnet/core/security/data-protection/implementation/key-management

稍后编辑:看起来如果您有多个应用程序,仅指定要在同一位置保留密钥是不够的.应用鉴别器有一个概念(所有应用程序都是隔离的).

您将需要以下内容:

services.AddDataProtection(configure => {
                configure.ApplicationDiscriminator = "App.X";
            }).PersistKeysToRedis(/* */);

锁定和竞赛条件问题仍然有效.

解决方法

不,这还不够. ASP.NET Core的数据保护默认根据文件路径或IIS托管信息隔离应用程序,因此多个应用程序可以共享一个密钥环,但仍然无法读取彼此的数据.

如docs state

By default,the Data Protection system isolates apps from one another,
even if they’re sharing the same physical key repository. This
prevents the apps from understanding each other’s protected payloads.
To share protected payloads between two apps,use SetApplicationName
with the same value for each app

public void ConfigureServices(IServiceCollection services)
{
    services.AddDataProtection()
        .SetApplicationName("shared app name");
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读