如何解决在 Linux(Ubuntu 18.04)中进行 EF Core 数据库脚手架的“无法使用 Kerberos 进行身份验证”问题?有啥解决办法吗?

     2023-02-15     245

关键词:

【中文标题】如何解决在 Linux(Ubuntu 18.04)中进行 EF Core 数据库脚手架的“无法使用 Kerberos 进行身份验证”问题?有啥解决办法吗?【英文标题】:How to solve 'Cannot authenticate using Kerberos' issue doing EF Core database scaffolding in Linux(Ubuntu 18.04)? Are there any solutions?如何解决在 Linux(Ubuntu 18.04)中进行 EF Core 数据库脚手架的“无法使用 Kerberos 进行身份验证”问题?有什么解决办法吗? 【发布时间】:2020-04-02 14:00:01 【问题描述】:

每个人。我一直在尝试使用 EntityFrameworkCore 开发简单的启动 AspNetCore 应用程序,以连接和使用 MS SQL 服务器数据库。并通过 Rider IDE、数据库客户端工具 (DBeaver) 和 dotnet 命令行界面 (dotnet ef) 管理所有这些。我使用的是数据库优先方法(在 mssql 服务器上创建数据库,用表填充它,然后基于表构建模型)。我的分步操作:

1) 为我在 Ubuntu 18.04 上工作的机器安装和设置 mssql 服务器。安装命令行工具“SQLCMD”。 /// 指南链接 - https://docs.microsoft.com/en-gb/sql/linux/quickstart-install-connect-ubuntu?view=sql-server-ver15

2)本地连接到我的 MSSQLServer 实例。 sqlcmd -S localhost -U SA -P 'MyPasswd'

3) 使用 Transact-SQL 创建的数据库并安装数据库客户端 (DBeaver) 来快速管理我现在和将来的数据库。

按照我的设想,下一步是使用有关将我的 Web 应用程序连接到数据库的教程,这些教程可以在 https://blog.jetbrains.com/dotnet/2017/08/09/running-entity-framework-core-commands-rider/ 和 https://www.entityframeworktutorial.net/efcore/create-model-for-existing-database-in-ef-core.aspx 找到

我的 ASP.NET Core 项目的包参考:

Microsoft.EntityFrameworkCore Microsoft.EntityFrameworkCore.SqlServer Microsoft.EntityFrameworkCore.Tools

在输入 CLI 命令后 dotnet ef dbcontext 脚手架“服务器=本地主机;数据库=WebAppDB;集成安全=真;” Microsoft.EntityFrameworkCore.SqlServer -c RsvpContext ( 构建“RsvpContext”上下文以连接到我的数据库 WebAppDB。)

我看到了我所看到的:

Build started...
Build succeeded.
Microsoft.Data.SqlClient.SqlException (0x80131904): **Cannot authenticate using 
Kerberos. Ensure Kerberos has been initialized on the client with 'kinit' and a 
Service Principal Name has been registered for the SQL Server to allow Kerberos 
authentication.**

ErrorCode=InternalError, Exception=Interop+NetSecurityNative+GssApiException: 
GSSAPI operation failed with error - Unspecified GSS failure.  Minor code may 
provide more information (SPNEGO cannot find mechanisms to negotiate).


   at System.Net.Security.NegotiateStreamPal.GssInitSecurityContext(SafeGssContextHandle& context, SafeGssCredHandle credential, Boolean isNtlm, SafeGssNameHandle targetName, GssFlags inFlags, Byte[] buffer, Byte[]& outputBuffer, UInt32& outFlags, Int32& isNtlmUsed)

   at System.Net.Security.NegotiateStreamPal.EstablishSecurityContext(SafeFreeNegoCredentials credential, SafeDeleteContext& context, String targetName, ContextFlagsPal inFlags, SecurityBuffer inputBuffer, SecurityBuffer outputBuffer, ContextFlagsPal& outFlags)

   at Microsoft.Data.SqlClient.SNI.SNIProxy.GenSspiClientContext(SspiClientContextStatus sspiClientContextStatus, Byte[] receivedBuff, Byte[]& sendBuff, Byte[] serverName)

   at Microsoft.Data.SqlClient.SNI.TdsParserStateObjectManaged.GenerateSspiClientContext(Byte[] receivedBuff, UInt32 receivedLength, Byte[]& sendBuff, UInt32& sendLength, Byte[] _sniSpnBuffer)

   at Microsoft.Data.SqlClient.TdsParser.SNISSPIData(Byte[] receivedBuff, UInt32 receivedLength, Byte[]& sendBuff, UInt32& sendLength)

   at Microsoft.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, Boolean applyTransientFaultHandling, String accessToken, DbConnectionPool pool, SqlAuthenticationProviderManager sqlAuthProviderManager)

   at Microsoft.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)

   at Microsoft.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions)

   at Microsoft.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)

   at Microsoft.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)

   at Microsoft.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)

   at Microsoft.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)

at Microsoft.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)

   at Microsoft.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)

   at Microsoft.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)

   at Microsoft.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)

   at Microsoft.Data.SqlClient.SqlConnection.Open()

   at Microsoft.EntityFrameworkCore.SqlServer.Scaffolding.Internal.SqlServerDatabaseModelFactory.Create(DbConnection connection, DatabaseModelFactoryOptions options)

at Microsoft.EntityFrameworkCore.SqlServer.Scaffolding.Internal.SqlServerDatabaseModelFactory.Create(String connectionString, DatabaseModelFactoryOptions options)

   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.ReverseEngineerScaffolder.ScaffoldModel(String connectionString, DatabaseModelFactoryOptions databaseOptions, ModelReverseEngineerOptions modelOptions, ModelCodeGenerationOptions codeOptions)

   at Microsoft.EntityFrameworkCore.Design.Internal.DatabaseOperations.ScaffoldContext(String provider, String connectionString, String outputDir, String outputContextDir, String dbContextClassName, IEnumerable`1 schemas, IEnumerable`1 tables, Boolean useDataAnnotations, Boolean overwriteFiles, Boolean useDatabaseNames)

   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.ScaffoldContextImpl(String provider, String connectionString, String outputDir, String outputDbContextDir, String dbContextClassName, IEnumerable`1 schemaFilters, IEnumerable`1 tableFilters, Boolean useDataAnnotations, Boolean overwriteFiles, Boolean useDatabaseNames)

   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.ScaffoldContext.<>c__DisplayClass0_0.<.ctor>b__0()

   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.<Execute>b__0()

   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
ClientConnectionId:38f805bc-5879-458b-9256-d6a201d7ce99
Cannot authenticate using Kerberos. Ensure Kerberos has been initialized on the 
client with 'kinit' and a Service Principal Name has been registered for the SQL 
Server to allow Kerberos authentication.
ErrorCode=InternalError, Exception=Interop+NetSecurityNative+GssApiException: 
GSSAPI operation failed with error - Unspecified GSS failure.  Minor code may 
provide more information (SPNEGO cannot find mechanisms to negotiate).

   at System.Net.Security.NegotiateStreamPal.GssInitSecurityContext(SafeGssContextHandle& context, SafeGssCredHandle credential, Boolean isNtlm, SafeGssNameHandle targetName, GssFlags inFlags, Byte[] buffer, Byte[]& outputBuffer, UInt32& outFlags, Int32& isNtlmUsed)

   at System.Net.Security.NegotiateStreamPal.EstablishSecurityContext(SafeFreeNegoCredentials credential, SafeDeleteContext& context, String targetName, ContextFlagsPal inFlags, SecurityBuffer inputBuffer, SecurityBuffer outputBuffer, ContextFlagsPal& outFlags)

   at Microsoft.Data.SqlClient.SNI.SNIProxy.GenSspiClientContext(SspiClientContextStatus sspiClientContextStatus, Byte[] receivedBuff, Byte[]& sendBuff, Byte[] serverName)

   at Microsoft.Data.SqlClient.SNI.TdsParserStateObjectManaged.GenerateSspiClientContext(Byte[] receivedBuff, UInt32 receivedLength, Byte[]& sendBuff, UInt32& sendLength, Byte[] _sniSpnBuffer)

   at Microsoft.Data.SqlClient.TdsParser.SNISSPIData(Byte[] receivedBuff, UInt32 receivedLength, Byte[]& sendBuff, UInt32& sendLength)

如果有人(最好是在 Linux 上工作)遇到同样的问题,请告诉我并分享您的解决方案(有关在这种情况下该怎么做的指南)。

【问题讨论】:

