未安装Kerberos库

时间:2018-06-13 18:58:45

标签: node.js mongodb kerberos

我有一个简单的项目来测试Kerberos身份验证。这是一台Windows机器。 在我的package.json中:

"dependencies": {
    "kerberos": "^0.0.24",
    "mongodb": "^3.0.10"
  }

连接网址:

const url = 'mongodb://userxxx%40XXXXX.XXXXX.COM:Password01@servername:27017/?authMechanism=GSSAPI&authSource=%24external&ssl=true';

但是,当我尝试连接代码时:

MongoClient.connect(url, (err, client) => { 
  if (err) {
    console.error(err);

我收到错误消息Error: Kerberos library is not installed

我尝试了nuking node_modules并重新安装所有内容。我尝试在全球和本地安装kerberos模块。每次都有相同的一致结果。寻找见解。谢谢。

编辑: 安装/编译期间没有错误:

$ yarn add mongodb kerberos
yarn add v1.5.1
info No lockfile found.
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved lockfile.
success Saved 8 new dependencies.
info Direct dependencies
├─ kerberos@0.0.24
└─ mongodb@3.0.10
info All dependencies
├─ bson@1.0.9
├─ kerberos@0.0.24
├─ mongodb-core@3.0.9
├─ mongodb@3.0.10
├─ nan@2.10.0
├─ require_optional@1.0.1
├─ resolve-from@2.0.0
└─ semver@5.5.0
Done in 23.56s.

编辑2:

C:\Users\username\Projects\node.js\kerberos-test>npm init -y
Wrote to C:\Users\username\Projects\node.js\kerberos-test\package.json:

{
  "name": "kerberos-test",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}



C:\Users\username\Projects\node.js\kerberos-test>npm install kerberos mongodb
--save

> kerberos@0.0.24 install C:\Users\username\Projects\node.js\kerberos-test\nod
e_modules\kerberos
> (node-gyp rebuild) || (exit 0)


C:\Users\username\Projects\node.js\kerberos-test\node_modules\kerberos>if not
defined npm_config_node_gyp (node "C:\Users\username\AppData\Roaming\npm\node_
modules\npm\node_modules\npm-lifecycle\node-gyp-bin\\..\..\node_modules\node-gyp
\bin\node-gyp.js" rebuild )  else (node "C:\Users\username\AppData\Roaming\npm
\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" rebuild )
Building the projects in this solution one at a time. To enable parallel build,
please add the "/m" switch.
  kerberos.cc
  worker.cc
  security_buffer.cc
  security_buffer_descriptor.cc
  security_context.cc
  security_credentials.cc
  win_delay_load_hook.cc
..\lib\win32\wrappers\security_credentials.cc(314): warning C4996: 'Nan::Callba
ck::Call': was declared deprecated [C:\Users\username\Projects\node.js\kerber
os-test\node_modules\kerberos\build\kerberos.vcxproj]
  C:\Users\username\Projects\node.js\kerberos-test\node_modules\nan\nan.h(161
  8): note: see declaration of 'Nan::Callback::Call'
..\lib\win32\wrappers\security_credentials.cc(341): warning C4996: 'Nan::Callba
ck::Call': was declared deprecated [C:\Users\username\Projects\node.js\kerber
os-test\node_modules\kerberos\build\kerberos.vcxproj]
  C:\Users\username\Projects\node.js\kerberos-test\node_modules\nan\nan.h(161
  8): note: see declaration of 'Nan::Callback::Call'
..\lib\win32\wrappers\security_context.cc(49): warning C4996: 'Nan::Callback::C
all': was declared deprecated [C:\Users\username\Projects\node.js\kerberos-te
st\node_modules\kerberos\build\kerberos.vcxproj]
  C:\Users\username\Projects\node.js\kerberos-test\node_modules\nan\nan.h(161
  8): note: see declaration of 'Nan::Callback::Call'
..\lib\win32\wrappers\security_context.cc(67): warning C4996: 'Nan::Callback::C
all': was declared deprecated [C:\Users\username\Projects\node.js\kerberos-te
st\node_modules\kerberos\build\kerberos.vcxproj]
  C:\Users\username\Projects\node.js\kerberos-test\node_modules\nan\nan.h(161
  8): note: see declaration of 'Nan::Callback::Call'
