[PR #9590] [MERGED] Closes #8233: Restrict API tokens by source IP #13491

Closed
opened 2025-12-29 23:19:11 +01:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netbox-community/netbox/pull/9590
Author: @jeremystretch
Created: 6/23/2022
Status: Merged
Merged: 6/23/2022
Merged by: @jeremystretch

Base: featureHead: 8233-api-token-ip


📝 Commits (10+)

  • 2587720 Fix 8878: Restrict API key usage by Source IP
  • 086e34f Updated docs relnotes to refer to 8233
  • fa4807b Update releasenotes
  • 536239d Merge branch 'feature' into issue_8233
  • 7043c6f Merge pull request #9175 from PieterL75/issue_8233
  • a38a880 Refactor source IP resolution logic
  • e3b7bba Add token authentication tests
  • 3c15419 Introduce IPNetworkSerializer to serialize allowed token IPs
  • d4db656 Allowed IPs should be optional on Token
  • 7e4b345 Update token model docs

📊 Changes

14 files changed (+221 additions, -16 deletions)

View changed files

📝 docs/models/users/token.md (+1 -1)
📝 docs/release-notes/version-3.3.md (+2 -0)
📝 netbox/netbox/api/__init__.py (+2 -1)
📝 netbox/netbox/api/authentication.py (+23 -1)
📝 netbox/netbox/api/fields.py (+19 -2)
📝 netbox/netbox/tests/test_authentication.py (+66 -1)
📝 netbox/templates/users/api_tokens.html (+11 -4)
📝 netbox/users/admin/__init__.py (+5 -1)
📝 netbox/users/admin/forms.py (+1 -1)
📝 netbox/users/api/serializers.py (+11 -2)
📝 netbox/users/forms.py (+10 -1)
netbox/users/migrations/0003_token_allowed_ips.py (+20 -0)
📝 netbox/users/models.py (+23 -1)
netbox/utilities/request.py (+27 -0)

📄 Description

Closes: #8233

This continues the work started by @PieterL75 in PR #9175.

  • Refactored the client IP evaluation logic into a utility function for future reuse
  • Introduced IPNetworkSerializer for validating allowed_ips array elements
  • Added token authentication tests

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/netbox-community/netbox/pull/9590 **Author:** [@jeremystretch](https://github.com/jeremystretch) **Created:** 6/23/2022 **Status:** ✅ Merged **Merged:** 6/23/2022 **Merged by:** [@jeremystretch](https://github.com/jeremystretch) **Base:** `feature` ← **Head:** `8233-api-token-ip` --- ### 📝 Commits (10+) - [`2587720`](https://github.com/netbox-community/netbox/commit/25877202983182fd12a7b6a31dedca7edf5a589c) Fix 8878: Restrict API key usage by Source IP - [`086e34f`](https://github.com/netbox-community/netbox/commit/086e34f728c4fb873b7e63561bc901e9954a5ec3) Updated docs relnotes to refer to 8233 - [`fa4807b`](https://github.com/netbox-community/netbox/commit/fa4807be8ccf93aed93c42dbcb5231e7657c8e54) Update releasenotes - [`536239d`](https://github.com/netbox-community/netbox/commit/536239d272d05fc5725f9058ccf520b881f827df) Merge branch 'feature' into issue_8233 - [`7043c6f`](https://github.com/netbox-community/netbox/commit/7043c6faf94504f014a84adfab4649154d1adcaa) Merge pull request #9175 from PieterL75/issue_8233 - [`a38a880`](https://github.com/netbox-community/netbox/commit/a38a880e67d78eba52f19cc4c2613e9399939c2f) Refactor source IP resolution logic - [`e3b7bba`](https://github.com/netbox-community/netbox/commit/e3b7bba84ff15ce0c1f512e5348cd13db89ecb0c) Add token authentication tests - [`3c15419`](https://github.com/netbox-community/netbox/commit/3c15419bd0e10a153713707655798d1ac22f194f) Introduce IPNetworkSerializer to serialize allowed token IPs - [`d4db656`](https://github.com/netbox-community/netbox/commit/d4db656940e98b597644106707b4d94a3628e895) Allowed IPs should be optional on Token - [`7e4b345`](https://github.com/netbox-community/netbox/commit/7e4b34560f47ef9f8189600ccd4377cb4fc7566c) Update token model docs ### 📊 Changes **14 files changed** (+221 additions, -16 deletions) <details> <summary>View changed files</summary> 📝 `docs/models/users/token.md` (+1 -1) 📝 `docs/release-notes/version-3.3.md` (+2 -0) 📝 `netbox/netbox/api/__init__.py` (+2 -1) 📝 `netbox/netbox/api/authentication.py` (+23 -1) 📝 `netbox/netbox/api/fields.py` (+19 -2) 📝 `netbox/netbox/tests/test_authentication.py` (+66 -1) 📝 `netbox/templates/users/api_tokens.html` (+11 -4) 📝 `netbox/users/admin/__init__.py` (+5 -1) 📝 `netbox/users/admin/forms.py` (+1 -1) 📝 `netbox/users/api/serializers.py` (+11 -2) 📝 `netbox/users/forms.py` (+10 -1) ➕ `netbox/users/migrations/0003_token_allowed_ips.py` (+20 -0) 📝 `netbox/users/models.py` (+23 -1) ➕ `netbox/utilities/request.py` (+27 -0) </details> ### 📄 Description ### Closes: #8233 This continues the work started by @PieterL75 in PR #9175. - Refactored the client IP evaluation logic into a utility function for future reuse - Introduced IPNetworkSerializer for validating `allowed_ips` array elements - Added token authentication tests --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
adam added the pull-request label 2025-12-29 23:19:11 +01:00
adam closed this issue 2025-12-29 23:19:12 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#13491