CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    George2 is offline Elite Member Power Poster
    Join Date
    Oct 2002
    Posts
    4,468

    store procedure security issue

    Hello everyone,

    I am not sure whether it is possible to setup a security policy like this with store procedure. The user account foo could only access database through store procedure, not possible to do other operations, like select/update on the tables of the database directly without using the store procedure.

    My store procedure is doing some select/update job. My confusion is, as the user needs to use the store procedure and the store procedure is doing select/update job, then I have to grant the user to have select/update privilege of the database tables? Then the user could skip using the store procedure and select/update database tables directly which causes a security hole. My purpose is to let user use store procedure all the time, no walk around to access database without using store procedure.

    Any advice to solve my probleme?

    thanks in advance,
    George

  2. #2
    Join Date
    Feb 2007
    Location
    Craiova, Romania
    Posts
    326

    Re: store procedure security issue

    See this article (user impersonation):
    http://www.mssqltips.com/tip.asp?tip=1579
    Something like:
    Code:
    ...
    EXECUTE AS 'UserWithSelectPermission"
    --do select statement(s) here
    REVERT
    ...
    Your user must have only the EXECUTE permission on the database.
    Last edited by marceln; December 26th, 2008 at 06:40 AM.

  3. #3
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: store procedure security issue

    Quote Originally Posted by George2 View Post
    Hello everyone,

    I am not sure whether it is possible to setup a security policy like this with store procedure. The user account foo could only access database through store procedure, not possible to do other operations, like select/update on the tables of the database directly without using the store procedure.

    My store procedure is doing some select/update job. My confusion is, as the user needs to use the store procedure and the store procedure is doing select/update job, then I have to grant the user to have select/update privilege of the database tables? Then the user could skip using the store procedure and select/update database tables directly which causes a security hole. My purpose is to let user use store procedure all the time, no walk around to access database without using store procedure.

    Any advice to solve my probleme?

    thanks in advance,
    George
    IF the user has EXECUTE permission on the stored procedure..AND the stored procedure does NOT have any dynamic SQL; then the user should NOT need rights directly to the table (The OWNER of the stored procedure does...)
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  4. #4
    George2 is offline Elite Member Power Poster
    Join Date
    Oct 2002
    Posts
    4,468

    Re: store procedure security issue

    Thanks TheCPUWizard,

    I have tested your idea. But met with a issue.

    I created a new user which is using SQL Server authentication type. The user default database is AdventureWorks. I grant the user rights of execute one store procedure of AdventureWorks (the store procedure is used to query some specific table) and denied the select rights of the user to select the specific table directly (using table, permission, deny select permission in management sonsole).

    But when I tried to use the user to login the management console (in order to test with execution of the store procedure and the select statement), I met with the following error when click login from management console. Do you have any ideas why?


    TITLE: Connect to Server
    ------------------------------

    Cannot connect to ..

    ------------------------------
    ADDITIONAL INFORMATION:

    A connection was successfully established with the server, but then an error occurred during the login process. (provider: Shared Memory Provider, error: 0 - No process is on the other end of the pipe.) (Microsoft SQL Server, Error: 233)

    For help, click: http://go.microsoft.com/fwlink?ProdN...3&LinkId=20476

    ------------------------------
    BUTTONS:

    OK
    ------------------------------

    Quote Originally Posted by TheCPUWizard View Post
    IF the user has EXECUTE permission on the stored procedure..AND the stored procedure does NOT have any dynamic SQL; then the user should NOT need rights directly to the table (The OWNER of the stored procedure does...)
    regards,
    George

  5. #5
    George2 is offline Elite Member Power Poster
    Join Date
    Oct 2002
    Posts
    4,468

    Re: store procedure security issue

    Thanks marceln,

    I read your recommended document, but I think it is not what I am asking for, actually my requirement is, I want to have a low privilege user and open the user to some 3rd party and then the 3rd party could only use the specific user to do some low privilege operations, like execute a specific store procedure and no access to direct write statement in ADO.Net to connect to my database and query the table. Any comments or ideas?

    Quote Originally Posted by marceln View Post
    See this article (user impersonation):
    http://www.mssqltips.com/tip.asp?tip=1579
    Something like:
    Code:
    ...
    EXECUTE AS 'UserWithSelectPermission"
    --do select statement(s) here
    REVERT
    ...
    Your user must have only the EXECUTE permission on the database.
    regards,
    George

  6. #6
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: store procedure security issue

    ADDITIONAL INFORMATION:

    A connection was successfully established with the server, but then an error occurred during the login process. (provider: Shared Memory Provider, error: 0 - No process is on the other end of the pipe.) (Microsoft SQL Server, Error: 233)
    User cannot log in to Management Studio. That is correct.

    You can't test a SP that way.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  7. #7
    George2 is offline Elite Member Power Poster
    Join Date
    Oct 2002
    Posts
    4,468

    Re: store procedure security issue

    Thanks dglienna,

    Quote Originally Posted by dglienna View Post
    User cannot log in to Management Studio. That is correct.

    You can't test a SP that way.
    Two more questions,

    1. who is able to log into management studio? what types of roles?

    2. what is your recommended way to test store procedure?

    regards,
    George

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured