Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 29th, 2004, 07:44 AM
Authorized User
 
Join Date: Oct 2004
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default restricting database user access, stored procedrs

Hi folks,
Here's a hard one.
We are building a web application which provides a central administration facility for multiple websites. It is built with ASP and uses SQL Server as the database. The administration pages are stored on a seperate domain so it is safe and secure and can't be tampered with in any way. However, the front end of each website is stored on their own website and I am trying to find some way of restricting access within SQL Server to only those records that belong to the website that is accessing the database.

we know that if database users are created then Restricted Access on tables can be possible.
Also restricted access on a particular column for update and select is also possible.
But we are not sure about row level access.

For example :
"Select * from tablename where siteid ='1242121112122' "
Above query will return all records with siteid = 1242121112122

The problem is that if the website owner has FTP user access because the front end runs on their domain so they could make the following changes in above query
"Select * from tablename"
Then it will show all of the records i.e. for all sites.
This we can't stop them from doing this if they have access to the same table as everyone else.

But, if Restricted Access on tables can be possible, then can Restricted Access on stored procedures be possible as well and then we can have a different stored procedure for each site. stored procedure 1 would say , "show records in table x where siteid = 123456789101112", stored procedure 2 would say , "show records in table x where siteid = 123456789101113" If this is possible, would it be possible only to give access to execute the procedure but not to read the SQL code inside the procedure for that database user?

Can anyone help?

Regards
Oliver Dempsey


 
Old October 30th, 2004, 12:03 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

I am not sure if you can restrict the users to select a certain set of rows. Instead I would say you can create VIEWs that would select the table based on just that SITEID. Give permission for the user to have access only on the view, not on the table. So that the user could access the table through view and not directly by any means.

Similarly, you can restrict the user to have just execute permission for any stored procs, but just an sp_helptext <stored_proc_Name> would show the code of the stored proc. I am not sure if you can restrict that too.

Hope that helps.
Cheers!

_________________________
- Vijay G
Strive for Perfection
 
Old October 31st, 2004, 10:33 AM
Authorized User
 
Join Date: Oct 2004
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Vijay,
thanks for your reply. can views accept parameters such as siteid or would you have to create a new view for each new site?

If new views had to be created for each site it would make the system less flexible.

Regards
Oliver



 
Old November 1st, 2004, 04:18 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Oliver,

Views do not take parameters, but stored procedures accept parameters. In your case, Views will not be the right solution. Stored Procedures should be what you are looking for.

Revoke all permission for that db user on that database.
Code:
Revoke all from testaccount
Then create a stored proc that accepts parameter and code it the way you want and grant execute permission for that user on the procedure, not on the table.
Code:
Grant Execute on PROC_NAME to testaccount
Now, login as that user and try
Code:
Select * from ANY_TABLENAME_In_That_DB
that results in error
Server: Msg 229, Level 14, State 5, Line 1
SELECT permission denied on object 'TABLENAME', database 'DB_NAME', owner 'dbo'.

The testaccount user is now allowed to execute the PROC, which works fine, but cannot play around with data/table there. Still [code]Sp_helptext PROC_NAME would show the code to the user. But that is harmless. That user can now do nothing with that.

Hope that helps.
Cheers!

_________________________
- Vijay G
Strive for Perfection
 
Old November 2nd, 2004, 05:33 PM
Authorized User
 
Join Date: Oct 2004
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks happygv,
that makes sense alright

therefore, if we have a stored procedure that says (in english) allow [siteid_parameter] to add, edit or delete only records where siteid=[siteid_parameter], then we can allow access for that user only to those records

thanks a million!
Oliver






Similar Threads
Thread Thread Starter Forum Replies Last Post
Restricting querystring change lily611 C# 2005 9 April 24th, 2008 03:05 AM
Restricting the # of digits after a decimal in a K stevenyoo321 VB How-To 1 April 18th, 2007 07:52 AM
Restricting the user from opening pages gaurav_jain2403 ASP.NET 1.0 and 1.1 Professional 1 January 19th, 2007 11:12 AM
Restricting the data in a ComboBox hemanth_p2p Visual Basic 2005 Basics 2 January 10th, 2006 02:23 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.