-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
User and Group object types missing from permissions in 4.0 #16138
Comments
I think this would sort out the oddities on the navigation menu, but would mean users can't see either the --- a/netbox/netbox/navigation/menu.py
+++ b/netbox/netbox/navigation/menu.py
@@ -372,19 +372,19 @@ ADMIN_MENU = Menu(
link=f'users:user_list',
link_text=_('Users'),
auth_required=True,
- permissions=[f'auth.view_user'],
+ permissions=[f'users.view_user'],
buttons=(
MenuItemButton(
link=f'users:user_add',
title='Add',
icon_class='mdi mdi-plus-thick',
- permissions=[f'auth.add_user']
+ permissions=[f'users.add_user']
),
MenuItemButton(
link=f'users:user_import',
title='Import',
icon_class='mdi mdi-upload',
- permissions=[f'auth.add_user']
+ permissions=[f'users.add_user']
)
)
),
@@ -392,19 +392,19 @@ ADMIN_MENU = Menu(
link=f'users:group_list',
link_text=_('Groups'),
auth_required=True,
- permissions=[f'auth.view_group'],
+ permissions=[f'users.view_group'],
buttons=(
MenuItemButton(
link=f'users:group_add',
title='Add',
icon_class='mdi mdi-plus-thick',
- permissions=[f'auth.add_group']
+ permissions=[f'users.add_group']
),
MenuItemButton(
link=f'users:group_import',
title='Import',
icon_class='mdi mdi-upload',
- permissions=[f'auth.add_group']
+ permissions=[f'users.add_group']
)
)
), |
This fixes the missing Object types on the permissions page, but the --- a/netbox/users/constants.py
+++ b/netbox/users/constants.py
@@ -3,8 +3,7 @@ from django.db.models import Q
OBJECTPERMISSION_OBJECT_TYPES = Q(
~Q(app_label__in=['account', 'admin', 'auth', 'contenttypes', 'sessions', 'taggit', 'users']) |
- Q(app_label='auth', model__in=['group', 'user']) |
- Q(app_label='users', model__in=['objectpermission', 'token'])
+ Q(app_label='users', model__in=['group', 'objectpermission', 'token', 'user'])
)
CONSTRAINT_TOKEN_USER = '$user' |
W.R.T why
As part of the migration, it looks like I note differences between the two migration scripts for users and group ContentTypes, but it is unclear how this affects the contents of |
Started from a clean installation
Inspect the database to get a grasp of how things connect in v3.7.8 netbox=# select id, username, is_superuser, is_staff from auth_user;
id | username | is_superuser | is_staff
----+----------+--------------+----------
1 | root | t | t
2 | jsmith | f | t
(2 rows) I see two users. netbox=# select * from auth_group;
id | name
----+-------
1 | admin
(1 row) I see one group. netbox=# select * from django_content_type where app_label in ('auth', 'users');
id | app_label | model
-----+-----------+------------------
3 | auth | permission
4 | auth | group
5 | auth | user
115 | users | userconfig
116 | users | token
117 | users | objectpermission
118 | users | netboxgroup
119 | users | netboxuser
(8 rows) I see the group and user permissions will be referenced by the content_type id netbox=# select * from auth_permission where content_type_id in (4, 5);
id | name | content_type_id | codename
----+------------------+-----------------+--------------
9 | Can add group | 4 | add_group
10 | Can change group | 4 | change_group
11 | Can delete group | 4 | delete_group
12 | Can view group | 4 | view_group
13 | Can add user | 5 | add_user
14 | Can change user | 5 | change_user
15 | Can delete user | 5 | delete_user
16 | Can view user | 5 | view_user
(8 rows) netbox=# select * from users_objectpermission;
id | name | description | enabled | actions | constraints
----+-------+-------------+---------+--------------------------+-------------
1 | admin | | t | {view,add,change,delete} |
(1 row) I see the permission have just created netbox=# select * from users_objectpermission_groups;
id | objectpermission_id | group_id
----+---------------------+----------
1 | 1 | 1
(1 row) Seems to link the permission to the admin group netbox=# select * from users_objectpermission_object_types;
id | objectpermission_id | contenttype_id
----+---------------------+----------------
1 | 1 | 4
2 | 1 | 5
(2 rows) Seems to link the permission to the group (4) and user (5) content types. Upgrade process instance to latest release
Inspect the database again to get a grasp of how things connect in v4.0.2 netbox=# select id, username, is_superuser, is_staff from auth_user;
ERROR: relation "auth_user" does not exist
LINE 1: select id, username, is_superuser, is_staff from auth_user;
^
netbox=# select id, username, is_superuser, is_staff from users_user;
id | username | is_superuser | is_staff
----+----------+--------------+----------
2 | jsmith | f | t
1 | root | t | t
(2 rows) The old netbox=# select * from auth_group;
id | name
----+------
(0 rows)
netbox=# select * from users_group;
id | name | description
----+-------+-------------
1 | admin |
(1 row)
netbox=# select * from django_content_type where app_label in ('auth', 'users');
id | app_label | model
-----+-----------+------------------
3 | auth | permission
4 | auth | group
115 | users | userconfig
116 | users | token
117 | users | objectpermission
140 | users | group
5 | users | user
(7 rows) The
netbox=# select * from auth_permission where content_type_id in (4, 5, 140);
id | name | content_type_id | codename
-----+------------------+-----------------+--------------
9 | Can add group | 4 | add_group
10 | Can change group | 4 | change_group
11 | Can delete group | 4 | delete_group
12 | Can view group | 4 | view_group
13 | Can add user | 5 | add_user
14 | Can change user | 5 | change_user
15 | Can delete user | 5 | delete_user
16 | Can view user | 5 | view_user
558 | Can add group | 140 | add_group
559 | Can change group | 140 | change_group
560 | Can delete group | 140 | delete_group
561 | Can view group | 140 | view_group
(12 rows) netbox=# select * from users_objectpermission;
id | name | description | enabled | actions | constraints
----+-------+-------------+---------+--------------------------+-------------
1 | admin | | t | {view,add,change,delete} |
(1 row) Unchanged from 3.7.8 netbox=# select * from users_objectpermission_groups;
ERROR: relation "users_objectpermission_groups" does not exist
LINE 1: select * from users_objectpermission_groups;
^
netbox=# select * from users_group_object_permissions;
id | objectpermission_id | group_id
----+---------------------+----------
1 | 1 | 1
(1 row) The old netbox=# select * from users_objectpermission_object_types;
id | objectpermission_id | objecttype_id
----+---------------------+---------------
1 | 1 | 4
2 | 1 | 5
(2 rows) Unchanged from 3.7.8 |
@ibuclaw Going through the other issues here - but FYI to clarify regarding the difference between auth.users and auth.groups remaining in the database. Django has support for custom user models, so when we replace users model the old one is replaced in the database (i.e. the old one is gone). For groups, Django doesn't have any built in support for replacing it so the old model will still be in the database (but un-used) along with the new one. |
@arthanson thanks for the clarification. So I guess there are three things that need addressing.
Is this an accurate reduction of the issue? |
Deployment Type
Self-hosted
NetBox Version
v4.0.2
Python Version
3.11
Steps to Reproduce
In the UI:
Authentication and Authorization > Group
still exists, but it does nothing (Admin > Groups is visible on the navigation bar, but accessing it returns 403 permission denied).Authentication and Authorization > User
is gone, and users who used to have that permission can no longer view/edit the Users page.In Postgresql:
psql -d netbox
\d
auth_user
and all other related tables are gone (suspect one of the migrations did it but it's unclear which).auth_group
andauth_group_permissions
remains but are empty (it's more clear that this is the migration, no apparent deletion of the table is present).Expected Behavior
I see that there's a couple migration scripts. I suspect that the DB migration from
auth_user
tousers_user
is incomplete but don't understand enough to definitively say so.The ability to manipulate Users and Groups should be possible by users without superuser powers. This is more obviously broken since 4.0.x.
Observed Behavior
Users with permission to view/change users and groups get 403 permission denied when accessing those pages.
The text was updated successfully, but these errors were encountered: