Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check who has access to symmetric keys in SQL Server

I would like to know all the users that have access to symmetric keys and the type of access they have. Can you please let me know how I can do this?

like image 725
user3229801 Avatar asked Feb 12 '23 17:02

user3229801


2 Answers

The answers above do not actually reflect the Object Name, please consider this instead:

select
      [database] = db_name()
    , u.name
    , p.permission_name
    , p.class
    , p.class_desc
    , ObjectNameForObjectORColumn
        = object_name(p.major_id) 
    , objectNameActual
        = case class_desc
            when 'SYMMETRIC_KEYS' then sm.name              
            when 'CERTIFICATE' then [cert].name             
      end
    , state_desc 
from sys.database_permissions  p 
inner join sys.database_principals u
    on p.grantee_principal_id = u.principal_id
left outer join sys.symmetric_keys sm
    on p.major_id = sm.symmetric_key_id
    and p.class_desc = 'SYMMETRIC_KEYS'
left outer join sys.certificates [cert]
    on p.major_id = [cert].[certificate_id]
    and p.class_desc = 'CERTIFICATE'
where class_desc in('SYMMETRIC_KEYS', 'CERTIFICATE')
order by u.name

More here https://danieladeniji.wordpress.com/2015/10/09/sql-server-list-permissions-for-user/

like image 137
Daniel Adeniji Avatar answered Feb 15 '23 09:02

Daniel Adeniji


Maybe this query can help:

select u.name, p.permission_name, p.class_desc, 
    object_name(p.major_id) ObjectName, state_desc 
from sys.database_permissions  p join sys.database_principals u
on p.grantee_principal_id = u.principal_id
where class_desc = 'SYMMETRIC_KEYS'
like image 45
Dusan Avatar answered Feb 15 '23 09:02

Dusan