Load external data into OPA: The Good, The Bad, and The Ugly
Tags: opa, authorization, tutorial, authz
Published: 2022-04-04 14:48:28


There are several ways to create a data fetching mechanism for OPA - each of them has its pros and cons. To make sense of these different methods, I've decided to create this guide that will help you figure out which data fetching method would be best for you, with full knowledge of each method’s ‘good, bad, and ugly’ aspects.
</b> 

#TL;DR - 

The methods that we are going to review are:

1. [Including data in JWT tokens](#1)

2. [Overload input for OPA within the query](#2)

3. [Polling for data using Bundles](#3)

4. [Pushing data into OPA using the API](#4)

5. [Pulling data using OPA during Policy Evaluation](#5)

6. [OPAL (Open Policy Administration Layer)](#6)


Before we dive into details, let’s first cover some basics - 


##What is OPA

Authorization is becoming increasingly complicated - applications are getting bigger and require handling more users than ever before, policies are becoming more complex and dependent on multiple factors (Like a client’s location, time of the action, user roles, and relations to resources).
This is where OPA (Open Policy Agent) comes in - OPA is a great open-source tool that allows us to evaluate complicated policies. It’s fast, part of the CNCF (Which means it adheres to CNCF’s guidelines and standards), and is used for handling permissions in some of the largest companies in the world (e.g. Netflix, Pinterest, and others). You can check out an introduction to OPA [here](https://www.permit.io/blog/introduction-to-opa). 
⁠
##How OPA Works with Data

Managing policies with OPA often requires relevant contextual data - Information about the user, the resource they are trying to access, etc. Without this information, OPA will not be able to make the right decisions when it comes to deciding on policies. 
For example - a policy that states “Only paying users can access this feature” requires OPA to have information on:

- Who my users are

- Which one of them is a paying user, and which isn’t

A policy that states “Users in the application can only access their own photos, or those of their children” requires OPA to know:

- Who are the application’s users

- Which user is a parent, which user is a child, and which user relates to who

- Which photo belongs to each user

Having access to this contextual data is thus critical for OPA to be able to make its decisions. 

The bottom-line question is - how can we bring this data into OPA, and which way is the most effective to do so? 

##The data fetching mechanism: Basic requirements
 
Before we dive into the different methods of fetching data for OPA, let’s agree on a couple of basic guidelines for how this data fetching mechanism should work:
It's necessary to be able to handle data about policies on a large scale

Because data can come from many sources, thus getting very complex very quickly, we want this mechanism to be as easily manageable as possible.

The data fetching mechanism needs to be operational in real-time (This is a crucial component that will allow us to avoid a [“New enemy attack”](https://storage.googleapis.com/pub-tools-public-publication-data/pdf/41f08f03da59f5518802898f68730e247e23c331.pdf) - a situation where a user with revoked permission can still access sensitive data because the permissions have not been updated in time between the different parts of the system).

It should be easy to maintain because the need for access control is here to stay and is likely to evolve in the future.

Now that we've established some basic requirements, let’s dive into the various data fetching mechanisms we can utilize to solve our issue in the most efficient way.


Let’s dive in!

</b>
<a name="1"></a>
#1. Including data in JWT tokens:

![Including data in JWT tokens](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ar131kmbns6u3bk7o5pc.png)

[JSON Web Tokens (JWT)](https://tools.ietf.org/html/rfc7519) allow you to securely transmit signed JSON data between software systems and are usually produced during the authentication process. JWTs can be sent to OPA as inputs thus enabling OPA to make decisions about a Policy query.

For example, this is what a [JWT with authorization data looks like](https://jwt.io/#debugger-io?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwicm9sZXMiOlsiYWRtaW4iXSwicmVsYXRlZF9pbWFnZXMiOlsiaW1hZ2UxLnBuZyIsImltYWdlMi5wbmciXSwiaWF0IjoxNTE2MjM5MDIyfQ.Qkur5-lKPBMhZLqgl-BjkZzyjiHVSoq1p1C36vUiuQU):


![JWT Example](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jcuh4sl91hxe76qlm0s2.png)

The first part is the algorithm for the secure signing, and in the middle, we can see the roles and related images for our authorization.

The good:
JWTs are an easy-to-use well-known technology that you probably already utilize in your system (as part of the authentication layer).

The bad:
JWTs have a size limit - not everything can be decoded into a JWT, while it looks OK in the example presented above, if a user [has 1000 files](https://jwt.io/#debugger-io?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwicm9sZXMiOlsiYWRtaW4iXSwicmVsYXRlZF9pbWFnZXMiOlsiaW1hZ2UwLnBuZyIsImltYWdlMS5wbmciLCJpbWFnZTIucG5nIiwiaW1hZ2UzLnBuZyIsImltYWdlNC5wbmciLCJpbWFnZTUucG5nIiwiaW1hZ2U2LnBuZyIsImltYWdlNy5wbmciLCJpbWFnZTgucG5nIiwiaW1hZ2U5LnBuZyIsImltYWdlMTAucG5nIiwiaW1hZ2UxMS5wbmciLCJpbWFnZTEyLnBuZyIsImltYWdlMTMucG5nIiwiaW1hZ2UxNC5wbmciLCJpbWFnZTE1LnBuZyIsImltYWdlMTYucG5nIiwiaW1hZ2UxNy5wbmciLCJpbWFnZTE4LnBuZyIsImltYWdlMTkucG5nIiwiaW1hZ2UyMC5wbmciLCJpbWFnZTIxLnBuZyIsImltYWdlMjIucG5nIiwiaW1hZ2UyMy5wbmciLCJpbWFnZTI0LnBuZyIsImltYWdlMjUucG5nIiwiaW1hZ2UyNi5wbmciLCJpbWFnZTI3LnBuZyIsImltYWdlMjgucG5nIiwiaW1hZ2UyOS5wbmciLCJpbWFnZTMwLnBuZyIsImltYWdlMzEucG5nIiwiaW1hZ2UzMi5wbmciLCJpbWFnZTMzLnBuZyIsImltYWdlMzQucG5nIiwiaW1hZ2UzNS5wbmciLCJpbWFnZTM2LnBuZyIsImltYWdlMzcucG5nIiwiaW1hZ2UzOC5wbmciLCJpbWFnZTM5LnBuZyIsImltYWdlNDAucG5nIiwiaW1hZ2U0MS5wbmciLCJpbWFnZTQyLnBuZyIsImltYWdlNDMucG5nIiwiaW1hZ2U0NC5wbmciLCJpbWFnZTQ1LnBuZyIsImltYWdlNDYucG5nIiwiaW1hZ2U0Ny5wbmciLCJpbWFnZTQ4LnBuZyIsImltYWdlNDkucG5nIiwiaW1hZ2U1MC5wbmciLCJpbWFnZTUxLnBuZyIsImltYWdlNTIucG5nIiwiaW1hZ2U1My5wbmciLCJpbWFnZTU0LnBuZyIsImltYWdlNTUucG5nIiwiaW1hZ2U1Ni5wbmciLCJpbWFnZTU3LnBuZyIsImltYWdlNTgucG5nIiwiaW1hZ2U1OS5wbmciLCJpbWFnZTYwLnBuZyIsImltYWdlNjEucG5nIiwiaW1hZ2U2Mi5wbmciLCJpbWFnZTYzLnBuZyIsImltYWdlNjQucG5nIiwiaW1hZ2U2NS5wbmciLCJpbWFnZTY2LnBuZyIsImltYWdlNjcucG5nIiwiaW1hZ2U2OC5wbmciLCJpbWFnZTY5LnBuZyIsImltYWdlNzAucG5nIiwiaW1hZ2U3MS5wbmciLCJpbWFnZTcyLnBuZyIsImltYWdlNzMucG5nIiwiaW1hZ2U3NC5wbmciLCJpbWFnZTc1LnBuZyIsImltYWdlNzYucG5nIiwiaW1hZ2U3Ny5wbmciLCJpbWFnZTc4LnBuZyIsImltYWdlNzkucG5nIiwiaW1hZ2U4MC5wbmciLCJpbWFnZTgxLnBuZyIsImltYWdlODIucG5nIiwiaW1hZ2U4My5wbmciLCJpbWFnZTg0LnBuZyIsImltYWdlODUucG5nIiwiaW1hZ2U4Ni5wbmciLCJpbWFnZTg3LnBuZyIsImltYWdlODgucG5nIiwiaW1hZ2U4OS5wbmciLCJpbWFnZTkwLnBuZyIsImltYWdlOTEucG5nIiwiaW1hZ2U5Mi5wbmciLCJpbWFnZTkzLnBuZyIsImltYWdlOTQucG5nIiwiaW1hZ2U5NS5wbmciLCJpbWFnZTk2LnBuZyIsImltYWdlOTcucG5nIiwiaW1hZ2U5OC5wbmciLCJpbWFnZTk5LnBuZyIsImltYWdlMTAwLnBuZyIsImltYWdlMTAxLnBuZyIsImltYWdlMTAyLnBuZyIsImltYWdlMTAzLnBuZyIsImltYWdlMTA0LnBuZyIsImltYWdlMTA1LnBuZyIsImltYWdlMTA2LnBuZyIsImltYWdlMTA3LnBuZyIsImltYWdlMTA4LnBuZyIsImltYWdlMTA5LnBuZyIsImltYWdlMTEwLnBuZyIsImltYWdlMTExLnBuZyIsImltYWdlMTEyLnBuZyIsImltYWdlMTEzLnBuZyIsImltYWdlMTE0LnBuZyIsImltYWdlMTE1LnBuZyIsImltYWdlMTE2LnBuZyIsImltYWdlMTE3LnBuZyIsImltYWdlMTE4LnBuZyIsImltYWdlMTE5LnBuZyIsImltYWdlMTIwLnBuZyIsImltYWdlMTIxLnBuZyIsImltYWdlMTIyLnBuZyIsImltYWdlMTIzLnBuZyIsImltYWdlMTI0LnBuZyIsImltYWdlMTI1LnBuZyIsImltYWdlMTI2LnBuZyIsImltYWdlMTI3LnBuZyIsImltYWdlMTI4LnBuZyIsImltYWdlMTI5LnBuZyIsImltYWdlMTMwLnBuZyIsImltYWdlMTMxLnBuZyIsImltYWdlMTMyLnBuZyIsImltYWdlMTMzLnBuZyIsImltYWdlMTM0LnBuZyIsImltYWdlMTM1LnBuZyIsImltYWdlMTM2LnBuZyIsImltYWdlMTM3LnBuZyIsImltYWdlMTM4LnBuZyIsImltYWdlMTM5LnBuZyIsImltYWdlMTQwLnBuZyIsImltYWdlMTQxLnBuZyIsImltYWdlMTQyLnBuZyIsImltYWdlMTQzLnBuZyIsImltYWdlMTQ0LnBuZyIsImltYWdlMTQ1LnBuZyIsImltYWdlMTQ2LnBuZyIsImltYWdlMTQ3LnBuZyIsImltYWdlMTQ4LnBuZyIsImltYWdlMTQ5LnBuZyIsImltYWdlMTUwLnBuZyIsImltYWdlMTUxLnBuZyIsImltYWdlMTUyLnBuZyIsImltYWdlMTUzLnBuZyIsImltYWdlMTU0LnBuZyIsImltYWdlMTU1LnBuZyIsImltYWdlMTU2LnBuZyIsImltYWdlMTU3LnBuZyIsImltYWdlMTU4LnBuZyIsImltYWdlMTU5LnBuZyIsImltYWdlMTYwLnBuZyIsImltYWdlMTYxLnBuZyIsImltYWdlMTYyLnBuZyIsImltYWdlMTYzLnBuZyIsImltYWdlMTY0LnBuZyIsImltYWdlMTY1LnBuZyIsImltYWdlMTY2LnBuZyIsImltYWdlMTY3LnBuZyIsImltYWdlMTY4LnBuZyIsImltYWdlMTY5LnBuZyIsImltYWdlMTcwLnBuZyIsImltYWdlMTcxLnBuZyIsImltYWdlMTcyLnBuZyIsImltYWdlMTczLnBuZyIsImltYWdlMTc0LnBuZyIsImltYWdlMTc1LnBuZyIsImltYWdlMTc2LnBuZyIsImltYWdlMTc3LnBuZyIsImltYWdlMTc4LnBuZyIsImltYWdlMTc5LnBuZyIsImltYWdlMTgwLnBuZyIsImltYWdlMTgxLnBuZyIsImltYWdlMTgyLnBuZyIsImltYWdlMTgzLnBuZyIsImltYWdlMTg0LnBuZyIsImltYWdlMTg1LnBuZyIsImltYWdlMTg2LnBuZyIsImltYWdlMTg3LnBuZyIsImltYWdlMTg4LnBuZyIsImltYWdlMTg5LnBuZyIsImltYWdlMTkwLnBuZyIsImltYWdlMTkxLnBuZyIsImltYWdlMTkyLnBuZyIsImltYWdlMTkzLnBuZyIsImltYWdlMTk0LnBuZyIsImltYWdlMTk1LnBuZyIsImltYWdlMTk2LnBuZyIsImltYWdlMTk3LnBuZyIsImltYWdlMTk4LnBuZyIsImltYWdlMTk5LnBuZyIsImltYWdlMjAwLnBuZyIsImltYWdlMjAxLnBuZyIsImltYWdlMjAyLnBuZyIsImltYWdlMjAzLnBuZyIsImltYWdlMjA0LnBuZyIsImltYWdlMjA1LnBuZyIsImltYWdlMjA2LnBuZyIsImltYWdlMjA3LnBuZyIsImltYWdlMjA4LnBuZyIsImltYWdlMjA5LnBuZyIsImltYWdlMjEwLnBuZyIsImltYWdlMjExLnBuZyIsImltYWdlMjEyLnBuZyIsImltYWdlMjEzLnBuZyIsImltYWdlMjE0LnBuZyIsImltYWdlMjE1LnBuZyIsImltYWdlMjE2LnBuZyIsImltYWdlMjE3LnBuZyIsImltYWdlMjE4LnBuZyIsImltYWdlMjE5LnBuZyIsImltYWdlMjIwLnBuZyIsImltYWdlMjIxLnBuZyIsImltYWdlMjIyLnBuZyIsImltYWdlMjIzLnBuZyIsImltYWdlMjI0LnBuZyIsImltYWdlMjI1LnBuZyIsImltYWdlMjI2LnBuZyIsImltYWdlMjI3LnBuZyIsImltYWdlMjI4LnBuZyIsImltYWdlMjI5LnBuZyIsImltYWdlMjMwLnBuZyIsImltYWdlMjMxLnBuZyIsImltYWdlMjMyLnBuZyIsImltYWdlMjMzLnBuZyIsImltYWdlMjM0LnBuZyIsImltYWdlMjM1LnBuZyIsImltYWdlMjM2LnBuZyIsImltYWdlMjM3LnBuZyIsImltYWdlMjM4LnBuZyIsImltYWdlMjM5LnBuZyIsImltYWdlMjQwLnBuZyIsImltYWdlMjQxLnBuZyIsImltYWdlMjQyLnBuZyIsImltYWdlMjQzLnBuZyIsImltYWdlMjQ0LnBuZyIsImltYWdlMjQ1LnBuZyIsImltYWdlMjQ2LnBuZyIsImltYWdlMjQ3LnBuZyIsImltYWdlMjQ4LnBuZyIsImltYWdlMjQ5LnBuZyIsImltYWdlMjUwLnBuZyIsImltYWdlMjUxLnBuZyIsImltYWdlMjUyLnBuZyIsImltYWdlMjUzLnBuZyIsImltYWdlMjU0LnBuZyIsImltYWdlMjU1LnBuZyIsImltYWdlMjU2LnBuZyIsImltYWdlMjU3LnBuZyIsImltYWdlMjU4LnBuZyIsImltYWdlMjU5LnBuZyIsImltYWdlMjYwLnBuZyIsImltYWdlMjYxLnBuZyIsImltYWdlMjYyLnBuZyIsImltYWdlMjYzLnBuZyIsImltYWdlMjY0LnBuZyIsImltYWdlMjY1LnBuZyIsImltYWdlMjY2LnBuZyIsImltYWdlMjY3LnBuZyIsImltYWdlMjY4LnBuZyIsImltYWdlMjY5LnBuZyIsImltYWdlMjcwLnBuZyIsImltYWdlMjcxLnBuZyIsImltYWdlMjcyLnBuZyIsImltYWdlMjczLnBuZyIsImltYWdlMjc0LnBuZyIsImltYWdlMjc1LnBuZyIsImltYWdlMjc2LnBuZyIsImltYWdlMjc3LnBuZyIsImltYWdlMjc4LnBuZyIsImltYWdlMjc5LnBuZyIsImltYWdlMjgwLnBuZyIsImltYWdlMjgxLnBuZyIsImltYWdlMjgyLnBuZyIsImltYWdlMjgzLnBuZyIsImltYWdlMjg0LnBuZyIsImltYWdlMjg1LnBuZyIsImltYWdlMjg2LnBuZyIsImltYWdlMjg3LnBuZyIsImltYWdlMjg4LnBuZyIsImltYWdlMjg5LnBuZyIsImltYWdlMjkwLnBuZyIsImltYWdlMjkxLnBuZyIsImltYWdlMjkyLnBuZyIsImltYWdlMjkzLnBuZyIsImltYWdlMjk0LnBuZyIsImltYWdlMjk1LnBuZyIsImltYWdlMjk2LnBuZyIsImltYWdlMjk3LnBuZyIsImltYWdlMjk4LnBuZyIsImltYWdlMjk5LnBuZyIsImltYWdlMzAwLnBuZyIsImltYWdlMzAxLnBuZyIsImltYWdlMzAyLnBuZyIsImltYWdlMzAzLnBuZyIsImltYWdlMzA0LnBuZyIsImltYWdlMzA1LnBuZyIsImltYWdlMzA2LnBuZyIsImltYWdlMzA3LnBuZyIsImltYWdlMzA4LnBuZyIsImltYWdlMzA5LnBuZyIsImltYWdlMzEwLnBuZyIsImltYWdlMzExLnBuZyIsImltYWdlMzEyLnBuZyIsImltYWdlMzEzLnBuZyIsImltYWdlMzE0LnBuZyIsImltYWdlMzE1LnBuZyIsImltYWdlMzE2LnBuZyIsImltYWdlMzE3LnBuZyIsImltYWdlMzE4LnBuZyIsImltYWdlMzE5LnBuZyIsImltYWdlMzIwLnBuZyIsImltYWdlMzIxLnBuZyIsImltYWdlMzIyLnBuZyIsImltYWdlMzIzLnBuZyIsImltYWdlMzI0LnBuZyIsImltYWdlMzI1LnBuZyIsImltYWdlMzI2LnBuZyIsImltYWdlMzI3LnBuZyIsImltYWdlMzI4LnBuZyIsImltYWdlMzI5LnBuZyIsImltYWdlMzMwLnBuZyIsImltYWdlMzMxLnBuZyIsImltYWdlMzMyLnBuZyIsImltYWdlMzMzLnBuZyIsImltYWdlMzM0LnBuZyIsImltYWdlMzM1LnBuZyIsImltYWdlMzM2LnBuZyIsImltYWdlMzM3LnBuZyIsImltYWdlMzM4LnBuZyIsImltYWdlMzM5LnBuZyIsImltYWdlMzQwLnBuZyIsImltYWdlMzQxLnBuZyIsImltYWdlMzQyLnBuZyIsImltYWdlMzQzLnBuZyIsImltYWdlMzQ0LnBuZyIsImltYWdlMzQ1LnBuZyIsImltYWdlMzQ2LnBuZyIsImltYWdlMzQ3LnBuZyIsImltYWdlMzQ4LnBuZyIsImltYWdlMzQ5LnBuZyIsImltYWdlMzUwLnBuZyIsImltYWdlMzUxLnBuZyIsImltYWdlMzUyLnBuZyIsImltYWdlMzUzLnBuZyIsImltYWdlMzU0LnBuZyIsImltYWdlMzU1LnBuZyIsImltYWdlMzU2LnBuZyIsImltYWdlMzU3LnBuZyIsImltYWdlMzU4LnBuZyIsImltYWdlMzU5LnBuZyIsImltYWdlMzYwLnBuZyIsImltYWdlMzYxLnBuZyIsImltYWdlMzYyLnBuZyIsImltYWdlMzYzLnBuZyIsImltYWdlMzY0LnBuZyIsImltYWdlMzY1LnBuZyIsImltYWdlMzY2LnBuZyIsImltYWdlMzY3LnBuZyIsImltYWdlMzY4LnBuZyIsImltYWdlMzY5LnBuZyIsImltYWdlMzcwLnBuZyIsImltYWdlMzcxLnBuZyIsImltYWdlMzcyLnBuZyIsImltYWdlMzczLnBuZyIsImltYWdlMzc0LnBuZyIsImltYWdlMzc1LnBuZyIsImltYWdlMzc2LnBuZyIsImltYWdlMzc3LnBuZyIsImltYWdlMzc4LnBuZyIsImltYWdlMzc5LnBuZyIsImltYWdlMzgwLnBuZyIsImltYWdlMzgxLnBuZyIsImltYWdlMzgyLnBuZyIsImltYWdlMzgzLnBuZyIsImltYWdlMzg0LnBuZyIsImltYWdlMzg1LnBuZyIsImltYWdlMzg2LnBuZyIsImltYWdlMzg3LnBuZyIsImltYWdlMzg4LnBuZyIsImltYWdlMzg5LnBuZyIsImltYWdlMzkwLnBuZyIsImltYWdlMzkxLnBuZyIsImltYWdlMzkyLnBuZyIsImltYWdlMzkzLnBuZyIsImltYWdlMzk0LnBuZyIsImltYWdlMzk1LnBuZyIsImltYWdlMzk2LnBuZyIsImltYWdlMzk3LnBuZyIsImltYWdlMzk4LnBuZyIsImltYWdlMzk5LnBuZyIsImltYWdlNDAwLnBuZyIsImltYWdlNDAxLnBuZyIsImltYWdlNDAyLnBuZyIsImltYWdlNDAzLnBuZyIsImltYWdlNDA0LnBuZyIsImltYWdlNDA1LnBuZyIsImltYWdlNDA2LnBuZyIsImltYWdlNDA3LnBuZyIsImltYWdlNDA4LnBuZyIsImltYWdlNDA5LnBuZyIsImltYWdlNDEwLnBuZyIsImltYWdlNDExLnBuZyIsImltYWdlNDEyLnBuZyIsImltYWdlNDEzLnBuZyIsImltYWdlNDE0LnBuZyIsImltYWdlNDE1LnBuZyIsImltYWdlNDE2LnBuZyIsImltYWdlNDE3LnBuZyIsImltYWdlNDE4LnBuZyIsImltYWdlNDE5LnBuZyIsImltYWdlNDIwLnBuZyIsImltYWdlNDIxLnBuZyIsImltYWdlNDIyLnBuZyIsImltYWdlNDIzLnBuZyIsImltYWdlNDI0LnBuZyIsImltYWdlNDI1LnBuZyIsImltYWdlNDI2LnBuZyIsImltYWdlNDI3LnBuZyIsImltYWdlNDI4LnBuZyIsImltYWdlNDI5LnBuZyIsImltYWdlNDMwLnBuZyIsImltYWdlNDMxLnBuZyIsImltYWdlNDMyLnBuZyIsImltYWdlNDMzLnBuZyIsImltYWdlNDM0LnBuZyIsImltYWdlNDM1LnBuZyIsImltYWdlNDM2LnBuZyIsImltYWdlNDM3LnBuZyIsImltYWdlNDM4LnBuZyIsImltYWdlNDM5LnBuZyIsImltYWdlNDQwLnBuZyIsImltYWdlNDQxLnBuZyIsImltYWdlNDQyLnBuZyIsImltYWdlNDQzLnBuZyIsImltYWdlNDQ0LnBuZyIsImltYWdlNDQ1LnBuZyIsImltYWdlNDQ2LnBuZyIsImltYWdlNDQ3LnBuZyIsImltYWdlNDQ4LnBuZyIsImltYWdlNDQ5LnBuZyIsImltYWdlNDUwLnBuZyIsImltYWdlNDUxLnBuZyIsImltYWdlNDUyLnBuZyIsImltYWdlNDUzLnBuZyIsImltYWdlNDU0LnBuZyIsImltYWdlNDU1LnBuZyIsImltYWdlNDU2LnBuZyIsImltYWdlNDU3LnBuZyIsImltYWdlNDU4LnBuZyIsImltYWdlNDU5LnBuZyIsImltYWdlNDYwLnBuZyIsImltYWdlNDYxLnBuZyIsImltYWdlNDYyLnBuZyIsImltYWdlNDYzLnBuZyIsImltYWdlNDY0LnBuZyIsImltYWdlNDY1LnBuZyIsImltYWdlNDY2LnBuZyIsImltYWdlNDY3LnBuZyIsImltYWdlNDY4LnBuZyIsImltYWdlNDY5LnBuZyIsImltYWdlNDcwLnBuZyIsImltYWdlNDcxLnBuZyIsImltYWdlNDcyLnBuZyIsImltYWdlNDczLnBuZyIsImltYWdlNDc0LnBuZyIsImltYWdlNDc1LnBuZyIsImltYWdlNDc2LnBuZyIsImltYWdlNDc3LnBuZyIsImltYWdlNDc4LnBuZyIsImltYWdlNDc5LnBuZyIsImltYWdlNDgwLnBuZyIsImltYWdlNDgxLnBuZyIsImltYWdlNDgyLnBuZyIsImltYWdlNDgzLnBuZyIsImltYWdlNDg0LnBuZyIsImltYWdlNDg1LnBuZyIsImltYWdlNDg2LnBuZyIsImltYWdlNDg3LnBuZyIsImltYWdlNDg4LnBuZyIsImltYWdlNDg5LnBuZyIsImltYWdlNDkwLnBuZyIsImltYWdlNDkxLnBuZyIsImltYWdlNDkyLnBuZyIsImltYWdlNDkzLnBuZyIsImltYWdlNDk0LnBuZyIsImltYWdlNDk1LnBuZyIsImltYWdlNDk2LnBuZyIsImltYWdlNDk3LnBuZyIsImltYWdlNDk4LnBuZyIsImltYWdlNDk5LnBuZyIsImltYWdlNTAwLnBuZyIsImltYWdlNTAxLnBuZyIsImltYWdlNTAyLnBuZyIsImltYWdlNTAzLnBuZyIsImltYWdlNTA0LnBuZyIsImltYWdlNTA1LnBuZyIsImltYWdlNTA2LnBuZyIsImltYWdlNTA3LnBuZyIsImltYWdlNTA4LnBuZyIsImltYWdlNTA5LnBuZyIsImltYWdlNTEwLnBuZyIsImltYWdlNTExLnBuZyIsImltYWdlNTEyLnBuZyIsImltYWdlNTEzLnBuZyIsImltYWdlNTE0LnBuZyIsImltYWdlNTE1LnBuZyIsImltYWdlNTE2LnBuZyIsImltYWdlNTE3LnBuZyIsImltYWdlNTE4LnBuZyIsImltYWdlNTE5LnBuZyIsImltYWdlNTIwLnBuZyIsImltYWdlNTIxLnBuZyIsImltYWdlNTIyLnBuZyIsImltYWdlNTIzLnBuZyIsImltYWdlNTI0LnBuZyIsImltYWdlNTI1LnBuZyIsImltYWdlNTI2LnBuZyIsImltYWdlNTI3LnBuZyIsImltYWdlNTI4LnBuZyIsImltYWdlNTI5LnBuZyIsImltYWdlNTMwLnBuZyIsImltYWdlNTMxLnBuZyIsImltYWdlNTMyLnBuZyIsImltYWdlNTMzLnBuZyIsImltYWdlNTM0LnBuZyIsImltYWdlNTM1LnBuZyIsImltYWdlNTM2LnBuZyIsImltYWdlNTM3LnBuZyIsImltYWdlNTM4LnBuZyIsImltYWdlNTM5LnBuZyIsImltYWdlNTQwLnBuZyIsImltYWdlNTQxLnBuZyIsImltYWdlNTQyLnBuZyIsImltYWdlNTQzLnBuZyIsImltYWdlNTQ0LnBuZyIsImltYWdlNTQ1LnBuZyIsImltYWdlNTQ2LnBuZyIsImltYWdlNTQ3LnBuZyIsImltYWdlNTQ4LnBuZyIsImltYWdlNTQ5LnBuZyIsImltYWdlNTUwLnBuZyIsImltYWdlNTUxLnBuZyIsImltYWdlNTUyLnBuZyIsImltYWdlNTUzLnBuZyIsImltYWdlNTU0LnBuZyIsImltYWdlNTU1LnBuZyIsImltYWdlNTU2LnBuZyIsImltYWdlNTU3LnBuZyIsImltYWdlNTU4LnBuZyIsImltYWdlNTU5LnBuZyIsImltYWdlNTYwLnBuZyIsImltYWdlNTYxLnBuZyIsImltYWdlNTYyLnBuZyIsImltYWdlNTYzLnBuZyIsImltYWdlNTY0LnBuZyIsImltYWdlNTY1LnBuZyIsImltYWdlNTY2LnBuZyIsImltYWdlNTY3LnBuZyIsImltYWdlNTY4LnBuZyIsImltYWdlNTY5LnBuZyIsImltYWdlNTcwLnBuZyIsImltYWdlNTcxLnBuZyIsImltYWdlNTcyLnBuZyIsImltYWdlNTczLnBuZyIsImltYWdlNTc0LnBuZyIsImltYWdlNTc1LnBuZyIsImltYWdlNTc2LnBuZyIsImltYWdlNTc3LnBuZyIsImltYWdlNTc4LnBuZyIsImltYWdlNTc5LnBuZyIsImltYWdlNTgwLnBuZyIsImltYWdlNTgxLnBuZyIsImltYWdlNTgyLnBuZyIsImltYWdlNTgzLnBuZyIsImltYWdlNTg0LnBuZyIsImltYWdlNTg1LnBuZyIsImltYWdlNTg2LnBuZyIsImltYWdlNTg3LnBuZyIsImltYWdlNTg4LnBuZyIsImltYWdlNTg5LnBuZyIsImltYWdlNTkwLnBuZyIsImltYWdlNTkxLnBuZyIsImltYWdlNTkyLnBuZyIsImltYWdlNTkzLnBuZyIsImltYWdlNTk0LnBuZyIsImltYWdlNTk1LnBuZyIsImltYWdlNTk2LnBuZyIsImltYWdlNTk3LnBuZyIsImltYWdlNTk4LnBuZyIsImltYWdlNTk5LnBuZyIsImltYWdlNjAwLnBuZyIsImltYWdlNjAxLnBuZyIsImltYWdlNjAyLnBuZyIsImltYWdlNjAzLnBuZyIsImltYWdlNjA0LnBuZyIsImltYWdlNjA1LnBuZyIsImltYWdlNjA2LnBuZyIsImltYWdlNjA3LnBuZyIsImltYWdlNjA4LnBuZyIsImltYWdlNjA5LnBuZyIsImltYWdlNjEwLnBuZyIsImltYWdlNjExLnBuZyIsImltYWdlNjEyLnBuZyIsImltYWdlNjEzLnBuZyIsImltYWdlNjE0LnBuZyIsImltYWdlNjE1LnBuZyIsImltYWdlNjE2LnBuZyIsImltYWdlNjE3LnBuZyIsImltYWdlNjE4LnBuZyIsImltYWdlNjE5LnBuZyIsImltYWdlNjIwLnBuZyIsImltYWdlNjIxLnBuZyIsImltYWdlNjIyLnBuZyIsImltYWdlNjIzLnBuZyIsImltYWdlNjI0LnBuZyIsImltYWdlNjI1LnBuZyIsImltYWdlNjI2LnBuZyIsImltYWdlNjI3LnBuZyIsImltYWdlNjI4LnBuZyIsImltYWdlNjI5LnBuZyIsImltYWdlNjMwLnBuZyIsImltYWdlNjMxLnBuZyIsImltYWdlNjMyLnBuZyIsImltYWdlNjMzLnBuZyIsImltYWdlNjM0LnBuZyIsImltYWdlNjM1LnBuZyIsImltYWdlNjM2LnBuZyIsImltYWdlNjM3LnBuZyIsImltYWdlNjM4LnBuZyIsImltYWdlNjM5LnBuZyIsImltYWdlNjQwLnBuZyIsImltYWdlNjQxLnBuZyIsImltYWdlNjQyLnBuZyIsImltYWdlNjQzLnBuZyIsImltYWdlNjQ0LnBuZyIsImltYWdlNjQ1LnBuZyIsImltYWdlNjQ2LnBuZyIsImltYWdlNjQ3LnBuZyIsImltYWdlNjQ4LnBuZyIsImltYWdlNjQ5LnBuZyIsImltYWdlNjUwLnBuZyIsImltYWdlNjUxLnBuZyIsImltYWdlNjUyLnBuZyIsImltYWdlNjUzLnBuZyIsImltYWdlNjU0LnBuZyIsImltYWdlNjU1LnBuZyIsImltYWdlNjU2LnBuZyIsImltYWdlNjU3LnBuZyIsImltYWdlNjU4LnBuZyIsImltYWdlNjU5LnBuZyIsImltYWdlNjYwLnBuZyIsImltYWdlNjYxLnBuZyIsImltYWdlNjYyLnBuZyIsImltYWdlNjYzLnBuZyIsImltYWdlNjY0LnBuZyIsImltYWdlNjY1LnBuZyIsImltYWdlNjY2LnBuZyIsImltYWdlNjY3LnBuZyIsImltYWdlNjY4LnBuZyIsImltYWdlNjY5LnBuZyIsImltYWdlNjcwLnBuZyIsImltYWdlNjcxLnBuZyIsImltYWdlNjcyLnBuZyIsImltYWdlNjczLnBuZyIsImltYWdlNjc0LnBuZyIsImltYWdlNjc1LnBuZyIsImltYWdlNjc2LnBuZyIsImltYWdlNjc3LnBuZyIsImltYWdlNjc4LnBuZyIsImltYWdlNjc5LnBuZyIsImltYWdlNjgwLnBuZyIsImltYWdlNjgxLnBuZyIsImltYWdlNjgyLnBuZyIsImltYWdlNjgzLnBuZyIsImltYWdlNjg0LnBuZyIsImltYWdlNjg1LnBuZyIsImltYWdlNjg2LnBuZyIsImltYWdlNjg3LnBuZyIsImltYWdlNjg4LnBuZyIsImltYWdlNjg5LnBuZyIsImltYWdlNjkwLnBuZyIsImltYWdlNjkxLnBuZyIsImltYWdlNjkyLnBuZyIsImltYWdlNjkzLnBuZyIsImltYWdlNjk0LnBuZyIsImltYWdlNjk1LnBuZyIsImltYWdlNjk2LnBuZyIsImltYWdlNjk3LnBuZyIsImltYWdlNjk4LnBuZyIsImltYWdlNjk5LnBuZyIsImltYWdlNzAwLnBuZyIsImltYWdlNzAxLnBuZyIsImltYWdlNzAyLnBuZyIsImltYWdlNzAzLnBuZyIsImltYWdlNzA0LnBuZyIsImltYWdlNzA1LnBuZyIsImltYWdlNzA2LnBuZyIsImltYWdlNzA3LnBuZyIsImltYWdlNzA4LnBuZyIsImltYWdlNzA5LnBuZyIsImltYWdlNzEwLnBuZyIsImltYWdlNzExLnBuZyIsImltYWdlNzEyLnBuZyIsImltYWdlNzEzLnBuZyIsImltYWdlNzE0LnBuZyIsImltYWdlNzE1LnBuZyIsImltYWdlNzE2LnBuZyIsImltYWdlNzE3LnBuZyIsImltYWdlNzE4LnBuZyIsImltYWdlNzE5LnBuZyIsImltYWdlNzIwLnBuZyIsImltYWdlNzIxLnBuZyIsImltYWdlNzIyLnBuZyIsImltYWdlNzIzLnBuZyIsImltYWdlNzI0LnBuZyIsImltYWdlNzI1LnBuZyIsImltYWdlNzI2LnBuZyIsImltYWdlNzI3LnBuZyIsImltYWdlNzI4LnBuZyIsImltYWdlNzI5LnBuZyIsImltYWdlNzMwLnBuZyIsImltYWdlNzMxLnBuZyIsImltYWdlNzMyLnBuZyIsImltYWdlNzMzLnBuZyIsImltYWdlNzM0LnBuZyIsImltYWdlNzM1LnBuZyIsImltYWdlNzM2LnBuZyIsImltYWdlNzM3LnBuZyIsImltYWdlNzM4LnBuZyIsImltYWdlNzM5LnBuZyIsImltYWdlNzQwLnBuZyIsImltYWdlNzQxLnBuZyIsImltYWdlNzQyLnBuZyIsImltYWdlNzQzLnBuZyIsImltYWdlNzQ0LnBuZyIsImltYWdlNzQ1LnBuZyIsImltYWdlNzQ2LnBuZyIsImltYWdlNzQ3LnBuZyIsImltYWdlNzQ4LnBuZyIsImltYWdlNzQ5LnBuZyIsImltYWdlNzUwLnBuZyIsImltYWdlNzUxLnBuZyIsImltYWdlNzUyLnBuZyIsImltYWdlNzUzLnBuZyIsImltYWdlNzU0LnBuZyIsImltYWdlNzU1LnBuZyIsImltYWdlNzU2LnBuZyIsImltYWdlNzU3LnBuZyIsImltYWdlNzU4LnBuZyIsImltYWdlNzU5LnBuZyIsImltYWdlNzYwLnBuZyIsImltYWdlNzYxLnBuZyIsImltYWdlNzYyLnBuZyIsImltYWdlNzYzLnBuZyIsImltYWdlNzY0LnBuZyIsImltYWdlNzY1LnBuZyIsImltYWdlNzY2LnBuZyIsImltYWdlNzY3LnBuZyIsImltYWdlNzY4LnBuZyIsImltYWdlNzY5LnBuZyIsImltYWdlNzcwLnBuZyIsImltYWdlNzcxLnBuZyIsImltYWdlNzcyLnBuZyIsImltYWdlNzczLnBuZyIsImltYWdlNzc0LnBuZyIsImltYWdlNzc1LnBuZyIsImltYWdlNzc2LnBuZyIsImltYWdlNzc3LnBuZyIsImltYWdlNzc4LnBuZyIsImltYWdlNzc5LnBuZyIsImltYWdlNzgwLnBuZyIsImltYWdlNzgxLnBuZyIsImltYWdlNzgyLnBuZyIsImltYWdlNzgzLnBuZyIsImltYWdlNzg0LnBuZyIsImltYWdlNzg1LnBuZyIsImltYWdlNzg2LnBuZyIsImltYWdlNzg3LnBuZyIsImltYWdlNzg4LnBuZyIsImltYWdlNzg5LnBuZyIsImltYWdlNzkwLnBuZyIsImltYWdlNzkxLnBuZyIsImltYWdlNzkyLnBuZyIsImltYWdlNzkzLnBuZyIsImltYWdlNzk0LnBuZyIsImltYWdlNzk1LnBuZyIsImltYWdlNzk2LnBuZyIsImltYWdlNzk3LnBuZyIsImltYWdlNzk4LnBuZyIsImltYWdlNzk5LnBuZyIsImltYWdlODAwLnBuZyIsImltYWdlODAxLnBuZyIsImltYWdlODAyLnBuZyIsImltYWdlODAzLnBuZyIsImltYWdlODA0LnBuZyIsImltYWdlODA1LnBuZyIsImltYWdlODA2LnBuZyIsImltYWdlODA3LnBuZyIsImltYWdlODA4LnBuZyIsImltYWdlODA5LnBuZyIsImltYWdlODEwLnBuZyIsImltYWdlODExLnBuZyIsImltYWdlODEyLnBuZyIsImltYWdlODEzLnBuZyIsImltYWdlODE0LnBuZyIsImltYWdlODE1LnBuZyIsImltYWdlODE2LnBuZyIsImltYWdlODE3LnBuZyIsImltYWdlODE4LnBuZyIsImltYWdlODE5LnBuZyIsImltYWdlODIwLnBuZyIsImltYWdlODIxLnBuZyIsImltYWdlODIyLnBuZyIsImltYWdlODIzLnBuZyIsImltYWdlODI0LnBuZyIsImltYWdlODI1LnBuZyIsImltYWdlODI2LnBuZyIsImltYWdlODI3LnBuZyIsImltYWdlODI4LnBuZyIsImltYWdlODI5LnBuZyIsImltYWdlODMwLnBuZyIsImltYWdlODMxLnBuZyIsImltYWdlODMyLnBuZyIsImltYWdlODMzLnBuZyIsImltYWdlODM0LnBuZyIsImltYWdlODM1LnBuZyIsImltYWdlODM2LnBuZyIsImltYWdlODM3LnBuZyIsImltYWdlODM4LnBuZyIsImltYWdlODM5LnBuZyIsImltYWdlODQwLnBuZyIsImltYWdlODQxLnBuZyIsImltYWdlODQyLnBuZyIsImltYWdlODQzLnBuZyIsImltYWdlODQ0LnBuZyIsImltYWdlODQ1LnBuZyIsImltYWdlODQ2LnBuZyIsImltYWdlODQ3LnBuZyIsImltYWdlODQ4LnBuZyIsImltYWdlODQ5LnBuZyIsImltYWdlODUwLnBuZyIsImltYWdlODUxLnBuZyIsImltYWdlODUyLnBuZyIsImltYWdlODUzLnBuZyIsImltYWdlODU0LnBuZyIsImltYWdlODU1LnBuZyIsImltYWdlODU2LnBuZyIsImltYWdlODU3LnBuZyIsImltYWdlODU4LnBuZyIsImltYWdlODU5LnBuZyIsImltYWdlODYwLnBuZyIsImltYWdlODYxLnBuZyIsImltYWdlODYyLnBuZyIsImltYWdlODYzLnBuZyIsImltYWdlODY0LnBuZyIsImltYWdlODY1LnBuZyIsImltYWdlODY2LnBuZyIsImltYWdlODY3LnBuZyIsImltYWdlODY4LnBuZyIsImltYWdlODY5LnBuZyIsImltYWdlODcwLnBuZyIsImltYWdlODcxLnBuZyIsImltYWdlODcyLnBuZyIsImltYWdlODczLnBuZyIsImltYWdlODc0LnBuZyIsImltYWdlODc1LnBuZyIsImltYWdlODc2LnBuZyIsImltYWdlODc3LnBuZyIsImltYWdlODc4LnBuZyIsImltYWdlODc5LnBuZyIsImltYWdlODgwLnBuZyIsImltYWdlODgxLnBuZyIsImltYWdlODgyLnBuZyIsImltYWdlODgzLnBuZyIsImltYWdlODg0LnBuZyIsImltYWdlODg1LnBuZyIsImltYWdlODg2LnBuZyIsImltYWdlODg3LnBuZyIsImltYWdlODg4LnBuZyIsImltYWdlODg5LnBuZyIsImltYWdlODkwLnBuZyIsImltYWdlODkxLnBuZyIsImltYWdlODkyLnBuZyIsImltYWdlODkzLnBuZyIsImltYWdlODk0LnBuZyIsImltYWdlODk1LnBuZyIsImltYWdlODk2LnBuZyIsImltYWdlODk3LnBuZyIsImltYWdlODk4LnBuZyIsImltYWdlODk5LnBuZyIsImltYWdlOTAwLnBuZyIsImltYWdlOTAxLnBuZyIsImltYWdlOTAyLnBuZyIsImltYWdlOTAzLnBuZyIsImltYWdlOTA0LnBuZyIsImltYWdlOTA1LnBuZyIsImltYWdlOTA2LnBuZyIsImltYWdlOTA3LnBuZyIsImltYWdlOTA4LnBuZyIsImltYWdlOTA5LnBuZyIsImltYWdlOTEwLnBuZyIsImltYWdlOTExLnBuZyIsImltYWdlOTEyLnBuZyIsImltYWdlOTEzLnBuZyIsImltYWdlOTE0LnBuZyIsImltYWdlOTE1LnBuZyIsImltYWdlOTE2LnBuZyIsImltYWdlOTE3LnBuZyIsImltYWdlOTE4LnBuZyIsImltYWdlOTE5LnBuZyIsImltYWdlOTIwLnBuZyIsImltYWdlOTIxLnBuZyIsImltYWdlOTIyLnBuZyIsImltYWdlOTIzLnBuZyIsImltYWdlOTI0LnBuZyIsImltYWdlOTI1LnBuZyIsImltYWdlOTI2LnBuZyIsImltYWdlOTI3LnBuZyIsImltYWdlOTI4LnBuZyIsImltYWdlOTI5LnBuZyIsImltYWdlOTMwLnBuZyIsImltYWdlOTMxLnBuZyIsImltYWdlOTMyLnBuZyIsImltYWdlOTMzLnBuZyIsImltYWdlOTM0LnBuZyIsImltYWdlOTM1LnBuZyIsImltYWdlOTM2LnBuZyIsImltYWdlOTM3LnBuZyIsImltYWdlOTM4LnBuZyIsImltYWdlOTM5LnBuZyIsImltYWdlOTQwLnBuZyIsImltYWdlOTQxLnBuZyIsImltYWdlOTQyLnBuZyIsImltYWdlOTQzLnBuZyIsImltYWdlOTQ0LnBuZyIsImltYWdlOTQ1LnBuZyIsImltYWdlOTQ2LnBuZyIsImltYWdlOTQ3LnBuZyIsImltYWdlOTQ4LnBuZyIsImltYWdlOTQ5LnBuZyIsImltYWdlOTUwLnBuZyIsImltYWdlOTUxLnBuZyIsImltYWdlOTUyLnBuZyIsImltYWdlOTUzLnBuZyIsImltYWdlOTU0LnBuZyIsImltYWdlOTU1LnBuZyIsImltYWdlOTU2LnBuZyIsImltYWdlOTU3LnBuZyIsImltYWdlOTU4LnBuZyIsImltYWdlOTU5LnBuZyIsImltYWdlOTYwLnBuZyIsImltYWdlOTYxLnBuZyIsImltYWdlOTYyLnBuZyIsImltYWdlOTYzLnBuZyIsImltYWdlOTY0LnBuZyIsImltYWdlOTY1LnBuZyIsImltYWdlOTY2LnBuZyIsImltYWdlOTY3LnBuZyIsImltYWdlOTY4LnBuZyIsImltYWdlOTY5LnBuZyIsImltYWdlOTcwLnBuZyIsImltYWdlOTcxLnBuZyIsImltYWdlOTcyLnBuZyIsImltYWdlOTczLnBuZyIsImltYWdlOTc0LnBuZyIsImltYWdlOTc1LnBuZyIsImltYWdlOTc2LnBuZyIsImltYWdlOTc3LnBuZyIsImltYWdlOTc4LnBuZyIsImltYWdlOTc5LnBuZyIsImltYWdlOTgwLnBuZyIsImltYWdlOTgxLnBuZyIsImltYWdlOTgyLnBuZyIsImltYWdlOTgzLnBuZyIsImltYWdlOTg0LnBuZyIsImltYWdlOTg1LnBuZyIsImltYWdlOTg2LnBuZyIsImltYWdlOTg3LnBuZyIsImltYWdlOTg4LnBuZyIsImltYWdlOTg5LnBuZyIsImltYWdlOTkwLnBuZyIsImltYWdlOTkxLnBuZyIsImltYWdlOTkyLnBuZyIsImltYWdlOTkzLnBuZyIsImltYWdlOTk0LnBuZyIsImltYWdlOTk1LnBuZyIsImltYWdlOTk2LnBuZyIsImltYWdlOTk3LnBuZyIsImltYWdlOTk4LnBuZyIsImltYWdlOTk5LnBuZyJdLCJpYXQiOjE1MTYyMzkwMjJ9.KGrocKdxHn_ZCkgfl5SAbKxCm8tbqVOBslU_x3SrYAg) the JWT length changes from 239 characters to 20,057 - and that’s considering a simple file name. With the full path, it’s even longer. Additionally, a JWT created during the authentication phase doesn’t include all the necessary information required to make the policy decision -  especially if you are using a vendor like Auth0 to authenticate. In addition, storing data in JWTs means we have to refresh the token (read as login/logout) every time we want to update the data. 

The ugly:
You might think it’s a good idea to start with JWTs because you don’t have a lot of data - as time goes by the amount of data grows exponentially, and the situation easily spirals out of control, with an enormous amount of JWTs floating around in each request. 

Bottom-line:
JWTs are ideal for simple identity-related data, and in general, it’s best to think of the claims and data in the JWT as hints about identity (given by the Identity-Management and Authentication layers) rather than verbatim data for authorization.

</b>
<a name="2"></a>
#2. Overload input for OPA within the query:

![Overload input for OPA within the query](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pbanaskj2vd000gw0io6.png)

Another option is to attach input for every policy query to OPA, adding the relevant data to it.  
It will look something like this in python pseudocode wrapping OPA:

```
def delete_image(user_id, image_id):
	policy_json_data = {}
	policy_json_data[“user_roles”] = get_user_roles(user_id) # returns list of roles like [“editor”]
	policy_json_data[”user_images”] = get_user_images(user_id) # returns list of images [“img.png”]

# sends request that looks like this:
# localhost:8181 -i -d ‘{"roles": ["pro"], "related_images": ["image0.png", "image1.png"], image_id: “image2.png”}’ -H 'Content-Type: application/json'
# and returns true / false
	permitted = check_opa_policy(policy_json_data, “delete”, image_id) 
	if not permitted:
		raise(AuthorizationError)
```

The good:
Using this method is simple, and it ensures that only the relevant data is cherry-picked for each query sent, thus avoiding loading/storing a lot of data in OPA.
 
The bad:
This method prevents us from following one of the most important best practices in building authorization - decoupling policy and code. As our code now has to take on the responsibility of tailoring the data for OPA. Having policy and code mixed together in one layer creates a situation where we struggle to upgrade, add capabilities and monitor the code overall as it is replicated between different microservices. Each change would require us to refactor large areas of code that only drift further from one another as these microservices develop.

The ugly:
Having so much code repetition is an antithesis to the [DRY](https://en.wikipedia.org/wiki/Don%27t_repeat_yourself) principle - creating a multitude of complications and difficulties as our application evolves. Considering the example code above for instance, a very similar code will be written to delete_image, update_image, and get_image.

Bottom-line:
In general, it is best to leave this method for simple cases or to augment more advanced cases with cherry-picking.

</b>
<a name="3"></a>
#3. Polling for data using Bundles


![Polling for data using Bundles](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eg63nn96nxolj31grutf.png)

The bundle feature periodically checks and downloads policy bundles from a centralized server, which can include both data and policies. An example of a simple way to implement this solution would be running an Nginx container that serves the bundle files and configuring OPA to fetch data from it (using s3 buckets is also a common pattern). The configuration for OPA will be as follows: 

```
services:
  nginx:
    url: https://my-nginx.example.com
    credentials:
      bearer:
        token: dGVzdGluZzp0ZXN0aW5n
        scheme: Basic

bundles:
  authz:
    service: nginx
    resource: /bundle.tar.gz
```

The good:
It allows you to load large amounts of data (much larger than the 2 previous methods), it has a delta bundle feature that lets you sync only new data (but not policy), it lets you have one source of truth, and it is more readable than JWTs.
 
The bad:
Using bundles doesn’t cut it when we have data that changes rapidly, as it requires triggering a full policy update for every small change - Making this a very inefficient process.

The ugly:
Even with the new delta bundle feature, you still need to manage and create the bundles on your own, and it works with polling which isn’t real-time.

In addition, being dependent on a polling interval means you have to choose between rapid polling which can result in high costs or slow polling which can lead to delays and risk of inconsistency.

The bottom line:
For cases where updates to data mainly come as part of the CI/CD cycle, bundles are a great option.  Bundles can also work well for static or rather static applications. For modern dynamic applications, this option might be too slow/inefficient on its own. 

</b>
<a name="4"></a>
#4. Pushing data into OPA using the API


![Pushing data into OPA using the API](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t9irp12udfrrqxgha8ha.png)

You can also push policy data into OPA with an API request - this approach is similar in most aspects to the bundle API, except it allows you to optimize for update latency and network traffic. It will look something like this in python pseudo-code:


```
def send_user_update_to_opa():
	requests.put(f”{opa_url}/users”, params={users: [user1,user2]})

def callback_on_new_user():
	all_users = get_all_users()
	send_update_to_opa(all_users)
```

In this example, we are updating the user list of OPA for each callback on new user creation.

The good:
This way you don’t need to load the entire bundle at every update, you can also update part of it, which is much more performant in terms of memory and network usage - as well as giving you more control of how you manage distributed data into OPA.

The bad:
Applying this method to import new kinds of data from different data sources is going to require a continuous effort of writing enormous amounts of code.

The ugly:
This method requires continuous maintenance - you can’t just set it up and forget about it. If left abandoned, this code will very quickly become obsolete. 

The bottom line: 
Great way to load data into OPA in a dynamic fashion, but requires a lot of development and administration in all but very simple cases.

</b>
<a name="5"></a>
#5. Pulling data using OPA during Policy Evaluation


![Pulling data using OPA during Policy Evaluation](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u433tzpk0er2ekgqw5rc.png)

OPA includes a function (`http.send()`) that allows it to reach out to external HTTP servers during evaluation and request additional data. It will look something like this in Rego pseudo-code:


```

default allow = false
 
allow = true {
    input.method == "GET"
    input.path = ["getSalary", user]
    managers := http.send(get_managers_url)
    managers := managers[input.user][_]
    contains(managers, user)
}

```

You can see the call to http.send(get_managers_url) that returns the list of the managers to help evaluate the policy. Similarly, you can embed more functions into OPA as a plugin to fetch data as part of a query from other sources.

The good:
This is a solid option to use when you have a very large volume of data that is required to make permission decisions, and you cannot load it all into OPA.

The bad:
Using this method puts a strain on OPA as it always comes with network latency that slows all of your policy evaluations. Additionally, this method is prone to network errors.  

The ugly:
Error handling with rego isn’t simple at all, and relying on this feature can lead to some [frustrating results](https://github.com/open-policy-agent/opa/pull/2763). While OPA and Rego can be used to evaluate policies very quickly, you may want to avoid adding more logic than you need.

The bottom line: 
This is a great way to load data into OPA in a highly dynamic way without writing a lot of code. That being said, this solution is not applicable when the relevant data requires parsing or edge case handling, which Rego lacks. 

</b>
<a name="6"></a>
#6. OPAL (Open Policy Administration Layer):

![OPAL Open Policy Administration Layer](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dd6vutu871xkn5ayvt27.png)

OPAL [is an open-source project](https://github.com/permitio/opal) for administering authorization and access control for OPA. OPAL responds to policy and data changes, pushes live updates to OPA agents, and thus brings open policy up to the speed needed by live applications.

To run OPAL with OPA you can simply [use the Docker example](https://github.com/permitio/opal/blob/master/docs/HOWTO/get_started_with_opal_docker_compose_tutorial.md). Send an [update to OPAL on every change in your data](https://github.com/permitio/opal/blob/master/docs/HOWTO/trigger_data_updates.md) or connect your data source's webhook with OPAL and let OPAL stream the updates to OPA.

The good:
OPAL includes live updates and Git tracking (GitOps) and saves you the hassle of having to write all the code by yourself like in the ‘Pushing Data with API’ option.

The bad:
OPAL is a fairly new library, it might take some time to learn and some work to integrate into your project.

The ugly:
First of all, OPAL is beautiful (But being one of the contributors to this open source project I might be biased). That being said, the architecture can be a bit more complicated than bundle server/JWTs, so you might need to take your time and make sure you understand it.

The bottom line:
OPAL is inspired by the way companies like Netflix work with OPA, but it requires some work to set up. Simple applications will do better with one of the other methods, but for full modern applications, OPAL is probably the more robust/reliable option. 

</b>

#Conclusion
There are various methods to build data fetching mechanisms - each of them having their own pros and cons. 

Some of these methods (Including data in JWT tokens and using Overload input for OPA within the query) could only prove useful in simple cases, some (Polling for data using Bundles) lack effectiveness in dynamic applications. Pushing data with API is a good solution to load data into OPA in a dynamic fashion while requiring a lot of development and administration, and Pulling data using OPA during Policy Evaluation is not applicable when the relevant data requires parsing or edge case handling. OPAL has the advantage of being a more robust/reliable solution, but it requires you to adopt new open-source-based technology.
The most important thing to take from this review is understanding the complexities and challenges of building data fetching mechanisms correctly, and understanding that every method has its pros and cons. 
⁠
⁠Still not sure which method is the right one for you and your architecture? Need someone to brainstorm with? Don’t be shy - reach out to us on our [Slack community](https://bit.ly/permitcommunity).