Join us Sept 17 at .local NYC! Use code WEB50 to save 50% on tickets. Learn more >
MongoDB Event
Docs 菜单
Docs 主页
/ / /
Ruby 驱动程序
/ /

Kerberos (GSSAPI)

通用安全服务API (GSSAPI)身份验证机制允许使用主体名称对Kerberos服务进行身份验证。 只有在向MongoDB Enterprise Advanced进行身份验证时才能使用此机制。

本页上的代码示例使用以下占位符:

  • <username>: LDAP username.

  • <hostname>: MongoDB 部署的网络解决。

  • <port>: MongoDB 部署的端口号。如果省略此参数,驾驶员将使用默认端口号 (27017)。连接到MongoDB Atlas 群集时,可以选择指定端口号。

  • <authentication_db>:包含用户的LDAP凭证的MongoDB 数据库。如果省略此参数,驾驶员将使用默认数据库(admin)。

要使用本页上的代码示例,请将这些占位符替换为您自己的值。

要将MongoDB Server配置为使用Kerberos,请参阅 MongoDB Server Kerberos文档。

To use the Kerberos authentication mechanism with the Ruby driver, you must install and load the mongo_kerberos library. To do so, add the following lines to your Gemfile:

gem 'mongo', '~> 2'
gem 'mongo_kerberos', '~> 2'

然后,将以下行添加到您的应用程序代码中:

require 'mongo'
require 'mongo_kerberos'

注意

使用Kerberos身份验证时,必须指定托管的完全限定域名 (FQDN)。

以下部分介绍如何将Kerberos身份验证与Ruby MRI 和 JRuby 结合使用。

如果您将Kerberos身份验证与Ruby MRI结合使用,则必须执行以下步骤:

  • 在驾驶员上建立Kerberos会话。驾驶员使用此会话向服务器证明用户的身份。

  • You must ensure that the host system is configured for Kerberos authentication. To learn more about configuring the host system to use Kerberos, see the Kerberos documentation or your operating system documentation for details.

Use the kinit utility to establish a Kerberos session.

如果您在JRuby中使用Kerberos身份验证,则可以使用上述 MRI进程从外部建立与驾驶员的Kerberos会话。您还可以通过将配置存储在 java.security.auth.login.config 系统属性中来提供 keytab文件的路径。您还必须配置Java运行时环境才能使用Kerberos。要学习;了解更多信息,请参阅MongoDB Java驱动程序Kerberos文档以获取更多信息。

选择 Connection StringClient Options标签页,查看使用Kerberos身份验证连接到MongoDB 的相应语法:

client = Mongo::Client.new("mongodb://<username>@<hostname>[:<port>]/<authentication_db>?authMechanism=GSSAPI")
client = Mongo::Client.new(['<hostname>[:<port>]'],
auth_mech: :gssapi,
user: '<username>')

注意

如果使用连接字符串连接到MongoDB,请确保对用户名中出现的所有特殊字符进行百分号编码。

要学习;了解有关本页讨论的任何方法或类型的更多信息,请参阅以下API文档:

后退

LDAP (Plain)

在此页面上