Menu Docs

Autenticar usando SASL autogerenciado e LDAP com ActiveDirectory

Observação

A partir do MongoDB 8.0, A autenticação e autorização LDAP estão obsoletas. O LDAP está disponível e continuará a operar sem alterações durante a vida útil do MongoDB 8. O LDAP será removido em uma futura versão principal.

Para obter detalhes, consulte Descontinuação do LDAP.

MongoDB Enterprise provides support for proxy authentication of users. This allows administrators to configure a MongoDB cluster to authenticate users by proxying authentication requests to a specified Lightweight Directory Access Protocol (LDAP) service.

Observação

Para binários do MongoDB 4.2 Enterprise vinculados ao libldap (como ao executar no RHEL), o acesso ao libldap é sincronizado, incorrendo em alguns custos de desempenho/latência.

Para binários do MongoDB 4.2 Enterprise vinculados ao libldap_r, não há alteração no comportamento de versões anteriores do MongoDB.

Aviso

O MongoDB Enterprise para Windows não suporta ligação via saslauthd.

  • Os servidores Linux MongoDB suportam ligação a um servidor LDAP através do daemon saslauthd.

  • Utilize conexões seguras criptografadas ou confiáveis entre clientes e o servidor, como também, entre o saslauthd e o servidor LDAP. O servidor LDAP utiliza o mecanismo SASL PLAIN, enviando e recebendo dados em texto sem formatação. Você deve usar apenas um canal confiável, como uma VPN, uma conexão criptografada com TLS/SSL ou uma rede cabeada confiável.

LDAP support for user authentication requires proper configuration of the saslauthd daemon process as well as the MongoDB server.

1

On systems that configure saslauthd with the /etc/sysconfig/saslauthd file, such as Red Hat Enterprise Linux, Fedora, CentOS, and Amazon Linux AMI, set the mechanism MECH to ldap:

MECH=ldap

On systems that configure saslauthd with the /etc/default/saslauthd file, such as Ubuntu, set the MECHANISMS option to ldap:

MECHANISMS="ldap"
2

On certain Linux distributions, saslauthd starts with the caching of authentication credentials enabled. Until restarted or until the cache expires, saslauthd will not contact the LDAP server to re-authenticate users in its authentication cache. This allows saslauthd to successfully authenticate users in its cache, even in the LDAP server is down or if the cached users' credentials are revoked.

To set the expiration time (in seconds) for the authentication cache, see the -t option of saslauthd.

3

If the saslauthd.conf file does not exist, create it. The saslauthd.conf file usually resides in the /etc folder. If specifying a different file path, see the -O option of saslauthd.

To use with ActiveDirectory, start saslauthd with the following configuration options set in the saslauthd.conf file:

ldap_servers: <ldap uri>
ldap_use_sasl: yes
ldap_mech: DIGEST-MD5
ldap_auth_method: fastbind

For the <ldap uri>, specify the uri of the ldap server. For example, ldap_servers: ldaps://ad.example.net.

For more information on saslauthd configuration, see http://www.openldap.org/doc/admin24/guide.html#Configuringsaslauthd.

4

Usar testsaslauthd utility to test the saslauthd configuration. For example:

testsaslauthd -u testuser -p testpassword -f /var/run/saslauthd/mux
  • 0: OK "Success" indicates successful authentication.

  • 0: NO "authentication failed" indicates a username, password, or configuration error.

Modify the file path with respect to the location of the saslauthd directory on the host operating system.

Importante

O diretório pai do arquivo de soquete de domínio Unix do saslauthd especificado para security.sasl.saslauthdSocketPath ou --setParameter saslauthdPath deve conceder permissões de leitura e execução (r-x) para:

  • O usuário iniciando o mongod ou mongos, ou

  • Um grupo ao qual esse usuário pertence.

O mongod ou mongos não pode autenticar com sucesso via saslauthd sem a permissão especificada no diretório saslauthd e seu conteúdo.

