This repository contains the code for sample application created for explaining the use of OPA for microservices authorization.
The example can be deployed on minikube by using the pre-compiled images on docker hub and the deployment\cpq.yaml file.
You should have minikube and kubectl installed on your machine before running this example.
-
Start the minikube cluster using
minikube start -
Clone the repo at a convenient path <REPO_PATH>
-
Swith the directory to the cloned repo
cd <REPO_PATH>/opa-ms-example -
Deploy the application using
kubectl apply -f deployment/cpq.yaml -
Check if all the pods are up and running
kubectl get pods
NAME READY STATUS RESTARTS AGE
authorization-785794bff5-vxqgj 2/2 Running 0 56m
customer-5fb899fb9d-986m7 1/1 Running 0 56m
offer-654cb448b8-sk8q4 1/1 Running 0 56m
ui-6f87bb9f4-94zpt 1/1 Running 0 56m
-
Get the URL for accessing application using
minikube service ui --url. The sample output can be likehttp://192.168.64.3:32306 -
Open a browser and past the URL above to navigate to the application.
-
Select a role from the dropdown on the page to start experimenting. If you don't select a role, the required
Authorizationheader will not be set causing intended failures. -
At first, you will not see any offers listed, and if you try
Create Offer, the operation will fail. This is because the authorization is not set yet. -
To add the authorization, first set the SERVICE_URL using
export SERVICE_URL=`minikube service ui --url`And then, update the policy using
curl -X PUT --data-binary @policies/httpapi.authz.rego \
$SERVICE_URL/authorization/v1/policies/httpapi/authz