[英]how to use username/password as credentials for nodejs grpc?
I'm trying to access the gNMI API on an Arista router.我正在尝试访问 Arista 路由器上的 gNMI API。 The interface is configured with only username/password (admin/admin) and no certificate.
该界面仅配置了用户名/密码 (admin/admin),没有证书。
This CLI command returns the capabilities此 CLI 命令返回功能
$ gnmic -a 10.72.47.100:32232 --username admin --password admin --skip-verify capabilities
I'm using @grpc/grpc-js
and ts-proto
for typescript model generation.我正在使用
@grpc/grpc-js
和ts-proto
来生成打字稿模型。
I have not been able to figure out how to make the same API call from node/typescript.我无法弄清楚如何从节点/打字稿进行相同的 API 调用。
Trying to combine an insecure with a call credentials gives this error Error: Cannot compose insecure credentials
尝试将不安全的凭据与呼叫凭据结合使用会出现此错误
Error: Cannot compose insecure credentials
import * as grpc from '@grpc/grpc-js';
import * as gnmi from './proto/github.com/openconfig/gnmi/proto/gnmi/gnmi';
const meta = new grpc.Metadata();
meta.add('username', 'admin');
meta.add('password', 'admin');
const channelCredentials = grpc.credentials.createInsecure();
const callCredentials = grpc.credentials.createFromMetadataGenerator( (options, callback) => {
callback(null, meta);
});
const credentials = grpc.credentials.combineChannelCredentials(
channelCredentials,
// callCredentials, <-- ** gives error: Error: Cannot compose insecure credentials **
);
const client = new gnmi.gNMIClient('10.72.47.100:32232', credentials);
const req: gnmi.CapabilityRequest = { extension: [] };
client.capabilities(req,
(error, response) => {
if (error) {
console.error(error);
process.exit(1);
}
console.info(response.gNMIVersion);
})
And passing the meta to the call gives me this error Error: 14 UNAVAILABLE: Connection dropped
.并将元数据传递给调用会给我这个错误
Error: 14 UNAVAILABLE: Connection dropped
。 I assume this is due to missing credentials我认为这是由于缺少凭据
const meta = new grpc.Metadata();
meta.add('username', 'admin');
meta.add('password', 'admin');
const Credentials = grpc.credentials.createInsecure();
const client = new gnmi.gNMIClient('10.72.47.100:32232', credentials);
const req: gnmi.CapabilityRequest = { extension: [] };
client.capabilities(req, meta
(error, response) => {
if (error) {
console.error(error);
process.exit(1);
}
console.info(response.gNMIVersion);
})
code: 14, details: 'Connection dropped',
metadata: Metadata, stack: 'Error: 14 UNAVAILABLE: Connection dropped
Any suggestions as how I can do this ?关于如何做到这一点的任何建议?
Thanks谢谢
gRPC does not allow composing call credentials with insecure channel credentials because call credentials generally contain sensitive information that should only be transmitted over secure connections. gRPC 不允许使用不安全的通道凭据组合呼叫凭据,因为呼叫凭据通常包含只能通过安全连接传输的敏感信息。 The simplest way to handle this is to secure the connection with TLS by using secure credentials on both the client and the server.
处理此问题的最简单方法是通过在客户端和服务器上使用安全凭据来保护与 TLS 的连接。 If that is not an option, you can also pass the metadata directly to each individual request instead of using call credentials.
如果这不是一个选项,您还可以将元数据直接传递给每个单独的请求,而不是使用呼叫凭据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.