Skip to content

Commit b8a8db0

Browse files
Closes #16107: Set LOGIN_REQUIRED to True by default (#16122)
* Closes #16107: Set LOGIN_REQUIRED to True by default * Update tests
1 parent b67eda4 commit b8a8db0

File tree

6 files changed

+15
-11
lines changed

6 files changed

+15
-11
lines changed

docs/configuration/security.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,12 @@ Note that enabling this setting causes NetBox to update a user's session in the
159159

160160
## LOGIN_REQUIRED
161161

162-
Default: False
162+
Default: True
163+
164+
When enabled, only authenticated users are permitted to access any part of NetBox. Disabling this will allow unauthenticated users to access most areas of NetBox (but not make any changes).
163165

164-
Setting this to True will permit only authenticated users to access any part of NetBox. By default, anonymous users are permitted to access most data in NetBox but not make any changes.
166+
!!! info "Changed in NetBox v4.0.2"
167+
Prior to NetBox v4.0.2, this setting was disabled by default.
165168

166169
---
167170

netbox/netbox/configuration_example.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,8 @@
157157
# authenticated to NetBox indefinitely.
158158
LOGIN_PERSISTENCE = False
159159

160-
# Setting this to True will permit only authenticated users to access any part of NetBox. By default, anonymous users
161-
# are permitted to access most data in NetBox but not make any changes.
162-
LOGIN_REQUIRED = False
160+
# Setting this to False will permit unauthenticated users to access most areas of NetBox (but not make any changes).
161+
LOGIN_REQUIRED = True
163162

164163
# The length of time (in seconds) for which a user will remain logged into the web UI before being prompted to
165164
# re-authenticate. (Default: 1209600 [14 days])

netbox/netbox/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@
105105
LANGUAGE_COOKIE_PATH = CSRF_COOKIE_PATH
106106
LOGGING = getattr(configuration, 'LOGGING', {})
107107
LOGIN_PERSISTENCE = getattr(configuration, 'LOGIN_PERSISTENCE', False)
108-
LOGIN_REQUIRED = getattr(configuration, 'LOGIN_REQUIRED', False)
108+
LOGIN_REQUIRED = getattr(configuration, 'LOGIN_REQUIRED', True)
109109
LOGIN_TIMEOUT = getattr(configuration, 'LOGIN_TIMEOUT', None)
110110
LOGOUT_REDIRECT_URL = getattr(configuration, 'LOGOUT_REDIRECT_URL', 'home')
111111
MEDIA_ROOT = getattr(configuration, 'MEDIA_ROOT', os.path.join(BASE_DIR, 'media')).rstrip('/')

netbox/netbox/tests/test_plugins.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ def test_admin(self):
4242
url = reverse('admin:dummy_plugin_dummymodel_add')
4343
self.assertEqual(url, '/admin/dummy_plugin/dummymodel/add/')
4444

45+
@override_settings(LOGIN_REQUIRED=False)
4546
def test_views(self):
4647

4748
# Test URL resolution
@@ -53,7 +54,7 @@ def test_views(self):
5354
response = client.get(url)
5455
self.assertEqual(response.status_code, 200)
5556

56-
@override_settings(EXEMPT_VIEW_PERMISSIONS=['*'])
57+
@override_settings(EXEMPT_VIEW_PERMISSIONS=['*'], LOGIN_REQUIRED=False)
5758
def test_api_views(self):
5859

5960
# Test URL resolution
@@ -65,6 +66,7 @@ def test_api_views(self):
6566
response = client.get(url)
6667
self.assertEqual(response.status_code, 200)
6768

69+
@override_settings(LOGIN_REQUIRED=False)
6870
def test_registered_views(self):
6971

7072
# Test URL resolution

netbox/utilities/testing/api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class APIViewTestCases:
7373

7474
class GetObjectViewTestCase(APITestCase):
7575

76-
@override_settings(EXEMPT_VIEW_PERMISSIONS=['*'])
76+
@override_settings(EXEMPT_VIEW_PERMISSIONS=['*'], LOGIN_REQUIRED=False)
7777
def test_get_object_anonymous(self):
7878
"""
7979
GET a single object as an unauthenticated user.
@@ -135,7 +135,7 @@ def test_options_object(self):
135135
class ListObjectsViewTestCase(APITestCase):
136136
brief_fields = []
137137

138-
@override_settings(EXEMPT_VIEW_PERMISSIONS=['*'])
138+
@override_settings(EXEMPT_VIEW_PERMISSIONS=['*'], LOGIN_REQUIRED=False)
139139
def test_list_objects_anonymous(self):
140140
"""
141141
GET a list of objects as an unauthenticated user.

netbox/utilities/testing/views.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class GetObjectViewTestCase(ModelViewTestCase):
6262
"""
6363
Retrieve a single instance.
6464
"""
65-
@override_settings(EXEMPT_VIEW_PERMISSIONS=['*'])
65+
@override_settings(EXEMPT_VIEW_PERMISSIONS=['*'], LOGIN_REQUIRED=False)
6666
def test_get_object_anonymous(self):
6767
# Make the request as an unauthenticated user
6868
self.client.logout()
@@ -421,7 +421,7 @@ class ListObjectsViewTestCase(ModelViewTestCase):
421421
"""
422422
Retrieve multiple instances.
423423
"""
424-
@override_settings(EXEMPT_VIEW_PERMISSIONS=['*'])
424+
@override_settings(EXEMPT_VIEW_PERMISSIONS=['*'], LOGIN_REQUIRED=False)
425425
def test_list_objects_anonymous(self):
426426
# Make the request as an unauthenticated user
427427
self.client.logout()

0 commit comments

Comments
 (0)