Fiware - 如何集成 Keyrock IdM、Wilma PEP Proxy 和 Orion Context Broker?

Fiware - How to integrate Keyrock IdM, Wilma PEP Proxy and Orion Context Broker?

我看了所有的Keyrock和Wilma的文档,也看了所有的FIWARE学院的视频,但是还是没有集成成功。我从几天前开始就在寻找这个,但没有成功。我认为 FIWARE 文档可以包含教程、实践...

我有一个带有 Orion Context Broker 的虚拟机和一个带有 Keyrock IdM 和 Wilma PEP 代理的容器。我正在尝试生成访问令牌以授予应用程序访问权限,但我仍然没有得到它。此外,我想知道如何在 Orion Context Broker 和一些物联网设备之间安全地交换消息。事实上,像 Keyrock IdM 示例所示,考虑 IoT 设备必须访问屏幕并输入其凭证以进行身份​​验证和授权是很复杂的。你有什么建议?

关于 Orion,它取决于要保护的接口,服务 API(即 Orion 通常在端口 1026 运行的侦听 REST 服务器)、通知 API 或两者:

  • 关于服务API:
    • Authentication & authorization:可以通过PEP实现。 下面documentation介绍两种PEP替代方案 实施。但是,请注意 PEP 不能独立工作,因为它 还需要 IDM 和访问控制才能工作。我明白@Alvaro 可以详细解释这个主题(关于 Wilma PEP)。它出来了 据我所知。
    • 加密:可以通过代理实现HTTPS-to-HTTP 桥(例如 ngnix)或由 Orion 本身使用 -https CLI 参数(与 -key-cert 结合使用)。这个 section of the documentation 详细说明。
  • 关于通知API:
    • Authentication & authorization: 当前实现 自定义通知(请参阅 NGSIv2 规范中的 "Custom notifications" 部分)允许您包含自定义 HTTP header 可用于身份验证(例如 X-Auth-Token header 需要 通过保护您的端点的 PEP 实例)。注意 目前这是以静态方式完成的,即 Orion 无法 直接与 IDM/AccessControl 互动以设置 X-Auth-Token 到期后动态价值等。但是,有可能开发一个 process 能够做到这一点并设置适当的 header (如果你有兴趣 在此我建议检查 "How to add a custom header in outgoing notifications with Orion?" post)。
    • 加密:可以在Rush组件中实现中继。这个 section of the documentation 详细说明。

更新: 自版本 1.7.0 以来,Orion 实现了本机 HTTPS 通知(即不需要 Rush)。

看到@albertinisg , I found a bash script 对令牌请求的回答。我将其更改为与我的本地实例一起使用并且有效。

在 FIWARE 门户注册我的应用程序后(more information here), I had to make a POST request to http://idm:8000/oauth2/token(idm 是我本地的 Keyrock 实例)。使用此有效令牌,我可以访问 Orion 中的内容。

import requests, json, getpass

TOKEN_URL = "http://idm:5000/v2.0/tokens"

USER = raw_input("Username: ")
PASSWORD = getpass.getpass("Password: ")
PAYLOAD = "{\"auth\": {\"passwordCredentials\": {\"username\":\""+USER+"\", \"password\":\""+PASSWORD+"\"}}}"
HEADERS =  {'content-type': 'application/json'}
RESP = requests.post(TOKEN_URL, data=PAYLOAD, headers=HEADERS)

PEP 代理 (Wilma) 配置 (config.js):

config.app_host = 'my_orion_ip'; //change to your Orion address
config.app_port = '1026'; //change to your Orion port

config.username = 'pep_proxy_credential_obtained_at_portal';
config.password = 'password_obtained_at_portal';

使用有效的令牌和 PEP 代理 (Wilma) 服务器 运行 此配置,可以控制对 Orion 的访问以请求 PEP 代理地址。 PEP 代理会将此请求重定向到 IdM (Keyrock),以便 IdM 可以验证 user/device 凭据。如果凭据有效,user/device 将收到有效令牌,现在 PEP 代理可以允许访问 Orion。

对于 HTTPS 通信,我将 Nginx 服务器配置为充当反向代理(.conf 文件):

server {
   listen       443;
   server_name  orion;

   ssl                  on;
   ssl_certificate      /etc/nginx/ssl/orion.crt;
   ssl_certificate_key  /etc/nginx/ssl/orion.key;
   ...
   ...
   location / {
      #root   orion:1026;   #/var/www/yourdomain.com;
       #index  index.php index.html index.htm;
       proxy_set_header        Host $host;
       proxy_set_header        X-Real-IP $remote_addr;
       proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
       proxy_set_header        X-Forwarded-Proto $scheme;

       # Fix the “It appears that your reverse proxy set up is broken" error.
       proxy_pass          http://orion:1026;
       proxy_read_timeout  90;
       proxy_redirect      http://orion:1026 https://orion;
   }
}

我做了一个关于FIWARE Orion、Wilma和Keyrock集成的简单教程:https://www.slideshare.net/daltoncezane/integrating-fiware-orion-keyrock-and-wilma

我希望这个回答可以帮助到其他人。

以下演示文稿将逐步向您展示如何创建基于 FIWARE 的物联网平台并使用 PEP 代理、Keystone 和 Keypass 来保护它。

https://docs.google.com/presentation/d/18LaWZSK4h2wncPF6hNAwK5MToLvJesR3XLrzsqrsmrw/edit?usp=sharing

希望对您有所帮助

谢谢