Home

Awesome

Kerberos

The kerberos package is a C++ extension for Node.js that provides cross-platform support for kerberos authentication using GSSAPI on linux/osx, and SSPI on windows. Much of the code in this module is adapted from ccs-kerberos and winkerberos.

Requirements

Linux

macOS

Windows

MongoDB Node.js Driver Version Compatibility

Only the following version combinations with the MongoDB Node.js Driver are considered stable.

kerberos@1.xkerberos@2.x
mongodb@6.xN/A
mongodb@5.x
mongodb@4.x
mongodb@3.xN/A

Installation

Now you can install kerberos with the following:

npm install kerberos

Prebuild Platforms

Below are the platforms that are available as prebuilds on each github release. prebuild-install downloads these automatically depending on the platform you are running npm install on.

Release Integrity

Releases are created automatically and signed using the Node team's GPG key. This applies to the git tag as well as all release packages provided as part of a GitHub release. To verify the provided packages, download the key and import it using gpg:

gpg --import node-driver.asc

The GitHub release contains a detached signature file for the NPM package (named kerberos-X.Y.Z.tgz.sig).

The following command returns the link npm package.

npm view kerberos@vX.Y.Z dist.tarball 

Using the result of the above command, a curl command can return the official npm package for the release.

To verify the integrity of the downloaded package, run the following command:

gpg --verify kerberos-X.Y.Z.tgz.sig kerberos-X.Y.Z.tgz

[!Note] No verification is done when using npm to install the package. To ensure release integrity when using npm, download the tarball manually from the GitHub release, verify the signature, then install the package from the downloaded tarball using npm install mongodb-X.Y.Z.tgz.

To verify the native .node packages, follow the same steps as above.

Testing

Run the test suite using:

docker run -i -v PATH_TO_KERBEROS_REPO:/app -w /app -e PROJECT_DIRECTORY=/app ubuntu:20.04 /bin/bash /app/.evergreen/run-tests-ubuntu.sh

NOTE: The test suite requires an active kerberos deployment.

Documentation

Classes

<dl> <dt><a href="#KerberosClient">KerberosClient</a></dt> <dd></dd> <dt><a href="#KerberosServer">KerberosServer</a></dt> <dd></dd> </dl>

Functions

<dl> <dt><a href="#checkPassword">checkPassword(username, password, service, [defaultRealm], [callback])</a> ⇒ <code>Promise</code></dt> <dd><p>This function provides a simple way to verify that a user name and password match those normally used for Kerberos authentication. It does this by checking that the supplied user name and password can be used to get a ticket for the supplied service. If the user name does not contain a realm, then the default realm supplied is used.</p> <p>For this to work properly the Kerberos must be configured properly on this machine. That will likely mean ensuring that the edu.mit.Kerberos preference file has the correct realms and KDCs listed.</p> <p>IMPORTANT: This method is vulnerable to KDC spoofing attacks and it should only be used for testing. Do not use this in any production system - your security could be compromised if you do.</p> </dd> <dt><a href="#principalDetails">principalDetails(service, hostname, [callback])</a> ⇒ <code>Promise</code></dt> <dd><p>This function returns the service principal for the server given a service type and hostname.</p> <p>Details are looked up via the <code>/etc/keytab</code> file.</p> </dd> <dt><a href="#initializeClient">initializeClient(service, [options], [callback])</a> ⇒ <code>Promise</code></dt> <dd><p>Initializes a context for client-side authentication with the given service principal.</p> </dd> <dt><a href="#initializeServer">initializeServer(service, [callback])</a> ⇒ <code>Promise</code></dt> <dd><p>Initializes a context for server-side authentication with the given service principal.</p> </dd> </dl>

<a name="KerberosClient"></a>

KerberosClient

Properties

NameTypeDescription
username<code>string</code>The username used for authentication
response<code>string</code>The last response received during authentication steps
responseConf<code>string</code>Indicates whether confidentiality was applied or not (GSSAPI only)
contextComplete<code>boolean</code>Indicates that authentication has successfully completed or not

<a name="KerberosClient+step"></a>

kerberosClient.step(challenge, [callback])

ParamTypeDescription
challenge<code>string</code>A string containing the base64-encoded server data (which may be empty for the first step)
[callback]<code>function</code>

Processes a single kerberos client-side step using the supplied server challenge.

