There seems to be three common approaches for mapping an application end user to a database user.
It seems that #3 is the most common in web application development. Why is there not a greater emphasis on the other two options?
Oracle encourages techniques like #2 using its proxy authentication features for the following reason:
Limited trust model-controlling the users on whose behalf middle tiers can connect, and the roles the middle tiers can assume for the user
Scalability-by supporting lightweight user sessions and eliminating the overhead of re-authenticating clients
Accountability, by preserving the identity of the real user through to the database, and enabling auditing of actions taken on behalf of the real user
Oracle's Proxy Authentication documentation
In addition to the simpler administration, there are performance advantages of option 3 on web-servers; this allows pooling of connections - i.e. a low number of physical database connections can be re-used continuously to service a large number of app users. This is known as the "trusted subsystem" model - i.e. your app-server validates external callers, but then the app-server itself is used as the identity for calling downwards. The biggest issue here is that for audit etc you need to keep telling the db who made the current change (things like USER_NAME()
, SUSER_SNAME()
cease to be useful) - and of course, this is relatively easy to spoof.
If the web-server used security per user, this wouldn't be possible - and so you'd essentially have to disable connection pooling. The act of establishing a connection is (relatively) expensive, so this would have a significant impact on performance. You wouldn't want to keep the (per-user) connection around between requests, as this would lead to a huge pool and a lot of open connections (also expensive).
The "per role" option site between them - but it is rare that roles are truly mutually exclusive, which makes this hard to implement.
With client apps that talk directly to the database, option 1 is the simplest to maintain, since you don't need to distribute any special account details to the client. The pooling likewise isn't an issue, since the client's machine is only acting as 1 user.
I'd like to add that method #1 requires the code that creates users of the application to run under a DB account that can mess with privileges. To me, this is an unnecessary risk.
Some of the reasons why N to 1 mapping is so much widely used could be possibly because of,
In a conventional software development database is considered as a mere repository and not beyond.
Programmers approach database as a black box and access privileges are considered as one time activity.
Programmers are happy to debug the code and resolve problems rather than worrying about security role definitions and maintenance at the database level.
In a typical application where there is a "User / Role maintenance" screen provided to admin user, it is easy to have tables like USER, SECURITY_ROLE, USER_SECURITY_ROLE etc. to maintain the application user information rather than creating user, security entries in database itself.
In case of not a well defined roles in business model (Dual roles, customizable access privileges etc.) it is easy to implement security at application level rather than at database.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With