问题描述
我想采用 FIWARE 作为我们物联网平台的一部分。 除了 Orion Context broker,我想使用 keyrock / wilma / AuthzForce 进行身份验证和授权。
通过阅读“逐步”和其他文档,我了解到物联网平台上有多个用户,可以单独控制对资源的访问。
我想显示用户登录我们的 IoT 应用程序后可以访问的所有资源(相当于传感器)的列表。 但是,我参考了keyrock和AuthzForce API,但我认为没有这样的API。 FIWARE 中不是有获取用户-资源(传感器)关系列表的 API 吗?
解决方法
FIWARE 并未与单个安全堆栈紧密绑定。 “逐步”tutorials 使用 Keyrock 和 Wilma 作为说明性示例,但您也可以轻松使用替代身份管理器,例如 Keycloak 或 Keystone - IDM 的作用很重要。
鉴于 FIWARE Catalogue 中的每个组件都是一个微服务,它们旨在做好一项工作而不是混合关注点,因此您需要进行以下设置 - 在 IDM 中保留角色和权限,添加静态向您的实体提供数据,以描述实体是什么以及谁“拥有”它们。
基本认证
对于每个登录用户都能够查看您的传感器的基本身份验证,这很容易:
- IDM 拥有用户、角色和权限。
- 设备由 IoT 代理配置 - 这会在上下文代理中创建实体。使用静态属性,例如
sensor
以便于查询(Device Model 建议类别:
"static_attributes": [
{"name": "category","type":"Text","value": ["sensor"]}
]
这将使客户能够在 /entities?q=category=="sensor"&type=Device
上进行查询以获取传感器类别中的所有设备。
如果所有登录用户都可以访问所有传感器,您只需在上下文代理前面放置一个 PEP 代理,该代理拒绝所有未经身份验证的请求(即没有承载令牌的请求)并通过这些请求已登录。
基本授权
对于登录用户能够查看他们拥有的传感器的基本授权,它有点复杂,您需要设置权限以允许角色访问:/entities?q=category=="sensor"&type=Device&owner==XXX
同时拒绝更广泛的查询,例如 /entities?type=device
- 然后您可以在配置时向设备添加额外的静态数据:
"static_attributes": [
{"name": "category","value": ["sensor"]}
{"name": "owner","value": "XXX"}
]
高级授权
对于高级授权,它会更加复杂,您的 Authzforce PDP 需要保留如下规则:
<Rule RuleId="xxxxx-xxxx-0000-0000-000000000000" Effect="Permit">
<Description>Query Devices</Description>
<Target>
<AnyOf>
<AllOf>
<Match MatchId="urn:oasis:names:tc:xacml:3.0:function:string-equals">
<AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">/entities?q=category=="sensor"&type=Device&owner==XXX</AttributeValue>
<AttributeDesignator Category="urn:oasis:names:tc:xacml:3.0:attribute-category:resource" AttributeId="urn:thales:xacml:2.0:resource:sub-resource-id" DataType="http://www.w3.org/2001/XMLSchema#string" MustBePresent="true" />
</Match>
</AllOf>
</AnyOf>
<AnyOf>
<AllOf>
<Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal">
<AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">GET</AttributeValue>
<AttributeDesignator Category="urn:oasis:names:tc:xacml:3.0:attribute-category:action" AttributeId="urn:oasis:names:tc:xacml:1.0:action:action-id" DataType="http://www.w3.org/2001/XMLSchema#string" MustBePresent="true" />
</Match>
</AllOf>
</AnyOf>
</Target>
<Condition>
<Apply FunctionId="urn:oasis:names:tc:xacml:3.0:function:any-of">
<Function FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-equal" />
<AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">security-role-0000-0000-000000000000</AttributeValue>
<AttributeDesignator Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject" AttributeId="urn:oasis:names:tc:xacml:2.0:subject:role" DataType="http://www.w3.org/2001/XMLSchema#string" MustBePresent="false" />
</Apply>
</Condition>
</Rule>
角色 security-role-0000-0000-000000000000
的用户可以如上所述向设备发出 GET 请求。
使用 XACML 可以使用 urn:oasis:names:tc:xacml:1.0:function:string-regexp-match
或 urn:oasis:names:tc:xacml:1.0:function:string-regexp-match
等函数扩展规则,但您应该寻找 XACML GUI 编辑器,XACML 3.0 spec 对机器来说比机器更容易人类。默认情况下,Wilma PEP 代理为 Authzforce 传递足够的信息来回答上面定义的规则,如果您想向匹配规则添加更多子句,您需要在 PEP 代理中自定义 PEP-PDP comms 以确保附加信息发送到 Authzforce 以允许其裁定请求。