How to determine SQL Security Login group for windows login when user is member of active directory security group.

  • My users login to SQLServer through Active Directory security group memberships.  These groups are security groups in SQLServer and used to assign permissions to database objects.

    My problem is that when I query system_user, current_user, suser_sname and user I get the individual user, not the group they are a member of.

    So where they login in through 'DOMAIN\SecurityGroup' I get back 'DOMAIN\UserName'

    When I try User_ID and user_name I get back the SQLServer role like 'dbo' and 'public'.

    How can I detemine which 'DOMAIN\SecurityGroup' is being used by 'DOMAIN\UserName' to access the database.

     

     

     

     

  • If the user is a member of a DOMAIN\SecurityGroup that has Sysadmin authority in SQL, then that will be used when accessing databases.  Otherwise you need to look at what DOMAIN\SecurityGroup(s) have ben given authority in each database.  If the user is a member of 2 SecurityGroups, with SecGroupA having select authority and SecGroupB having insert authority, then the user can select and insert.

    Original author: https://github.com/SQL-FineBuild/Common/wiki/ 1-click install and best practice configuration of SQL Server 2019, 2017 2016, 2014, 2012, 2008 R2, 2008 and 2005.

    When I give food to the poor they call me a saint. When I ask why they are poor they call me a communist - Archbishop Hélder Câmara

  • Thanks EdVassie, but that does not really address the issue.  I don't have a problem with internal SQL security on objects.

    The issue is the delegated permission from Active Directory.  I want to know the DOMAIN\SecurityGroup with which the DOMAIN\User has gained access to the database.  As a work around I have a mapping table in my database that maps Active Directory users to their groups.  This can be handled by .NET in the front end, but I won't even mention the legacy platform I'm working with here.

    If I know the  DOMAIN\SecurityGroup, which I have used for login and object permissions, then I can query sp_helprotect and determine what permissions the current user has on the object, and hence what controls to enable.  Otherwise I would have to wait for a fail on commit, which would be annoying for the user as they would not know until the end of a process whether it will succeed. 

     

     

  • 2 issues

    1st....can a user belong to more than 1 AD security group...(for different reasons).  Technically I think the answer would be yes....so I think you need to cater for looping through multiple results.

    2nd....you should be looking to build an AD lookup/interface routine to execute this functionaility...I've seen others point to resources for doing such actions....search for "AD, SQL, Lookup/interface" and see if anything useful comes up.  I don't think it's a native SQL "system variable".

  • i've a similar requirement. My server has a really messy security system. there are different domains with different trust level and users are granted access to the SQL server by 1) directly granting access to their domain ids or 2)sometimes through group membership or 3) domain local groups or 4) local groups etc.

    So when ever we have a server migration, there will be some people who complain they had access onthe old server but doesn't have access on the new server. So finally it would come up to determine, how they had permission on the first place.

    So is there an option anywhere in sQL to determine, what are the access levels through which the user have access right now.

  • Yes, a Windows account can be a member of multiple security groups. Yes, Windows security groups can nest within Active Directory. To be honest, as a former directory services administrator, your directory services administrators should be able to provide these mappings to you. There's nothing native within SQL Server that gets it all. Your DS admins should have the tools which do.

    K. Brian Kelley
    @kbriankelley

  • Good question, I was also looking for a query to tell me quickly which grp does a domain\user belongs to, the closest I think is(not a complete answer), xp_logininfo

    EXEC XP_LOGININFO 'domain\groupname','members'

    EXEC XP_LOGININFO 'domain\groupname','all'

    -- let me know if there is another easier way.

  • SQL Secure does a fine job of determining inherited permissions.

    Jeff Bennett

    Saint Louis

  • SQL Secure does a fine job of determining inherited permissions.

    Jeff Bennett

    Saint Louis

  • The xp_logininfo reports the Domain groups (or other valid SQL login) how the user is being granted access.

    https://msdn.microsoft.com/en-us/library/ms190369.aspx

    EXEC xp_logininfo 'BUILTIN\Administrators';

    EXEC xp_logininfo 'Contoso\JSmith'

    Result:

    account nametypeprivilegemapped login namepermission path

    Contoso\JSmithuseradmin Contoso\JSmith Contoso\DBAdmins

  • i've put together this cursor in the past that iterates through all windows groups in SQL, and enumerates their members.

    finally, i account names that were found for admin vs user priviledges.

    i tested this on a server that has no individual windows logins, all logins inherited through groups,and i get the individuals i'm looking for.

    IF OBJECT_ID('[tempdb].[dbo].[#TMP]') IS NOT NULL

    DROP TABLE [dbo].[#TMP]

    CREATE TABLE [dbo].[#TMP] (

    [ACCOUNT NAME] NVARCHAR(256) NULL ,

    [TYPE] VARCHAR(8) NULL ,

    [PRIVILEGE] VARCHAR(8) NULL ,

    [MAPPED LOGIN NAME] NVARCHAR(256) NULL ,

    [PERMISSION PATH] NVARCHAR(256) NULL )

    USE MASTER

    declare

    @isql varchar(2000),

    @name varchar(64)

    declare c1 cursor for

    select name FROM master.sys.server_principals

    WHERE type_desc = 'WINDOWS_GROUP'

    AND name NOT LIKE '%$%'

    AND name not like 'NT SERVICE\%'

    open c1

    fetch next from c1 into @name

    While @@fetch_status <> -1

    begin

    select @isql = 'INSERT INTO #TMP EXEC master..xp_logininfo @acctname = ''' + @name +''',@option = ''members'' '

    print @isql

    exec(@isql)

    fetch next from c1 into @name

    end

    close c1

    deallocate c1

    SELECT * FROM #tmp

    --SELECT IS_SRVROLEMEMBER('sysadmin',[Account Name]),* FROM #tmp

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

Viewing 11 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic. Login to reply