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

IBM Cloud Functions - Securing API keys & Passwords inside Functions / node.js

我在 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 而不是文字键。我在左侧菜单中定义了参数 'parameters'。但我不知道这在安全性方面是好是坏?

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

let smtpConfig = {
    host: 'mail.myz.net',
    port: 122,
    secure: false, // use TLS
    auth: {
        user: 'mymail@xyz.com', 
        pass: 'mypassword'
    }

使用机密的方法是 bind them to actions or packages. You can bind services to the functions 或任意凭据。

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

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