是否需要安装具有 SQL 服务器传输和 Windows 身份验证的 NServiceBus 端点作为用户 运行 服务?

Does an NServiceBus endpoint with SQL Server transport and Windows authentication need to be installed as the user running the service?

我正在安装一个使用 SQL 服务器传输的 NServiceBus 4.x 端点。 运行安装程序(通过 Octopus Deploy,默认情况下 运行s 作为本地系统)...

.\NServiceBus.Host.exe /install NServiceBus.Production /serviceName=$name /username:"$username" /password:"$password

...我得到一个错误:

Failed to execute installers: System.Data.SqlClient.SqlException (0x80131904): Login failed for user 'DOMAIN\MACHINENAME$'.

如果安装程序在 运行 时连接到 SQL 服务器,这是预期的行为:本地系统在离开框时成为计算机帐户,并且计算机帐户无权访问运输数据库。

不过,我不打算运行端点作为本地系统。相反,我打算使用可以访问传输数据库的域服务帐户,所以...

是否可以使用 SQL 服务器传输作为无权访问传输数据库的用户安装 NServiceBus 端点?

额外问题:此行为在 4.x 之后的 NServiceBus 版本中是否已更改?

这里的问题是 NServiceBus.Host.exe 是使用您所说的 Octopus Deploy 和 /install 运行s NServiceBus 安装程序的凭据执行的。

一些备选方案:

  1. 运行 Octopus Deploy Agent 具有允许在此部署阶段对数据库进行架构更改的权限。

  2. 不是直接执行主机,而是使用不同的凭据启动 shell,以便主机 运行 具有具有适当权限的凭据。

  3. 不使用主机,使用自托管。通过 sc.exe 注册该服务以使用正确的凭据注册 windows 服务,并使用 endpointConfiguration.EnableInstallers() 控制安装程序是否必须 运行.

  4. 像 (3) 一样使用自托管,不要使用 endpointConfiguration.EnableInstallers() 但编写所有任务的脚本并让这些 运行 独立于 'windows service' 注册任务。或者,您可以改为使用 sc.exe 来注册 NServiceBus.Host.exe,这样 /install 就不会是 运行.

我建议不要总是 运行 endpointConfiguration.EnableInstallers() 在端点上。您应该区分部署和 运行 时间。在部署期间,您将创建表、架构等,但在 运行 时,该帐户不应具有创建或删除表的权限和 运行 最低权限。