views:

94

answers:

3

I know there are plenty of questions here already about this topic (I've read through as many as I could find), but I haven't yet been able to figure out how best to satisfy my particular criteria. Here are the goals:

  1. The ASP.NET application will run on a few different web servers, including localhost workstations for development. This means encrypting web.config using a machine key is out. Each "type" or environment of web server (dev, test, prod) has its own corresponding database (dev, test, prod). We want to separate these connection strings so that a developer working on the "dev" code is not able to see any "prod" connection string passwords, nor allow these production passwords to ever get deployed to the wrong server or committed to SVN.

  2. The application will should be able to decide which connection string to attempt to use based on the server name (using a switch statement). For example, "localhost" and "dev.example.com" will should know to use the DevDatabaseConnectionString, "test.example.com" will use the TestDatabaseConnectionString, and "www.example.com" will use the ProdDatabaseConnectionString, for example. The reason for this is to limit the chance for any deployment accidents, where the wrong type of web server connects to the wrong database.

  3. Ideally, the exact same executables and web.config should be able to run on any of these environments, without needing to tailor or configure each environment separately every time that we deploy (something that seems like it would be easy to forget/mess up one day during a deployment, which is why we moved away from having just one connectionstring that has to be changed on each target). Deployment is currently accomplished via FTP. Update: Using "build events " and revising our deployment procedures is probably not a bad idea.

  4. We will not have command-line access to the production web server. This means using aspnet_regiis.exe to encrypt the web.config is out. Update: We can do this programmatically so this point is moot.

  5. We would prefer to not have to recompile the application whenever a password changes, so using web.config (or db.config or whatever) seems to make the most sense.

  6. A developer should not be able to get to the production database password. If a developer checks the source code out onto their localhost laptop (which would determine that it should be using the DevDatabaseConnectionString, remember?) and the laptop gets lost or stolen, it should not be possible to get at the other connection strings. Thus, having a single RSA private key to un-encrypt all three passwords cannot be considered. (Contrary to #3 above, it does seem like we'd need to have three separate key files if we went this route; these could be installed once per machine, and should the wrong key file get deployed to the wrong server, the worst that should happen is that the app can't decrypt anything---and not allow the wrong host to access the wrong database!)

  7. UPDATE/ADDENDUM: The app has several separate web-facing components to it: a classic ASMX Web Services project, an ASPX Web Forms app, and a newer MVC app. In order to not go mad having the same connection string configured in each of these separate projects for each separate environment, it would be nice to have this only appear in one place. (Probably in our DAL class library or in a single linked config file.)

I know this is probably a subjective question (asking for a "best" way to do something), but given the criteria I've mentioned, I'm hoping that a single best answer will indeed arise.

Thank you!

+1  A: 
  1. you can have multiple web servers with the same encrypted key. you would do this in machine config just ensure each key is the same.

..

one common practice, is to store first connection string encrypted somewhere on the machine such as registry. after the server connects using that string, it will than retrieve all other connection strings which would be managed in the database (also encrypted). that way connection strings can be dynamically generated based on authorization requirements (requestor, application being used, etc) for example the same tables can be accessed with different rights depending on context and users/groups

i believe this scenario addresses all (or most?) of your points..

Sonic Soul
Regarding making the machine.config the same on everyone's machine (servers and dev workstations), would this not then allow a developer to decrypt the production database connection string? I am hoping to achieve a separation whereby this would _not_ be possible. (Worst-case scenario, a developer laptop is stolen and can be used to gain access to this!)
Funka
no.. if you can't break the encryption on one machine, why would you be able to do the same thing on another machine? it doesn't make it any less secure to have the same key on all web servers.
Sonic Soul
If we give the developers the same machine key as is used on the production webserver, they (or whoever steals their computer) don't need to "break" anything. We've just given them the key!
Funka
how does having a different key on each web server solve the scenario you've just described?
Sonic Soul
I have edited my question and clarified #1. The point was to provide some background details in order to arrive at a good solution, not to presume that such a solution might have anything to do with a machine.config file or not. (And hence why I'm asking!) Thx!
Funka
+3  A: 

Integrated authentication/windows authentication is a good option. No passwords, at least none that need be stored in the web.config. In fact, it's the option I prefer unless admins have explicity taken it away from me.

Personally, for anything that varies by machine (which isn't just connection string) I put in a external reference from the web.config using this technique: http://www.devx.com/vb2themax/Tip/18880

When I throw code over the fence to the production server admin, he gets a new web.config, but doesn't get the external file-- he uses the one he had earlier.

MatthewMartin
using integrated/windows auth would simplify this, but does that not shift somewhat of the burden to the system/machine administrators (setting up the users/credentials/domain etc) away from the programmers? If someone wants to work from home on their own machine, having a connection string to the dev database allows them to get right to work and not worry about this aspect.
Funka
I put a lot of thought into this once when I was trying to figure out how to make an ASP.NET app (a blog like thing) as easy to deploy for people for whom it was unreasonable to ask to know even basic admin tasks. I decided only a file based database would be easy enough. dasBlog (which uses solely XML files as a db) is a good example of this. But even then, after removing the need for a config string, password or user ID, you still have to make the files writable and give NTFS write permissions to the IIS account. For ultimate simplicity, find a DB+webserver with no security what-so-ever.
MatthewMartin
Using a separate .config file is certainly a good idea and one I'm looking into. Using a different key name in each (tied to a particular server name, as we're currently already doing) could eliminate the possibility for the wrong file to be used in the wrong environment. We would probably want to not have this file checked into SVN to minimize someone grabbing the wrong "version" of this file, and of course to not expose the passwords to it either.
Funka
Running a site/db with no security whatsoever would _certainly_ be the ultimate form of simplicity; unfortunately, we need our lovely SQL Server and need to allow only the right people to be looking around in it!
Funka
+1  A: 
Funka