SQL Server用户权限审核

时间:2017-02-10 06:43:06

标签: sql sql-server sql-server-2008 sql-server-2012 database-administration

以下是可能的SQL服务器dba

的要求

想出一些流程来审核谁有权访问什么。可能包括:

1)服务器登录

2)本地管理员

3)SQL服务器级角色,尤其是sysadmin

4)数据库dbo,读者,作家

5)master,msdb access

6)来自用户帐户的链接服务器使用

7)明确的公共补助金 等

有人可以提供我如何实现上述

谢谢, SREE

2 个答案:

答案 0 :(得分:1)

您需要使用系统表/视图。其中一个主要表(实际上是一个视图)将是[master].[sys].[server_principals],用户将被找到。

您还会发现[master].[sys].[server_permissions]有用,因为它有权限,[master].[sys].[server_role_members]您可以找到角色。您可以在此处找到数据库[master].[sys].[sysdatabases]

记下与用户相关的principalid。

同样在每个数据库中,您都可以找到[Table].[sys].[sysusers][Table].[sys].[syslogins]

等观点

您必须自己完成工作才能获得所需的应用程序。您可以在线查找有关上表的大量信息。

答案 1 :(得分:0)

我尝试了自己的问题,下面解决了我的目的

set nocount on
declare @permission table (
Database_Name sysname,
User_Role_Name sysname,
Account_Type nvarchar(60),
Action_Type nvarchar(128),
Permission nvarchar(60),
ObjectName sysname null,
Object_Type nvarchar(60)
)
declare @dbs table (dbname sysname)
declare @Next sysname
insert into @dbs
select name from sys.databases order by name
select top 1 @Next = dbname from @dbs
while (@@rowcount<>0)
begin
insert into @permission
exec('use [' + @Next + ']
declare @objects table (obj_id int, obj_type char(2))
insert into @objects
select id, xtype from master.sys.sysobjects
insert into @objects
select object_id, type from sys.objects

SELECT ''' + @Next + ''', a.name as ''User or Role Name'', a.type_desc as ''Account Type'',
d.permission_name as ''Type of Permission'', d.state_desc as ''State of Permission'',
OBJECT_SCHEMA_NAME(d.major_id) + ''.'' + object_name(d.major_id) as ''Object Name'',
case e.obj_type
when ''AF'' then ''Aggregate function (CLR)''
when ''C'' then ''CHECK constraint''
when ''D'' then ''DEFAULT (constraint or stand-alone)''
when ''F'' then ''FOREIGN KEY constraint''
when ''PK'' then ''PRIMARY KEY constraint''
when ''P'' then ''SQL stored procedure''
when ''PC'' then ''Assembly (CLR) stored procedure''
when ''FN'' then ''SQL scalar function''
when ''FS'' then ''Assembly (CLR) scalar function''
when ''FT'' then ''Assembly (CLR) table-valued function''
when ''R'' then ''Rule (old-style, stand-alone)''
when ''RF'' then ''Replication-filter-procedure''
when ''S'' then ''System base table''
when ''SN'' then ''Synonym''
when ''SQ'' then ''Service queue''
when ''TA'' then ''Assembly (CLR) DML trigger''
when ''TR'' then ''SQL DML trigger''
when ''IF'' then ''SQL inline table-valued function''
when ''TF'' then ''SQL table-valued-function''
when ''U'' then ''Table (user-defined)''
when ''UQ'' then ''UNIQUE constraint''
when ''V'' then ''View''
when ''X'' then ''Extended stored procedure''
when ''IT'' then ''Internal table''
end as ''Object Type''
FROM [' + @Next + '].sys.database_principals a 
left join [' + @Next + '].sys.database_permissions d on a.principal_id = d.grantee_principal_id
left join @objects e on d.major_id = e.obj_id
order by a.name, d.class_desc')
delete @dbs where dbname = @Next
select top 1 @Next = dbname from @dbs
end
set nocount off
select * from @permission