Coder Social home page Coder Social logo

avallbona / impostor Goto Github PK

View Code? Open in Web Editor NEW
157.0 7.0 31.0 94 KB

Django app that enables staff to log in as other users using their own credentials.

License: MIT License

Python 91.82% HTML 8.18%
impersonation django python hacktoberfest

impostor's Introduction

Impostor

pypi codecov Downloads Hit counter Python versions PyPI - Django Version Python package Upload Python Package Codacy Badge

Impostor is a Django application which allows staff members to login as a different user by using their own username and password.

Login

Login

Logged as

Logged as

Impostor log

Impostor log

Every such authentication is recorded in database and listed in admin interface to everyone with an access to ImpostorLog interface. However it is not possible to delete log entries through admin interface to make covering tracks more difficult.

Impostor was tested with Django 1.11 and above. It might work with other versions too. It also depends on Django's authentication system and assumes you use its usernames for authentication.

Impostor is a MMM project developed by Marko Samastur ([email protected]) and maintained by Andreu Vallbona ([email protected])
licensed under MIT license.

Installation

Impostor won't work, if you are not using Django's auth system. It currently uses settings AUTH_USER_MODEL(default: django.contrib.auth.models.User) USERNAME_FIELD(default: username) or username as authentication parameter along with password and user object _default_manager get_by_natural_key function for returning user object from USERNAME_FIELD.

First install impostor app files as you would any other Django app

pip install impostor

Next some changes to your Django settings file are inorder.

Add impostor.backend.AuthBackend To AUTHENTICATION_BACKENDS : This will add impostor auth backend to other backends. AUTHENTICATION_BACKENDS is a tuple listing backends and if you don't have it yet, then add following lines to your settings:

AUTHENTICATION_BACKENDS = (
    'impostor.backend.AuthBackend',
    'django.contrib.auth.backends.ModelBackend',
)

Also add impostor app to INSTALLED_APPS.

INSTALLED_APPS = [
    '...', 
    'impostor',
]

In order to be able to see the user logged as anotheruser in the django admin, be sure to include the 'impostor' app before the 'django.contrib.admin' in the INSTALLED_APPS.

Run

python manage.py migrate

to create needed table and you are set.

Usage

By now you should have a working system. This means that your superuser users (users with is_superuser flag set to True) can log in as different user by using their password and following concatenation:

staff_username as users_username

Example: Let's say my username is markos and I want to login as user fry. Then I would use 'markos as fry' as my username and my normal password for password.

Every such log in is logged in ImpostorLog table that can be seen through Django admin interface, but for obvious security reasons can't be manipulated there.

You can widen set of users who can impose as other users by adding a setting IMPOSTOR_GROUP to settings.py. Users belonging to a group with this name will also be able to pretend to be somebody else (but not superusers).

Impostor also provides a replacement authentication form, because two usernames can easily exceed 30 character limit of original form. Its name is BigAuthenticationForm and you can find it in impostor.forms.

NOTE: Only superuser users can use this (you have to turn on is_superuser for every user that needs this privilege) or those belonging to IMPOSTOR_GROUP and every such log in gets recorded.

Also use IMPOSTOR_GROUP cautiously because it still allows impersonating somebody with different set of permissions (and hence security breach).

Contributing

Contributions are very welcome. Tests can be run with tox, please ensure the coverage at least stays the same before you submit a pull request.

Local development

Install all the python interpreters you need via pyenv. E.g.:

pyenv install 3.9.2
pyenv install 3.8.8
pyenv install 3.7.7
pyenv install 3.6.13
pyenv install 3.5.3

and then make them global with:

pyenv global 3.9.2 3.8.8 3.7.7 3.6.13 3.5.3 

Run the tests

tox

Issues

If you encounter any problems, please file an issue along with a detailed description.

TODO/Wishlist

  • record when impostor logs out
  • mark "hijacked" requests (so impostor can tell when he is using website as somebody else and avoid doing something stupid or that you can limit what is doable in such case)
  • framework for easy notification of hijacked users (so you can notify them that their account has been accessed if you wish)
  • add some tests to improve the coverage

impostor's People

Contributors

avallbona avatar dependabot[bot] avatar gregtap avatar iamsauravsharma avatar ignaciomaestro avatar pre-commit-ci[bot] avatar samastur avatar zen4ever avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

impostor's Issues

Replace is_staff with is_superuser

With Impostor i'm able to login as another user, as a superuser too, right? Thus there's no reason to let it available to the staff instead of the restricted superusers "group".

On the other hand, i need to give access to the admin site to translators and content managers, but i don't want to give them super powers :)

no support for custom user models...

See

impostor.ImpostorLog.imposted_as: (fields.E301) Field defines a relation with the model 'auth.User', which has been swapped out.
HINT: Update the relation to point at 'settings.AUTH_USER_MODEL'.
impostor.ImpostorLog.impostor: (fields.E301) Field defines a relation with the model 'auth.User', which has been swapped out.
HINT: Update the relation to point at 'settings.AUTH_USER_MODEL'.

Bug in backend

Are you aware on the fact that you do not check if a user is superuser in the backend? You check if a user is staff in stead. Meaning that anyone can login as anyone when they know the username and have a User account themselves.

Release on pypi

Hi there,

Thanks for this useful project. Would you mind releasing this project on pypi?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.