IBM Cloud Functions - 在 Functions / node.js 中保护 API 密钥和密码

问题描述

我在 IBM Cloud Function 中获得了一些 Node.js 代码。我已将其作为 Web 操作启用,并通过 Watson Assistant 的 Webhook 调用函数

将我的 API 密钥和其他密码作为可读文本保存在 IBM Cloud Function 中是否安全?或者我应该如何引用密钥和密码

这里有两个摘录作为例子:

function main(params) {
    if (params.actionJoke == 'joke') {
        const optionsDad = {
            method: "GET",uri: "https://dad-jokes.p.rapidapi.com/random/joke",json: true,"resolveWithFullResponse": true,"headers": {
                "x-rapidapi-host": "dad-jokes.p.rapidapi.com","x-rapidapi-key": "myapiCODEgoesHERE","useQueryString": true
            }

在第一个示例中,我可以使用 params.apiKey 代替文字键。我在左侧菜单“参数”中定义了参数。但我不知道这在安全性方面是好是坏?

但是,对于我的第二个示例,此方法不起作用。或者至少我不知道如何在语义上正确地做到这一点。

let smtpConfig = {
    host: 'mail.myz.net',port: 122,secure: false,// use TLS
    auth: {
        user: '[email protected]',pass: 'mypassword'
    }

解决方法

处理机密的方法是bind them to actionspackages。您可以bind services to the functions或任意凭据。

我推荐我在 enhancing security by rotating service credentials 上的博客,其中有一节介绍了使用 __bx_creds 环境对象的 Cloud Functions。

查看此 file from a tutorial 如何在环境中的操作中访问凭据。