Can't create prefix via available-prefixes API endpoint with all needed constraint permissions #4595

Closed
opened 2025-12-29 18:38:04 +01:00 by adam · 6 comments
Owner

Originally created by @Dimaqa on GitHub (Feb 25, 2021).

Originally assigned to: @jeremystretch on GitHub.

Environment

  • Python version: 3.6.9
  • NetBox version: 2.10.3

Steps to Reproduce

  1. As admin create active prefix
  2. Create permission to view all prefixes
  3. Create permission to add reserved prefix
  4. As test user with permissions above POST on /api/ipam/prefixes/{created_active_prefix_id}/available-prefixes/ with body {"status" : "reserved", "prefix_length" : 24}
  5. API will return 404 NOT FOUND error
  6. GET on /api/ipam/prefixes/{created_active_prefix_id}/available-prefixes/ works fine

Expected Behavior

Create reserved child prefix.

Observed Behavior

NOT FOUND error

This is related to #5841, but deserves separate bugreport.
Creation via web interface works fine.

Originally created by @Dimaqa on GitHub (Feb 25, 2021). Originally assigned to: @jeremystretch on GitHub. <!-- NOTE: IF YOUR ISSUE DOES NOT FOLLOW THIS TEMPLATE, IT WILL BE CLOSED. This form is only for reporting reproducible bugs. If you need assistance with NetBox installation, or if you have a general question, please start a discussion instead: https://github.com/netbox-community/netbox/discussions Please describe the environment in which you are running NetBox. Be sure that you are running an unmodified instance of the latest stable release before submitting a bug report, and that any plugins have been disabled. --> ### Environment * Python version: 3.6.9 * NetBox version: 2.10.3 <!-- Describe in detail the exact steps that someone else can take to reproduce this bug using the current stable release of NetBox. Begin with the creation of any necessary database objects and call out every operation being performed explicitly. If reporting a bug in the REST API, be sure to reconstruct the raw HTTP request(s) being made: Don't rely on a client library such as pynetbox. --> ### Steps to Reproduce 1. As admin create active prefix 2. Create permission to view all prefixes 3. Create permission to add reserved prefix 4. As test user with permissions above POST on /api/ipam/prefixes/{created_active_prefix_id}/available-prefixes/ with body {"status" : "reserved", "prefix_length" : 24} 5. API will return 404 NOT FOUND error 6. GET on /api/ipam/prefixes/{created_active_prefix_id}/available-prefixes/ works fine <!-- What did you expect to happen? --> ### Expected Behavior Create reserved child prefix. <!-- What happened instead? --> ### Observed Behavior NOT FOUND error This is related to #5841, but deserves separate bugreport. Creation via web interface works fine.
adam added the type: bugstatus: accepted labels 2025-12-29 18:38:04 +01:00
adam closed this issue 2025-12-29 18:38:05 +01:00
Author
Owner

@DanSheps commented on GitHub (Feb 25, 2021):

So just so we are clear. The test user has the following permissions:

  • View all prefixes
  • Create prefixes with status "reserved" (only)
@DanSheps commented on GitHub (Feb 25, 2021): So just so we are clear. The test user has the following permissions: * View all prefixes * Create prefixes with status "reserved" (only)
Author
Owner

@Dimaqa commented on GitHub (Feb 25, 2021):

Yes, that's right.
image

@Dimaqa commented on GitHub (Feb 25, 2021): Yes, that's right. ![image](https://user-images.githubusercontent.com/33034690/109172820-3bf96f80-7794-11eb-9f0b-a9b4a2d68d4a.png)
Author
Owner

@jeremystretch commented on GitHub (Mar 11, 2021):

The 404 is returned due to a permissions failure. DRF is checking the necessary permissions (POST, status=reserved) against the parent prefix object rather than the one being created. I'm not sure how to properly adjust the permissions evaluation.

As a workaround, you can request the next available prefix using GET, and then create it directly using a POST to the /api/ipam/prefixes/ endpoint.

@jeremystretch commented on GitHub (Mar 11, 2021): The 404 is returned due to a permissions failure. DRF is checking the necessary permissions (POST, status=reserved) against the parent prefix object rather than the one being created. I'm not sure how to properly adjust the permissions evaluation. As a workaround, you can request the next available prefix using GET, and then create it directly using a POST to the `/api/ipam/prefixes/` endpoint.
Author
Owner

@Dimaqa commented on GitHub (Mar 15, 2021):

Can't you override permission_classes in PrefixViewSet with custom permission class with same idea as in def get_serializer_class(self):? Because it's not that simple to ensure parrallel lock in your workaround

@Dimaqa commented on GitHub (Mar 15, 2021): Can't you override `permission_classes ` in `PrefixViewSet` with custom permission class with same idea as in `def get_serializer_class(self):`? Because it's not that simple to ensure parrallel lock in your workaround
Author
Owner

@github-actions[bot] commented on GitHub (Apr 30, 2021):

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. Please see our contributing guide.

@github-actions[bot] commented on GitHub (Apr 30, 2021): This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. Please see our [contributing guide](https://github.com/netbox-community/netbox/blob/develop/CONTRIBUTING.md).
Author
Owner

@github-actions[bot] commented on GitHub (Jul 25, 2021):

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. Please see our contributing guide.

@github-actions[bot] commented on GitHub (Jul 25, 2021): This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. Please see our [contributing guide](https://github.com/netbox-community/netbox/blob/develop/CONTRIBUTING.md).
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#4595