Returns: <code>Promise</code> - returns Promise if no callback passed
<a name="KerberosClient+wrap"></a>

kerberosClient.wrap(challenge, [options], [callback])

ParamTypeDescription
challenge<code>string</code>The response returned after calling unwrap
[options]<code>object</code>Optional settings
[options.user]<code>string</code>The user to authorize
[options.protect]<code>boolean</code>Indicates if the wrap should request message confidentiality
[callback]<code>function</code>

Perform the client side kerberos wrap step.

Returns: <code>Promise</code> - returns Promise if no callback passed
<a name="KerberosClient+unwrap"></a>

kerberosClient.unwrap(challenge, [callback])

ParamTypeDescription
challenge<code>string</code>A string containing the base64-encoded server data
[callback]<code>function</code>

Perform the client side kerberos unwrap step

Returns: <code>Promise</code> - returns Promise if no callback passed
<a name="KerberosServer"></a>

KerberosServer

Properties

NameTypeDescription
username<code>string</code>The username used for authentication
response<code>string</code>The last response received during authentication steps
targetName<code>string</code>The target used for authentication
contextComplete<code>boolean</code>Indicates that authentication has successfully completed or not

<a name="KerberosServer+step"></a>

kerberosServer.step(challenge, [callback])

ParamTypeDescription
challenge<code>string</code>A string containing the base64-encoded client data
[callback]<code>function</code>

Processes a single kerberos server-side step using the supplied client data.

Returns: <code>Promise</code> - returns Promise if no callback passed
<a name="checkPassword"></a>

checkPassword(username, password, service, [defaultRealm], [callback])

ParamTypeDescription
username<code>string</code>The Kerberos user name. If no realm is supplied, then the defaultRealm will be used.
password<code>string</code>The password for the user.
service<code>string</code>The Kerberos service to check access for.
[defaultRealm]<code>string</code>The default realm to use if one is not supplied in the user argument.
[callback]<code>function</code>

This function provides a simple way to verify that a user name and password match those normally used for Kerberos authentication. It does this by checking that the supplied user name and password can be used to get a ticket for the supplied service. If the user name does not contain a realm, then the default realm supplied is used.

For this to work properly the Kerberos must be configured properly on this machine. That will likely mean ensuring that the edu.mit.Kerberos preference file has the correct realms and KDCs listed.

IMPORTANT: This method is vulnerable to KDC spoofing attacks and it should only be used for testing. Do not use this in any production system - your security could be compromised if you do.

Returns: <code>Promise</code> - returns Promise if no callback passed
<a name="principalDetails"></a>

principalDetails(service, hostname, [callback])

ParamTypeDescription
service<code>string</code>The Kerberos service type for the server.
hostname<code>string</code>The hostname of the server.
[callback]<code>function</code>

This function returns the service principal for the server given a service type and hostname.

Details are looked up via the /etc/keytab file.

Returns: <code>Promise</code> - returns Promise if no callback passed
<a name="initializeClient"></a>

initializeClient(service, [options], [callback])

ParamTypeDescription
service<code>string</code>A string containing the service principal in the form 'type@fqdn' (e.g. 'imap@mail.apple.com').
[options]<code>object</code>Optional settings
[options.principal]<code>string</code>Optional string containing the client principal in the form 'user@realm' (e.g. 'jdoe@example.com').
[options.flags]<code>number</code>Optional integer used to set GSS flags. (e.g. GSS_C_DELEG_FLAG|GSS_C_MUTUAL_FLAG|GSS_C_SEQUENCE_FLAG will allow for forwarding credentials to the remote host)
[options.mechOID]<code>number</code>Optional GSS mech OID. Defaults to None (GSS_C_NO_OID). Other possible values are GSS_MECH_OID_KRB5, GSS_MECH_OID_SPNEGO.
[callback]<code>function</code>

Initializes a context for client-side authentication with the given service principal.

Returns: <code>Promise</code> - returns Promise if no callback passed
<a name="initializeServer"></a>

initializeServer(service, [callback])

ParamTypeDescription
service<code>string</code>A string containing the service principal in the form 'type@fqdn' (e.g. 'imap@mail.apple.com').
[callback]<code>function</code>

Initializes a context for server-side authentication with the given service principal.

Returns: <code>Promise</code> - returns Promise if no callback passed