Controlling access to ORDS RESTful Services

In this blog post I will explain how access control in ORDS REST services can be configured. I will discuss both module protection and pattern protection, and explain in which situations these should be used. Furthermore I will investigate what will happen if module protection and pattern protection partly overlap.
Protection by modules
In ORDS RESTful services, the services in a particular schema are organized into modules. Within a module you must then define one or more templates, which are attached to the specific handlers (mostly GET and/or POST). So, it would be logical to combine several templates that are functionally close (e.g. acting on the same entity) together into one module. One advantage of a module is that they can be directly protected by a privilege. When a new template is added to a protected module, that new template is also automatically protected.
I will give an example to show how this works. To keep my own record of my energy consumption, I have created a number of services to get and store gas and electricity meter readings. I have defined two modules, gas and electricity, and both have a template with a GET handler to retrieve meter readings, and a template with a POST handler to store meter readings.
As you can see, these modules are not yet protected by a privilege. Of course I want to change that, because now everyone has access. So I create two privileges, gasprivilege and electricityprivilege, and assign these to the gas and electricity module respectively.
Two remarks on these privileges:
I could also have created one privilege and protected both modules by this privilege. One privilege can protect multiple modules.
The other way around does not apply. A module can only be protected by one privilege. If I added the gas module to the electricityprivilege in the example above, the gas module would have been detached from the gasprivilege which I had assigned before. This happens without warning!
Protection by patterns
What if we want to protect just our templates with POST handlers (to change information), but leave the templates with GET handlers (to retrieve information) unprotected? Both modules contain both kinds of templates, so we could not do it by assigning privileges to modules. Fortunately, we can also assign privileges to specific patterns. So, in our case we create a new privilege called writeprivilege, and under the Protected Resources section at the bottom we add the patterns of both templates with POST handlers:
When we detach the module privileges (gasprivilege and electricityprivilege) from the modules, we can now see that the template with the POST handler is protected, and the template with the GET handler is not:
Now we have already seen that a module can only be protected by one privilege. So what about patterns? That is a bit fuzzy. If I try to assign the same pattern "/electricity/reading/*" (that I assigned to writeprivilege) to another privilege, I get an error, without further specification, just
But I could assign a pattern "/electricity/*", which has an overlap with the already assigned pattern "/electricity/reading/*", without problem. Also, I could assign the module gas to the gasprivilige, while one the templates is protected by the writeprivilege. Again, when no roles are assigned, the modules and templates are protected (but all clients with valid credentials have access). When we want to create a more fine-grained access control, we have to know what's going on. So let's find out.
Overlapping modules and patterns
We create the following situation:
gasprivilege protects the module gas
writeprivilege protects the patterns /electricity/reading/* and /gas/reading/*
This is equivalent to
| /module/template | module privilege | pattern privilege |
|---|---|---|
| /electricity/reading/v1 | - | writeprivilege |
| /electricity/readings/v1 | - | - |
| /gas/reading/v1 | gasprivilege | writeprivilege |
| gas/readings/v1 | gasprivilege | - |
We now assign the gasprivilege to the role gasrole, and the writeprivilege to the role writerole. Then we test access to the REST services with a client that is assigned consecutively no roles, gasrole, writerole, and both gasrole and writerole.
In the table the results are shown, where a dash (-) stands for no access (401 Unauthorized) and a V stands for access.
| /module/template | no roles | gasrole | writerole | both roles |
|---|---|---|---|---|
| /electricity/reading/v1 | - | - | V | V |
| /electricity/readings/v1 | V | V | V | V |
| /gas/reading/v1 | - | - | - | V |
| gas/readings/v1 | - | V | - | V |
From the results it is clear that for the POST on the gas module now both the gasrole (protected on module level) and the writerole (protected on pattern level) are required to access the service.
This means that if we want to grant some users access to all services on the gas module, and some other users access to all write services, we cannot define a privilege on the gas module and a privilege on the write patterns, because to have access to the gas write service you would need both privileges, and therefore more privileges than desirable. So, a more detailed privilege definition is needed.
Conclusion
Access control in ORDS RESTful Services can be done both by protecting modules and by protecting patterns. Protecting modules is preferable, because templates that are added to a protected module are automatically protected. But to achieve this the module structure should be carefully designed, with access control in mind.
For a fine-grained access control, or when creating access control for an already existing module structure, each template (or a group of templates) can be individually protected by a separate privilege. Care should be taken that there is no overlap in templates, and that new templates will also be protected by a privilege.
Comments
Join the discussionNo comments yet. Be the first to comment.





