In your organization, the mesh operator may want to set a policy for subset of proxies in the mesh.
At the same time, service owners may want to exercise additional policies.
For example, the mesh operator may want to enable JWT token validation for all proxies in the mesh
apiVersion: kuma.io/v1alpha1
kind: MeshOPA
metadata:
name: mopa-mesh-operator
namespace: kong-mesh-system
labels:
kuma.io/mesh: default
spec:
targetRef:
kind: Mesh
default:
appendPolicies:
- rego:
inlineString: |
package operator
import input.attributes.request.http as http_request
default allow = false
token = {"valid": valid, "payload": payload} {
[_, encoded] := split(http_request.headers.authorization, " ")
[valid, _, payload] := io.jwt.decode_verify(encoded, {"secret": "secret"})
}
allow {
is_token_valid
action_allowed
}
is_token_valid {
token.valid
now := time.now_ns() / 1000000000
token.payload.nbf <= now
now < token.payload.exp
}
action_allowed {
http_request.method == "GET"
token.payload.role == "admin"
}
Service owner wants to block all requests on path /blocked
:
apiVersion: kuma.io/v1alpha1
kind: MeshOPA
metadata:
name: mopa-service-owner
namespace: kong-mesh-system
labels:
kuma.io/mesh: default
spec:
targetRef:
kind: MeshService
name: test-server_kuma-demo_svc_80
default:
appendPolicies:
- rego:
inlineString: |
package serviceowner
default allow = true
deny {
input.parsed_path == ["blocked"]
}
appendPolicies
is a list you can append, therefore in the case of the data plane proxy test-server_kuma-demo_svc_80
service, both policies will be applied.
Kong Mesh will autogenerate an additional OPA decision policy:
package implicitkmesh
import data.operator
import data.serviceowner
allow {
data.operator.allow
not data.operator.deny
data.serviceowner.allow
not data.serviceowner.deny
}
It also configures the OPA agent decision path (plugins.envoy_ext_authz_grpc.path
) to implicitkmesh/allow
.
You can also add a rego policy which is not part of the decision.
Set a appendPolicies[*].ignoreDecision
to true so the rego policy won’t be added to autogenerated decision policy.
This way, the mesh operator can expose utility functions to service owner.