2

我正在尝试如下设置我的 OPA。

  1. OPA 在 Kubernetes 中作为 sidecar 安装
  2. 政策将作为捆绑包进行管理
  3. OPA 策略将从单独的服务中存储和提供 [捆绑]
  4. 需要使用 config-file 配置 OPA 以从外部服务获取策略
  5. config-file 将作为配置映射存储在 kubernetes 中。
  6. 该配置映射需要在 --config-file 中使用

我在 Kubernetes 中的配置图

kubectl create configmap policyconfig --from-file=./config/config.yaml

我的边车 OPA

 - name: opa
          image: openpolicyagent/opa:latest
          args:
            - "run"
            - "--server"
            - "--addr=0.0.0.0:443"
            - "--addr=0.0.0.0:8181"
            - "--config-file=policyconfig"
      volumes:
        - name: policyconfig
          configMap:
            name: policyconfig

让我知道是否可以以这种方式实施

4

3 回答 3

3

您可以使用kube-mgmt作为 sidecar 在 Kubernetes 上管理 OPA。

kube-mgmt 自动发现存储在 Kubernetes 的 ConfigMaps 中的策略,并将它们加载到 OPA 中。kube-mgmt 假设 ConfigMap 包含策略,如果 ConfigMap 是:

  1. 在 --policies 选项中列出的命名空间中创建。如果您指定 --policies=*,那么 kube-mgmt 将在所有命名空间中查找策略。
  2. 标有 openpolicyagent.org/policy=rego

奥帕

https://medium.com/capital-one-tech/policy-enabled-kubernetes-with-open-policy-agent-3b612b3f0203

更新:

根据您当前的设置和要求,您需要添加一个volumeMounts以使其工作

 - name: opa
          image: openpolicyagent/opa:latest
          args:
            - "run"
            - "--server"
            - "--addr=0.0.0.0:443"
            - "--addr=0.0.0.0:8181"
            - "--config-file=policyconfig"
          volumeMounts:
          - name: policyconfig
            mountPath: /config
      volumes:
        - name: policyconfig
          configMap:
            name: policyconfig
于 2020-04-30T08:55:20.920 回答
2

或者,您可以使用Gatekeeper。除了kube-mgmt (Gatekeeper 1.0) 之外,它还提供了 (per this ):

  • 可扩展的参数化策略库
  • 用于实例化策略库的原生 Kubernetes CRD(又名“约束”)
  • 用于扩展策略库的原生 Kubernetes CRD(又名“约束模板”)
  • 审计功能

另一个最近的工具是MagTape

于 2020-04-30T18:59:11.733 回答
0

似乎我也在尝试实现相同的目标 - 通过 Envoy 到 OPA 使用 bundle API。

我的 bundle-API 配置 –</p>

  apiVersion: v1
  kind: ConfigMap
  metadata:
    name: policyconfig
  data:
    config.yaml: |
      services:
        - name: controller
          url: https://opa-bundle-bucket1.s3-us-west-1.amazonaws.com/bundles/authz.gz
      bundles:
        envoy/authz:
          service: controller
          resource: authz.gz
          polling:
            min_delay_seconds: 10
            max_delay_seconds: 20
      plugins:
        envoy_ext_authz_grpc:
          addr: :9191
          path: envoy/authz/allow
          dry-run: false
          enable-reflection: false

我在 kubernetes 中的配置映射 - kubectl create configmap policyconfig --from-file=./config/config.yaml

我的边车 OPA -

  - name: opa
  # the latest released image of OPA-Envoy.
  image: openpolicyagent/opa:latest-envoy
  securityContext:
    runAsUser: 1111
  volumeMounts:
  - readOnly: true
    mountPath: /config
    name: policyconfig
  args:
  - "run"
  - "--server"
  - "--addr=localhost:8181"
  - "--diagnostic-addr=0.0.0.0:8282"
  - "--set=plugins.envoy_ext_authz_grpc.addr=:9191"
  - "--set=plugins.envoy_ext_authz_grpc.query=data.envoy.authz.allow"
  - "--set=decision_logs.console=true"
  - "--ignore=.*"
  - "--config-file=/config/config.yaml"
    volumes:
    - name: policyconfig
    configMap:
      name: policyconfig

预期行为:- Envoy 将调用 OPA,并且 OPA 将请求发送到 bundle-server 以获取最新的策略和数据。

实际行为:- Envoy 正在调用 OPA,但 OPA 策略无法下载。

Let me know what I am doing wrong here.
于 2021-02-23T23:16:03.847 回答