..\lib\win32\wrappers\security_context.cc(612): warning C4311: 'type cast': poi
nter truncation from 'unsigned long *' to 'unsigned long' [C:\Users\username\
Projects\node.js\kerberos-test\node_modules\kerberos\build\kerberos.vcxproj]
..\lib\win32\wrappers\security_context.cc(612): warning C4302: 'type cast': tru
ncation from 'unsigned long *' to 'unsigned long' [C:\Users\username\Projects
\node.js\kerberos-test\node_modules\kerberos\build\kerberos.vcxproj]
  base64.c
  kerberos_sspi.c
     Creating library C:\Users\username\Projects\node.js\kerberos-test\node_m
  odules\kerberos\build\Release\kerberos.lib and object C:\Users\username\Pro
  jects\node.js\kerberos-test\node_modules\kerberos\build\Release\kerberos.exp
  Generating code
  Finished generating code
  kerberos.vcxproj -> C:\Users\username\Projects\node.js\kerberos-test\node_m
  odules\kerberos\build\Release\\kerberos.node
  kerberos.vcxproj -> C:\Users\username\Projects\node.js\kerberos-test\node_m
  odules\kerberos\build\Release\kerberos.pdb (Full PDB)
npm notice created a lockfile as package-lock.json. You should commit this file.

npm WARN kerberos-test@1.0.0 No description
npm WARN kerberos-test@1.0.0 No repository field.

+ kerberos@0.0.24
+ mongodb@3.0.10
added 8 packages from 13 contributors and audited 8 packages in 22.648s
found 0 vulnerabilities


C:\Users\username\Projects\node.js\kerberos-test>

从另一个测试项目中复制index.js文件后:

C:\Users\username\Projects\node.js\kerberos-test>node index.js
Error: Kerberos library is not installed
    at SSPI.auth (C:\Users\username\Projects\node.js\kerberos-test\node_module
s\mongodb-core\lib\auth\sspi.js:58:41)
    at authenticate (C:\Users\username\Projects\node.js\kerberos-test\node_mod
ules\mongodb-core\lib\connection\pool.js:244:17)
    at authenticateLiveConnections (C:\Users\username\Projects\node.js\kerbero
s-test\node_modules\mongodb-core\lib\connection\pool.js:831:7)
    at C:\Users\username\Projects\node.js\kerberos-test\node_modules\mongodb-c
ore\lib\connection\pool.js:876:5
    at waitForLogout (C:\Users\username\Projects\node.js\kerberos-test\node_mo
dules\mongodb-core\lib\connection\pool.js:867:34)
    at Pool.auth (C:\Users\username\Projects\node.js\kerberos-test\node_module
s\mongodb-core\lib\connection\pool.js:874:3)
    at Server.auth (C:\Users\username\Projects\node.js\kerberos-test\node_modu
les\mongodb-core\lib\topologies\server.js:922:20)
    at Server.auth (C:\Users\username\Projects\node.js\kerberos-test\node_modu
les\mongodb\lib\topologies\topology_base.js:379:30)
    at authenticate (C:\Users\username\Projects\node.js\kerberos-test\node_mod
ules\mongodb\lib\authenticate.js:56:23)
    at module.exports (C:\Users\username\Projects\node.js\kerberos-test\node_m
odules\mongodb\lib\authenticate.js:112:12)

C:\Users\username\Projects\node.js\kerberos-test>

1 个答案:

答案 0 :(得分:0)

经过一番挖掘后,我在mongodb-core / lib / auth / sspi.js中找到了这个:

try {
  Kerberos = require_optional('kerberos').Kerberos;
  // Authentication process for Mongo
  MongoAuthProcess = require_optional('kerberos').processes.MongoAuthProcess;
} catch (err) {} // eslint-disable-line

问题是它默默地捕获错误并且不报告任何内容。将console.log(err)放入catch后,我看到以下错误:

Error: optional dependency [kerberos] found but version [0.0.24] did not satisfy constraint [^0.0.23]
sspi.js:34
code:"OPTIONAL_MODULE_NOT_FOUND"
message:"optional dependency [kerberos] found but version [0.0.24] did not satisfy constraint [^0.0.23]"
stack:"Error: optional dependency [kerberos] found but version [0.0.24] did not satisfy constraint [^0.0.23]\n    at require_optional (c:\Users\apolkousky\Projects\node.js\kerberos-test\node_modules\require_optional\index.js:109:19)\n    at Object.<anonymous> (c:\Users\apolkousky\Projects\node.js\kerberos-test\node_modules\mongodb-core\lib\auth\sspi.js:29:14)\n    at Module._compile (module.js:643:30)\n    at Object.Module._extensions..js (module.js:654:10)\n    at Module.load (module.js:556:32)\n    at tryModuleLoad (module.js:499:12)\n    at Function.Module._load (module.js:491:3)\n    at Module.require (module.js:587:17)\n    at require (internal/module.js:11:18)\n    at Object.<anonymous> (c:\Users\apolkousky\Projects\node.js\kerberos-test\node_modules\mongodb-core\lib\connection\pool.js:25:10)"
__proto__:Object {constructor: , name: "Error", message: "", …}

将kerberos降级到版本0.0.23解决了这个问题。