1

Add the user to the $external database in MongoDB. To specify the user's privileges, assign roles to the user.

Para usar Sessões de cliente e garantias de consistência causal com usuários de autenticação $external (usuários Kerberos, LDAP ou X.509), os nomes de usuário não podem ter mais de 10k bytes.

For example, the following adds a user with read-only access to the records database.

db.getSiblingDB("$external").createUser(
{
user : <username>,
roles: [ { role: "read", db: "records" } ]
}
)

Add additional principals as needed. For more information about creating and managing users, see Comandos de gerenciamento de usuários.

2

To configure the MongoDB server to use the saslauthd instance for proxy authentication, include the following options when starting mongod:

If you use the authorization option to enforce authentication, you will need privileges to create a user.

For socket path of /<some>/<path>/saslauthd, set the saslauthdPath to /<some>/<path>/saslauthd/mux, as in the following command line example:

mongod --auth --setParameter saslauthdPath=/<some>/<path>/saslauthd/mux --setParameter authenticationMechanisms=PLAIN

Inclua opções adicionais, conforme necessário, para sua configuração. Por exemplo, se você deseja que clientes remotos se conectem à sua implantação ou se os membros da implantação forem executados em hosts diferentes, especifique o --bind_ip.

Or if using a YAML format configuration file, specify the following settings in the file:

security:
authorization: enabled
setParameter:
saslauthdPath: /<some>/<path>/saslauthd/mux
authenticationMechanisms: PLAIN

Or, if using the older configuration file format:

auth=true
setParameter=saslauthdPath=/<some>/<path>/saslauthd/mux
setParameter=authenticationMechanisms=PLAIN

To use the default Unix-domain socket path, set the saslauthdPath to the empty string "", as in the following command line example:

mongod --auth --setParameter saslauthdPath="" --setParameter authenticationMechanisms=PLAIN

Inclua opções adicionais, conforme necessário, para sua configuração. Por exemplo, se você deseja que clientes remotos se conectem à sua implantação ou se os membros da implantação forem executados em hosts diferentes, especifique o --bind_ip.

Or if using a YAML format configuration file, specify the following settings in the file:

security:
authorization: enabled
setParameter:
saslauthdPath: ""
authenticationMechanisms: PLAIN

Or, if using the older configuration file format:

auth=true
setParameter=saslauthdPath=""
setParameter=authenticationMechanisms=PLAIN

Inclua opções adicionais, conforme necessário, para sua configuração. Por exemplo, se você deseja que clientes remotos se conectem à sua implantação ou se os membros da implantação forem executados em hosts diferentes, especifique a configuração net.bindIp.

3

You can authenticate from the command line during connection, or connect first and then authenticate using db.auth() method.

To authenticate when connecting with mongosh, run mongosh with the following command-line options, substituting <host> and <user>, and enter your password when prompted:

mongosh --host <host> --authenticationMechanism PLAIN --authenticationDatabase '$external' -u <user> -p

Alternatively, connect without supplying credentials and then call the db.auth() method on the $external database. Specify the value "PLAIN" in the mechanism field, the user and password in the user and pwd fields respectively. Use the default digestPassword value (false) since the server must receive an undigested password to forward on to saslauthd, as in the following example:

Dica

Você pode usar o método passwordPrompt() em conjunto com vários métodos e comandos de gerenciamento de autenticação de usuário para solicitar a senha em vez de especificar a senha diretamente na chamada de método ou comando. No entanto, você ainda pode especificar a senha diretamente como faria com versões anteriores do shell mongo.

db.getSiblingDB("$external").auth(
{
mechanism: "PLAIN",
user: <username>,
pwd: passwordPrompt() // or cleartext password
}
)

Digite a senha quando solicitado.

The server forwards the password in plain text. In general, use only on a trusted channel (VPN, TLS/SSL, trusted wired network). See Considerations.