SQL Clone
SQLServerCentral is supported by Redgate
Log in  ::  Register  ::  Not logged in

Restrict the usage of a SQL Server Authenticated Application Id

SQL Server login ids may not be the most secure thing in the world but they are likely to be around for quite a while and one of the more common uses of them is as an application id. An application uses a SQL Server id to connect to SQL and then controls its own security internally. The problem comes in when developers decide “Hey, I have the password to the app id, it has way more permissions in the database than I do. I’ll just use it.” So why is that a problem? Well, here are a few examples:

  • Clear text passwords. There are ways to send an encrypted password to SQL but if the developer is doing something like this they probably aren’t using them.
  • Lack of clear accountability. There is no way to know for certain who is using the id. It could be anyone.
  • Permissions are controlled for a reason. This developer is using permissions not properly granted to them, possibly causing a data breach through a lack of understanding of why these procedures are in place. Heck, they could be the data breach themselves. It wouldn’t be the first time an employee has stolen data.
  • Avoiding being accused of stealing data. Guess what, if you have access to this account and data is stolen using it, you are a suspect. No one want’s that unless it’s unavoidable right?
  • Not to mention that SQL Authentication is just less secure to begin with.

Anyone of these would cause you to fail a security audit. All of them together? Not good.

So how do we fix it? Well, the best possible method is to not give your developers the password. Use config files containing an encrypted copy of the password and you can dramatically limit knowledge of the password. However, that isn’t necessarily a quick or easy solution (modifying the app to use a config file at all for example). So what to do in the meantime?

The simplest thing to do is to create a logon trigger to control where this account can come from. Before we start if you are going to use a logon trigger make sure you know how to log in and disable it if there are any mistakes.

USE master
CREATE TRIGGER [Control_AppLogin] 
	DECLARE @error nvarchar(150);
	-- Check for the app login name.
	IF ORIGINAL_LOGIN() = 'test_app_login'
        AND (
			-- Check that the application is Management Studio.
			APP_NAME() = 'Microsoft SQL Server Management Studio - Query'
			-- Make sure that the connection is coming from the application server
			OR HOST_NAME() <> 'ApplicationServerName'
		SET @error = HOST_NAME() + N' attempted to login in using ' + ORIGINAL_LOGIN() + ' from Management Studio.' ;
		RAISERROR (@error, 25, 1) WITH LOG;

Note: The same trigger could hit several app ids at once, multiple applications etc. Here I’m hitting one login and I’m being pretty specific about the application name (although it does appear the object explorer uses the same name). I’m also saying that all connections have to come from a specific machine (the application server).

The downside here is that you can fairly easily pretend you are coming in through a different application or even a different machine. Heck, the way things are set up you could just use Excel from the application machine to access the data. The upside is that most people wouldn’t bother even if they did know how. The problem is, this comes under the heading of “security by obscurity” which really isn’t. It’s going to help prevent accidental issues but not necessarily intentional ones. Which is why the top two methods are Use Windows Authentication and if for some reason that isn’t possible Minimize the number of people who have access to the password.


My name is Kenneth Fisher and I am Senior DBA for a large (multi-national) insurance company. I have been working with databases for over 20 years starting with Clarion and Foxpro. I’ve been working with SQL Server for 12 years but have only really started “studying” the subject for the last 3. I don’t have any real "specialities" but I enjoy trouble shooting and teaching. Thus far I’ve earned by MCITP Database Administrator 2008, MCTS Database Administrator 2005, and MCTS Database Developer 2008. I’m currently studying for my MCITP Database Developer 2008 and should start in on the 2012 exams next year. My blog is at www.sqlstudies.com.


Leave a comment on the original post [sqlstudies.com, opens in a new window]

Loading comments...