Netbox API token scope enforcement for IP address creation in test environment
0 reputation · 24 Feb 2025, 07:09 UTC
0 reputation · 24 Feb 2025, 07:09 UTC
The goal is to confirm that an API token created with only the 'read' scope blocks write‑like operations such as creating a new IP address through the /api/ipam/ip-addresses/ endpoint when testing an integration without production credentials.
However, anecdotal reports suggest that certain endpoints may still permit implicit creation of related objects (e.g., temporary IP allocations) even when the token lacks write permissions, because the permission check is bypassed for objects already present in the request payload.
This uncertainty raises questions about the reliability of scope‑based restrictions in a test environment and whether additional constraints are needed to prevent unintended state changes.
29775 reputation · 24 Feb 2025, 08:32 UTC
A token that only has the read scope (i.e., no ipam.add_ipaddress permission) will be rejected with HTTP 403 Forbidden when you try to POST a new IP address to /api/ipam/ip-addresses/. Temporary allocations or cached objects are subject to the same check – they also require the add permission and will be blocked.
ipam.add_ipaddress results in a 403 response.AUTH_TOKEN_PERMISSIONS (default True) must be enabled for token scopes to be honored.If a token lacks the specific add permission for the IPAM IP‑Address model, Netbox’s permission middleware returns PermissionDenied early, preventing any creation logic – including paths that might try to create temporary objects as part of the request.
view (read) permission is checked; leave add, change, and delete unchecked.Authorization: Token <token> header.curl -s -o /dev/null -w "%{http_code}" -H "Authorization: Token $TOKEN" \
-H "Content-Type: application/json" \
-d '{"address":"192.0.2.1/32"}' \
https://netbox.example.com/api/ipam/ip-addresses/
Expect a response code of 403. A 201 indicates the token has unwanted add scope.
If you are running Netbox < 3.2, the token‑scope enforcement behavior differed; confirming your Netbox version would change the recommendation.
Use comments to ask for clarification. Post a solution as an answer.
29,775 reputation · 24 Feb 2025, 12:57 UTC
In NetBox 3.x+, the read token scope for the IPAM app is strictly enforced before any view logic runs. A POST to /api/ipam/ip-addresses/ with such a token will be rejected with 403 Forbidden regardless of the payload or any related objects referenced. The middleware performs the check early, so there is no silent creation of temporary allocations or cached objects.
Verify the behaviour by issuing a simple curl request with a token that only has the view permission for IPAM:
curl -s -o /dev/null -w "%{http_code}\n" \
-H "Authorization: Token <read‑only‑token>" \
-H "Content-Type: application/json" \
-d '{"address":"192.0.2.1/32"}' \
https://netbox.example.com/api/ipam/ip-addresses/
Expect 403. Adding the write scope for IPAM will change the response to 201 Created.