473,761 Members | 1,808 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Best practice? Web application: single PostgreSQL user vs. multipleusers

I'm trying to get a feel for what most people are doing or consider best
practice.

Given a mod_perl application talking to a PostgreSQL database on the
same host, where different users are logging onto the web server using
LDAP for authentication, do most people

1) have the web server connecting to the database using its own user
account (possibly through ident), and controlling access to different
database entities strictly through the application itself

2) have the web server connecting to the database actually using the
user's account (possibly using LDAP authentication against PostgreSQL),
and controlling access to different database entities through GRANT, etc.

Obviously, (2) leads to more database connections, and you still have to
have the application do some work in terms of which forms are available
to which users, etc. But I'm a little worried about whether it's best
security practice.

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Nov 22 '05
20 6640
Hi Keith, et. al
I think we might be talking about two different things- unless you are equating persistant connections to connection pooling. Perhaps that is correct but let me example a little more what I was talking about. It might be a little
off-topic but I want to be clear in the archives.
Ok, but connection pooling necessitates "account pooling" which is the first
approach.
My particular environment is Linux, Apache, mod_perl and PostgreSQL. The user and group that the web server runs as has no permissions to anything. When a client's app need a DB, we create an account in PG for them and grant
permissions to the web user for the objects it needs access to.
This sounds very much like the "one account per role" compromise suggested
earlier.
a previous connection to **that** client's database (via a global
variable). If not (or if that connection is "busy") a new one is created. The maximum number of connections would be equal to the maximum number of Apache listeners. That's assuming you don't use other application logic to control it. For those who aren't familiar with mod_perl, the benefit is that not
only does your script run as an object in the Apache server but the database connection objects will persist. When you don't do the persistent connections, the difference is that your application object in Apache will have to open the database connection everytime. For local connections to PostgreSQL, I really haven't seen that much of a difference but in my "test" case, I'm
pretty sure I wasn't implementing the persistent-ness of the script correctly and the application was not being hit with any significant load.
Ok, I see what you are talking about here.

Does this mean, then, that the mod_perl scripts must have access to be able
to log into the database as any user even without the user supplying
credentials? i.e. are the credentials for the database itself provided by
the user or by configuring the app? It sounds to me like you then have to
check the username and password against a table in your database, requiring
a pre-existing connection.

Of course if all users at a client have the same rights, then your approach
is similar to mine. If not, then the db provides little security if the app
breaks.
I thought connection pooling was more generic- any connection from the web
server/application business logic could be reused for any db connection. Please correct me if I'm wrong here.

You are right, but I generally think that the account pooling approach is
mostly important if you are also pooling connections. At least with one
session per user, you can do better enforcement. For example, here is how
my largest application handles it.

HERMES (http://hermesweb.sourceforge.net) calls a PHP script (using its own
PAM model) to authenticate the user based on username and password, though I
should change this to make it more general. Currently two modes are
supported on PostgreSQL: DB Native and Shared Account.

DB Native is the preferred access method. In this method, the username and
password supplied to the application correspond to the database account.
The authentication is handled by logging into the database with the username
and password supplied. Permissions are then enforced by the database level
permissions. The only drawback to this approack is that the fact that
HERMES uses its own permission catalogs that allow administrators to assign
the consistant permissions to related groups of tables. In this mode, these
permissions need to be compiled, or activated, into database permissions
before they take effect, but users may have whatever permissions that might
have (including create table and temp permissions).

In shared account mode, things are handled differently (requiring only 2
accounts). The user provides a username and password. The username and
password are passed to the login function, which logs in with a shared
account and runs the authenticate(us ername, password) stored proceedure
(which runs as security definer). This function creates a temporary table
of authenticated users from the current connection (allowing a su-like
function, but not currently supported). The shared user does NOT have
permission to write to this table.

Permissions are then enforced via triggers which check current_user against
a list of db users exempted from trigger-based permissions enforcement. The
authenticated username is then used to check insert, update, or delete
permissions directly against the HERMES permission catalogs.

Select Permissions are enforced by moving the tables (when installing the
shared hosting layer) into a shadow schema and revoking permission from the
shared user to select from these tables. Views are then created in place of
the tables which contain oid's as well the normal columns, and perform a
similar check to the ones that the insert/update/delete triggers do.
Update, insert, and delete functions pass back to the previous table either
by oid or by primary key (unsupported at the moment, but being worked on).

The major restrictions here include a performance hit, and the fact that the
shared user must not have create table or temp permissions in the current
database. However, as a list of db users which bypass the trigger
permissions are maintained, automated backup tools can still be used. The
other user MUST have temp permissions (and preferably create table perms
too).

Of course, the choice of approaches also requires that user creation,
permissions activation, etc. are all handled by stored proceedures, though
most fo the logic will probably be moved back into triggers.

Best Wishes,
Chris Travers
---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postg resql.org so that your
message can get through to the mailing list cleanly

Nov 22 '05 #21

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
9269
by: DrUg13 | last post by:
In java, this seems so easy. You need a new object Object test = new Object() gives me exactly what I want. could someone please help me understand the different ways to do the same thing in C++. I find my self sometimes, trying Object app = Object(); Object *app = Object(); Object app = new Object();
136
9444
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their code was littered with document.all and eval, for example, and I wanted to create a practical list of best practices that they could easily put to use. The above URL is version 1.0 (draft) that resulted. IMO, it is not a replacement for the FAQ,...
6
1559
by: RS | last post by:
Hi, What's the best practice to save user preferences for a .NET application . For example if the user does not want anymore to see Tip-Of-The-Day (TOTD), the user can tick a checkbox on the window showing the tip (TOTD). That tick will be recorded so that next time the user logs in, the application will suppress the display of TOTD. Now if I expand this simple example, say the user is so expert at what he does with the application he...
3
1812
by: Phil Campaigne | last post by:
I am developing a java/postgresql application using ant and junit. I want to deploy tested builds along with matching tables with test data in them. What is the best way to deploy the tables and data to postgresql to match a war file? thanks, Phil
4
2627
by: Collin Peters | last post by:
I have searched the Internet... but haven't found much relating to this. I am wondering on what the best practices are for migrating a developmemnt database to a release database. Here is the simplest example of my situation (real world would be more complex). Say you have two versions of your application. A release version and a development version. After a month of developing you are ready to release a new version. There have...
3
2324
by: Michael Glaesemann | last post by:
Hello all, Recently I've been thinking about different methods of managing users that log into a PostgreSQL-backed application. The users I'm thinking of are not necessarily DBAs: they're application users that really shouldn't even be aware that they are being served by the world's most advanced open source database server. I appreciate any thoughts or feedback people may have, as I'm trying to decide which is the most appropriate way...
5
2532
by: BK | last post by:
We've got a fairly large scale development process under way in .NET 2003. We are about a month away from go-live for phase 1, second phase is rather short and all work should be completed in the next 2 months. Looking back on problems encountered, we want to learn from this project. FWIW, we are nearly on time with the original time line (only off by about a month), and we actually added more functionality than the original specs...
3
3166
by: Venkat | last post by:
Hi, We have a windows application developed in c# and SQL Server 2005. Our application need to execute more than one command (ExecuteReader and ExecuteScalar) at a single time. Till now we have we use with only one connection created during start up of application and will be displose/closed when user logs out of application. With the single database connection we have problems when trying to execute more than command at a particular...
2
2169
by: sabbadin12 | last post by:
Hi, I'm going to work on an application that uses a postgreSQL database so that it can uses SQLServer 2005. I think I solved most problems on the programming side, but I still have some doubts on the DB side regarding how to handle the creation of the db schema on sqlserver and how to handle the every day dba work. 1) should I try to use an ER tool like Embarcadero and have its logical model be the master copy ? (i did some tests, it...
0
9554
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9377
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10136
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9811
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8814
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5405
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3913
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3509
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2788
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.