Skip to main content

Quickstart Guide

1. Install jsPolicy#

Install jsPolicy to your Kubernetes cluster via Helm v3:

helm install jspolicy jspolicy -n jspolicy --create-namespace --repo https://charts.loft.sh

2. Create a Policy#

Create the file policy.yaml:

# policy.yaml
apiVersion: policy.jspolicy.com/v1beta1
kind: JsPolicy
metadata:
name: "deny-default-namespace.company.tld"
spec:
operations: ["CREATE"]
resources: ["*"]
scope: Namespaced
javascript: |
if (request.namespace === "default") {
deny("Creation of resources within the default namespace is not allowed!");
}
Policy Code

Note that for the sake of simplicity, the above example places the policy logic directly inside the YAML definition of this JsPolicy resource. To take full advantage of JavaScript or TypeScript development and testing tooling, you may want to load the policy code directly from a JavaScript or TypeScript file. See Writing Policies for details.

3. Apply The Policy#

Apply the policy in your cluster:

kubectl apply -f policy.yaml

4. See Policy In Action#

kubectl create deployment nginx-deployment -n default --image=nginx