views:

615

answers:

7

When supporting a new web app in an enterprise environment, it is often necessary to log in as a specific user in order to diagnose a real or perceived problem they are having. Two opposing issues apply here:

  1. Best practice is to use hashed or encrypted passwords, not clear text. Sometimes, there is a third-party SSO (single sign-on) in the middle. There is no way to retrieve the user's password. Unless the user provides it (not encouraged), there is no way to log in as that user.

  2. Many web app's have personalization and complex authorization. Different users have different roles (admin, manager, user) with different permissions. Sometimes users can only see their data -- their customers or tasks. Some users have read-only access, while others can edit. So, each user's view of the web app is unique.

Assume that in an enterprise environment, it isn't feasible to go to the user's desk, or to connect directly to their machine.

How do you handle this situation?

Edit: I want to reiterate that in a large financial institution or typical Fortune 500 company with hundreds of thousands of employees all of the country, and around the world, it is not possible for a mere developer in some IT unit to be able to directly access a user's machine. Some of those are public-facing web apps used by customers (such as online banking and stock trading). And, many of those are intranet applications rely on Active Directory or an SSO, meaning that user credentials are the same for many applications. I do thank you all for your suggestions; some may be highly useful in other kinds of environments.

+1  A: 

An administrator should be able to change a user's password. Change the password for the user to something you know. You can then log in as that user.

Tell the user to reset his/her password after you are done debugging.

Matt Brunell
This is unfortunate: why should the user be inconvenienced because you were debugging?
Ned Batchelder
True. If it were possible to 'clone' a user account and use that instead, the end user may not be inconvenienced. This may or may not be feasible. Also, if you can use a 'debuguser' account to see the problem, that may also be preferable--but it may not reproduce.
Matt Brunell
+1  A: 

Usually by some sort of remote control software that can be used to view their desktop. If they're on a Windows terminal server, then the built in admin tools can be used for that. Otherwise I'd use something like VNC across an internal network, or an external service like LogMeIn (http://www.logmein.com/).

fwzgekg
A: 
  1. Could you have a testing environment where there is a regular cut of live data copied to (obviously sanitised to meet any security or data protection issues). A user similar in setup to the one having trouble could be used to troubleshoot or indeed the very user if this is allowed.

  2. Use a remote desktop client as mentioned in other answers, but again this may not be practical for you. If you have these rights within the domain, I have heard of error handling even doing a screenscrape and including this in logs! but this sounds a little odd to me.

  3. Could you have an admin tool to clone a user into a demo account?

dove
+5  A: 

For our web applications we use a process that for lack of a better term is defined as 'hijacking' a user's account.

Basically, administrators can 'hijack' a user's account with a simple button click. In the code, you simply use a unique identifier (user id works in a less secure environment) that then establishes the necessary credentials in the session so that they can then work within that user's profile. For a more secure environment you could use a unique hash for each user.

In order to ensure that this hijack method is secure, it always first verifies that the request is being made by an authenticated administrator with the appropriate rights. Because of this it becomes necessary for either the administrator's session to be hijacked or for their authentication credentials to be captured in order for someone to ever exploit the hijack function within the application.

Noah Goodrich
We also use this method, particularly important when some of our users don't have a username (they use SSO instead). It simply uses the same session system as the username/password and SSO login methods, but from a button in the hijacked account's profile page. We were coerced to give some of our phone support staff permission to hijack user accounts, and they have found it invaluable.
eswald
+2  A: 

I had 4 ideas. While I was typing 3 of them were already suggested (so I upvoted them)

Variant on idea 3 - impersonation:

To make this as "identical as possible" to a normal login with minimal code changes, you might add the ability to impersonate directly at login by supplying Admin credentials plus an alternate username, e.g. login as Admin:user, adminpassword. The system would treat this exactly as logging in as user with userpassword.

Idea 4: Can you access the password store? If so, temporarily replace the user's hash with the hash of a known password. (the passwords are often stored online in a database. A SQL Query tool can do the swaps )

Markc
I like where you're going with #3, and Ned has amplified on that.
DOK
+16  A: 

A number of these ideas inconvenience the user, either by forcing them to change their password, or by occupying their desktop for your debugging session.

Markc's idea is the best: augment your authentication logic to allow superusers to log in as a particular user by supplying not the user's credentials, but the user's name plus their superuser credentials.

I've done it like this in the past (pseudo-ish python):

if is_user_authenticated(username, userpassword):
    login the user
else if ':' in userpassword:
    supername, superpassword = userpassword.split(':')
    if is_superuser_authenticated(supername, superpassword):
        login the user

In other words, if the username and password don't authenticate, if the password has a colon, then it's actually the admin username and admin password joined by a colon, so login as the username if they are the right admin username and password.

This means you can login as the user without knowing their secrets, and without inconveniencing them.

Ned Batchelder
Yes, I think this sounds feasible. In order to reach the app at all, a valid "guest admin" user might have to be created. When that user logs in, they'd get a special UI to enter the username (and other possible info that would've come from someplace like Active Directory, such as Group or Dept).
DOK
There's no need for a special UI. Enter a user's name into the username field, and supername:superpass into the password field.
Ned Batchelder
A: 

The solution we have used in our web apps is to have the authN/authZ return the desired user as the effective user. We do this by having an admin feature to setup a masquerade, and then when we ask for the currently logged in user (current_user), we handle the masquerade:

  def current_user_with_effective_user
    if masked?
      current_user_without_effective_user.masquerade_as
    else
      current_user_without_effective_user
    end
  end
  alias_method_chain, :current_user, :effective_user