Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable file-based session storage #2426

Closed
ghost opened this issue Sep 13, 2018 · 3 comments
Closed

Enable file-based session storage #2426

ghost opened this issue Sep 13, 2018 · 3 comments
Labels
status: accepted This issue has been accepted for implementation type: feature Introduction of new functionality to the application

Comments

@ghost
Copy link

ghost commented Sep 13, 2018

Environment

  • Python version: 3.5.2
  • NetBox version: 2.4.4

Proposed Functionality

Enable "LOGIN_REQUIRED = True" to be set in the configuration.py file for a hot standby / read only copy of netbox and for login to work.

Use Case

Netbox administrator creates two installations and configures them as a MASTER / SLAVE hot standby using postgre. Netbox administrators employer requires logins to be enabled on the Netbox servers due to the nature of the information held within.

This does not present an issue on the MASTER but when attempting to login to the SLAVE this does not work. This would be how it is intended to work currently which is why this is submitted as a feature request and not a bug.

selection_010

Database Changes

Unknown

External Dependencies

Unknown

@jeremystretch
Copy link
Member

Login is not supported on the standby because sessions are stored in the database and the database is read-only, as the error message indicates. Changing this requires designating a new location for session storage; options are listed here.

The best we can do is expose the SESSION_ENGINE setting, as setting up memcached or file storage is out of scope for the project.

@jeremystretch jeremystretch added the status: under review Further discussion is needed to determine this issue's scope and/or implementation label Sep 13, 2018
@jeremystretch jeremystretch changed the title Login to hot standby Enable file-based session storage Nov 13, 2018
@jeremystretch jeremystretch added status: accepted This issue has been accepted for implementation type: feature Introduction of new functionality to the application beta and removed status: under review Further discussion is needed to determine this issue's scope and/or implementation labels Nov 13, 2018
jeremystretch added a commit that referenced this issue Nov 13, 2018
…authentication without write access to database
@jeremystretch
Copy link
Member

I've exposed the SESSION_FILE_PATH configuration setting which, if defined, will enable local file storage for session data. Session data will continue to be stored in the database by default.

@kartiksubbarao
Copy link

kartiksubbarao commented Apr 8, 2019

It looks like SESSION_FILE_PATH may not be sufficient for logins to work on read-only replicas. Even after setting SESSION_FILE_PATH, I get an exception cannot execute UPDATE in a read-only transaction, which is caused by django trying to update the last_login field in the database. As mentioned in this mailing list thread, here's the relevant line from the stack trace:

File "/usr/local/lib/python3.5/dist-packages/django/contrib/auth/models.py", line 20, in update_last_login
    user.save(update_fields=['last_login'])

I did some searching and came across this link:

https://stackoverflow.com/questions/49025407/in-django-1-11-how-to-allow-users-to-login-on-a-read-only-database

It refers to a python module called django-no-last-login which calls user_logged_in.disconnect(update_last_login) to disable the update:

https://github.com/MSA-Argentina/django-no-last-login/blob/master/nolastlogin/models.py#L11

Perhaps something like this might be needed to get this functionality working. Or perhaps I'm missing something. Is anyone able to get logins to read-only replicas to work properly?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: accepted This issue has been accepted for implementation type: feature Introduction of new functionality to the application
Projects
None yet
Development

No branches or pull requests

2 participants