21
Practice
1. Create two roles (the password must match the name):
– employee — store employee,
– buyer — customer.
Make sure that the created roles can connect to the database.
2. Revoke the rights of the role public to perform all functions and
connect to the database.
3. Delimit access in such a way that:
– the employee could only order books and add authors and
books,
– the buyer could only purchase books.
Check the changes in the application.
1. The employee is an internal user of the application, authentication is
performed at the database level.
The buyer is an external user. In a real online store, the management of
such users falls to the application, and all queries come to the database
from one “generalized” role (buyer). The identifier of a specific customer can
be passed as a parameter (but we do not do this in our application).
3. Generally speaking, access control should be embedded in the
application. In our educational application, it is not implemented on purpose:
instead, on the web page, you can explicitly select the role on behalf of
which the query will be sent to the database.
This allows you to see how the server side will behave if the application is
not working correctly.
So, users need to get:
●
The right to connect to the bookstore database and access the bookstore
schema.
●
Access to views that are accessed directly.
●
Access to functions that are called as part of the API. If you leave the
SECURITY INVOKER functions in, you will have to grant access to all the
“underlying” objects (tables, other functions). However, it is more
convenient to simply declare API functions as SECURITY DEFINER.
Of course, roles need to be granted privileges only on those objects that
they should have access to.