Domain Admin Account Accessing SQL ServerSQL Server 2008 R2 recognizes a domain account as a SQL Server accountPreferred Methods of Indexing MS SQL Server Audit Data to SplunkSysAdmin server role and Active Directory GroupsWhat are the risks (if any) of sharing a service account on more than one server?Security for SSIS packages in SQL Server - use a domain account?Grant Admin to an Active Directory account in SQL ServerSQL Server Service Account Configuration - one account per Server?SQL Server Express 2012 SP1 let me log in, but shouldn't haveWhy use domain account for SQL Server service?How do I add read/write permissions on a directory for an SQL Server account

What are the odds of rolling specific ability score totals in D&D?

Why aren't rockets built with truss structures inside their fuel & oxidizer tanks to increase structural strength?

Doesn't the speed of light limit imply the same electron can be annihilated twice?

What are the advantages of this gold finger shape?

What is the hottest thing in the universe?

Are there examples in Tanach of 3 or more parties having an ongoing conversation?

Telephone number in spoken words

Is it OK to draw different current from L1 and L2 on NEMA 14-50?

Do I have to cite common CS algorithms?

Did DOS zero out the BSS area when it loaded a program?

Global BGP Routing only by only importing supernet prefixes

What is the prop for Thor's hammer made of?

Causal Diagrams using Wolfram?

Is it really Security Misconfiguration to show a version number?

How come the Rambam forbids picking up money found in the street?

Bringing Power Supplies on Plane?

What can Amex do if I cancel their card after using the sign up bonus miles?

How can I find an old paper when the usual methods fail?

Running code generated in realtime in JavaScript with eval()

Why aren't rainbows blurred-out into nothing after they are produced?

What should we do with manuals from the 80s?

Help, I cannot decide when to start the story

How does the Athlete Feat affect the Ravnica Centaur playable race?

What would it take to get a message to another star?



Domain Admin Account Accessing SQL Server


SQL Server 2008 R2 recognizes a domain account as a SQL Server accountPreferred Methods of Indexing MS SQL Server Audit Data to SplunkSysAdmin server role and Active Directory GroupsWhat are the risks (if any) of sharing a service account on more than one server?Security for SSIS packages in SQL Server - use a domain account?Grant Admin to an Active Directory account in SQL ServerSQL Server Service Account Configuration - one account per Server?SQL Server Express 2012 SP1 let me log in, but shouldn't haveWhy use domain account for SQL Server service?How do I add read/write permissions on a directory for an SQL Server account






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








2















I was monitoring some SQL calls using SQL Server Profiler and noticed a Domain Admin account accessing SQL quite a bit. We do not have a DBA at this point. There are two developers and I am one of them. Is this a bad practice and/or a security risk? I ask because the latest rash of ransomware attacks have a strong emphasis on hijacking Domain Admin account privileges so I am concerned.










share|improve this question



















  • 1





    Is the said domain admin AD account (assuming an individual user) also sysadmin on sql server? If so, then sure it's a risk that can be mitigated by only using a sql authenitcation account for sysadmin.

    – scsimon
    Aug 2 at 15:28












  • @Piotr I totally agree. I am trying to do what I can with the resources that we have in the meantime.

    – Bill Greer
    Aug 2 at 15:34






  • 1





    Brent Ozar just did a nice series that may help. Security was week 5.

    – scsimon
    Aug 2 at 15:37






  • 3





    @scsimon I just noticed that all domain users are sysadmins. Oh lord help us!

    – Bill Greer
    Aug 2 at 15:37

















2















I was monitoring some SQL calls using SQL Server Profiler and noticed a Domain Admin account accessing SQL quite a bit. We do not have a DBA at this point. There are two developers and I am one of them. Is this a bad practice and/or a security risk? I ask because the latest rash of ransomware attacks have a strong emphasis on hijacking Domain Admin account privileges so I am concerned.










share|improve this question



















  • 1





    Is the said domain admin AD account (assuming an individual user) also sysadmin on sql server? If so, then sure it's a risk that can be mitigated by only using a sql authenitcation account for sysadmin.

    – scsimon
    Aug 2 at 15:28












  • @Piotr I totally agree. I am trying to do what I can with the resources that we have in the meantime.

    – Bill Greer
    Aug 2 at 15:34






  • 1





    Brent Ozar just did a nice series that may help. Security was week 5.

    – scsimon
    Aug 2 at 15:37






  • 3





    @scsimon I just noticed that all domain users are sysadmins. Oh lord help us!

    – Bill Greer
    Aug 2 at 15:37













2












2








2








I was monitoring some SQL calls using SQL Server Profiler and noticed a Domain Admin account accessing SQL quite a bit. We do not have a DBA at this point. There are two developers and I am one of them. Is this a bad practice and/or a security risk? I ask because the latest rash of ransomware attacks have a strong emphasis on hijacking Domain Admin account privileges so I am concerned.










share|improve this question














I was monitoring some SQL calls using SQL Server Profiler and noticed a Domain Admin account accessing SQL quite a bit. We do not have a DBA at this point. There are two developers and I am one of them. Is this a bad practice and/or a security risk? I ask because the latest rash of ransomware attacks have a strong emphasis on hijacking Domain Admin account privileges so I am concerned.







sql-server security






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Aug 2 at 14:58









Bill GreerBill Greer

1315 bronze badges




1315 bronze badges










  • 1





    Is the said domain admin AD account (assuming an individual user) also sysadmin on sql server? If so, then sure it's a risk that can be mitigated by only using a sql authenitcation account for sysadmin.

    – scsimon
    Aug 2 at 15:28












  • @Piotr I totally agree. I am trying to do what I can with the resources that we have in the meantime.

    – Bill Greer
    Aug 2 at 15:34






  • 1





    Brent Ozar just did a nice series that may help. Security was week 5.

    – scsimon
    Aug 2 at 15:37






  • 3





    @scsimon I just noticed that all domain users are sysadmins. Oh lord help us!

    – Bill Greer
    Aug 2 at 15:37












  • 1





    Is the said domain admin AD account (assuming an individual user) also sysadmin on sql server? If so, then sure it's a risk that can be mitigated by only using a sql authenitcation account for sysadmin.

    – scsimon
    Aug 2 at 15:28












  • @Piotr I totally agree. I am trying to do what I can with the resources that we have in the meantime.

    – Bill Greer
    Aug 2 at 15:34






  • 1





    Brent Ozar just did a nice series that may help. Security was week 5.

    – scsimon
    Aug 2 at 15:37






  • 3





    @scsimon I just noticed that all domain users are sysadmins. Oh lord help us!

    – Bill Greer
    Aug 2 at 15:37







1




1





Is the said domain admin AD account (assuming an individual user) also sysadmin on sql server? If so, then sure it's a risk that can be mitigated by only using a sql authenitcation account for sysadmin.

– scsimon
Aug 2 at 15:28






Is the said domain admin AD account (assuming an individual user) also sysadmin on sql server? If so, then sure it's a risk that can be mitigated by only using a sql authenitcation account for sysadmin.

– scsimon
Aug 2 at 15:28














@Piotr I totally agree. I am trying to do what I can with the resources that we have in the meantime.

– Bill Greer
Aug 2 at 15:34





@Piotr I totally agree. I am trying to do what I can with the resources that we have in the meantime.

– Bill Greer
Aug 2 at 15:34




1




1





Brent Ozar just did a nice series that may help. Security was week 5.

– scsimon
Aug 2 at 15:37





Brent Ozar just did a nice series that may help. Security was week 5.

– scsimon
Aug 2 at 15:37




3




3





@scsimon I just noticed that all domain users are sysadmins. Oh lord help us!

– Bill Greer
Aug 2 at 15:37





@scsimon I just noticed that all domain users are sysadmins. Oh lord help us!

– Bill Greer
Aug 2 at 15:37










3 Answers
3






active

oldest

votes


















5














You could use the following query to provide some quick details about the domain admin:



SELECT des.session_id
, des.host_name
, des.login_time
, des.is_user_process
, des.last_request_start_time
, dest.text
FROM sys.dm_exec_sessions des
INNER JOIN sys.dm_exec_connections dec ON des.session_id = dec.session_id
CROSS APPLY sys.dm_exec_sql_text(dec.most_recent_sql_handle) dest
WHERE des.login_name = N'DOMAINAccountName'


It'll show the name of the client machine where they are connecting from, and the last statement they executed.



In general, you probably want to explicitly control who has access to the SQL Server, especially for security-sensitive accounts such as members of the sysadmin and securityadmin server roles. The principle of least privilege applies.



This query will show you the members of each server-level role:



SELECT spr.name
, spm.name
FROM sys.server_principals spr
INNER JOIN sys.server_role_members srm ON spr.principal_id = srm.role_principal_id
INNER JOIN sys.server_principals spm ON srm.member_principal_id = spm.principal_id
ORDER BY spr.name
, spm.name;


In general, this list should be as small as possible. Pay particular attention to the securityadmin and sysadmin roles.



As an aside, you want to limit the number of people who have access to the Domain Admins AD group since members of that group could restart your SQL Server in such a way that they can gain access to it, even if they haven't been explicitly granted access. There are a lot of security implications to be aware of domain-wide for highly privileged groups such as the Domain Admins.






share|improve this answer


































    2














    There is good information in the two existing answers, and you should follow-up on what they suggest.



    But be aware that in some cases the account might not be actively connecting, we have seen cases where a user who has SSMS open and has a servers listed in their Central Management Servers (CMS), show as connected when if fact they are not actively doing anything on the server, nor are they intentionally connected.



    I looked for documentation of this occurring and why, to reference in this post but I am not finding anything.






    share|improve this answer
































      1














      It's not good idea to have built-in accounts or default security groups i.e. Domain Users, Domain Admins etc.. to have access on SQL Server. Instead, create separate windows account/domain security groups to have access on SQL Server.



      Also, some of best practices as follows, for more details have a look at security benchmark



      Server Level



      • Always disable sa login on production server (create a new login with sysadmin permissions before disabling sa)


      • Do NOT let every login added into sysadmin server role, consider server hosts multiple databases that are related different applications, which have no relation each other. There are cases (I do not agree) that the application user required full permissions on the database server, in that case it's better to have separate instance.


      Database Level



      • Track regularly on Orphaned Users (especially when DB restored from unknown backups), drop them accordingly


      • Beware db_owner database role have same level of access (within database) as sysadmin


      Following query helps to find Orphaned Users from all databases:



      exec sp_MSforeachdb
      'Use [?];
      select DB_NAME () as DBName, dp.name,
      dp.principal_id,
      dp.type,
      dp.type_desc,
      dp.sid,
      sp.sid,
      ''use '' + cast(DB_NAME () as varchar(50)) + ''; if not exists (select containment from sys.databases where not containment = 0) drop user ['' + dp.name + '']'' as FixCommand
      from sys.database_principals as dp
      left outer join sys.server_principals as sp on dp.sid = sp.sid
      where dp.principal_id > 4 AND sp.sid is null and dp.type in (''S'', ''U'', ''G'')'
      go





      share|improve this answer





























        Your Answer








        StackExchange.ready(function()
        var channelOptions =
        tags: "".split(" "),
        id: "182"
        ;
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function()
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled)
        StackExchange.using("snippets", function()
        createEditor();
        );

        else
        createEditor();

        );

        function createEditor()
        StackExchange.prepareEditor(
        heartbeatType: 'answer',
        autoActivateHeartbeat: false,
        convertImagesToLinks: false,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: null,
        bindNavPrevention: true,
        postfix: "",
        imageUploader:
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        ,
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        );



        );













        draft saved

        draft discarded


















        StackExchange.ready(
        function ()
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f244430%2fdomain-admin-account-accessing-sql-server%23new-answer', 'question_page');

        );

        Post as a guest















        Required, but never shown

























        3 Answers
        3






        active

        oldest

        votes








        3 Answers
        3






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        5














        You could use the following query to provide some quick details about the domain admin:



        SELECT des.session_id
        , des.host_name
        , des.login_time
        , des.is_user_process
        , des.last_request_start_time
        , dest.text
        FROM sys.dm_exec_sessions des
        INNER JOIN sys.dm_exec_connections dec ON des.session_id = dec.session_id
        CROSS APPLY sys.dm_exec_sql_text(dec.most_recent_sql_handle) dest
        WHERE des.login_name = N'DOMAINAccountName'


        It'll show the name of the client machine where they are connecting from, and the last statement they executed.



        In general, you probably want to explicitly control who has access to the SQL Server, especially for security-sensitive accounts such as members of the sysadmin and securityadmin server roles. The principle of least privilege applies.



        This query will show you the members of each server-level role:



        SELECT spr.name
        , spm.name
        FROM sys.server_principals spr
        INNER JOIN sys.server_role_members srm ON spr.principal_id = srm.role_principal_id
        INNER JOIN sys.server_principals spm ON srm.member_principal_id = spm.principal_id
        ORDER BY spr.name
        , spm.name;


        In general, this list should be as small as possible. Pay particular attention to the securityadmin and sysadmin roles.



        As an aside, you want to limit the number of people who have access to the Domain Admins AD group since members of that group could restart your SQL Server in such a way that they can gain access to it, even if they haven't been explicitly granted access. There are a lot of security implications to be aware of domain-wide for highly privileged groups such as the Domain Admins.






        share|improve this answer































          5














          You could use the following query to provide some quick details about the domain admin:



          SELECT des.session_id
          , des.host_name
          , des.login_time
          , des.is_user_process
          , des.last_request_start_time
          , dest.text
          FROM sys.dm_exec_sessions des
          INNER JOIN sys.dm_exec_connections dec ON des.session_id = dec.session_id
          CROSS APPLY sys.dm_exec_sql_text(dec.most_recent_sql_handle) dest
          WHERE des.login_name = N'DOMAINAccountName'


          It'll show the name of the client machine where they are connecting from, and the last statement they executed.



          In general, you probably want to explicitly control who has access to the SQL Server, especially for security-sensitive accounts such as members of the sysadmin and securityadmin server roles. The principle of least privilege applies.



          This query will show you the members of each server-level role:



          SELECT spr.name
          , spm.name
          FROM sys.server_principals spr
          INNER JOIN sys.server_role_members srm ON spr.principal_id = srm.role_principal_id
          INNER JOIN sys.server_principals spm ON srm.member_principal_id = spm.principal_id
          ORDER BY spr.name
          , spm.name;


          In general, this list should be as small as possible. Pay particular attention to the securityadmin and sysadmin roles.



          As an aside, you want to limit the number of people who have access to the Domain Admins AD group since members of that group could restart your SQL Server in such a way that they can gain access to it, even if they haven't been explicitly granted access. There are a lot of security implications to be aware of domain-wide for highly privileged groups such as the Domain Admins.






          share|improve this answer





























            5












            5








            5







            You could use the following query to provide some quick details about the domain admin:



            SELECT des.session_id
            , des.host_name
            , des.login_time
            , des.is_user_process
            , des.last_request_start_time
            , dest.text
            FROM sys.dm_exec_sessions des
            INNER JOIN sys.dm_exec_connections dec ON des.session_id = dec.session_id
            CROSS APPLY sys.dm_exec_sql_text(dec.most_recent_sql_handle) dest
            WHERE des.login_name = N'DOMAINAccountName'


            It'll show the name of the client machine where they are connecting from, and the last statement they executed.



            In general, you probably want to explicitly control who has access to the SQL Server, especially for security-sensitive accounts such as members of the sysadmin and securityadmin server roles. The principle of least privilege applies.



            This query will show you the members of each server-level role:



            SELECT spr.name
            , spm.name
            FROM sys.server_principals spr
            INNER JOIN sys.server_role_members srm ON spr.principal_id = srm.role_principal_id
            INNER JOIN sys.server_principals spm ON srm.member_principal_id = spm.principal_id
            ORDER BY spr.name
            , spm.name;


            In general, this list should be as small as possible. Pay particular attention to the securityadmin and sysadmin roles.



            As an aside, you want to limit the number of people who have access to the Domain Admins AD group since members of that group could restart your SQL Server in such a way that they can gain access to it, even if they haven't been explicitly granted access. There are a lot of security implications to be aware of domain-wide for highly privileged groups such as the Domain Admins.






            share|improve this answer















            You could use the following query to provide some quick details about the domain admin:



            SELECT des.session_id
            , des.host_name
            , des.login_time
            , des.is_user_process
            , des.last_request_start_time
            , dest.text
            FROM sys.dm_exec_sessions des
            INNER JOIN sys.dm_exec_connections dec ON des.session_id = dec.session_id
            CROSS APPLY sys.dm_exec_sql_text(dec.most_recent_sql_handle) dest
            WHERE des.login_name = N'DOMAINAccountName'


            It'll show the name of the client machine where they are connecting from, and the last statement they executed.



            In general, you probably want to explicitly control who has access to the SQL Server, especially for security-sensitive accounts such as members of the sysadmin and securityadmin server roles. The principle of least privilege applies.



            This query will show you the members of each server-level role:



            SELECT spr.name
            , spm.name
            FROM sys.server_principals spr
            INNER JOIN sys.server_role_members srm ON spr.principal_id = srm.role_principal_id
            INNER JOIN sys.server_principals spm ON srm.member_principal_id = spm.principal_id
            ORDER BY spr.name
            , spm.name;


            In general, this list should be as small as possible. Pay particular attention to the securityadmin and sysadmin roles.



            As an aside, you want to limit the number of people who have access to the Domain Admins AD group since members of that group could restart your SQL Server in such a way that they can gain access to it, even if they haven't been explicitly granted access. There are a lot of security implications to be aware of domain-wide for highly privileged groups such as the Domain Admins.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Aug 2 at 15:57

























            answered Aug 2 at 15:41









            Max VernonMax Vernon

            55.4k13 gold badges120 silver badges247 bronze badges




            55.4k13 gold badges120 silver badges247 bronze badges


























                2














                There is good information in the two existing answers, and you should follow-up on what they suggest.



                But be aware that in some cases the account might not be actively connecting, we have seen cases where a user who has SSMS open and has a servers listed in their Central Management Servers (CMS), show as connected when if fact they are not actively doing anything on the server, nor are they intentionally connected.



                I looked for documentation of this occurring and why, to reference in this post but I am not finding anything.






                share|improve this answer





























                  2














                  There is good information in the two existing answers, and you should follow-up on what they suggest.



                  But be aware that in some cases the account might not be actively connecting, we have seen cases where a user who has SSMS open and has a servers listed in their Central Management Servers (CMS), show as connected when if fact they are not actively doing anything on the server, nor are they intentionally connected.



                  I looked for documentation of this occurring and why, to reference in this post but I am not finding anything.






                  share|improve this answer



























                    2












                    2








                    2







                    There is good information in the two existing answers, and you should follow-up on what they suggest.



                    But be aware that in some cases the account might not be actively connecting, we have seen cases where a user who has SSMS open and has a servers listed in their Central Management Servers (CMS), show as connected when if fact they are not actively doing anything on the server, nor are they intentionally connected.



                    I looked for documentation of this occurring and why, to reference in this post but I am not finding anything.






                    share|improve this answer













                    There is good information in the two existing answers, and you should follow-up on what they suggest.



                    But be aware that in some cases the account might not be actively connecting, we have seen cases where a user who has SSMS open and has a servers listed in their Central Management Servers (CMS), show as connected when if fact they are not actively doing anything on the server, nor are they intentionally connected.



                    I looked for documentation of this occurring and why, to reference in this post but I am not finding anything.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Aug 2 at 17:27









                    James JenkinsJames Jenkins

                    2,5312 gold badges24 silver badges48 bronze badges




                    2,5312 gold badges24 silver badges48 bronze badges
























                        1














                        It's not good idea to have built-in accounts or default security groups i.e. Domain Users, Domain Admins etc.. to have access on SQL Server. Instead, create separate windows account/domain security groups to have access on SQL Server.



                        Also, some of best practices as follows, for more details have a look at security benchmark



                        Server Level



                        • Always disable sa login on production server (create a new login with sysadmin permissions before disabling sa)


                        • Do NOT let every login added into sysadmin server role, consider server hosts multiple databases that are related different applications, which have no relation each other. There are cases (I do not agree) that the application user required full permissions on the database server, in that case it's better to have separate instance.


                        Database Level



                        • Track regularly on Orphaned Users (especially when DB restored from unknown backups), drop them accordingly


                        • Beware db_owner database role have same level of access (within database) as sysadmin


                        Following query helps to find Orphaned Users from all databases:



                        exec sp_MSforeachdb
                        'Use [?];
                        select DB_NAME () as DBName, dp.name,
                        dp.principal_id,
                        dp.type,
                        dp.type_desc,
                        dp.sid,
                        sp.sid,
                        ''use '' + cast(DB_NAME () as varchar(50)) + ''; if not exists (select containment from sys.databases where not containment = 0) drop user ['' + dp.name + '']'' as FixCommand
                        from sys.database_principals as dp
                        left outer join sys.server_principals as sp on dp.sid = sp.sid
                        where dp.principal_id > 4 AND sp.sid is null and dp.type in (''S'', ''U'', ''G'')'
                        go





                        share|improve this answer































                          1














                          It's not good idea to have built-in accounts or default security groups i.e. Domain Users, Domain Admins etc.. to have access on SQL Server. Instead, create separate windows account/domain security groups to have access on SQL Server.



                          Also, some of best practices as follows, for more details have a look at security benchmark



                          Server Level



                          • Always disable sa login on production server (create a new login with sysadmin permissions before disabling sa)


                          • Do NOT let every login added into sysadmin server role, consider server hosts multiple databases that are related different applications, which have no relation each other. There are cases (I do not agree) that the application user required full permissions on the database server, in that case it's better to have separate instance.


                          Database Level



                          • Track regularly on Orphaned Users (especially when DB restored from unknown backups), drop them accordingly


                          • Beware db_owner database role have same level of access (within database) as sysadmin


                          Following query helps to find Orphaned Users from all databases:



                          exec sp_MSforeachdb
                          'Use [?];
                          select DB_NAME () as DBName, dp.name,
                          dp.principal_id,
                          dp.type,
                          dp.type_desc,
                          dp.sid,
                          sp.sid,
                          ''use '' + cast(DB_NAME () as varchar(50)) + ''; if not exists (select containment from sys.databases where not containment = 0) drop user ['' + dp.name + '']'' as FixCommand
                          from sys.database_principals as dp
                          left outer join sys.server_principals as sp on dp.sid = sp.sid
                          where dp.principal_id > 4 AND sp.sid is null and dp.type in (''S'', ''U'', ''G'')'
                          go





                          share|improve this answer





























                            1












                            1








                            1







                            It's not good idea to have built-in accounts or default security groups i.e. Domain Users, Domain Admins etc.. to have access on SQL Server. Instead, create separate windows account/domain security groups to have access on SQL Server.



                            Also, some of best practices as follows, for more details have a look at security benchmark



                            Server Level



                            • Always disable sa login on production server (create a new login with sysadmin permissions before disabling sa)


                            • Do NOT let every login added into sysadmin server role, consider server hosts multiple databases that are related different applications, which have no relation each other. There are cases (I do not agree) that the application user required full permissions on the database server, in that case it's better to have separate instance.


                            Database Level



                            • Track regularly on Orphaned Users (especially when DB restored from unknown backups), drop them accordingly


                            • Beware db_owner database role have same level of access (within database) as sysadmin


                            Following query helps to find Orphaned Users from all databases:



                            exec sp_MSforeachdb
                            'Use [?];
                            select DB_NAME () as DBName, dp.name,
                            dp.principal_id,
                            dp.type,
                            dp.type_desc,
                            dp.sid,
                            sp.sid,
                            ''use '' + cast(DB_NAME () as varchar(50)) + ''; if not exists (select containment from sys.databases where not containment = 0) drop user ['' + dp.name + '']'' as FixCommand
                            from sys.database_principals as dp
                            left outer join sys.server_principals as sp on dp.sid = sp.sid
                            where dp.principal_id > 4 AND sp.sid is null and dp.type in (''S'', ''U'', ''G'')'
                            go





                            share|improve this answer















                            It's not good idea to have built-in accounts or default security groups i.e. Domain Users, Domain Admins etc.. to have access on SQL Server. Instead, create separate windows account/domain security groups to have access on SQL Server.



                            Also, some of best practices as follows, for more details have a look at security benchmark



                            Server Level



                            • Always disable sa login on production server (create a new login with sysadmin permissions before disabling sa)


                            • Do NOT let every login added into sysadmin server role, consider server hosts multiple databases that are related different applications, which have no relation each other. There are cases (I do not agree) that the application user required full permissions on the database server, in that case it's better to have separate instance.


                            Database Level



                            • Track regularly on Orphaned Users (especially when DB restored from unknown backups), drop them accordingly


                            • Beware db_owner database role have same level of access (within database) as sysadmin


                            Following query helps to find Orphaned Users from all databases:



                            exec sp_MSforeachdb
                            'Use [?];
                            select DB_NAME () as DBName, dp.name,
                            dp.principal_id,
                            dp.type,
                            dp.type_desc,
                            dp.sid,
                            sp.sid,
                            ''use '' + cast(DB_NAME () as varchar(50)) + ''; if not exists (select containment from sys.databases where not containment = 0) drop user ['' + dp.name + '']'' as FixCommand
                            from sys.database_principals as dp
                            left outer join sys.server_principals as sp on dp.sid = sp.sid
                            where dp.principal_id > 4 AND sp.sid is null and dp.type in (''S'', ''U'', ''G'')'
                            go






                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited Aug 5 at 11:59

























                            answered Aug 2 at 15:40









                            Shekar KolaShekar Kola

                            1719 bronze badges




                            1719 bronze badges






























                                draft saved

                                draft discarded
















































                                Thanks for contributing an answer to Database Administrators Stack Exchange!


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid


                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.

                                To learn more, see our tips on writing great answers.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function ()
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f244430%2fdomain-admin-account-accessing-sql-server%23new-answer', 'question_page');

                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown







                                Popular posts from this blog

                                Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

                                Circuit construction for execution of conditional statements using least significant bitHow are two different registers being used as “control”?How exactly is the stated composite state of the two registers being produced using the $R_zz$ controlled rotations?Efficiently performing controlled rotations in HHLWould this quantum algorithm implementation work?How to prepare a superposed states of odd integers from $1$ to $sqrtN$?Why is this implementation of the order finding algorithm not working?Circuit construction for Hamiltonian simulationHow can I invert the least significant bit of a certain term of a superposed state?Implementing an oracleImplementing a controlled sum operation

                                Magento 2 “No Payment Methods” in Admin New OrderHow to integrate Paypal Express Checkout with the Magento APIMagento 1.5 - Sales > Order > edit order and shipping methods disappearAuto Invoice Check/Money Order Payment methodAdd more simple payment methods?Shipping methods not showingWhat should I do to change payment methods if changing the configuration has no effects?1.9 - No Payment Methods showing upMy Payment Methods not Showing for downloadable/virtual product when checkout?Magento2 API to access internal payment methodHow to call an existing payment methods in the registration form?