How to deny access to SQL Server to certain login over SSMS, but allow over .Net SqlClient Data Provider












9















We have a situation where Developers do not have any UPDATE permissions, BUT they work with applications and see connection strings -> they know passwords from some SQL accounts (example SQLLogin1) that have UPDATE permissions. Our operations currently are not perfect, and sometimes production data needs to be modified (no GUI for that yet).



Instead of contacting DBA, and asking him to modify the data, Developer would (improperly) use SQL account SQLLogin1 (that has permission to modify the data),
and connect over SQL Server Management Studio to modify the data himself.



DBA can not change password for SQLLogin1 without Developer seeing the new connection string and new password, since the application connection string that uses SQLLogin1 is maintained by Developer.



Question:



Is there a way to deny access to SQLLogin1 SQL login, but only if it is connecting over SSMS?



At the same time if SQLLogin1 is connecting over .Net SqlClient Data Provider (program_name in the sys.dm_exec_sessions), it must be allowed to login.



This way we want to not let Developer connect over SSMS using SQLLogin1, while the application that is using SQLLogin1, would still be able to connect.










share|improve this question




















  • 2





    You can use a server logon trigger to force a login failure when connecting to the server. Be careful when implementing one of these, if not coded properly you will be rejecting logins (make sure to test in proper test environment). docs.microsoft.com/en-us/sql/relational-databases/triggers/…

    – EzLo
    yesterday








  • 10





    While blocking SSMS might work, it's not a security solution. You can set the program_name to anything you want, even in SSMS by setting Application Name=whatever in the Additional Connection Parameters. For a security solution, prevent the devs from seeing the passwords for production databases.

    – David Browne - Microsoft
    yesterday






  • 4





    How would this prevent them from making a console application to run the same update statement? If anything you're making this ugly process even more ugly.

    – Deacon
    yesterday






  • 8





    "BUT they work with applications and see connection strings -> they know passwords from some SQL accounts ... that have UPDATE permissions." There's your problem. Have proper account management and don't give them passwords they're not authorized to use. If you don't trust them to handle the account responsibly, then they shouldn't have it.

    – jpmc26
    yesterday








  • 5





    I think @jpmc26 is on the money. This sounds like a XY-problem where you shouldn’t worry about SSMS access but about developers having credentials they shouldn’t have. There are ways to handle the secrets so that devs don’t need production credentials - and it sounds like that’s what you are after.

    – vhu
    yesterday
















9















We have a situation where Developers do not have any UPDATE permissions, BUT they work with applications and see connection strings -> they know passwords from some SQL accounts (example SQLLogin1) that have UPDATE permissions. Our operations currently are not perfect, and sometimes production data needs to be modified (no GUI for that yet).



Instead of contacting DBA, and asking him to modify the data, Developer would (improperly) use SQL account SQLLogin1 (that has permission to modify the data),
and connect over SQL Server Management Studio to modify the data himself.



DBA can not change password for SQLLogin1 without Developer seeing the new connection string and new password, since the application connection string that uses SQLLogin1 is maintained by Developer.



Question:



Is there a way to deny access to SQLLogin1 SQL login, but only if it is connecting over SSMS?



At the same time if SQLLogin1 is connecting over .Net SqlClient Data Provider (program_name in the sys.dm_exec_sessions), it must be allowed to login.



This way we want to not let Developer connect over SSMS using SQLLogin1, while the application that is using SQLLogin1, would still be able to connect.










share|improve this question




















  • 2





    You can use a server logon trigger to force a login failure when connecting to the server. Be careful when implementing one of these, if not coded properly you will be rejecting logins (make sure to test in proper test environment). docs.microsoft.com/en-us/sql/relational-databases/triggers/…

    – EzLo
    yesterday








  • 10





    While blocking SSMS might work, it's not a security solution. You can set the program_name to anything you want, even in SSMS by setting Application Name=whatever in the Additional Connection Parameters. For a security solution, prevent the devs from seeing the passwords for production databases.

    – David Browne - Microsoft
    yesterday






  • 4





    How would this prevent them from making a console application to run the same update statement? If anything you're making this ugly process even more ugly.

    – Deacon
    yesterday






  • 8





    "BUT they work with applications and see connection strings -> they know passwords from some SQL accounts ... that have UPDATE permissions." There's your problem. Have proper account management and don't give them passwords they're not authorized to use. If you don't trust them to handle the account responsibly, then they shouldn't have it.

    – jpmc26
    yesterday








  • 5





    I think @jpmc26 is on the money. This sounds like a XY-problem where you shouldn’t worry about SSMS access but about developers having credentials they shouldn’t have. There are ways to handle the secrets so that devs don’t need production credentials - and it sounds like that’s what you are after.

    – vhu
    yesterday














9












9








9


2






We have a situation where Developers do not have any UPDATE permissions, BUT they work with applications and see connection strings -> they know passwords from some SQL accounts (example SQLLogin1) that have UPDATE permissions. Our operations currently are not perfect, and sometimes production data needs to be modified (no GUI for that yet).



Instead of contacting DBA, and asking him to modify the data, Developer would (improperly) use SQL account SQLLogin1 (that has permission to modify the data),
and connect over SQL Server Management Studio to modify the data himself.



