Developer Product Briefs

Secure Your Data With SQL Server

Learn how defining levels of database access, for both nonsensitive and sensitive data, can help protect you from system failure.

Secure Your Data With SQL Server
Learn how defining levels of database access, for both nonsensitive and sensitive data, can help protect you from system failure.
by Alex Papadimoulis

May 1, 2006

In most installations, SQL Server acts as the bottom layer in a standard application stack (user interface, middle tier, and database). Users rarely know what type of database they're using, let alone access and use it directly. For this reason, database security configuration is minimal, and often lax. Sometimes only an easy-to-guess username and password sit between the database and the middle tier.

At first, a lack of security doesn't seem like a problem. If your database is behind a firewall and your users and developers are trusted, you'd think no one would maliciously delete your database. But it takes only one disgruntled (and dedicated) employee to render the system nearly useless by making slow, eroding changes to your business data. And in addition to malicious changes, you have to worry about accidental changes as well. Fortunately, you can take some simple security measures to greatly prevent accidental and malicious damage.

An application database should define at least three different levels of access:

  • User access executes only a set of known queries defined within your application.
  • Developer access provides read-only access to nonsensitive data for production support purposes.
  • Administrator access offers full access to all database objects and data.

The first step in defining these access levels is setting up your security principals (for example, entities that utilize database resources). SQL Server offers a number of mechanisms for database access; their appropriateness depends on your application environment:

  • Integrated, User: Windows logons are granted access on an individual basis.
  • Integrated, Group: A Windows group is granted access, and only current members of the group are granted access.
  • SQL User, Individual: For every user accessing your database, a SQL Server logon is created and granted appropriate access.
  • SQL User, Single: A single SQL Server logon is created and granted access.

Once you've set up your principals, you must enforce each access level. The easiest access level to establish is the administrator level. Simply add the principal to the db_owner role with this command:

USE <database_name>
EXEC sp_addrolemember 'db_owner', '<principal_name>'

As long as you don't have sensitive data in your database, the developer access level is just as easy to set up: Simply add the principal to the db_datareader role. Sensitive data, such as bank account numbers, should be assessed on a case-by-case basis. You can secure it with one of these techniques:

  • Table-level security prevents SELECT access to a specific table with the DENY statement.
  • Column-level security is similar to table-level security; it uses the DENY statement to restrict SELECT access on a column.
  • Encryption: Data can be encrypted at the application level or, in SQL Server 2005, with built-in cryptography functions.

Implementing the user access level requires a slightly different approach: stored procedures. In stored procedures, the user principal requires an EXECUTE privilege for each procedure run by the application. However, if your application has already been developed with inline SQL, you have only one alternative to giving full access. You must grant SELECT, INSERT, UPDATE, and DELETE privileges on tables and columns based on the queries run by the application.

About the Author
Alex Papadimoulis lives in Berea, Ohio. The principal member of Inedo, LLC, he uses his 10 years of IT experience to bring custom software solutions to small- and mid-sized businesses and to help other software development organizations utilize best practices in their products. On the Internet, Alex can usually be found answering questions in various newsgroups and posting some rather interesting real-life examples of how not to program on his Web site TheDailyWTF.com. You can contact Alex directly via email at [email protected].

About the Author

Alex Papadimoulis lives in Berea, Ohio. The principal member of Inedo, LLC, he uses his 10 years of IT experience to bring custom software solutions to small- and mid-sized businesses and to help other software development organizations utilize best practices in their products. On the Internet, Alex can usually be found answering questions in various newsgroups and posting some rather interesting real-life examples of how not to program on his Web site TheDailyWTF.com. You can contact Alex directly via email at [email protected].,

comments powered by Disqus

Featured

  • Full Stack Hands-On Development with .NET

    In the fast-paced realm of modern software development, proficiency across a full stack of technologies is not just beneficial, it's essential. Microsoft has an entire stack of open source development components in its .NET platform (formerly known as .NET Core) that can be used to build an end-to-end set of applications.

  • .NET-Centric Uno Platform Debuts 'Single Project' for 9 Targets

    "We've reduced the complexity of project files and eliminated the need for explicit NuGet package references, separate project libraries, or 'shared' projects."

  • Creating Reactive Applications in .NET

    In modern applications, data is being retrieved in asynchronous, real-time streams, as traditional pull requests where the clients asks for data from the server are becoming a thing of the past.

  • AI for GitHub Collaboration? Maybe Not So Much

    No doubt GitHub Copilot has been a boon for developers, but AI might not be the best tool for collaboration, according to developers weighing in on a recent social media post from the GitHub team.

  • Visual Studio 2022 Getting VS Code 'Command Palette' Equivalent

    As any Visual Studio Code user knows, the editor's command palette is a powerful tool for getting things done quickly, without having to navigate through menus and dialogs. Now, we learn how an equivalent is coming for Microsoft's flagship Visual Studio IDE, invoked by the same familiar Ctrl+Shift+P keyboard shortcut.

Subscribe on YouTube