Policy authoring with Kong Gateway amounts to describing which HTTP APIs should be allowed or denied. Those policies are enforced by Kong Gateway, and a rejected API request is never seen by the service.
When you add the Kong Gateway system, ingress policy is automatically installed. In the Styra DAS, click ingress folders from your Kong Gateway system to see the policies.
- Ingress: Policy that either allows or denies incoming traffic.
Write Ingress Policy
Use Open Policy Agent's policy language called Rego to author policies.
For an introduction to Rego, Styra recommends you to read the following resources:
When writing Rego policies, you need to know the format of the JSON that is provided to each of your policies as input. The following shows a sample input provided by Kong Gateway for ingress policy. This sample includes HTTP method, requested path, source address and headers with destination address.
When writing policies, the allow or deny rules are written to describe the conditions under which a request is allowed or denied. By default, requests are all allowed, so you must write policy to deny them.
For example, if you want to allow all
GET requests and deny all
POST requests to the root path, then write the following
# allow GET requests to the root path
input.method == "GET"
input.path == "/"
# deny POST requests to the root path
input.method == "POST"
input.path == "/"
The decision mapping for Kong Gateway systems relies on the presence of well-known field to correctly parse the results. The decision mapper expects allowed field in the result.
"allowed": false // boolean value to determine if decision was Allowed or Denied
// an absence of this value will mark the decision as Unknown