Remove the old code
After deleting the inline authorization code fromcanReadRepo()
, the function looks like this:
backend/src/authz.ts
- Instantiate the Oso Cloud client with a configuration file
- Create
User
andRepository
resources - Call
authorizeLocal()
to receive a query that will yield the authorization decision - Return the query as an authorization decision
Next steps
Add policy tests
With Oso Cloud, you can write tests to validate your policy behaves as you expect. This delivers confidence that your existing functionality remains intact as you extend your policy. Add the following test to validate the “read repository” action:Make use of Polar abstractions and shorthand rules
You do not want to leave your authorization logic ashas_permission
statements
for long. Polar provides some powerful features that will make your authorization logic better encapsulated and more concise. Some of these are:
You can incorporate these next. For example, you can modify the existing Polar as follows:
backend/policy.polar
Use feature flags
With this approach, you run your existing logic alongside the Oso Cloud logic for a period of time. As a result, you can use feature flags to migrate from one to the other. This provides a phased rollout to monitor app behavior over time. This permits quick restoration of the original logic if something unexpected happens.Monitor query performance
As your application grows, you may find that database performance degrades. With Local Authorization, the database operation is isolated to a single, distinct line of code. This encapsulation is easy to instrument and monitor performance. If you find that an authorization query starts to become a bottleneck, you can centralize the data for that query in Oso Cloud.When you centralize data in Oso Cloud, fact queries happen on our servers.
This reduces load on your databases, but it requires an
initial
sync
of your data and then updates
when it changes. We recommend keeping your data in your application databases
so to maintain a single source of truth for authorization data.