Principal of Least Privilege

The Principal of Least Privilege is the concept of running with the lowest permission set possible.  Historically we developers tend to run on accounts that have Administrator level privileges.  It's been talked about over and over that we shouldn't so I'm not going to get into that here.  We know that we should, but we're either to lazy or not able to accomplish this feat.

I just got a new laptop and I was setting it up last week when I ran into some interesting things.  I'm running Vista with least privileges and I didn't even notice or care.  Then I tried to install a couple of developer tools into the Program Files folder and run them.  Sure I got the now infamous prompt "Are you sure?" that Vista is known for, but that wasn't the problem.  I actually didn't mind it since I was xcopy-ing files into a semi-system folder.  I don't want that to happen without me knowing.

Instead the thing that really got me worked up happened when I went to run them.  Both applications failed to run successfully for roughly the same reason: trying to write to the application's installation directory.  When I looked into the error logs, both application were trying to save user configuration files (like settings and most recent files) to their directories. 

Why?  Haven't we as developers gotten past this back, oh, when we were working in VB6 (or whatever you worked in at that time)?

It was so bad that one application had to be killed from Task Manager to get out of it.  You couldn't shut it down in any other way.  To the folks who wrote these apps (and got sternly worded defects logged by me), I can't believe that you'd do this.  Especially with the reason (yes this is what I was told by one) that "...we didn't want to spread files related to the application all over the file system..."  Anyways, Least Privilege is tough to accomplish.  I don't need to be hindered by the tools that I'm using on top of everything else.

posted @ Monday, April 07, 2008 9:29 PM

Print

Comments on this entry:

# re: Principal of Least Privilege

Left by Joshua McKinney at 4/8/2008 12:07 AM
Gravatar
Perhaps name and shame is the key here.

# re: Principal of Least Privilege

Left by Jon Limjap at 4/8/2008 2:05 AM
Gravatar
N00bness is something that gets more irritating as we gain more experience, but everyone goes through it.

However, if this guy (person who justified saving in installation directory) has something like 5 or more years under their belt, that's a red flag.

# re: Principal of Least Privilege

Left by Jimmy Bogard at 4/8/2008 6:28 AM
Gravatar
It's so easy to test for, too. One of the first things we did when testing was to install as an admin, then use it as a non-admin. This 5 minute exercise pointed us in the right direction.

# re: Principal of Least Privilege

Left by Shaneo at 4/8/2008 9:48 AM
Gravatar
Donald, I can understand your frustration.

Can you explain to your devoted readers what would be the proper way to implement such functionality?

# re: Principal of Least Privilege

Left by Tom Opgenorth at 4/9/2008 7:50 AM
Gravatar
You know, if you were using Linux or OS X, you wouldn't have this problem. It was solved under *nix a long time ago. :)

@shaneo: things like a user's config files should be saved in the user's home directory, not in the application directory.

# re: Principal of Least Privilege

Left by Donald Belcham at 4/9/2008 9:10 PM
Gravatar
@Joshua -- I've told the people involved what they needed to know. I don't see what naming names is going to do at this point.

@Jimmy -- I completely agree. Not only should we developers be verifying things like this, but any test teams should be required to run under Least Privilege at all times. We devs miss stuff that testers never will.

@Shaneo -- Tom's comment is correct. If you have user settings being stored in your application, they should be pushed to a place that the user will have almost guaranteed access to. The most likely place is the user's AppData folder. For me on Vista that would be:

C:\Users\Donald\AppData\Local\MyApplicationName

@Tom -- don't you have VSS corruption to fix?

# re: Principal of Least Privilege

Left by flipdoubt at 4/12/2008 2:15 PM
Gravatar
Fess up, Donald: what kind of laptop?

I'm not asking Donald to name names, but doesn't Visual Studio complain that it won't run properly if it doesn't run with elevated access?


# re: Principal of Least Privilege

Left by Donald Belcham at 4/12/2008 8:39 PM
Gravatar
@flipdoubt -- You're right, VS does throw a bit of a hissy fit if you don't run it with elevated privileges. I've just succumbed to this pain, so VS is not one of the two that were on the list.

The laptop -- Dell Inspiron 1720 with 4GB of memory and dual internal hard drives...one for the host machine and one for nothing but virtualized stuff. It's pretty sweet with the exception of no context menu button.
Comments have been closed on this topic.