Showing posts with label permissions. Show all posts
Showing posts with label permissions. Show all posts

Wednesday, March 28, 2012

Row-level Security: Permissions required on base table?

I'm implementing row-level security in a SQL Server database that uses Microsoft Access for the front end. I'm using a UDF (a view behaves the same way) to restrict access to specific rows of a base table based on membership in a role. According to the reading I've done, if the base table has DENY ALL permissions for the role, and the UDF has GRANT ALL, members of the role should be able to update records in the base table via the UDF, without having direct access to the base table. However, I find that unless I grant appropriate permissions on the base table, the user is unable to update the table via the UDF.

Is this expected behavior? Nothing I've read suggests I should have to grant permissions on the columns of the base table.

Yes, that is expected behavior.

Permissions in SQL Server have three values: GRANT, DENY, or 'unsaid'.

If you have been GRANTed permission for a table, obviously you have permission.

If your permission is 'unsaid', then you 'may' still have permission due to permission having been granted to another role that includes you.

But IF you have been explicited DENY(ied), that 'trumps' all.

Think of it this way.

Children have a knack of knowing how to 'scope out' their parents. Perhaps a son wants to go out with friends. He may approach Mom and 'feel her out' to find out if she 'might' say yes WITHOUT directly asking her. He knows that if he asks her and she says 'No', his plans are shot because he cannot then go and ask Dad (DENY). So he will attempt to find out if it is 'safe' to ask her. If it seems safe, he will ask and he's 'home free' (GRANT).

However, if he feels that she would probably say No, then without having asked, he is now free to ask Dad. So Mom was 'unsaid', if permission can be had by another route, it will work for him.

So anytime permission is an explicit DENY, there is no route around it.

Often, in a strong SQL Server security model, TABLE permissions are left 'unsaid', and access is GRANTed through VIEWS, Functions, and Stored Procedures. Users are also added to the db_DenyDataReader and db_DenyDataWriter roles to prohibit them having direct table access.

|||

Thanks for responding.

Ah, yes, that's what I thought. But if I leave the permissions on the base table "unsaid", and grant all on the UDF, Access tells me that the recordset is not updatable (maybe because it can't "see" the PK column?). So I'm back to having to grant permissions in the base table, which is unacceptable.

I read through the good whitepaper on row-level security by Rask, Rubin and Neumann. The architecture they propose is great, but overkill for what I need to do. Nevertheless, I set up a test using their methodology: DENY ALL on the base table, GRANT ALL on a view, and put an INSTEAD OF trigger on the view to verify appropriate access and perform an update. But because Access thinks the recordset isn't updatable, the trigger never fires. If I grant SELECT permissions to just the PK column of the base table, Access thinks the recordset is updatable, but I still can't get the trigger to fire because Access wants at least SELECT permissions on the other base table columns before it will even try to perform the update.

|||

I would suggest the following topics from BOL:

· CREATE VIEW (http://msdn2.microsoft.com/en-us/library/ms187956.aspx), got to the section Updatable Views

· Modifying Data Through a View (http://msdn2.microsoft.com/en-us/library/ms180800.aspx)

I hope this information helps,

-Raul Garcia

SDE/T

SQL Server Engine

|||

In addition to Raul's suggestions, I offer the following insight.

Access will allow you to UPDATE or DELETE a row without the table having a primary key (or some unique identifier.)

SQL Server does NOT allow UPDATES or DELETES unless there is a unambiguous way to be certain what row is being addressed. If the VIEW does not include a PK, or unique identifier, it would not be updatable.

|||Thanks for the references, I'll read through them and see where they lead. I note that these are from SQL Server 2005 BOL, and the server that must host the application I'm working with is SQL Server 2000 SP4. I'm just wondering whether you know whether the support for updatable views changed between SQL 2000 and 2005?|||

As far as I understand, updatable views should be supported in SQL Server 2000 SP4, but I am not 100% sure if all the documentation in the links I included may apply to SQL Server 2000 SP4 as well.

I would recommend trying to find the same topic in BOL fro SQL Server 2000 and giving it a try; if you have any further questions please let us know, we will be glad to help.

Thanks,

-Raul Garcia

SDE/T

SQL Server Engine

|||

Thanks to both you and Arnie for responding to this inquiry.

The problem turns out to have been an interaction between SQL Server and Access. In order for Access to update a SQL Server view, the view must be declared the WITH VIEW_METADATA option. If designing the view in Access, this is accomplished by checking the view option "Update using view rules" on the properties page. Once I did this, I was able to DENY ALL on the base table and GRANT ALL on the view, and the view was updatable via Access with appropriate security.

I ran a SQL Profiler trace to see what Access was sending to SQL Server when the option was properly set--it showed that the UPDATE statement Access generated was against the view, not the base tables. Without using the VIEW_METADATA option, Access does not consider the recordset updatable (hence my original question), so it doesn't generate an UPDATE statement. So I couldn't run a trace to see what happens in that case. I expect that if I could, the UPDATE would be going against the base table rather than the view.

Again, thanks for your help.

Row-level Security: Permissions required on base table?

I'm implementing row-level security in a SQL Server database that uses Microsoft Access for the front end. I'm using a UDF (a view behaves the same way) to restrict access to specific rows of a base table based on membership in a role. According to the reading I've done, if the base table has DENY ALL permissions for the role, and the UDF has GRANT ALL, members of the role should be able to update records in the base table via the UDF, without having direct access to the base table. However, I find that unless I grant appropriate permissions on the base table, the user is unable to update the table via the UDF.

Is this expected behavior? Nothing I've read suggests I should have to grant permissions on the columns of the base table.

Yes, that is expected behavior.

Permissions in SQL Server have three values: GRANT, DENY, or 'unsaid'.

If you have been GRANTed permission for a table, obviously you have permission.

If your permission is 'unsaid', then you 'may' still have permission due to permission having been granted to another role that includes you.

But IF you have been explicited DENY(ied), that 'trumps' all.

Think of it this way.

Children have a knack of knowing how to 'scope out' their parents. Perhaps a son wants to go out with friends. He may approach Mom and 'feel her out' to find out if she 'might' say yes WITHOUT directly asking her. He knows that if he asks her and she says 'No', his plans are shot because he cannot then go and ask Dad (DENY). So he will attempt to find out if it is 'safe' to ask her. If it seems safe, he will ask and he's 'home free' (GRANT).

However, if he feels that she would probably say No, then without having asked, he is now free to ask Dad. So Mom was 'unsaid', if permission can be had by another route, it will work for him.

So anytime permission is an explicit DENY, there is no route around it.

Often, in a strong SQL Server security model, TABLE permissions are left 'unsaid', and access is GRANTed through VIEWS, Functions, and Stored Procedures. Users are also added to the db_DenyDataReader and db_DenyDataWriter roles to prohibit them having direct table access.

|||

Thanks for responding.

Ah, yes, that's what I thought. But if I leave the permissions on the base table "unsaid", and grant all on the UDF, Access tells me that the recordset is not updatable (maybe because it can't "see" the PK column?). So I'm back to having to grant permissions in the base table, which is unacceptable.

I read through the good whitepaper on row-level security by Rask, Rubin and Neumann. The architecture they propose is great, but overkill for what I need to do. Nevertheless, I set up a test using their methodology: DENY ALL on the base table, GRANT ALL on a view, and put an INSTEAD OF trigger on the view to verify appropriate access and perform an update. But because Access thinks the recordset isn't updatable, the trigger never fires. If I grant SELECT permissions to just the PK column of the base table, Access thinks the recordset is updatable, but I still can't get the trigger to fire because Access wants at least SELECT permissions on the other base table columns before it will even try to perform the update.

|||

I would suggest the following topics from BOL:

· CREATE VIEW (http://msdn2.microsoft.com/en-us/library/ms187956.aspx), got to the section Updatable Views

· Modifying Data Through a View (http://msdn2.microsoft.com/en-us/library/ms180800.aspx)

I hope this information helps,

-Raul Garcia

SDE/T

SQL Server Engine

|||

In addition to Raul's suggestions, I offer the following insight.

Access will allow you to UPDATE or DELETE a row without the table having a primary key (or some unique identifier.)

SQL Server does NOT allow UPDATES or DELETES unless there is a unambiguous way to be certain what row is being addressed. If the VIEW does not include a PK, or unique identifier, it would not be updatable.

|||Thanks for the references, I'll read through them and see where they lead. I note that these are from SQL Server 2005 BOL, and the server that must host the application I'm working with is SQL Server 2000 SP4. I'm just wondering whether you know whether the support for updatable views changed between SQL 2000 and 2005?|||

As far as I understand, updatable views should be supported in SQL Server 2000 SP4, but I am not 100% sure if all the documentation in the links I included may apply to SQL Server 2000 SP4 as well.

I would recommend trying to find the same topic in BOL fro SQL Server 2000 and giving it a try; if you have any further questions please let us know, we will be glad to help.

Thanks,

-Raul Garcia

SDE/T

SQL Server Engine

|||

Thanks to both you and Arnie for responding to this inquiry.

The problem turns out to have been an interaction between SQL Server and Access. In order for Access to update a SQL Server view, the view must be declared the WITH VIEW_METADATA option. If designing the view in Access, this is accomplished by checking the view option "Update using view rules" on the properties page. Once I did this, I was able to DENY ALL on the base table and GRANT ALL on the view, and the view was updatable via Access with appropriate security.

I ran a SQL Profiler trace to see what Access was sending to SQL Server when the option was properly set--it showed that the UPDATE statement Access generated was against the view, not the base tables. Without using the VIEW_METADATA option, Access does not consider the recordset updatable (hence my original question), so it doesn't generate an UPDATE statement. So I couldn't run a trace to see what happens in that case. I expect that if I could, the UPDATE would be going against the base table rather than the view.

Again, thanks for your help.

sql

Tuesday, March 20, 2012

row level permissions

is there a simple procedure to run to find what the row level permissions are on each user?

thanks.

I am not clear with the requirement. There is no row level permission in sql server if its refering to Table rows. You can give table level permission or you can create views as per the conditions and give permission to views.

Madhu

|||I should clearify. I'm looing for table level permissions. I assume there is a simple procedure to run to find this information for each user.|||

Take a look at the INFORMATION_SCHEMA.TABLE_PRIVILEGES view. This might provide the detail you're looking for.

HTH!

|||

or you can use sp_helprotect /sys.database_permissions and fn_builtin_permissions to get the permission on objects.

Read about

SP_HELPROTECT/sys.database_permissions (sql server 2005) in BOL

Madhu

Row level permissions

Does SQL Server 2000 have support for row level permissions?
DenisDenis,
not directly, but this can be mimiced by using view based security and the
with check option.
Regards,
Paul Ibison|||Hi,
Row level security can not be set directly, Have a look inthe below article.
es.htm" target="_blank">http://vyaskn.tripod.com/ row_level...as
es.htm
Thanks
Hari
MCDBA
"Denis Crotty" <anonymous@.discussions.microsoft.com> wrote in message
news:A669D750-7E3F-473A-8A86-F17D1C222A3C@.microsoft.com...
> Does SQL Server 2000 have support for row level permissions?
> Denis|||Wow. The database I'm designing is fairly large I think, 40+ tables. So I'
m looking at adding a user column for every table and then creating views an
d stored procedures for every type of access to these tables? Or am I not u
nderstanding the article?
Denis|||Can you point me to a good reference?
Denis|||Denis,
Hari's (Vyas's) reference is a good one. If you want to relate the
SUSER_SNAME() function to something business related (rather than creating
columns on each table with usernames), you could use a UDF in the view which
takes the SESER_SNAME() scalar value as an argument. Using a UDF and another
table will also allow a one-to-many relationship to be established (eg if
user JoeBloggs maps to two cities and you want a view on a sales table which
needs to be partitioned according to user and city).
HTH,
Paul Ibison|||Denis,
please see my reply above.
HTH,
Paul Ibison|||Thanks for the reply,
I'm sorry, it must be like talking to a wall but I'm not really understandin
g what you mean. What is SESER_SNAME()?
The database I have is functionally like the article described. I have mult
iple users submitting the same type of data, but when they later want to vie
w it they are not allowed to see anyones but their own. They want it set up
centralized, because noone
wants to have to hire a DBA. The data they enter gets placed in the appropr
iate tables, as I mentioned there are 40+ table (does that constitute a larg
e database structure?). I'm unclear whether we are talking about creating a
view for every table alon
g with SP's for inserts, updates and deletes, or if I'm misunderstanding.
Sorry, if you can help me clear this up it would be greatly appreciated,
Denis|||Denis,
SUSER_SNAME() returns the login which can be mapped to a column in each
table. Yes, you'll need a view on each table if you need row-level security
on each table. However, you don't necessarily need an extra column on the
table which is populated with loginnames. This is the easiest way, but if
you use a UDF, you can transform the login into something business related.
The view in this case would be
select col1, col2...
from table1
where colx = dbo.myudf(suser_sname())
As far as the sps are concerned, you could code in a check to suser_sname()
to verify that the user can do the appropriate action, or more simply just
access the view from the stored procedure. If the view is created using WITH
CHECK, they can't do an invalid insert. Updates and deletes will only apply
to rows accessed through the view, which must be valid anyway.
HTH,
Paul Ibison|||Thanks Paul,
Your help saved me hours of redesign down the road.
Denis

Row level and column level permissions.

Dear All,
Any recommendations on best practices for implementing row level and column level permissions in an SQL server database. I did some googling and i could find some recommendations for implementing row level permissions.(I am aware that Yukon is going to ha
ve this feature built-in, am using SQL 2k). All of them were seemed to be specific to applications.
Regarding column level security what concerns me is that, i want this to be applicable for my reporting tool(either crystal or sql reporting services).
Thanks in advance.
regards
Arun
You could use roles and have different views based on the columns you want
each role to see?
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/
"Arun" <ar_kumar@.hotmail.com> wrote in message
news:0C4D56B1-7357-45D1-8EF4-FAE3E8FD5A29@.microsoft.com...
> Dear All,
> Any recommendations on best practices for implementing row level and
column level permissions in an SQL server database. I did some googling and
i could find some recommendations for implementing row level permissions.(I
am aware that Yukon is going to have this feature built-in, am using SQL
2k). All of them were seemed to be specific to applications.
> Regarding column level security what concerns me is that, i want this to
be applicable for my reporting tool(either crystal or sql reporting
services).
> Thanks in advance.
> regards
> Arun
|||Hi i did consider this option, i am worried if i have too many users and too many roles?
|||Maybe the problem is the number of columns? I can understand how you can
have a lot of users, but why would you need a lot of different roles unless
you have 18 billion columns and need a role for every single permutation?
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/
"Arun" <ar_kumar@.hotmail.com> wrote in message
news:0618401B-03CB-422A-9EBF-1309E459D21D@.microsoft.com...
> Hi i did consider this option, i am worried if i have too many users and
too many roles?
|||Hi
Thanks for your reply.I am not considering direct sql statements to come from anywhere. I meant all the access will be restricted using sp's. I have to consider reporting also. where a report (crystal mostly) will read directly from an sp to produce repor
ts. Do you have any links that tells about implementing column level permissions.
Thanks in advance
regards
Arun

Row level and column level permissions.

Dear All,
Any recommendations on best practices for implementing row level and column
level permissions in an SQL server database. I did some googling and i could
find some recommendations for implementing row level permissions.(I am awar
e that Yukon is going to ha
ve this feature built-in, am using SQL 2k). All of them were seemed to be sp
ecific to applications.
Regarding column level security what concerns me is that, i want this to be
applicable for my reporting tool(either crystal or sql reporting services).
Thanks in advance.
regards
ArunYou could use roles and have different views based on the columns you want
each role to see?
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/
"Arun" <ar_kumar@.hotmail.com> wrote in message
news:0C4D56B1-7357-45D1-8EF4-FAE3E8FD5A29@.microsoft.com...
> Dear All,
> Any recommendations on best practices for implementing row level and
column level permissions in an SQL server database. I did some googling and
i could find some recommendations for implementing row level permissions.(I
am aware that Yukon is going to have this feature built-in, am using SQL
2k). All of them were seemed to be specific to applications.
> Regarding column level security what concerns me is that, i want this to
be applicable for my reporting tool(either crystal or sql reporting
services).
> Thanks in advance.
> regards
> Arun|||Hi i did consider this option, i am worried if i have too many users and too
many roles?|||Maybe the problem is the number of columns? I can understand how you can
have a lot of users, but why would you need a lot of different roles unless
you have 18 billion columns and need a role for every single permutation?
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/
"Arun" <ar_kumar@.hotmail.com> wrote in message
news:0618401B-03CB-422A-9EBF-1309E459D21D@.microsoft.com...
> Hi i did consider this option, i am worried if i have too many users and
too many roles?|||Hi
Thanks for your reply.I am not considering direct sql statements to come fro
m anywhere. I meant all the access will be restricted using sp's. I have to
consider reporting also. where a report (crystal mostly) will read directly
from an sp to produce repor
ts. Do you have any links that tells about implementing column level permiss
ions.
Thanks in advance
regards
Arun

Row level and column level permissions.

Dear All
Any recommendations on best practices for implementing row level and column level permissions in an SQL server database. I did some googling and i could find some recommendations for implementing row level permissions.(I am aware that Yukon is going to have this feature built-in, am using SQL 2k). All of them were seemed to be specific to applications
Regarding column level security what concerns me is that, i want this to be applicable for my reporting tool(either crystal or sql reporting services)
Thanks in advance
regard
ArunYou could use roles and have different views based on the columns you want
each role to see?
--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/
"Arun" <ar_kumar@.hotmail.com> wrote in message
news:0C4D56B1-7357-45D1-8EF4-FAE3E8FD5A29@.microsoft.com...
> Dear All,
> Any recommendations on best practices for implementing row level and
column level permissions in an SQL server database. I did some googling and
i could find some recommendations for implementing row level permissions.(I
am aware that Yukon is going to have this feature built-in, am using SQL
2k). All of them were seemed to be specific to applications.
> Regarding column level security what concerns me is that, i want this to
be applicable for my reporting tool(either crystal or sql reporting
services).
> Thanks in advance.
> regards
> Arun|||Maybe the problem is the number of columns? I can understand how you can
have a lot of users, but why would you need a lot of different roles unless
you have 18 billion columns and need a role for every single permutation?
--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/
"Arun" <ar_kumar@.hotmail.com> wrote in message
news:0618401B-03CB-422A-9EBF-1309E459D21D@.microsoft.com...
> Hi i did consider this option, i am worried if i have too many users and
too many roles?