views:

108

answers:

4

Hi all, I need some opinions.

I'm going to develop a POS and inventory software for a friend. This is a one man small scale project so I want to make the architecture as simple as possible.

I'm using Winform to develop the GUI (web interface doesn't make sense for POS software). For the database, I am using Postgresql.

The program will control access based on user roles, so either I have to develop a middle tier, using a web server, to control user access or I can just set user priveleges directly in Postgresql.

Developing a middle tier will be time consuming, and the maintenance will be more complex. So I prefer to set access control directly in the database.

Now it appears that using database to control user access is troublesome. I have to set priveleges for each role. Not to mention that for some tables, the priveleges are at column level. This makes reasoning about the security very hard.

So what I'm doing now is to set all the tables to be inaccessible except by superusers. The program will connect to the database using public role. Because the tables are inaccessible by public, I'm going to make publicly accessible stored functions with SECURITY DEFINER (with superuser role). The only way to access the tables is by using these functions.

I'll put the user roles and passwords in a table. Because the user table itself is inaccessible by non-superuser, I'll make a login function, let's call it fn_login(username, password). fn_login will return a session key if login is successful.

To call other functions, we need to supply session key for the user, e.g.: fn_purchase_list(session_key), fn_purchase_new(session_key, purchase_id, ...).

That way, I'm treating the stored functions as APIs. Adding new user will be easier as I only need to add new rows in the user table rather than adding new Postgresql roles. I won't need to set priveleges at column level. All controls will be done programmatically.

So what do you think? Is this approach feasible and scalable? Is there a better way to do it?

Thanks!

+2  A: 

I believe there is a better way to do it. But since you haven't discussed what type of security you need, I cannot elaborate on specifics.

Since you are developing the application code in .NET, that code needs to be trusted (unlike a web application). Therefore, why don't you simply implement your roles and permissions in the application code, rather than the database?

My concern with your stated approach is the human overhead of stored procedures. Would much rather see you write the stated functions in C#, rather than in PostgreSQL. Then, standard version control and software development techniques could apply.

gahooa
+1  A: 

If you wait until somebody has at your database to check security, I think you'll be too late. That's a client/server mentality that went out at the end of the 90s. It's part of the reason why n-tier architectures came into vogue. Client/server can't scale horizontally as well as an n-tier solution.

I'd advise that you take better advantage of the middle tier. Security should be a cross-cutting concern that's further up the stack than your persistence layer.

duffymo
Not every application needs to scale. 90's client/server tech is more than viable for many organizations. Since the simple fact that larger organizations actually managed to get by using the tech is indicative that it was effective. Perhaps not optimal, but at least workable. And likely, this application isn't anywhere close to having these issues. Sure there are limitations, it's a design consideration like anything else.
Will Hartung
But the questioner specifically asked "Is this approach feasible and scalable?" Feasible? Of course. Scalable? It depends on how far one needs to go, and there was no hint about that.
duffymo
Well, I read "one man small scale project so I want to make the architecture as simple as possible" and figured that question was already answered.
Will Hartung
@Will - good point. You might be right.
duffymo
A: 

If the MANAGEMENT of the database security is the issue, then you should add the task of automating that management. That means that you can store higher level data with the database tables, and then your application can convert that data in to the appropriate details and artifacts that the database requires.

It sounds like the database has the detail that you need, you just need to facilitate the management of that detail, and roll that in to your app.

Will Hartung
A: 

My honest advice: Do not invent POS and inventory software. Take one of existing projects and make it better.

filiprem