Require a bearer token
Reject any request without an Authorization bearer header, with an inline Rego policy compiled when the resource is applied.
Configuration
apiVersion: kuma.io/v1alpha1
kind: MeshOPA
metadata:
name: require-token
namespace: kong-mesh-demo
labels:
kuma.io/mesh: default
spec:
targetRef:
kind: Dataplane
labels:
app: backend
default:
appendPolicies:
- rego:
type: InsecureInline
insecureInline:
value: |
package envoy.authz
import input.attributes.request.http as http_request
default allow = false
allow {
startswith(http_request.headers.authorization, "Bearer ")
}Copied!
type: MeshOPA
name: require-token
mesh: default
spec:
targetRef:
kind: Dataplane
labels:
app: backend
default:
appendPolicies:
- rego:
type: InsecureInline
insecureInline:
value: |
package envoy.authz
import input.attributes.request.http as http_request
default allow = false
allow {
startswith(http_request.headers.authorization, "Bearer ")
}Copied!
Adjust konnect_mesh_control_plane.my_meshcontrolplane.id and konnect_mesh.my_mesh.name according to your current configuration.
resource "konnect_mesh_opa" "require_token" {
provider = konnect-beta
type = "MeshOPA"
name = "require-token"
spec = {
target_ref = {
kind = "Dataplane"
labels = {
app = "backend"
}
}
default = {
append_policies = [
{
rego = {
type = "InsecureInline"
insecure_inline = {
value = <<-EOT
package envoy.authz
import input.attributes.request.http as http_request
default allow = false
allow {
startswith(http_request.headers.authorization, "Bearer ")
}
EOT
}
}
}
]
}
}
labels = {
"kuma.io/mesh" = konnect_mesh.my_mesh.name
}
cp_id = konnect_mesh_control_plane.my_meshcontrolplane.id
mesh = konnect_mesh.my_mesh.name
}
Copied!