Cumulocity 微服务部署:访问被拒绝
Cumulocity microservice deployment: access is denied
我的目标(背景信息)
我想在 cumulocity 上开发一个 java 微服务。它应该能够执行以下操作:
我将按如下方式将“112233”发送到微服务:
https://myTenant.cumulocity.com/service/my-application-name/decode?data=112233
然后,微服务应将数据拆分为“11”用于第一次测量,“22”用于第二次测量等。这些测量值将 POSTed 为 cumulocity。
我的问题
我现在坚持让 Hello, microservice tutorial 工作。我无法将微服务(zip 文件)部署到 cumulocity。
"error":"security/Forbidden","info":"https://www.cumulocity.com/guides/reference-guide/#error_reporting","message":"Access is denied"}
(我是管理员用户。)
我还尝试通过网站上传 zip 文件,这创建了一个 HOSTED
应用程序而不是 MICROSERVICE
。通过 POST 请求将我的 zip 上传到 HOSTED
应用程序实际上有效(我显然不需要)。
我怀疑我收到 "access denied" 错误,因为 cumulocity 认为我将 HOSTED
应用程序上传到 MICROSERVICE
。
到目前为止我做了什么
代码端
我从 cumulocity bitbucket development b运行ch 下载了 hello-world-microservice example。 (此代码在默认 b运行ch 上不可用)。
我将 cumulocity 版本更改为 9.3.0
,似乎只有这个版本存在。
HelloWorldMain.java未经编辑
这是我的 cumulocity.json 清单文件:(角色没有区别)
{
"apiVersion":"1",
"type":"MICROSERVICE",
"version":"@project.version@",
"availability":"PRIVATE",
"provider":{
"name":"Cumulocity GmbH"
},
"isolation":"MULTI_TENANT",
"requiredRoles":[
"ROLE_APPLICATION_MANAGEMENT_ADMIN",
"ROLE_MEASUREMENT_ADMIN",
"ROLE_INVENTORY_ADMIN"
],
"roles":[
"ROLE_APPLICATION_MANAGEMENT_ADMIN",
"ROLE_MEASUREMENT_ADMIN",
"ROLE_INVENTORY_ADMIN"
],
"livenessProbe":{
"httpGet":{
"path":"/health",
"port":80
},
"initialDelaySeconds":15,
"periodSeconds":10
},
"readinessProbe":{
"httpGet":{
"path":"/health",
"port":80
}
}
}
这是我的application.properties文件
application.name=my-application-name
server.port=80
C8Y.baseURL=https://myTenant.cumulocity.com
C8Y.bootstrap.tenant=myTenant
C8Y.bootstrap.user=servicebootstrap_my-application-name
C8Y.bootstrap.password={SECRET_BOOTSTRAP_PASSW}
C8Y.user={MY_USERNAME}
C8Y.password={SECRET_PASSW}
C8Y.bootstrap.register=true
C8Y.microservice.isolation=MULTI_TENANT
C8Y.bootstrap.initialDelay=10000
Cumulocity 侧
我成功创建了一个微服务应用程序,
获取 https://myTenant.cumulocity.com/application/applications/5886 returns:
{
"availability":"PRIVATE",
"id":"5886",
"key":"my-application-key",
"manifest":{
"imports":[
],
"noAppSwitcher":true
},
"name":"my-application-name",
"owner":{
"self":"https://myTenant.cumulocity.com/tenant/tenants/myTenant",
"tenant":{
"id":"myTenant"
}
},
"requiredRoles":[
"ROLE_APPLICATION_MANAGEMENT_ADMIN",
"ROLE_MEASUREMENT_ADMIN",
"ROLE_INVENTORY_ADMIN"
],
"roles":[
"ROLE_APPLICATION_MANAGEMENT_ADMIN",
"ROLE_MEASUREMENT_ADMIN",
"ROLE_INVENTORY_ADMIN"
],
"self":"https://myTenant.cumulocity.com/application/applications/5886",
"type":"MICROSERVICE"
}
我也成功订阅了这个应用程序。
当我尝试将 zip 文件上传到 cumulocity 时,出现此错误:
"error":"security/Forbidden","info":"https://www.cumulocity.com/guides/reference-guide/#error_reporting","message":"Access is denied"}
(上传到 HOSTED
类型的应用程序工作正常,但我不想要那样。)
note: I also tried to use the microservice deploy script, this gave the same result as doing everything manually.
尝试在本地运行它
因为我无法让它在 cumulocity 平台上运行,我尝试通过 docker 在本地 运行 它。我用这个命令 运行 它:
docker run -e "C8Y_MICROSERVICE_ISOLATION=MULTI_TENANT" 10aa0b73ddb3
note: I had to add the "C8Y_MICROSERVICE_ISOLATION=MULTI_TENANT" environment variable. if I didn't add this, I'd get credential/permission issues. This seems weird to me, since all other info is read from the application.properties file except for this one.
在本地 docker 上 运行 宁此图像时我没有错误。
根据Hello, microservice tutorial,我应该可以要求curl -H "Authorization: {AUTHORIZATION}" https://myTenant.cumulocity.com/service/my-application-name/hello?who=me
这个returns:
{"error":"microservice/Not Found","info":"https://www.cumulocity.com/guides/reference-guide/#error_reporting","message":"Microservice my-application-name not found."}
回到问题
有没有其他人在 cumulocity 上设置微服务有困难?
有什么我完全监督的吗?
微服务托管需要分配给您的租户,否则它将无法工作,在这种情况下 API 将 return 被禁止。因此,您的用户可能没有问题,但您的租户没有激活该功能。
我的目标(背景信息)
我想在 cumulocity 上开发一个 java 微服务。它应该能够执行以下操作:
我将按如下方式将“112233”发送到微服务:
https://myTenant.cumulocity.com/service/my-application-name/decode?data=112233
然后,微服务应将数据拆分为“11”用于第一次测量,“22”用于第二次测量等。这些测量值将 POSTed 为 cumulocity。
我的问题
我现在坚持让 Hello, microservice tutorial 工作。我无法将微服务(zip 文件)部署到 cumulocity。
"error":"security/Forbidden","info":"https://www.cumulocity.com/guides/reference-guide/#error_reporting","message":"Access is denied"}
(我是管理员用户。)
我还尝试通过网站上传 zip 文件,这创建了一个 HOSTED
应用程序而不是 MICROSERVICE
。通过 POST 请求将我的 zip 上传到 HOSTED
应用程序实际上有效(我显然不需要)。
我怀疑我收到 "access denied" 错误,因为 cumulocity 认为我将 HOSTED
应用程序上传到 MICROSERVICE
。
到目前为止我做了什么
代码端
我从 cumulocity bitbucket development b运行ch 下载了 hello-world-microservice example。 (此代码在默认 b运行ch 上不可用)。
我将 cumulocity 版本更改为 9.3.0
,似乎只有这个版本存在。
HelloWorldMain.java未经编辑
这是我的 cumulocity.json 清单文件:(角色没有区别)
{
"apiVersion":"1",
"type":"MICROSERVICE",
"version":"@project.version@",
"availability":"PRIVATE",
"provider":{
"name":"Cumulocity GmbH"
},
"isolation":"MULTI_TENANT",
"requiredRoles":[
"ROLE_APPLICATION_MANAGEMENT_ADMIN",
"ROLE_MEASUREMENT_ADMIN",
"ROLE_INVENTORY_ADMIN"
],
"roles":[
"ROLE_APPLICATION_MANAGEMENT_ADMIN",
"ROLE_MEASUREMENT_ADMIN",
"ROLE_INVENTORY_ADMIN"
],
"livenessProbe":{
"httpGet":{
"path":"/health",
"port":80
},
"initialDelaySeconds":15,
"periodSeconds":10
},
"readinessProbe":{
"httpGet":{
"path":"/health",
"port":80
}
}
}
这是我的application.properties文件
application.name=my-application-name
server.port=80
C8Y.baseURL=https://myTenant.cumulocity.com
C8Y.bootstrap.tenant=myTenant
C8Y.bootstrap.user=servicebootstrap_my-application-name
C8Y.bootstrap.password={SECRET_BOOTSTRAP_PASSW}
C8Y.user={MY_USERNAME}
C8Y.password={SECRET_PASSW}
C8Y.bootstrap.register=true
C8Y.microservice.isolation=MULTI_TENANT
C8Y.bootstrap.initialDelay=10000
Cumulocity 侧
我成功创建了一个微服务应用程序,
获取 https://myTenant.cumulocity.com/application/applications/5886 returns:
{
"availability":"PRIVATE",
"id":"5886",
"key":"my-application-key",
"manifest":{
"imports":[
],
"noAppSwitcher":true
},
"name":"my-application-name",
"owner":{
"self":"https://myTenant.cumulocity.com/tenant/tenants/myTenant",
"tenant":{
"id":"myTenant"
}
},
"requiredRoles":[
"ROLE_APPLICATION_MANAGEMENT_ADMIN",
"ROLE_MEASUREMENT_ADMIN",
"ROLE_INVENTORY_ADMIN"
],
"roles":[
"ROLE_APPLICATION_MANAGEMENT_ADMIN",
"ROLE_MEASUREMENT_ADMIN",
"ROLE_INVENTORY_ADMIN"
],
"self":"https://myTenant.cumulocity.com/application/applications/5886",
"type":"MICROSERVICE"
}
我也成功订阅了这个应用程序。
当我尝试将 zip 文件上传到 cumulocity 时,出现此错误:
"error":"security/Forbidden","info":"https://www.cumulocity.com/guides/reference-guide/#error_reporting","message":"Access is denied"}
(上传到 HOSTED
类型的应用程序工作正常,但我不想要那样。)
note: I also tried to use the microservice deploy script, this gave the same result as doing everything manually.
尝试在本地运行它
因为我无法让它在 cumulocity 平台上运行,我尝试通过 docker 在本地 运行 它。我用这个命令 运行 它:
docker run -e "C8Y_MICROSERVICE_ISOLATION=MULTI_TENANT" 10aa0b73ddb3
note: I had to add the "C8Y_MICROSERVICE_ISOLATION=MULTI_TENANT" environment variable. if I didn't add this, I'd get credential/permission issues. This seems weird to me, since all other info is read from the application.properties file except for this one.
在本地 docker 上 运行 宁此图像时我没有错误。
根据Hello, microservice tutorial,我应该可以要求curl -H "Authorization: {AUTHORIZATION}" https://myTenant.cumulocity.com/service/my-application-name/hello?who=me
这个returns:
{"error":"microservice/Not Found","info":"https://www.cumulocity.com/guides/reference-guide/#error_reporting","message":"Microservice my-application-name not found."}
回到问题
有没有其他人在 cumulocity 上设置微服务有困难?
有什么我完全监督的吗?
微服务托管需要分配给您的租户,否则它将无法工作,在这种情况下 API 将 return 被禁止。因此,您的用户可能没有问题,但您的租户没有激活该功能。