23
Practice
1. Create two roles (the password must match the role’s name):
– employee: the store’s employee
– buyer: a customer
Make sure that the created roles can connect to the database.
2. Revoke the privileges to execute all functions and to connect to
the database from the public role.
3. Configure access control as follows:
– employee can only order books or add new authors and books
– buyer can only purchase books
Check that the application works as expected with these settings
enabled.
Task 1. The employee role is an internal user of the application; its
authentication is performed at the server level.
The buyer role is an external user. In a real online store, such users are
managed by the application while all the queries are sent to the server on
behalf of a single generic role (buyer); the ID of a particular customer can
be passed as a parameter (but we do not do it in our application).
Task 3. In general, access control must be implemented in the application
as well. In our bookstore application, there is no access control for a reason:
instead, its web interface allows you to explicitly select the role on behalf of
which to execute the query. As a result, you can see what happens on the
server side if the application behavior is incorrect.
So, we need to grant the following privileges:
- The right to connect to the bookstore database and to access the
bookstore schema.
- Access to views that will be called directly.
- Access to functions called as part of the API. With the default SECURITY
INVOKER rights, the function would require access to all the underlying
objects (tables and other functions). But it is more convenient to simply
declare API functions as SECURITY DEFINER.
Naturally, the roles must be granted privileges only on those objects that
they need to access.