Results 1 to 8 of 8

Thread: SQL server running stored proc as different user

  1. #1

    Thread Starter
    Frenzied Member Fishcake's Avatar
    Join Date
    Feb 2001
    Location
    Derby, UK
    Posts
    1,092

    SQL server running stored proc as different user

    Sorry I couldn't come up with a title that encapsulates my question so....

    I don't think this is possible but figured it was worth a try:
    Is it possible for a user to run a stored procedure that drops a table when they themselves don't have permission to drop that table?

    Cheers.

  2. #2
    Hyperactive Member
    Join Date
    Feb 2006
    Location
    Philippines
    Posts
    468

    Re: SQL server running stored proc as different user

    it will run if you have permission onthe stored procedure but it will prompt an error

  3. #3
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: SQL server running stored proc as different user

    Quote Originally Posted by mikee_phil
    it will run if you have permission onthe stored procedure but it will prompt an error
    Are you really sure about that?

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  4. #4
    Fanatic Member kaffenils's Avatar
    Join Date
    Apr 2004
    Location
    Norway
    Posts
    946

    Re: SQL server running stored proc as different user

    Quote Originally Posted by Fishcake
    Sorry I couldn't come up with a title that encapsulates my question so....

    I don't think this is possible but figured it was worth a try:
    Is it possible for a user to run a stored procedure that drops a table when they themselves don't have permission to drop that table?

    Cheers.
    When executing a stored procedure on SQL Server 2000 you execute it with the permissions of the owner. If the owner has permissions to delete the table then there should be no problem for you to execute the procedure that deletes that table even though you don't have explicit permissions to delete it.

    On SQL Server 2005 it is different. You can define whos permsissions should be used when executing a stored procedure.

  5. #5
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: SQL server running stored proc as different user

    So, since all our SPROCS are owned by DBO - they have full rights to do whatever they want - right?

    We only ever give EXEC permission to users for our SPROCS...

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  6. #6
    Fanatic Member kaffenils's Avatar
    Join Date
    Apr 2004
    Location
    Norway
    Posts
    946

    Re: SQL server running stored proc as different user

    Quote Originally Posted by szlamany
    So, since all our SPROCS are owned by DBO - they have full rights to do whatever they want - right?

    We only ever give EXEC permission to users for our SPROCS...
    Yes. User permissions are overridden by stored procedures, even explicit DENYs, but only within the database where the sproc exists. If the sproc accesses data from another database,n then the user will need explicit permissions to these data.

  7. #7
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: SQL server running stored proc as different user

    So, since all our SPROCS are owned by DBO - they have full rights to do whatever they want - right?
    No, not whatever they want (they being the stored procedure). You cannot execute statements, on behalf of users, that create database items (like Tables, Rules, Views) or statements that are only granted to predefined roles (such as Drop Table).

  8. #8
    Fanatic Member kaffenils's Avatar
    Join Date
    Apr 2004
    Location
    Norway
    Posts
    946

    Re: SQL server running stored proc as different user

    Quote Originally Posted by brucevde
    No, not whatever they want (they being the stored procedure). You cannot execute statements, on behalf of users, that create database items (like Tables, Rules, Views) or statements that are only granted to predefined roles (such as Drop Table).
    You are right and I am wrong . Permissions defined by predefined roles, like DDL rights, are not inherited, so CREATE and DROP statements would require the user to be member of the db_ddladmin role.

    Permission inheritance are explained in BOL if you look at "ownership chains".
    Last edited by kaffenils; Aug 15th, 2006 at 12:53 AM.

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