Kubernetes -用作窗格中主应用程序代理的容器之一

lh80um4z  于 2022-12-11  发布在  Kubernetes
关注(0)|答案(1)|浏览(107)

我有两个应用程序-一个是基于java的REST应用程序(“A”),另一个是基于go lang的rego策略框架(“B”)。
我已经在K8中将这两个应用程序作为容器运行在一个单独的pod中。但是,我不确定如何让传入的HTTP请求首先命中“B”rego策略框架,并根据策略决策将请求转发到“A”。有没有办法实现这一点?

dgtucam1

dgtucam11#

I am not sure how can I get the incoming HTTP requests to first hit the “B” rego policy framework
A "rego policy framework", e.g. OpenPolicyAgent are typically used as an assisting container.
In this setup, your application receives the request, then ask the "rego policy framework" container, "is this request allowed?", then your application continue to process the request.
See e.g OpenPolicyAgent example - HTTP API Authorization with this part, to ask if the request is allowed.

# ask OPA for a policy decision
# (in reality OPA URL would be constructed from environment)
rsp = requests.post("http://127.0.0.1:8181/v1/data/httpapi/authz", json=input_dict)
if rsp.json()["allow"]:
  # HTTP API allowed
else:
  # HTTP API denied

相关问题