-
The link to impersonate users is not available by default. To activate this tool, you need to set the
IMPERSONATION_URL
environment variable with the frontend URL where the auth params are taken and sent back to the server at/api/v1/impersonations
. Additionally, you need to enable theimpersonation_tool
feature flag, which is already registered and can be activated via the admin panel. -
Add
include API::Concerns::Impersonation::Hooks
toapp/controllers/api/v1/api_controller.rb
in order to set theimpersonated_by
attribute in thecurrent_user
and theimpersonated
header in the response.
-
Access Impersonation Link:
AdminUser
s can find a link to impersonate users within the ActiveAdmin show page for users.
-
Initiate Impersonation Request:
- When an
AdminUser
clicks on the impersonation link, a request containing signed data is sent to a route specified by theIMPERSONATION_URL
environment variable.
- When an
-
Verify Data and Obtain Authentication Headers:
- The designated route responsible for handling the signed data must make a POST request to
api/v1/impersonations
. This action retrieves the necessary authentication headers, including an additional header indicating that the headers are associated with an ongoing impersonation session. This extra header is namedimpersonated
.
- The designated route responsible for handling the signed data must make a POST request to
-
Establish Impersonation Session:
- With the obtained headers, the frontend is equipped to make requests to the server, effectively simulating the experience of being another user.
This workflow ensures a secure and seamless user impersonation process for AdminUser
s. Adjust the configurations as needed based on your environment and requirements.
The signed data has a TTL of 5 minutes, to change this value update the Impersonation::Verifier::EXPIRATION
constant.
Impersonated sessions have a TTL of 1 hour, to change this value update the lifespan at app/objects/impersonation/authenticator.rb
- Before using this tool check your compliance with GDPR, SOC-2, and other security standards concerning sensitive data.
- Define policies that explicitly allow or disallow actions when using the user impersonation feature.
- Authentication is managed by Devise. Admin users without a valid session cannot utilize the impersonation tool.
- Ensure robust permissions and auditing mechanisms:
- Limit impersonation to specific roles, such as admins and the support team.
- Log every impersonation attempt, capturing details like the admin, the impersonated user, actions performed, and timestamps.
- Implement a clear indication in the UI when impersonation is active to avoid confusion. Consider using a banner or color change for visibility.
Before integrating a new Analitycs Tool, it's important to keep in mind that the impersonation feature can impact the metrics obtained.
Consider the actions that can be generated by a user who is impersonating, as the data may not accurately reflect real user activity. Examples of affected indicators could include clicks and visits.