简体   繁体   English

来自 OpenWhisk 的 cloudant 查询的安全性

[英]Security of cloudant query from OpenWhisk

I'm building an Angular SPA with a Cloudant data store on Bluemix.我正在使用 Bluemix 上的 Cloudant 数据存储构建一个 Angular SPA。

Since the Bluemix implementation of OpenWhisk doesn't use VCAP services, I see 3 options to use OpenWhisk as my api provider for cloudant queries for my Angular app:由于 OpenWhisk 的 Bluemix 实现不使用 VCAP 服务,因此我看到了 3 个选项来使用 OpenWhisk 作为我的 api 提供程序来为我的 Angular 应用程序进行 cloudant 查询:

  1. Follow the pattern of passing credentials as seen here: https://github.com/IBM-Bluemix/openwhisk-visionapp (very interesting approach btw)遵循传递凭证的模式,如下所示: https : //github.com/IBM-Bluemix/openwhisk-visionapp (顺便说一句,非常有趣的方法)
  2. Include the credentials as though I'm running locally as seen here: https://github.com/IBM-Bluemix/nodejs-cloudant/blob/master/app.js包括凭据,就像我在本地运行一样,如下所示: https : //github.com/IBM-Bluemix/nodejs-cloudant/blob/master/app.js
  3. Use the http API as seen here: https://docs.cloudant.com/api.html (which highlights the security problem passing credentials.使用 http API,如下所示: https : //docs.cloudant.com/api.html (突出显示传递凭据的安全问题。