在 Linux 服务器上配置 Kerboros 是一个漫长的过程,而且并不简单。简单的答案是在此处使用 SQL 身份验证。除非您非常熟悉 Linux 和 SQL Server,否则我不建议您尝试走 Kerboros 路线。 preferably working on Linux Windows 使用 Kerberos 进行 Windows 身份验证,其中配置由操作系统在加入域、机器启动等时自动执行。Linux 并非如此。您没有在问题中发布任何 Kerberos 配置步骤。机器是 AD 域的一部分吗? Kerberos 是否以其他方式配置? Ensure Kerberos has been initialized on the client with 'kinit' and a Service Principal Name has been registered for the SQL Server to allow Kerberos authentication.你这样做了吗? @PanagiotisKanavos,回答你的 1 个问题,我可以说没有配置通过 Kerberos 的连接,原因是在键入 SELECT auth_scheme FROM sys.dm_exec_connections WHERE session_id = @@spid 后;控制台输出是 auth_scheme | SQL 这是来自博客docs.microsoft.com/en-us/sql/database-engine/configure-windows/… 我只是不知道下一步该做什么 【参考方案1】:

在我们的案例中,我们最近在从内部部署转换为 azure kubernetes 云解决方案时遇到了这个问题。

简短的回答,它与集成身份验证有关。

我们将集成安全性更改为 false,因此集成身份验证应类似于 (integrated security=false;),并且我们还在连接字符串 (User ID=YourProperUserName;Password=YourProperUserPassword;) 中提供了具有正确访问权限的用户名和密码。

问题解决了。

【讨论】:

除了上面的答案之外,如果您的连接字符串中存在 Trusted_Connection=True 。删除它。【参考方案2】:

在您的连接字符串中更改Integrated Security=false

【讨论】:

请不要重复回答。没用。

如何在虚拟机Ubuntu 18.04上安装catkin

】如何在虚拟机Ubuntu18.04上安装catkin【英文标题】:HowtoinstallcatkinonavirtualmachineUbuntu18.04【发布时间】:2019-09-2317:11:48【问题描述】:我觉得我有靛蓝...我按照说明操作:https://wiki.ros.org/catkin#Installing_catkin有人可以帮我解决这个问... 查看详情

ubuntu18.04蓝牙打开无效,解决办法升级内核(代码片段)

http://kernel.ubuntu.com/~kernel-ppa/mainline/上面的链接是linux内核版本,蓝牙不管用可能是linux内核版本过低,本人亲自实验过,升级到4.20.5-042005-generic可以打开了蓝牙,就是打开速度很慢,需要等待3到5秒升级内核步骤,以4.20.5-042005-generic为例1.... 查看详情

在 ubuntu 18.04 LTS 中安装 rock-robotics 包时出现问题 [已解决]

】在ubuntu18.04LTS中安装rock-robotics包时出现问题[已解决]【英文标题】:problemwhileinstallingrock-roboticspackageinubuntu18.04LTS[SOLVED]【发布时间】:2020-06-2411:03:14【问题描述】:已解决(见答案)问题我已按照“https://www.rock-robotics.org/documen... 查看详情

如何修复 Ubuntu 18.04 上没有声音?

】如何修复Ubuntu18.04上没有声音?【英文标题】:HowtofixNosoundonUbuntu18.04?【发布时间】:2020-05-0619:08:42【问题描述】:1)几个月来,我一直在使用带有Windows10双启动的Ubuntu18.04。今天突然我的声音停止在Ubunutu上工作。活动->声音... 查看详情

如何删除安装在 ubuntu 18.04 上的 boost

】如何删除安装在ubuntu18.04上的boost【英文标题】:Howtoremoveboostinstalledonubuntu18.04【发布时间】:2021-02-1012:45:27【问题描述】:我已通过命令删除了Boost。在version.hpp中显示1.65.1sudoapt-get--purgeremovelibboost-all-dev但是我有boost1.75版本我... 查看详情

如何在专用 Ubuntu 18.04 服务器上激活 IPv6?

】如何在专用Ubuntu18.04服务器上激活IPv6?【英文标题】:HowtoactivateIPv6ondedicatedUbuntu18.04server?【发布时间】:2022-01-1012:57:46【问题描述】:大家!我不是专家,而是兼职管理员;如果问题太简单,请原谅:如何在我的专用Ubuntu18.04... 查看详情

尝试在 linux ubuntu 18.04 LTS 上安装 docker 存储库时出错

】尝试在linuxubuntu18.04LTS上安装docker存储库时出错【英文标题】:Errorbytryinginstallingdockerrepositoryonlinuxubuntu18.04LTS【发布时间】:2019-07-2022:58:06【问题描述】:抱歉,语言是德语。所以我添加了docker的仓库:sudoadd-apt-repository"deb[arch=... 查看详情

如何在 ubuntu 18.04 上设置 oracle 即时客户端?

】如何在ubuntu18.04上设置oracle即时客户端?【英文标题】:howdoisetuporacleinstantclientonubuntu18.04?【发布时间】:2021-04-1101:16:12【问题描述】:所以我试图在zabbix上通过ODBC监控oracle数据库,但是我的zabbix服务器是ubuntu18.04,我真的很... 查看详情

如何允许节点在 Ubuntu 18.04 上监听 1024 以下的端口?

】如何允许节点在Ubuntu18.04上监听1024以下的端口?【英文标题】:HowcanIallownodetolistentoportsbelow1024onUbuntu18.04?【发布时间】:2019-04-2523:08:49【问题描述】:我可以在安装了nvm的节点中使用任何大于1023的PORT和server.listen(PORT)。非特权... 查看详情

解决ubuntu18.04安装nvidia驱动开机卡死

...者处理这个问题的过程分享给大家,在遇到相同情况后,如何不重装系统,将N卡驱动卸载掉,顺利进入系统。首先,因为我们现在无法进入图形界面,所以需要进入单用户模式下,在单用户模式下进行Nvidia驱动卸载操作,在grub... 查看详情

如何关闭或退出安装在我的 Ubuntu 18.04 中的 Docker?

】如何关闭或退出安装在我的Ubuntu18.04中的Docker?【英文标题】:HowcanishutdownorexitfromDockerinstalledinmyUbuntu18.04?【发布时间】:2019-09-1323:09:00【问题描述】:我希望在打开具有Ubuntu18.04作为操作系统的笔记本电脑时启动Xampp。事实上... 查看详情

尝试在 Ubuntu 18.04 上安装 CUDA 9.2

】尝试在Ubuntu18.04上安装CUDA9.2【英文标题】:TryingtoinstallCUDA9.2onUbuntu18.04【发布时间】:2019-01-1805:49:27【问题描述】:我正在,遵循this网站:我已经下载了NVIDIACUDAToolkit(shell脚本cuda_9.2.88_396.26_linux),但是当我运行它时($sudoshc... 查看详情

ubuntu18.04安装ros配置环境没有那个文件或目录的解决办法(代码片段)

...rdirectory的错误在经过一番查询后发现网上给的Ubuntu16.04的解决办法#解決方法:在终端输入gedit~/.bashrc#在打开文件的最后找到bash:/opt/ros/kinetic/setup.bash删除重复的多余配置,如果没有多余项查 查看详情

如何从安装在 Ubuntu 18.04 VirtualBox 上的 Wordpress Web 界面写入/上传

】如何从安装在Ubuntu18.04VirtualBox上的WordpressWeb界面写入/上传【英文标题】:HowtoWrite/UploadfromWordpressWebInterfaceInstalledonUbuntu18.04VirtualBox【发布时间】:2019-06-1815:59:27【问题描述】:主机:Windows1064bitVirtualBox:Ubuntu18.04Apache2.4、MySQL5.... 查看详情

如何在 Ubuntu 18.04 上安装最新的 openjdk 12

】如何在Ubuntu18.04上安装最新的openjdk12【英文标题】:Howtoinstallthelatestopenjdk12onUbuntu18.04【发布时间】:2019-09-2102:10:43【问题描述】:我已经通过发出命令安装了默认jdk:apt-getinstalldefault-jdk这将安装openjdk11并且apt-get似乎将文件安... 查看详情

如何在ubuntu18.04中使用privoxy实现ubuntu终端的scientificsurftheinternet(代码片段)

总结一下如何在Ubuntu18.04中使用privoxy实现ubuntu终端的scientificsurftheInternet安装privoxysudoapt-getinstallprivoxy如果安装遇到报错E:Sub-process/usr/bin/dpkgreturnedanerrorcode(1)"的错误可以在/var/lib/dpkg目录下执行sudocpinfoinfo.ba 查看详情

如何在线将ubuntu18.04升级到ubuntu20.04

将Ubuntu18.04升级到Ubuntu20.04在将系统升级运行到下一个主要发行版本之前,请确保已备份当前系统,以使您可以恢复原状,以防万一。备份过程不在本指南的范围内。运行系统更新首先将Ubuntu18.04系统软件包更新和升级... 查看详情

pip

如何在Ubuntu18.04上安装Pip[日期:2018-05-15] 来源:Linux公社作者:醉落红尘 [字体:大中小]Pip是一个软件包管理系统,它简化了用Python编写的软件包(如Python包索引(PyPI)中的软件包)的安装和管理。在Ubuntu18.04上缺省没有安装Pip... 查看详情