DBA can not change password for SQLLogin1 without Developer seeing the new connection string and new password, since the application connection string that uses SQLLogin1 is maintained by Developer.



Question:



Is there a way to deny access to SQLLogin1 SQL login, but only if it is connecting over SSMS?



At the same time if SQLLogin1 is connecting over .Net SqlClient Data Provider (program_name in the sys.dm_exec_sessions), it must be allowed to login.



This way we want to not let Developer connect over SSMS using SQLLogin1, while the application that is using SQLLogin1, would still be able to connect.










share|improve this question
















We have a situation where Developers do not have any UPDATE permissions, BUT they work with applications and see connection strings -> they know passwords from some SQL accounts (example SQLLogin1) that have UPDATE permissions. Our operations currently are not perfect, and sometimes production data needs to be modified (no GUI for that yet).



Instead of contacting DBA, and asking him to modify the data, Developer would (improperly) use SQL account SQLLogin1 (that has permission to modify the data),
and connect over SQL Server Management Studio to modify the data himself.



DBA can not change password for SQLLogin1 without Developer seeing the new connection string and new password, since the application connection string that uses SQLLogin1 is maintained by Developer.



Question:



Is there a way to deny access to SQLLogin1 SQL login, but only if it is connecting over SSMS?



At the same time if SQLLogin1 is connecting over .Net SqlClient Data Provider (program_name in the sys.dm_exec_sessions), it must be allowed to login.



This way we want to not let Developer connect over SSMS using SQLLogin1, while the application that is using SQLLogin1, would still be able to connect.







sql-server permissions access-control






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited yesterday









EzLo

2,3161420




2,3161420










asked yesterday









voodoo_shvoodoo_sh

21118




21118








  • 2





    You can use a server logon trigger to force a login failure when connecting to the server. Be careful when implementing one of these, if not coded properly you will be rejecting logins (make sure to test in proper test environment). docs.microsoft.com/en-us/sql/relational-databases/triggers/…

    – EzLo
    yesterday








  • 10





    While blocking SSMS might work, it's not a security solution. You can set the program_name to anything you want, even in SSMS by setting Application Name=whatever in the Additional Connection Parameters. For a security solution, prevent the devs from seeing the passwords for production databases.

    – David Browne - Microsoft
    yesterday






  • 4





    How would this prevent them from making a console application to run the same update statement? If anything you're making this ugly process even more ugly.

    – Deacon
    yesterday






  • 8





    "BUT they work with applications and see connection strings -> they know passwords from some SQL accounts ... that have UPDATE permissions." There's your problem. Have proper account management and don't give them passwords they're not authorized to use. If you don't trust them to handle the account responsibly, then they shouldn't have it.

    – jpmc26
    yesterday








  • 5





    I think @jpmc26 is on the money. This sounds like a XY-problem where you shouldn’t worry about SSMS access but about developers having credentials they shouldn’t have. There are ways to handle the secrets so that devs don’t need production credentials - and it sounds like that’s what you are after.

    – vhu
    yesterday














  • 2





    You can use a server logon trigger to force a login failure when connecting to the server. Be careful when implementing one of these, if not coded properly you will be rejecting logins (make sure to test in proper test environment). docs.microsoft.com/en-us/sql/relational-databases/triggers/…

    – EzLo
    yesterday








  • 10





    While blocking SSMS might work, it's not a security solution. You can set the program_name to anything you want, even in SSMS by setting Application Name=whatever in the Additional Connection Parameters. For a security solution, prevent the devs from seeing the passwords for production databases.

    – David Browne - Microsoft
    yesterday






  • 4





    How would this prevent them from making a console application to run the same update statement? If anything you're making this ugly process even more ugly.

    – Deacon
    yesterday






  • 8





    "BUT they work with applications and see connection strings -> they know passwords from some SQL accounts ... that have UPDATE permissions." There's your problem. Have proper account management and don't give them passwords they're not authorized to use. If you don't trust them to handle the account responsibly, then they shouldn't have it.

    – jpmc26
    yesterday








  • 5





    I think @jpmc26 is on the money. This sounds like a XY-problem where you shouldn’t worry about SSMS access but about developers having credentials they shouldn’t have. There are ways to handle the secrets so that devs don’t need production credentials - and it sounds like that’s what you are after.

    – vhu
    yesterday








2




2





You can use a server logon trigger to force a login failure when connecting to the server. Be careful when implementing one of these, if not coded properly you will be rejecting logins (make sure to test in proper test environment). docs.microsoft.com/en-us/sql/relational-databases/triggers/…

– EzLo
yesterday







You can use a server logon trigger to force a login failure when connecting to the server. Be careful when implementing one of these, if not coded properly you will be rejecting logins (make sure to test in proper test environment). docs.microsoft.com/en-us/sql/relational-databases/triggers/…

– EzLo
yesterday






10




10





While blocking SSMS might work, it's not a security solution. You can set the program_name to anything you want, even in SSMS by setting Application Name=whatever in the Additional Connection Parameters. For a security solution, prevent the devs from seeing the passwords for production databases.

– David Browne - Microsoft
yesterday





While blocking SSMS might work, it's not a security solution. You can set the program_name to anything you want, even in SSMS by setting Application Name=whatever in the Additional Connection Parameters. For a security solution, prevent the devs from seeing the passwords for production databases.

– David Browne - Microsoft
yesterday




4




4





How would this prevent them from making a console application to run the same update statement? If anything you're making this ugly process even more ugly.

– Deacon
yesterday





How would this prevent them from making a console application to run the same update statement? If anything you're making this ugly process even more ugly.

– Deacon
yesterday




8




8





"BUT they work with applications and see connection strings -> they know passwords from some SQL accounts ... that have UPDATE permissions." There's your problem. Have proper account management and don't give them passwords they're not authorized to use. If you don't trust them to handle the account responsibly, then they shouldn't have it.

– jpmc26
yesterday







"BUT they work with applications and see connection strings -> they know passwords from some SQL accounts ... that have UPDATE permissions." There's your problem. Have proper account management and don't give them passwords they're not authorized to use. If you don't trust them to handle the account responsibly, then they shouldn't have it.

– jpmc26
yesterday






5




5





I think @jpmc26 is on the money. This sounds like a XY-problem where you shouldn’t worry about SSMS access but about developers having credentials they shouldn’t have. There are ways to handle the secrets so that devs don’t need production credentials - and it sounds like that’s what you are after.

– vhu
yesterday





I think @jpmc26 is on the money. This sounds like a XY-problem where you shouldn’t worry about SSMS access but about developers having credentials they shouldn’t have. There are ways to handle the secrets so that devs don’t need production credentials - and it sounds like that’s what you are after.

– vhu
yesterday










4 Answers
4






active

oldest

votes


















9














You can use a server logon trigger to make custom logon validations and reject them whenever you see fit. You will see this trigger listed below "Server Objects" and inside "Triggers" if you are using SSMS.



For example:



CREATE TRIGGER strRejectSSMSConnectionForSQLLogin1
ON ALL SERVER FOR LOGON
AS
BEGIN

IF ORIGINAL_LOGIN() = N'SQLLogin1' AND PROGRAM_NAME() LIKE N'Microsoft SQL Server Management Studio%'
BEGIN
RAISERROR('Direct connection by SSMS refused.', 16, 1)
ROLLBACK
END

END


The ROLLBACK inside the trigger will reject the connection (there's an implicit transaction wrapping the call to the trigger on the logon event).



Be careful when implementing logon triggers, if not coded properly you will be rejecting logins that should be able to login (including your own!). Make sure to test on test/dev environments first.



Keep in mind that this code is executed before the session is created, so system views that rely on the session id (SPID) won't contain the currently checked login until the triggers ends without rollback or high enough failure.






share|improve this answer
























  • thank you! question - if I make any mistake in logon trigger, and it blocks even sysadmin account from logging in, is there still a way to get into SQL Server and disable logon trigger ?

    – voodoo_sh
    yesterday






  • 2





    You can drop the trigger without it firing if you connect with a DAC (dedicated administrator connection). It's a particular single-user connection you can issue against the server whenever things go wrong. It's usually used directly with sqlcmd, but you can do it with SSMS too. docs.microsoft.com/en-us/previous-versions/sql/…

    – EzLo
    yesterday








  • 6





    This will work for a few minutes, until the developer uses a different tool. You simply cannot keep a good developer out if they know a login with permissions.

    – Joe
    yesterday






  • 2





    This is more an policy solution than a security solution. IE the logon trigger makes it clear that it's against policy to directly connect to the production database. And since it's unlikely you can protect against a actually malicous developer anyway, that may be good enough.

    – David Browne - Microsoft
    yesterday













  • @voodoo_sh: Be prepared to find a backdoor in the program codebase.

    – Joshua
    yesterday



















12














I think there is no reliable solution for your problem since Application Name is modifiable parameter that cam be changed by any user.



Here is how to change it within SSMS:



In Connect to Database Object dialog choose Options, open Additional Connection Parameters and choose any name for Application Name like this:



enter image description here



Now sys.dm_exec_sessions DMV and Program_name() will show you what you passed in your connection string in Application Name parameter:



enter image description here






share|improve this answer































    3














    You can't cut off a specific client, as already detailed in the other answers.



    The solution is to remove the access privileges to the production systems from the developer's accounts.



    Any change must be scripted and a dba will run the script.



    Deployment is performed by a sysadmin; devs produce a package they give to someone with proper privileges and devs never see the configs used on production systems.



    Debugging is arranged on a case by case basis with a copy of the production data in a staging environment as a preferred solution or a temporary account with limited privileges if needed.






    share|improve this answer































      0















      1. In the ideal sense, this is a process / policy / management issue. Even if someone knows the password, if it is against company policy for anyone but a DBA to connect to Production (well, you might have a Release Engineering team and/or sys admins, etc), and there are penalties for breaking the rules, then that should be sufficient (assuming that such rules are enforced).


      2. Trying to prevent a particular application from connecting is impossible. As sepupic demonstrated, it is fairly easy to change the "program name". But even if the developer can't figure that out, there are plenty of other programs that can connect to SQL Server. Most people will have access to SQLCMD.exe and even the deprecated OSQL.exe. The developer can connect from within Visual Studio, and they can even create their own app to connect via ".Net SqlClient Data Provider". Oh, and now we even have Azure Data Studio. It's just too many.



      3. Still, this might could still be possible if we approach it from the other direction: instead of preventing application X from connecting, how about only allowing application Y to connect? Sure, we again get into the "program name", and even "hostname" can be spoofed, BUT, I am pretty sure that the client's IP Address cannot be spoofed (at least not through the connection string keywords). You know the IP Address of the app server(s), or can easily find it from the sys.dm_exec_connections DMV (in the client_net_address field).



        Starting with the Logon Trigger suggested by EzLo, we can modify the logic that determines if the connection is valid or not to be the following:



        IF (ORIGINAL_LOGIN() = N'SQLLogin1'
        AND (
        CONVERT(VARCHAR(10), CONNECTIONPROPERTY('net_transport')) <> 'TCP'
        OR CONVERT(VARCHAR(10), CONNECTIONPROPERTY('client_net_address')) <> '10.10.10.10'
        -- uncomment below (and comment-out line above) if app uses multiple IP addresses
        -- OR CONVERT(VARCHAR(10), CONNECTIONPROPERTY('client_net_address'))
        -- NOT IN ( '10.10.10.10', '10.10.10.11', ...)
        ))
        BEGIN
        RAISERROR('Non-application connection refused.', 16, 1);
        ROLLBACK;
        END;


        The only ways in now would be to either log onto the Production machine, or to have their workstation spoof the IP of the app server. Hopefully devs do not have any access to log onto Production. And spoofing an existing IP on a network causes problems which might adversely affect Production, so they won't be trying that, right? Right?








      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%2f231228%2fhow-to-deny-access-to-sql-server-to-certain-login-over-ssms-but-allow-over-net%23new-answer', 'question_page');
        }
        );

        Post as a guest















        Required, but never shown

























        4 Answers
        4






        active

        oldest

        votes








        4 Answers
        4






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        9














        You can use a server logon trigger to make custom logon validations and reject them whenever you see fit. You will see this trigger listed below "Server Objects" and inside "Triggers" if you are using SSMS.



        For example:



        CREATE TRIGGER strRejectSSMSConnectionForSQLLogin1
        ON ALL SERVER FOR LOGON
        AS
        BEGIN

        IF ORIGINAL_LOGIN() = N'SQLLogin1' AND PROGRAM_NAME() LIKE N'Microsoft SQL Server Management Studio%'
        BEGIN
        RAISERROR('Direct connection by SSMS refused.', 16, 1)
        ROLLBACK
        END

        END


        The ROLLBACK inside the trigger will reject the connection (there's an implicit transaction wrapping the call to the trigger on the logon event).



        Be careful when implementing logon triggers, if not coded properly you will be rejecting logins that should be able to login (including your own!). Make sure to test on test/dev environments first.



        Keep in mind that this code is executed before the session is created, so system views that rely on the session id (SPID) won't contain the currently checked login until the triggers ends without rollback or high enough failure.






        share|improve this answer
























        • thank you! question - if I make any mistake in logon trigger, and it blocks even sysadmin account from logging in, is there still a way to get into SQL Server and disable logon trigger ?

          – voodoo_sh
          yesterday






        • 2





          You can drop the trigger without it firing if you connect with a DAC (dedicated administrator connection). It's a particular single-user connection you can issue against the server whenever things go wrong. It's usually used directly with sqlcmd, but you can do it with SSMS too. docs.microsoft.com/en-us/previous-versions/sql/…

          – EzLo
          yesterday








        • 6





          This will work for a few minutes, until the developer uses a different tool. You simply cannot keep a good developer out if they know a login with permissions.

          – Joe
          yesterday






        • 2





          This is more an policy solution than a security solution. IE the logon trigger makes it clear that it's against policy to directly connect to the production database. And since it's unlikely you can protect against a actually malicous developer anyway, that may be good enough.

          – David Browne - Microsoft
          yesterday













        • @voodoo_sh: Be prepared to find a backdoor in the program codebase.

          – Joshua
          yesterday
















        9














        You can use a server logon trigger to make custom logon validations and reject them whenever you see fit. You will see this trigger listed below "Server Objects" and inside "Triggers" if you are using SSMS.



        For example:



        CREATE TRIGGER strRejectSSMSConnectionForSQLLogin1
        ON ALL SERVER FOR LOGON
        AS
        BEGIN

        IF ORIGINAL_LOGIN() = N'SQLLogin1' AND PROGRAM_NAME() LIKE N'Microsoft SQL Server Management Studio%'
        BEGIN
        RAISERROR('Direct connection by SSMS refused.', 16, 1)
        ROLLBACK
        END

        END


        The ROLLBACK inside the trigger will reject the connection (there's an implicit transaction wrapping the call to the trigger on the logon event).



        Be careful when implementing logon triggers, if not coded properly you will be rejecting logins that should be able to login (including your own!). Make sure to test on test/dev environments first.



        Keep in mind that this code is executed before the session is created, so system views that rely on the session id (SPID) won't contain the currently checked login until the triggers ends without rollback or high enough failure.






        share|improve this answer
























        • thank you! question - if I make any mistake in logon trigger, and it blocks even sysadmin account from logging in, is there still a way to get into SQL Server and disable logon trigger ?

          – voodoo_sh
          yesterday






        • 2





          You can drop the trigger without it firing if you connect with a DAC (dedicated administrator connection). It's a particular single-user connection you can issue against the server whenever things go wrong. It's usually used directly with sqlcmd, but you can do it with SSMS too. docs.microsoft.com/en-us/previous-versions/sql/…

          – EzLo
          yesterday








        • 6





          This will work for a few minutes, until the developer uses a different tool. You simply cannot keep a good developer out if they know a login with permissions.

          – Joe
          yesterday






        • 2





          This is more an policy solution than a security solution. IE the logon trigger makes it clear that it's against policy to directly connect to the production database. And since it's unlikely you can protect against a actually malicous developer anyway, that may be good enough.

          – David Browne - Microsoft
          yesterday













        • @voodoo_sh: Be prepared to find a backdoor in the program codebase.

          – Joshua
          yesterday














        9












        9








        9







        You can use a server logon trigger to make custom logon validations and reject them whenever you see fit. You will see this trigger listed below "Server Objects" and inside "Triggers" if you are using SSMS.



        For example:



        CREATE TRIGGER strRejectSSMSConnectionForSQLLogin1
        ON ALL SERVER FOR LOGON
        AS
        BEGIN

        IF ORIGINAL_LOGIN() = N'SQLLogin1' AND PROGRAM_NAME() LIKE N'Microsoft SQL Server Management Studio%'
        BEGIN
        RAISERROR('Direct connection by SSMS refused.', 16, 1)
        ROLLBACK
        END

        END


        The ROLLBACK inside the trigger will reject the connection (there's an implicit transaction wrapping the call to the trigger on the logon event).



        Be careful when implementing logon triggers, if not coded properly you will be rejecting logins that should be able to login (including your own!). Make sure to test on test/dev environments first.



        Keep in mind that this code is executed before the session is created, so system views that rely on the session id (SPID) won't contain the currently checked login until the triggers ends without rollback or high enough failure.






        share|improve this answer













        You can use a server logon trigger to make custom logon validations and reject them whenever you see fit. You will see this trigger listed below "Server Objects" and inside "Triggers" if you are using SSMS.



        For example:



        CREATE TRIGGER strRejectSSMSConnectionForSQLLogin1
        ON ALL SERVER FOR LOGON
        AS
        BEGIN

        IF ORIGINAL_LOGIN() = N'SQLLogin1' AND PROGRAM_NAME() LIKE N'Microsoft SQL Server Management Studio%'
        BEGIN
        RAISERROR('Direct connection by SSMS refused.', 16, 1)
        ROLLBACK
        END

        END


        The ROLLBACK inside the trigger will reject the connection (there's an implicit transaction wrapping the call to the trigger on the logon event).



        Be careful when implementing logon triggers, if not coded properly you will be rejecting logins that should be able to login (including your own!). Make sure to test on test/dev environments first.



        Keep in mind that this code is executed before the session is created, so system views that rely on the session id (SPID) won't contain the currently checked login until the triggers ends without rollback or high enough failure.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered yesterday









        EzLoEzLo

        2,3161420




        2,3161420













        • thank you! question - if I make any mistake in logon trigger, and it blocks even sysadmin account from logging in, is there still a way to get into SQL Server and disable logon trigger ?

          – voodoo_sh
          yesterday






        • 2





          You can drop the trigger without it firing if you connect with a DAC (dedicated administrator connection). It's a particular single-user connection you can issue against the server whenever things go wrong. It's usually used directly with sqlcmd, but you can do it with SSMS too. docs.microsoft.com/en-us/previous-versions/sql/…

          – EzLo
          yesterday








        • 6





          This will work for a few minutes, until the developer uses a different tool. You simply cannot keep a good developer out if they know a login with permissions.

          – Joe
          yesterday






        • 2





          This is more an policy solution than a security solution. IE the logon trigger makes it clear that it's against policy to directly connect to the production database. And since it's unlikely you can protect against a actually malicous developer anyway, that may be good enough.

          – David Browne - Microsoft
          yesterday













        • @voodoo_sh: Be prepared to find a backdoor in the program codebase.

          – Joshua
          yesterday



















        • thank you! question - if I make any mistake in logon trigger, and it blocks even sysadmin account from logging in, is there still a way to get into SQL Server and disable logon trigger ?

          – voodoo_sh
          yesterday






        • 2





          You can drop the trigger without it firing if you connect with a DAC (dedicated administrator connection). It's a particular single-user connection you can issue against the server whenever things go wrong. It's usually used directly with sqlcmd, but you can do it with SSMS too. docs.microsoft.com/en-us/previous-versions/sql/…

          – EzLo
          yesterday








        • 6





          This will work for a few minutes, until the developer uses a different tool. You simply cannot keep a good developer out if they know a login with permissions.

          – Joe
          yesterday






        • 2





          This is more an policy solution than a security solution. IE the logon trigger makes it clear that it's against policy to directly connect to the production database. And since it's unlikely you can protect against a actually malicous developer anyway, that may be good enough.

          – David Browne - Microsoft
          yesterday













        • @voodoo_sh: Be prepared to find a backdoor in the program codebase.

          – Joshua
          yesterday

















        thank you! question - if I make any mistake in logon trigger, and it blocks even sysadmin account from logging in, is there still a way to get into SQL Server and disable logon trigger ?

        – voodoo_sh
        yesterday





        thank you! question - if I make any mistake in logon trigger, and it blocks even sysadmin account from logging in, is there still a way to get into SQL Server and disable logon trigger ?

        – voodoo_sh
        yesterday




        2




        2





        You can drop the trigger without it firing if you connect with a DAC (dedicated administrator connection). It's a particular single-user connection you can issue against the server whenever things go wrong. It's usually used directly with sqlcmd, but you can do it with SSMS too. docs.microsoft.com/en-us/previous-versions/sql/…

        – EzLo
        yesterday







        You can drop the trigger without it firing if you connect with a DAC (dedicated administrator connection). It's a particular single-user connection you can issue against the server whenever things go wrong. It's usually used directly with sqlcmd, but you can do it with SSMS too. docs.microsoft.com/en-us/previous-versions/sql/…

        – EzLo
        yesterday






        6




        6





        This will work for a few minutes, until the developer uses a different tool. You simply cannot keep a good developer out if they know a login with permissions.

        – Joe
        yesterday





        This will work for a few minutes, until the developer uses a different tool. You simply cannot keep a good developer out if they know a login with permissions.

        – Joe
        yesterday




        2




        2





        This is more an policy solution than a security solution. IE the logon trigger makes it clear that it's against policy to directly connect to the production database. And since it's unlikely you can protect against a actually malicous developer anyway, that may be good enough.

        – David Browne - Microsoft
        yesterday







        This is more an policy solution than a security solution. IE the logon trigger makes it clear that it's against policy to directly connect to the production database. And since it's unlikely you can protect against a actually malicous developer anyway, that may be good enough.

        – David Browne - Microsoft
        yesterday















        @voodoo_sh: Be prepared to find a backdoor in the program codebase.

        – Joshua
        yesterday





        @voodoo_sh: Be prepared to find a backdoor in the program codebase.

        – Joshua
        yesterday













        12














        I think there is no reliable solution for your problem since Application Name is modifiable parameter that cam be changed by any user.



        Here is how to change it within SSMS:



        In Connect to Database Object dialog choose Options, open Additional Connection Parameters and choose any name for Application Name like this:



        enter image description here



        Now sys.dm_exec_sessions DMV and Program_name() will show you what you passed in your connection string in Application Name parameter:



        enter image description here






        share|improve this answer




























          12














          I think there is no reliable solution for your problem since Application Name is modifiable parameter that cam be changed by any user.



          Here is how to change it within SSMS:



          In Connect to Database Object dialog choose Options, open Additional Connection Parameters and choose any name for Application Name like this:



          enter image description here



          Now sys.dm_exec_sessions DMV and Program_name() will show you what you passed in your connection string in Application Name parameter:



          enter image description here






          share|improve this answer


























            12












            12








            12







            I think there is no reliable solution for your problem since Application Name is modifiable parameter that cam be changed by any user.



            Here is how to change it within SSMS:



            In Connect to Database Object dialog choose Options, open Additional Connection Parameters and choose any name for Application Name like this:



            enter image description here



            Now sys.dm_exec_sessions DMV and Program_name() will show you what you passed in your connection string in Application Name parameter:



            enter image description here






            share|improve this answer













            I think there is no reliable solution for your problem since Application Name is modifiable parameter that cam be changed by any user.



            Here is how to change it within SSMS:



            In Connect to Database Object dialog choose Options, open Additional Connection Parameters and choose any name for Application Name like this:



            enter image description here



            Now sys.dm_exec_sessions DMV and Program_name() will show you what you passed in your connection string in Application Name parameter:



            enter image description here







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered yesterday









            sepupicsepupic

            7,686820




            7,686820























                3














                You can't cut off a specific client, as already detailed in the other answers.



                The solution is to remove the access privileges to the production systems from the developer's accounts.



                Any change must be scripted and a dba will run the script.



                Deployment is performed by a sysadmin; devs produce a package they give to someone with proper privileges and devs never see the configs used on production systems.



                Debugging is arranged on a case by case basis with a copy of the production data in a staging environment as a preferred solution or a temporary account with limited privileges if needed.






                share|improve this answer




























                  3














                  You can't cut off a specific client, as already detailed in the other answers.



                  The solution is to remove the access privileges to the production systems from the developer's accounts.



                  Any change must be scripted and a dba will run the script.



                  Deployment is performed by a sysadmin; devs produce a package they give to someone with proper privileges and devs never see the configs used on production systems.



                  Debugging is arranged on a case by case basis with a copy of the production data in a staging environment as a preferred solution or a temporary account with limited privileges if needed.






                  share|improve this answer


























                    3












                    3








                    3







                    You can't cut off a specific client, as already detailed in the other answers.



                    The solution is to remove the access privileges to the production systems from the developer's accounts.



                    Any change must be scripted and a dba will run the script.



                    Deployment is performed by a sysadmin; devs produce a package they give to someone with proper privileges and devs never see the configs used on production systems.



                    Debugging is arranged on a case by case basis with a copy of the production data in a staging environment as a preferred solution or a temporary account with limited privileges if needed.






                    share|improve this answer













                    You can't cut off a specific client, as already detailed in the other answers.



                    The solution is to remove the access privileges to the production systems from the developer's accounts.



                    Any change must be scripted and a dba will run the script.



                    Deployment is performed by a sysadmin; devs produce a package they give to someone with proper privileges and devs never see the configs used on production systems.



                    Debugging is arranged on a case by case basis with a copy of the production data in a staging environment as a preferred solution or a temporary account with limited privileges if needed.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered yesterday









                    PaoloPaolo

                    354212




                    354212























                        0















                        1. In the ideal sense, this is a process / policy / management issue. Even if someone knows the password, if it is against company policy for anyone but a DBA to connect to Production (well, you might have a Release Engineering team and/or sys admins, etc), and there are penalties for breaking the rules, then that should be sufficient (assuming that such rules are enforced).


                        2. Trying to prevent a particular application from connecting is impossible. As sepupic demonstrated, it is fairly easy to change the "program name". But even if the developer can't figure that out, there are plenty of other programs that can connect to SQL Server. Most people will have access to SQLCMD.exe and even the deprecated OSQL.exe. The developer can connect from within Visual Studio, and they can even create their own app to connect via ".Net SqlClient Data Provider". Oh, and now we even have Azure Data Studio. It's just too many.



                        3. Still, this might could still be possible if we approach it from the other direction: instead of preventing application X from connecting, how about only allowing application Y to connect? Sure, we again get into the "program name", and even "hostname" can be spoofed, BUT, I am pretty sure that the client's IP Address cannot be spoofed (at least not through the connection string keywords). You know the IP Address of the app server(s), or can easily find it from the sys.dm_exec_connections DMV (in the client_net_address field).



                          Starting with the Logon Trigger suggested by EzLo, we can modify the logic that determines if the connection is valid or not to be the following:



                          IF (ORIGINAL_LOGIN() = N'SQLLogin1'
                          AND (
                          CONVERT(VARCHAR(10), CONNECTIONPROPERTY('net_transport')) <> 'TCP'
                          OR CONVERT(VARCHAR(10), CONNECTIONPROPERTY('client_net_address')) <> '10.10.10.10'
                          -- uncomment below (and comment-out line above) if app uses multiple IP addresses
                          -- OR CONVERT(VARCHAR(10), CONNECTIONPROPERTY('client_net_address'))
                          -- NOT IN ( '10.10.10.10', '10.10.10.11', ...)
                          ))
                          BEGIN
                          RAISERROR('Non-application connection refused.', 16, 1);
                          ROLLBACK;
                          END;


                          The only ways in now would be to either log onto the Production machine, or to have their workstation spoof the IP of the app server. Hopefully devs do not have any access to log onto Production. And spoofing an existing IP on a network causes problems which might adversely affect Production, so they won't be trying that, right? Right?








                        share|improve this answer




























                          0















                          1. In the ideal sense, this is a process / policy / management issue. Even if someone knows the password, if it is against company policy for anyone but a DBA to connect to Production (well, you might have a Release Engineering team and/or sys admins, etc), and there are penalties for breaking the rules, then that should be sufficient (assuming that such rules are enforced).


                          2. Trying to prevent a particular application from connecting is impossible. As sepupic demonstrated, it is fairly easy to change the "program name". But even if the developer can't figure that out, there are plenty of other programs that can connect to SQL Server. Most people will have access to SQLCMD.exe and even the deprecated OSQL.exe. The developer can connect from within Visual Studio, and they can even create their own app to connect via ".Net SqlClient Data Provider". Oh, and now we even have Azure Data Studio. It's just too many.



                          3. Still, this might could still be possible if we approach it from the other direction: instead of preventing application X from connecting, how about only allowing application Y to connect? Sure, we again get into the "program name", and even "hostname" can be spoofed, BUT, I am pretty sure that the client's IP Address cannot be spoofed (at least not through the connection string keywords). You know the IP Address of the app server(s), or can easily find it from the sys.dm_exec_connections DMV (in the client_net_address field).



                            Starting with the Logon Trigger suggested by EzLo, we can modify the logic that determines if the connection is valid or not to be the following:



                            IF (ORIGINAL_LOGIN() = N'SQLLogin1'
                            AND (
                            CONVERT(VARCHAR(10), CONNECTIONPROPERTY('net_transport')) <> 'TCP'
                            OR CONVERT(VARCHAR(10), CONNECTIONPROPERTY('client_net_address')) <> '10.10.10.10'
                            -- uncomment below (and comment-out line above) if app uses multiple IP addresses
                            -- OR CONVERT(VARCHAR(10), CONNECTIONPROPERTY('client_net_address'))
                            -- NOT IN ( '10.10.10.10', '10.10.10.11', ...)
                            ))
                            BEGIN
                            RAISERROR('Non-application connection refused.', 16, 1);
                            ROLLBACK;
                            END;


                            The only ways in now would be to either log onto the Production machine, or to have their workstation spoof the IP of the app server. Hopefully devs do not have any access to log onto Production. And spoofing an existing IP on a network causes problems which might adversely affect Production, so they won't be trying that, right? Right?








                          share|improve this answer


























                            0












                            0








                            0








                            1. In the ideal sense, this is a process / policy / management issue. Even if someone knows the password, if it is against company policy for anyone but a DBA to connect to Production (well, you might have a Release Engineering team and/or sys admins, etc), and there are penalties for breaking the rules, then that should be sufficient (assuming that such rules are enforced).


                            2. Trying to prevent a particular application from connecting is impossible. As sepupic demonstrated, it is fairly easy to change the "program name". But even if the developer can't figure that out, there are plenty of other programs that can connect to SQL Server. Most people will have access to SQLCMD.exe and even the deprecated OSQL.exe. The developer can connect from within Visual Studio, and they can even create their own app to connect via ".Net SqlClient Data Provider". Oh, and now we even have Azure Data Studio. It's just too many.



                            3. Still, this might could still be possible if we approach it from the other direction: instead of preventing application X from connecting, how about only allowing application Y to connect? Sure, we again get into the "program name", and even "hostname" can be spoofed, BUT, I am pretty sure that the client's IP Address cannot be spoofed (at least not through the connection string keywords). You know the IP Address of the app server(s), or can easily find it from the sys.dm_exec_connections DMV (in the client_net_address field).



                              Starting with the Logon Trigger suggested by EzLo, we can modify the logic that determines if the connection is valid or not to be the following:



                              IF (ORIGINAL_LOGIN() = N'SQLLogin1'
                              AND (
                              CONVERT(VARCHAR(10), CONNECTIONPROPERTY('net_transport')) <> 'TCP'
                              OR CONVERT(VARCHAR(10), CONNECTIONPROPERTY('client_net_address')) <> '10.10.10.10'
                              -- uncomment below (and comment-out line above) if app uses multiple IP addresses
                              -- OR CONVERT(VARCHAR(10), CONNECTIONPROPERTY('client_net_address'))
                              -- NOT IN ( '10.10.10.10', '10.10.10.11', ...)
                              ))
                              BEGIN
                              RAISERROR('Non-application connection refused.', 16, 1);
                              ROLLBACK;
                              END;


                              The only ways in now would be to either log onto the Production machine, or to have their workstation spoof the IP of the app server. Hopefully devs do not have any access to log onto Production. And spoofing an existing IP on a network causes problems which might adversely affect Production, so they won't be trying that, right? Right?








                            share|improve this answer














                            1. In the ideal sense, this is a process / policy / management issue. Even if someone knows the password, if it is against company policy for anyone but a DBA to connect to Production (well, you might have a Release Engineering team and/or sys admins, etc), and there are penalties for breaking the rules, then that should be sufficient (assuming that such rules are enforced).


                            2. Trying to prevent a particular application from connecting is impossible. As sepupic demonstrated, it is fairly easy to change the "program name". But even if the developer can't figure that out, there are plenty of other programs that can connect to SQL Server. Most people will have access to SQLCMD.exe and even the deprecated OSQL.exe. The developer can connect from within Visual Studio, and they can even create their own app to connect via ".Net SqlClient Data Provider". Oh, and now we even have Azure Data Studio. It's just too many.



                            3. Still, this might could still be possible if we approach it from the other direction: instead of preventing application X from connecting, how about only allowing application Y to connect? Sure, we again get into the "program name", and even "hostname" can be spoofed, BUT, I am pretty sure that the client's IP Address cannot be spoofed (at least not through the connection string keywords). You know the IP Address of the app server(s), or can easily find it from the sys.dm_exec_connections DMV (in the client_net_address field).



                              Starting with the Logon Trigger suggested by EzLo, we can modify the logic that determines if the connection is valid or not to be the following:



                              IF (ORIGINAL_LOGIN() = N'SQLLogin1'
                              AND (
                              CONVERT(VARCHAR(10), CONNECTIONPROPERTY('net_transport')) <> 'TCP'
                              OR CONVERT(VARCHAR(10), CONNECTIONPROPERTY('client_net_address')) <> '10.10.10.10'
                              -- uncomment below (and comment-out line above) if app uses multiple IP addresses
                              -- OR CONVERT(VARCHAR(10), CONNECTIONPROPERTY('client_net_address'))
                              -- NOT IN ( '10.10.10.10', '10.10.10.11', ...)
                              ))
                              BEGIN
                              RAISERROR('Non-application connection refused.', 16, 1);
                              ROLLBACK;
                              END;


                              The only ways in now would be to either log onto the Production machine, or to have their workstation spoof the IP of the app server. Hopefully devs do not have any access to log onto Production. And spoofing an existing IP on a network causes problems which might adversely affect Production, so they won't be trying that, right? Right?









                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered 3 hours ago









                            Solomon RutzkySolomon Rutzky

                            48.9k581177




                            48.9k581177






























                                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%2f231228%2fhow-to-deny-access-to-sql-server-to-certain-login-over-ssms-but-allow-over-net%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

                                Tabula Rosettana

                                Chemia organometallica

                                YA sci-fi/fantasy/horror book about a kid that has to overcome a lot of trials