Since my service is not intended for publishing (it's intended for my own app) I'm thinking option 2 is my "least of all evils" choice.由于我的服务不用于发布(它用于我自己的应用程序),因此我认为选项 2 是我的“万无一失”的选择。 Am I missing something?我错过了什么吗? My thinking is such that while fragile to changes it would be the most secure since credentials aren't passed in the open.我的想法是,虽然易受变化影响,但它是最安全的,因为凭证不会公开传递。 The serverless infrastructure would have to be hacked...无服务器基础设施将不得不被黑客入侵......

Thanks in advance!提前致谢!

(lengthy) Update: (apologies in advance) (冗长)更新:(提前道歉)

I've gotten a little farther along but still no answer - stuck in execution right now.我已经走得更远了,但仍然没有答案 - 现在卡在执行中。

To clarify, my objective is for the app to flow from Angular Client -> OpenWhisk -> Cloudant.澄清一下,我的目标是让应用程序从 Angular Client -> OpenWhisk -> Cloudant 流动。

In this simplest use case, I want to pass a startTime parameter and an endTime parameter, have OpenWhisk fetch all the records in that time range with all fields, and passing back selected fields.在这个最简单的用例中,我想传递一个 startTime 参数和一个 endTime 参数,让 OpenWhisk 获取该时间范围内所有字段的所有记录,并传回选定的字段。 In my example, I have USGS earthquake data in a modified GeoJSON format.在我的示例中,我拥有经过修改的 GeoJSON 格式的 USGS 地震数据。

Following information from the following articles below, I've concluded that I can invoke the wsk command line actions and use the bindings I've setup from within my Javascript function and therefore not pass my credentials to the database.根据以下文章中的信息,我得出结论,我可以调用 wsk 命令行操作并使用我从 Javascript 函数中设置的绑定,因此不会将我的凭据传递给数据库。 This gives me a measure of security (still question the rest endpoint of my OpenWhisk action) but I figure once I get my sample running I think through that part of it.这为我提供了一定程度的安全性(仍然质疑我的 OpenWhisk 操作的其余端点),但我认为一旦我运行了我的示例,我就会考虑其中的那一部分。

My command line (that works): wsk action invoke /my@orgname.com_mybluemixspace/mycfAppName/exec-query-find --blocking --result --param dbname perils --param query {\\"selector\\":{\\"_id\\":{\\"$gt\\":0},\\"properties.time\\":{\\"$gt\\":1484190609500,\\"$lt\\":1484190609700}}}我的命令行(有效): wsk action invoke /my@orgname.com_mybluemixspace/mycfAppName/exec-query-find --blocking --result --param dbname perils --param query {\\"selector\\":{\\"_id\\":{\\"$gt\\":0},\\"properties.time\\":{\\"$gt\\":1484190609500,\\"$lt\\":1484190609700}}}

This successfully returns the following:这成功返回以下内容:
{ "docs": [ { "_id": "eq1484190609589", "_rev": "1-b4fe3de75d9c5efc0eb05df38f056a65", "dbSaveTime": 1.484191201099e+12, "fipsalpha": "AK", "fipsnumer": "02", "geometry": { "coordinates": [ -149.3691, 62.5456, 0 ], "type": "Point" }, "id": "ak15062242", "properties": { "alert": null, "cdi": null, "code": "15062242", "detail": "http://earthquake.usgs.gov/earthquakes/feed/v1.0/detail/ak15062242.geojson", "dmin": null, "felt": null, "gap": null, "ids": ",ak15062242,", "mag": 1.4, "magType": "ml", "mmi": null, "net": "ak", "nst": null, "place": "45km ENE of Talkeetna, Alaska", "rms": 0.5, "sig": 30, "sources": ",ak,", "status": "automatic", "time": 1.484190609589e+12, "title": "M 1.4 - 45km ENE of Talkeetna, Alaska", "tsunami": 0, "type": "earthquake", "types": ",geoserve,origin,", "tz": -540, "updated": 1.484191127265e+12, "url": "http://earthquake.usgs.gov/earthquakes/eventpage/ak15062242" }, "type": "Feature" } ] }

The action I created in OpenWhisk (below) returns an Internal Server Error.我在 OpenWhisk(如下)中创建的操作返回内部服务器错误。 I'm passing the input value as我将输入值传递为
{ "startTime": "1484161200000", "endTime": "1484190000000" }

Here's the code for my action:这是我的操作代码:

`var openWhisk = require('openwhisk');
var ow = openWhisk({
    api_key:'im really a host'
});

function main(params) {

  return new Promise(function(resolve, reject) {
  ow.actions.invoke({
    actionName:'/my@orgname.com_mybluemixspace/mycfAppName/exec-query-find',
    blocking:true,
    parameters:{
      dbname: 'perils',
      query:  {
        "selector": {
          "_id": {
            "$gt": 0
          },
          "properties.time": {
            "$gt": params.startTime,
            "$lt": params.endTime
          }
        }
      }
    }
    }).then(function(res) {
            //get the raw result
            var raw = res.response.result.rows;
            //lets make a new one
            var result = [];
            raw.forEach(function(c) {
                result.push({id:c.docs._id, time:c.docs.properties.time, title:c.docs.properties.title});
            });
            resolve({result:result});
        });
    });
}`

Here are the links to my research: http://infrastructuredevops.com/08-17-2016/news-openwhisk-uniq.html以下是我的研究链接: http : //infrastructuredevops.com/08-17-2016/news-openwhisk-uniq.html
Useful because of the use of the exec-query-find and selector syntax usage but also cool for the update function I need to build for populating my data!有用,因为使用了 exec-query-find 和选择器语法用法,而且对于我需要构建以填充我的数据的更新函数也很酷!

https://www.raymondcamden.com/2016/12/23/going-serverless-with-openwhisk https://www.raymondcamden.com/2016/12/23/going-serverless-with-openwhisk
The article referenced by @csantanapr @csantanapr 引用的文章

Am I overlooking something?我是否忽略了什么?

Thanks!谢谢!

I'm assuming what you are trying to do is to access your Cloudant DB directly from your angular client side code from the Browser.我假设您想要做的是直接从浏览器的角度客户端代码访问您的 Cloudant 数据库。

If you don't need any business logic, or you can get away by using Cloudant features (design docs, views, map, reduce, etc..) and you are generating Cloudant API keys with certain access (ie write vs. read), then you don't need a server or serveless middlewear/tier.如果您不需要任何业务逻辑,或者您可以通过使用 Cloudant 功能(设计文档、视图、映射、缩减等)来摆脱困境,并且您正在生成具有特定访问权限(即写入与读取)的 Cloudant API 密钥,那么您就不需要服务器或无服务器中间件/层。

But now let's get real, most people need that tier, and if you are looking a OpenWhisk, then you are in good luck this is very easy to do.但现在让我们现实一点,大多数人都需要该层,如果您正在寻找 OpenWhisk,那么您很幸运,这很容易做到。

OpenWhisk on Bluemix support VCAP service credentials, but in a different way. Bluemix 上的 OpenWhisk 支持 VCAP 服务凭证,但方式不同。 Let's name you have a Bluemix Org carlos@example.com and space dev that would translate to OpenWhisk namespace carlos@example.com_dev让我们命名您有一个 Bluemix Org carlos@example.com和 space dev ,它将转换为 OpenWhisk 名称空间carlos@example.com_dev

If you add a Cloudant service under the space dev in Bluemix, this will generate service key credentials for this Cloudant Account.如果您在 Bluemix 中的 space dev下添加 Cloudant 服务,这将为此 Cloudant 帐户生成服务密钥凭证。 This credentials give you super power access meaning you are admin.此凭据为您提供超级权力访问权限,这意味着您是管理员。

If you want to use this Cloudant credentials in OpenWhisk, you can use the automatic binding generated with the cloudant package.如果您想在 OpenWhisk 中使用此 Cloudant 凭证,您可以使用由 cloudant 包生成的自动绑定。 To do this using the OpenWhisk CLI run wsk package refresh this will pull the Cloudant credentials and create you a new package with the credentials binded as default parameter for all the cloudant actions under that package.要使用 OpenWhisk CLI 执行此操作,运行wsk package refresh这将拉取 Cloudant 凭据并为您创建一个新包,其中凭据绑定为该包下所有 cloudant 操作的默认参数。 This is modified version of #1 above这是上面#1的修改版本

Another alternative is to bind the credentials manually to a package or an action as default parameters, this makes sense when you don't want to use the super power admin credentials, and you generated a Cloudant API key for a specific database.另一种替代方法是将凭证手动绑定到包或操作作为默认参数,当您不想使用超级管理员凭证并且您为特定数据库生成了 Cloudant API 密钥时,这是有意义的。 This is option #1 above.这是上面的选项#1。

I would not recommend to put the credentials in source code #2我不建议将凭据放在源代码中 #2

For option #3, what's insecure is to pass your credentials as part of the URL like https://username:password@user.cloudant.com , but passing the username and password in the Authorization header over https is secured.对于选项 #3,不安全的是将您的凭据作为 URL 的一部分(如https://username:password@user.cloudant.com )传递,但通过 https 在Authorization标头中传递用户名和密码是安全的。 This is because even if you are using secure transport https everything in the URI/URL is not encrypted anyone can see that value, but passing secrets in body or header is standard practice as this is transfer after secure connection is established.这是因为即使您使用安全传输 https,URI/URL 中的所有内容都未加密,任何人都可以看到该值,但在正文或标头中传递机密是标准做法,因为这是在建立安全连接后进行传输。

Then you create actions that use the credentials as parameters in your OpenWhisk actions to build your business logic for your backend.然后,您创建使用凭据作为 OpenWhisk 操作中的参数的操作,以便为您的后端构建业务逻辑。

Then how to do you access this backend from the Browser, well OpenWhisk has a API Gateway feature in experimental that allows your to expose your actions as public APIs with CORS enable.那么如何从浏览器访问这个后端,OpenWhisk 有一个实验性的 API 网关功能,允许您将您的操作公开为启用 CORS 的公共 API。

Only a url is expose, your credentials as default parameters are never expose.只有一个 url 是公开的,您的凭据作为默认参数永远不会公开。

If you want to see an example on check out Raymond Camden Blog posts where he show Ionic/Angular App accessing his Cloudant Database of Cats https://www.raymondcamden.com/2016/12/23/going-serverless-with-openwhisk如果您想查看有关查看 Raymond Camden 博客文章的示例,其中他展示了 Ionic/Angular 应用程序访问他的 Cloudant 猫数据库https://www.raymondcamden.com/2016/12/23/going-serverless-with-openwhisk

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM