Enable file-based session storage #2004

Closed
opened 2025-12-29 17:21:22 +01:00 by adam · 3 comments
Owner

Originally created by @ghost on GitHub (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

Originally created by @ghost on GitHub (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](https://user-images.githubusercontent.com/29404816/45485291-f45f0480-b74e-11e8-991f-c4bd8c0335e3.png) ### Database Changes Unknown ### External Dependencies Unknown
adam added the status: acceptedtype: feature labels 2025-12-29 17:21:22 +01:00
adam closed this issue 2025-12-29 17:21:22 +01:00
Author
Owner

@jeremystretch commented on GitHub (Sep 13, 2018):

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 commented on GitHub (Sep 13, 2018): 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](https://docs.djangoproject.com/en/2.1/topics/http/sessions/#configuring-the-session-engine). 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.
Author
Owner

@jeremystretch commented on GitHub (Nov 13, 2018):

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.

@jeremystretch commented on GitHub (Nov 13, 2018): 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.
Author
Owner

@kartiksubbarao commented on GitHub (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?

@kartiksubbarao commented on GitHub (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](https://groups.google.com/forum/?utm_medium=email&utm_source=footer#!topic/netbox-discuss/1tYF9d-wRl8), 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 in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#2004