Kerberos与SQL Server的连接是否需要在连接属性中提供密码? [英] Does Kerberos connection to the SQL server needs password to be supplied in connection properties?

查看:142
本文介绍了Kerberos与SQL Server的连接是否需要在连接属性中提供密码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用keytab连接到sql server,并且抛出以下错误

com.microsoft.sqlserver.jdbc.SQLServerException:无法使用Kerberos主体DOMAIN \ User登录,请检查您的凭据. Kerberos登录失败:集成身份验证失败.由于javax.security.auth.login.LoginException而导致ClientConnectionId:6f436f49-b0bf-441e-bab3-e6af86ac8361(无法获得任何属性:con属性中的[password,PASSWORD]无法从用户那里获取身份验证信息) 在com.microsoft.sqlserver.jdbc.KerbAuthentication.intAuthInit(KerbAuthentication.java:108) 在com.microsoft.sqlserver.jdbc.KerbAuthentication.GenerateClientContext(KerbAuthentication.java:399) 在com.microsoft.sqlserver.jdbc.SQLServerConnection.sendLogon(SQLServerConnection.java:4049) 在com.microsoft.sqlserver.jdbc.SQLServerConnection.logon(SQLServerConnection.java:3157) 在com.microsoft.sqlserver.jdbc.SQLServerConnection.access $ 100(SQLServerConnection.java:82) 在com.microsoft.sqlserver.jdbc.SQLServerConnection $ LogonCommand.doExecute(SQLServerConnection.java:3121) 在com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:7151) 在com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:2478) 在com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:2026) 在com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:1687) 在com.microsoft.sqlserver.jdbc.SQLServerConnection.connectInternal(SQLServerConnection.java:1528) 在com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:866) 在com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:569) 在java.sql.DriverManager.getConnection(未知来源) 在java.sql.DriverManager.getConnection(未知来源) 在com.adventnet.appmanager.server.mssql.datacollection.MSSQLKerberosAuthenticationTest.main(MSSQLKerberosAuthenticationTest.java:47) 由以下原因引起:javax.security.auth.login.LoginException:无法获取任何属性:con属性中的[password,PASSWORD]无法从用户那里获取身份验证信息 在com.sun.security.auth.module.Krb5LoginModule.promptForPass(未知来源) 在com.sun.security.auth.module.Krb5LoginModule.attemptAuthentication(未知来源) 在com.sun.security.auth.module.Krb5LoginModule.login(未知来源) 在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)处 在sun.reflect.NativeMethodAccessorImpl.invoke(未知来源) 在sun.reflect.DelegatingMethodAccessorImpl.invoke(未知来源) 在java.lang.reflect.Method.invoke(未知来源) 在javax.security.auth.login.LoginContext.invoke(未知来源) 在javax.security.auth.login.LoginContext.access $ 000(未知源) 在javax.security.auth.login.LoginContext $ 4.run(未知源) 在javax.security.auth.login.LoginContext $ 4.run(未知源) 在java.security.AccessController.doPrivileged(本机方法) 在javax.security.auth.login.LoginContext.invokePriv中(未知源) 在javax.security.auth.login.LoginContext.login处(未知来源) 在com.microsoft.sqlserver.jdbc.KerbAuthentication.intAuthInit(KerbAuthentication.java:87) ...另外15个

当我尝试使用密码时,它已成功连接.

String home = System.getProperty("user.dir");
String  filePath = home + File.separator + "conf" + File.separator + "KerberosConfigurations" + File.separator + "MSSQL";// NO I18N
System.setProperty("java.security.krb5.debug", "true");
System.setProperty("java.security.auth.login.config", filePath+File.separator+"login.conf");
System.setProperty("java.security.krb5.conf", filePath+File.separator+"krb5.ini");
System.setProperty("javax.security.auth.useSubjectCredsOnly", "false");
String connectionUrl = "jdbc:sqlserver://"+hostName+":"+port+";databaseName=master;sendStringParametersAsUnicode=true;applicationName=test;"; //NO I18N
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Properties dbConProp = new Properties();
dbConProp.put("integratedSecurity", "true");
dbConProp.put("authenticationScheme", "JavaKerberos");
dbConProp.put("instanceName",instanceName);
dbConProp.put("user",user);
//dbConProp.put("password",pwd);
con = DriverManager.getConnection(connectionUrl,dbConProp);

对于kerberos连接,连接属性中的密码是否是必需的?单靠Keytab还不够吗?

解决方案

首先需要对域进行身份验证.例如在使用 MIT Kerberos 的Linux和MacOS上,您可以使用kinit命令以获取一张kerberos票.

一旦被授予,您就可以通过该票证向Sql进行身份验证,而无需提供其他任何东西.

[更新]

如果您的主机和目标都在Windows域中,并且它们都在同一个域中,那么您应该已经可以使用了.

也就是说,如果运行引擎的服务帐户具有创建

Does password in connection properties is mandatory for kerberos connection? Keytab alone not sufficient ?

The client needs to be authenticated to the domain first. e.g. on Linux and MacOS using MIT Kerberos, you can use the kinit command to get a kerberos ticket.

Once granted you can then authenticate to Sql via that ticket without supplying anything else.

[Update]

If your host and target are both on a Windows domain and they're on the same domain, then you should already be good to go.

That said, Sql will only allow you to authenticate using Kerberos if the service account that is running the engine has privileges to create a Service Principal Name (or a user with appropriate rights has created a SPN with the setSPN command).

You can tell if Sql's been able to register the SPN by looking at the Sql Error Log for text like

The SQL Server Network Interface library successfully registered the Service Principal Name (SPN) [ MSSQLSvc/MySqlServerHostName:1433 ] for the SQL Server service

There's a lot to Kerberos than can be covered in just a StackOverflow Answer.

这篇关于Kerberos与SQL Server的连接是否需要在连接属性中提供密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