简体   繁体   English

如何使用用户名/密码作为 nodejs grpc 的凭据?

[英]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-jsts-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.

相关问题 如何为Elasticjs客户端指定凭证用户名/密码? - How to specify credentials username/password for elasticjs client? 使用NodeJS的用户名/密码的TLS - TLS with username/password with NodeJS RESTful服务需要用户名和密码才能获得令牌,可以将凭据(用户名和密码)保存在服务器端nodejs中吗? - restful service requires username and password to get the token, is it ok to save the credentials(user and pass) in server side nodejs? 错误:错误的用户名/密码 nodemailer-sengrid-transport 使用 NodeJs - Error: Bad username/password nodemailer-sengrid-transport use NodeJs 验证密码和用户名nodejs mysql - validation of password and username nodejs mysql 使用 mongodb 在 nodejs 中验证用户名和密码 - Authenticating Username and Password in nodejs with mongodb 不接受Node.js nodemailer用户名和密码 - Nodejs nodemailer Username and Password not accepted 如何在没有用户名/密码的nodejs中创建JWT用户/访问令牌? - How to create JWT user/access token in nodejs without username/password? 如何在nodejs中设置ftp-srv的用户名和密码? - how to set username and password of ftp-srv in nodejs? 如何使用用户名和密码连接到 redis db - how to connect to redis db with username and password nodejs node-redis
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM