netbox-permissions-matrix-plugin 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- netbox_permissions_matrix_plugin-0.1.0/.gitignore +13 -0
- netbox_permissions_matrix_plugin-0.1.0/CHANGELOG.md +28 -0
- netbox_permissions_matrix_plugin-0.1.0/LICENSE +202 -0
- netbox_permissions_matrix_plugin-0.1.0/PKG-INFO +91 -0
- netbox_permissions_matrix_plugin-0.1.0/README.md +65 -0
- netbox_permissions_matrix_plugin-0.1.0/netbox_permissions_matrix_plugin/__init__.py +25 -0
- netbox_permissions_matrix_plugin-0.1.0/netbox_permissions_matrix_plugin/api/__init__.py +0 -0
- netbox_permissions_matrix_plugin-0.1.0/netbox_permissions_matrix_plugin/api/serializers.py +72 -0
- netbox_permissions_matrix_plugin-0.1.0/netbox_permissions_matrix_plugin/api/urls.py +11 -0
- netbox_permissions_matrix_plugin-0.1.0/netbox_permissions_matrix_plugin/api/views.py +155 -0
- netbox_permissions_matrix_plugin-0.1.0/netbox_permissions_matrix_plugin/applier.py +78 -0
- netbox_permissions_matrix_plugin-0.1.0/netbox_permissions_matrix_plugin/conf.py +21 -0
- netbox_permissions_matrix_plugin-0.1.0/netbox_permissions_matrix_plugin/core/__init__.py +4 -0
- netbox_permissions_matrix_plugin-0.1.0/netbox_permissions_matrix_plugin/core/cells.py +48 -0
- netbox_permissions_matrix_plugin-0.1.0/netbox_permissions_matrix_plugin/core/model.py +164 -0
- netbox_permissions_matrix_plugin-0.1.0/netbox_permissions_matrix_plugin/core/planner.py +259 -0
- netbox_permissions_matrix_plugin-0.1.0/netbox_permissions_matrix_plugin/core/token.py +39 -0
- netbox_permissions_matrix_plugin-0.1.0/netbox_permissions_matrix_plugin/core/yaml_io.py +200 -0
- netbox_permissions_matrix_plugin-0.1.0/netbox_permissions_matrix_plugin/loader.py +118 -0
- netbox_permissions_matrix_plugin-0.1.0/netbox_permissions_matrix_plugin/matrix.py +130 -0
- netbox_permissions_matrix_plugin-0.1.0/netbox_permissions_matrix_plugin/navigation.py +46 -0
- netbox_permissions_matrix_plugin-0.1.0/netbox_permissions_matrix_plugin/service.py +303 -0
- netbox_permissions_matrix_plugin-0.1.0/netbox_permissions_matrix_plugin/static/netbox_permissions_matrix_plugin/matrix.css +331 -0
- netbox_permissions_matrix_plugin-0.1.0/netbox_permissions_matrix_plugin/static/netbox_permissions_matrix_plugin/matrix.js +746 -0
- netbox_permissions_matrix_plugin-0.1.0/netbox_permissions_matrix_plugin/templates/netbox_permissions_matrix_plugin/inc/shell.html +115 -0
- netbox_permissions_matrix_plugin-0.1.0/netbox_permissions_matrix_plugin/templates/netbox_permissions_matrix_plugin/inc/state.html +1 -0
- netbox_permissions_matrix_plugin-0.1.0/netbox_permissions_matrix_plugin/templates/netbox_permissions_matrix_plugin/matrix.html +32 -0
- netbox_permissions_matrix_plugin-0.1.0/netbox_permissions_matrix_plugin/templates/netbox_permissions_matrix_plugin/principal_tab.html +20 -0
- netbox_permissions_matrix_plugin-0.1.0/netbox_permissions_matrix_plugin/templates/netbox_permissions_matrix_plugin/who_can.html +118 -0
- netbox_permissions_matrix_plugin-0.1.0/netbox_permissions_matrix_plugin/urls.py +9 -0
- netbox_permissions_matrix_plugin-0.1.0/netbox_permissions_matrix_plugin/version.py +1 -0
- netbox_permissions_matrix_plugin-0.1.0/netbox_permissions_matrix_plugin/views.py +102 -0
- netbox_permissions_matrix_plugin-0.1.0/pyproject.toml +69 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project are documented here. Format: [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
4
|
+
versioning: [SemVer](https://semver.org/).
|
|
5
|
+
|
|
6
|
+
## [Unreleased]
|
|
7
|
+
|
|
8
|
+
## [0.1.0] - 2026-10-19
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- Export the matrix as YAML (shown columns and rows, every action) and import such a file: within the file's scope
|
|
13
|
+
the changes are staged for the normal review, nothing is written until Apply. Groups, users and object types are
|
|
14
|
+
named, never numbered, so a file can move between NetBox instances. Also `POST import/` in the REST API.
|
|
15
|
+
- Matrix page in Admin > Authentication, right below Permissions: action tabs, search, app filter, user
|
|
16
|
+
columns, column picker, bulk toggles, gear panel, staged changes with review and apply.
|
|
17
|
+
- Who can page per object type, and a Permissions Matrix tab on each group.
|
|
18
|
+
- Change planner: turns matrix cell changes into create, update and delete operations on NetBox's own
|
|
19
|
+
permissions, splitting shared permissions so no other group or user changes access.
|
|
20
|
+
- REST API: `matrix/`, `principal/`, `plan/`, `apply/` and `import/` under `/api/plugins/permissions-matrix/`, with a
|
|
21
|
+
version token against concurrent changes and NetBox permission checks on every operation. Read-only API tokens
|
|
22
|
+
cannot plan, apply or import.
|
|
23
|
+
- Documentation site: installation, quick start, configuration, the matrix, how changes map to permissions, who can,
|
|
24
|
+
group tab, export and import, permissions, REST API, limitations, troubleshooting and development.
|
|
25
|
+
- Project scaffold: plugin configuration, settings, CI, release and documentation workflows, development stack.
|
|
26
|
+
|
|
27
|
+
[Unreleased]: https://github.com/thomaschristory/netbox-permissions-matrix-plugin/compare/v0.1.0...HEAD
|
|
28
|
+
[0.1.0]: https://github.com/thomaschristory/netbox-permissions-matrix-plugin/releases/tag/v0.1.0
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: netbox-permissions-matrix-plugin
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Show and edit NetBox object permissions as a matrix of object types and groups.
|
|
5
|
+
Project-URL: Homepage, https://github.com/thomaschristory/netbox-permissions-matrix-plugin
|
|
6
|
+
Project-URL: Documentation, https://thomaschristory.github.io/netbox-permissions-matrix-plugin/
|
|
7
|
+
Project-URL: Repository, https://github.com/thomaschristory/netbox-permissions-matrix-plugin
|
|
8
|
+
Project-URL: Changelog, https://github.com/thomaschristory/netbox-permissions-matrix-plugin/blob/main/CHANGELOG.md
|
|
9
|
+
Project-URL: Issues, https://github.com/thomaschristory/netbox-permissions-matrix-plugin/issues
|
|
10
|
+
Author: Thomas Christory
|
|
11
|
+
License-Expression: Apache-2.0
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Keywords: access-control,netbox,netbox-plugin,permissions,rbac
|
|
14
|
+
Classifier: Development Status :: 3 - Alpha
|
|
15
|
+
Classifier: Framework :: Django
|
|
16
|
+
Classifier: Intended Audience :: System Administrators
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
22
|
+
Classifier: Topic :: System :: Networking
|
|
23
|
+
Classifier: Topic :: System :: Systems Administration :: Authentication/Directory
|
|
24
|
+
Requires-Python: >=3.12
|
|
25
|
+
Description-Content-Type: text/markdown
|
|
26
|
+
|
|
27
|
+
# netbox-permissions-matrix-plugin
|
|
28
|
+
|
|
29
|
+
[](https://github.com/thomaschristory/netbox-permissions-matrix-plugin/actions/workflows/ci.yml)
|
|
30
|
+
[](https://pypi.org/project/netbox-permissions-matrix-plugin/)
|
|
31
|
+
[](https://pypi.org/project/netbox-permissions-matrix-plugin/)
|
|
32
|
+
|
|
33
|
+
A NetBox plugin that shows NetBox's object permissions as a matrix: object types down the side, groups (and
|
|
34
|
+
optionally users) across the top, one checkbox per cell for the selected action. Ticking and unticking cells edits
|
|
35
|
+
NetBox's own permissions, with a review of every change before it is written.
|
|
36
|
+
|
|
37
|
+
**Documentation: https://thomaschristory.github.io/netbox-permissions-matrix-plugin/**
|
|
38
|
+
|
|
39
|
+
> **Status: pre-release.** Below 1.0, read the review dialog before applying changes.
|
|
40
|
+
|
|
41
|
+
## Features
|
|
42
|
+
|
|
43
|
+
- One page answers "what can this group do?" and "who can change prefixes?".
|
|
44
|
+
- View, Add, Change, Delete and custom action tabs; bulk toggles per row, app and column.
|
|
45
|
+
- Edits native `ObjectPermission` records only. No models, no migrations; uninstalling leaves a normal setup.
|
|
46
|
+
- Safe with shared permissions: a change for one group never changes another group's access.
|
|
47
|
+
- Stage, review, apply: every created, changed or deleted permission is shown first and written in one transaction.
|
|
48
|
+
- Who can page per object type, and a Permissions Matrix tab on each group.
|
|
49
|
+
- Export to YAML and import back, on the same NetBox or another one, through the same review.
|
|
50
|
+
|
|
51
|
+
## Compatibility
|
|
52
|
+
|
|
53
|
+
| Plugin | NetBox | Python |
|
|
54
|
+
|--------|--------|--------|
|
|
55
|
+
| 0.1 | 4.7.0 and later | 3.12 to 3.14 |
|
|
56
|
+
|
|
57
|
+
## Quick start
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
pip install netbox-permissions-matrix-plugin
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
```python
|
|
64
|
+
# configuration.py
|
|
65
|
+
PLUGINS = ["netbox_permissions_matrix_plugin"]
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Run `python manage.py collectstatic --no-input`, restart NetBox and open **Admin > Authentication > Permissions
|
|
69
|
+
Matrix**.
|
|
70
|
+
|
|
71
|
+
## Documentation
|
|
72
|
+
|
|
73
|
+
- [Installation](https://thomaschristory.github.io/netbox-permissions-matrix-plugin/installation/)
|
|
74
|
+
- [Quick start](https://thomaschristory.github.io/netbox-permissions-matrix-plugin/quickstart/)
|
|
75
|
+
- [Configuration](https://thomaschristory.github.io/netbox-permissions-matrix-plugin/configuration/)
|
|
76
|
+
- [Design](https://thomaschristory.github.io/netbox-permissions-matrix-plugin/DESIGN/)
|
|
77
|
+
|
|
78
|
+
## Development
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
make dev # NetBox 4.7 with the plugin on http://localhost:8000 (admin / admin)
|
|
82
|
+
make seed # sample groups, users and overlapping permissions
|
|
83
|
+
make test # unit tests, no NetBox needed
|
|
84
|
+
make test-netbox # integration tests inside the dev stack
|
|
85
|
+
make lint # ruff
|
|
86
|
+
make docs # build the documentation site
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## License
|
|
90
|
+
|
|
91
|
+
Apache-2.0, see [LICENSE](https://github.com/thomaschristory/netbox-permissions-matrix-plugin/blob/main/LICENSE).
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# netbox-permissions-matrix-plugin
|
|
2
|
+
|
|
3
|
+
[](https://github.com/thomaschristory/netbox-permissions-matrix-plugin/actions/workflows/ci.yml)
|
|
4
|
+
[](https://pypi.org/project/netbox-permissions-matrix-plugin/)
|
|
5
|
+
[](https://pypi.org/project/netbox-permissions-matrix-plugin/)
|
|
6
|
+
|
|
7
|
+
A NetBox plugin that shows NetBox's object permissions as a matrix: object types down the side, groups (and
|
|
8
|
+
optionally users) across the top, one checkbox per cell for the selected action. Ticking and unticking cells edits
|
|
9
|
+
NetBox's own permissions, with a review of every change before it is written.
|
|
10
|
+
|
|
11
|
+
**Documentation: https://thomaschristory.github.io/netbox-permissions-matrix-plugin/**
|
|
12
|
+
|
|
13
|
+
> **Status: pre-release.** Below 1.0, read the review dialog before applying changes.
|
|
14
|
+
|
|
15
|
+
## Features
|
|
16
|
+
|
|
17
|
+
- One page answers "what can this group do?" and "who can change prefixes?".
|
|
18
|
+
- View, Add, Change, Delete and custom action tabs; bulk toggles per row, app and column.
|
|
19
|
+
- Edits native `ObjectPermission` records only. No models, no migrations; uninstalling leaves a normal setup.
|
|
20
|
+
- Safe with shared permissions: a change for one group never changes another group's access.
|
|
21
|
+
- Stage, review, apply: every created, changed or deleted permission is shown first and written in one transaction.
|
|
22
|
+
- Who can page per object type, and a Permissions Matrix tab on each group.
|
|
23
|
+
- Export to YAML and import back, on the same NetBox or another one, through the same review.
|
|
24
|
+
|
|
25
|
+
## Compatibility
|
|
26
|
+
|
|
27
|
+
| Plugin | NetBox | Python |
|
|
28
|
+
|--------|--------|--------|
|
|
29
|
+
| 0.1 | 4.7.0 and later | 3.12 to 3.14 |
|
|
30
|
+
|
|
31
|
+
## Quick start
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
pip install netbox-permissions-matrix-plugin
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
# configuration.py
|
|
39
|
+
PLUGINS = ["netbox_permissions_matrix_plugin"]
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Run `python manage.py collectstatic --no-input`, restart NetBox and open **Admin > Authentication > Permissions
|
|
43
|
+
Matrix**.
|
|
44
|
+
|
|
45
|
+
## Documentation
|
|
46
|
+
|
|
47
|
+
- [Installation](https://thomaschristory.github.io/netbox-permissions-matrix-plugin/installation/)
|
|
48
|
+
- [Quick start](https://thomaschristory.github.io/netbox-permissions-matrix-plugin/quickstart/)
|
|
49
|
+
- [Configuration](https://thomaschristory.github.io/netbox-permissions-matrix-plugin/configuration/)
|
|
50
|
+
- [Design](https://thomaschristory.github.io/netbox-permissions-matrix-plugin/DESIGN/)
|
|
51
|
+
|
|
52
|
+
## Development
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
make dev # NetBox 4.7 with the plugin on http://localhost:8000 (admin / admin)
|
|
56
|
+
make seed # sample groups, users and overlapping permissions
|
|
57
|
+
make test # unit tests, no NetBox needed
|
|
58
|
+
make test-netbox # integration tests inside the dev stack
|
|
59
|
+
make lint # ruff
|
|
60
|
+
make docs # build the documentation site
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## License
|
|
64
|
+
|
|
65
|
+
Apache-2.0, see [LICENSE](https://github.com/thomaschristory/netbox-permissions-matrix-plugin/blob/main/LICENSE).
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
from .version import __version__
|
|
2
|
+
|
|
3
|
+
try:
|
|
4
|
+
from netbox.plugins import PluginConfig
|
|
5
|
+
except ImportError: # imported outside NetBox (pure unit tests, build tools)
|
|
6
|
+
PluginConfig = None
|
|
7
|
+
|
|
8
|
+
if PluginConfig is not None:
|
|
9
|
+
from .conf import DEFAULTS
|
|
10
|
+
|
|
11
|
+
class PermissionsMatrixConfig(PluginConfig):
|
|
12
|
+
name = "netbox_permissions_matrix_plugin"
|
|
13
|
+
verbose_name = "Permissions Matrix"
|
|
14
|
+
description = "Show and edit NetBox object permissions as a matrix of object types and groups"
|
|
15
|
+
version = __version__
|
|
16
|
+
author = "Thomas Christory"
|
|
17
|
+
author_email = "9317624+thomaschristory@users.noreply.github.com"
|
|
18
|
+
base_url = "permissions-matrix"
|
|
19
|
+
min_version = "4.7.0"
|
|
20
|
+
# No max_version: the plugin only uses the stable permission model, and CI also runs against NetBox's next
|
|
21
|
+
# release.
|
|
22
|
+
required_settings = []
|
|
23
|
+
default_settings = DEFAULTS
|
|
24
|
+
|
|
25
|
+
config = PermissionsMatrixConfig
|
|
File without changes
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
from rest_framework import serializers
|
|
2
|
+
|
|
3
|
+
from ..core.model import UNSET, CellChange, PermEdit, PrincipalRef
|
|
4
|
+
|
|
5
|
+
ACTION = r"^[a-z_][a-z0-9_]{0,29}$" # ObjectPermission.actions items are CharField(max_length=30)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class PrincipalSerializer(serializers.Serializer):
|
|
9
|
+
type = serializers.ChoiceField(choices=["group", "user"])
|
|
10
|
+
id = serializers.IntegerField(min_value=1)
|
|
11
|
+
|
|
12
|
+
def to_internal_value(self, data):
|
|
13
|
+
value = super().to_internal_value(data)
|
|
14
|
+
return PrincipalRef(value["type"], value["id"])
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class CellChangeSerializer(serializers.Serializer):
|
|
18
|
+
principal = PrincipalSerializer()
|
|
19
|
+
object_type = serializers.RegexField(r"^[a-z0-9_]+\.[a-z0-9_]+$", max_length=200)
|
|
20
|
+
action = serializers.RegexField(ACTION)
|
|
21
|
+
granted = serializers.BooleanField()
|
|
22
|
+
|
|
23
|
+
def validate_object_type(self, value):
|
|
24
|
+
if value not in self.context["object_types"]:
|
|
25
|
+
raise serializers.ValidationError(f"{value} is not an object type permissions can be assigned to.")
|
|
26
|
+
return value
|
|
27
|
+
|
|
28
|
+
def to_internal_value(self, data):
|
|
29
|
+
return CellChange(**super().to_internal_value(data))
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class PermEditSerializer(serializers.Serializer):
|
|
33
|
+
principal = PrincipalSerializer()
|
|
34
|
+
action = serializers.RegexField(ACTION)
|
|
35
|
+
name = serializers.CharField(max_length=100, required=False)
|
|
36
|
+
description = serializers.CharField(max_length=200, required=False, allow_blank=True)
|
|
37
|
+
enabled = serializers.BooleanField(required=False)
|
|
38
|
+
constraints = serializers.JSONField(required=False, allow_null=True)
|
|
39
|
+
add_actions = serializers.ListField(child=serializers.RegexField(ACTION), required=False)
|
|
40
|
+
add_groups = serializers.ListField(child=serializers.IntegerField(min_value=1), required=False)
|
|
41
|
+
add_users = serializers.ListField(child=serializers.IntegerField(min_value=1), required=False)
|
|
42
|
+
|
|
43
|
+
def validate_constraints(self, value):
|
|
44
|
+
if value is not None and not isinstance(value, dict | list):
|
|
45
|
+
raise serializers.ValidationError("Constraints must be an object, a list of objects, or null.")
|
|
46
|
+
if isinstance(value, list) and not all(isinstance(c, dict) for c in value):
|
|
47
|
+
raise serializers.ValidationError("A list of constraints must contain only objects.")
|
|
48
|
+
return value
|
|
49
|
+
|
|
50
|
+
def to_internal_value(self, data):
|
|
51
|
+
value = super().to_internal_value(data)
|
|
52
|
+
return PermEdit(
|
|
53
|
+
principal=value["principal"],
|
|
54
|
+
action=value["action"],
|
|
55
|
+
name=value.get("name", UNSET),
|
|
56
|
+
description=value.get("description", UNSET),
|
|
57
|
+
enabled=value.get("enabled", UNSET),
|
|
58
|
+
constraints=value.get("constraints", UNSET),
|
|
59
|
+
add_actions=tuple(value.get("add_actions", ())),
|
|
60
|
+
add_groups=tuple(value.get("add_groups", ())),
|
|
61
|
+
add_users=tuple(value.get("add_users", ())),
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
class ChangeSetSerializer(serializers.Serializer):
|
|
66
|
+
changes = CellChangeSerializer(many=True, required=False, default=list)
|
|
67
|
+
edits = PermEditSerializer(many=True, required=False, default=list)
|
|
68
|
+
token = serializers.CharField(required=False, max_length=64)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
class ImportSerializer(serializers.Serializer):
|
|
72
|
+
yaml = serializers.CharField(trim_whitespace=False)
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
from django.urls import path
|
|
2
|
+
|
|
3
|
+
from . import views
|
|
4
|
+
|
|
5
|
+
urlpatterns = [
|
|
6
|
+
path("matrix/", views.MatrixView.as_view(), name="matrix"),
|
|
7
|
+
path("principal/", views.PrincipalView.as_view(), name="principal"),
|
|
8
|
+
path("plan/", views.PlanView.as_view(), name="plan"),
|
|
9
|
+
path("apply/", views.ApplyView.as_view(), name="apply"),
|
|
10
|
+
path("import/", views.ImportView.as_view(), name="import"),
|
|
11
|
+
]
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
from django.core.exceptions import PermissionDenied, ValidationError
|
|
2
|
+
from django.db import transaction
|
|
3
|
+
from django.http import Http404
|
|
4
|
+
from rest_framework import status
|
|
5
|
+
from rest_framework.exceptions import NotFound
|
|
6
|
+
from rest_framework.exceptions import PermissionDenied as APIPermissionDenied
|
|
7
|
+
from rest_framework.exceptions import ValidationError as APIValidationError
|
|
8
|
+
from rest_framework.permissions import SAFE_METHODS, BasePermission, IsAuthenticated
|
|
9
|
+
from rest_framework.response import Response
|
|
10
|
+
from rest_framework.views import APIView
|
|
11
|
+
|
|
12
|
+
from .. import loader, service
|
|
13
|
+
from ..applier import apply_plan
|
|
14
|
+
from ..conf import get_setting
|
|
15
|
+
from ..core import yaml_io
|
|
16
|
+
from ..core.model import PrincipalRef
|
|
17
|
+
from .serializers import ChangeSetSerializer, ImportSerializer
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class WriteEnabled(BasePermission):
|
|
21
|
+
"""Refuse API tokens without write enabled on unsafe methods, as NetBox's own write endpoints do.
|
|
22
|
+
|
|
23
|
+
NetBox's TokenWritePermission also refuses session authentication, which the matrix page uses (with CSRF).
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
message = "This API token is not write-enabled."
|
|
27
|
+
|
|
28
|
+
def has_permission(self, request, view):
|
|
29
|
+
token = request.auth
|
|
30
|
+
return request.method in SAFE_METHODS or token is None or bool(getattr(token, "write_enabled", False))
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def _ints(values):
|
|
34
|
+
try:
|
|
35
|
+
return tuple(int(v) for v in values)
|
|
36
|
+
except ValueError as exc:
|
|
37
|
+
raise APIValidationError({"detail": "IDs must be integers."}) from exc
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def _bool(value, default):
|
|
41
|
+
if value is None:
|
|
42
|
+
return default
|
|
43
|
+
return value.lower() in ("1", "true", "yes", "on")
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def _change_set(request):
|
|
47
|
+
object_types = {r.object_type for r in loader.rows()}
|
|
48
|
+
serializer = ChangeSetSerializer(data=request.data, context={"object_types": object_types})
|
|
49
|
+
serializer.is_valid(raise_exception=True)
|
|
50
|
+
return serializer.validated_data
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def _guard(func):
|
|
54
|
+
"""Turn the service's Django exceptions into API responses."""
|
|
55
|
+
|
|
56
|
+
def wrapper(self, request, *args, **kwargs):
|
|
57
|
+
try:
|
|
58
|
+
return func(self, request, *args, **kwargs)
|
|
59
|
+
except PermissionDenied as exc:
|
|
60
|
+
raise APIPermissionDenied(str(exc)) from exc
|
|
61
|
+
except ValidationError as exc:
|
|
62
|
+
raise APIValidationError(exc.message_dict if hasattr(exc, "error_dict") else exc.messages) from exc
|
|
63
|
+
|
|
64
|
+
return wrapper
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
class MatrixView(APIView):
|
|
68
|
+
"""The matrix for one action: rows, columns, cell states and the permissions behind each cell."""
|
|
69
|
+
|
|
70
|
+
permission_classes = [IsAuthenticated]
|
|
71
|
+
|
|
72
|
+
@_guard
|
|
73
|
+
def get(self, request):
|
|
74
|
+
params = request.query_params
|
|
75
|
+
query = service.MatrixQuery(
|
|
76
|
+
action=params.get("action", "view"),
|
|
77
|
+
include_users=_bool(params.get("include_users"), get_setting("show_users_by_default")),
|
|
78
|
+
group_ids=_ints(params.getlist("group_id")),
|
|
79
|
+
user_ids=_ints(params.getlist("user_id")),
|
|
80
|
+
app_labels=tuple(params.getlist("app_label")),
|
|
81
|
+
)
|
|
82
|
+
return Response(service.matrix_payload(request.user, query))
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
class PrincipalView(APIView):
|
|
86
|
+
"""One group's or user's cells for every action."""
|
|
87
|
+
|
|
88
|
+
permission_classes = [IsAuthenticated]
|
|
89
|
+
|
|
90
|
+
@_guard
|
|
91
|
+
def get(self, request):
|
|
92
|
+
kind = request.query_params.get("type")
|
|
93
|
+
if kind not in ("group", "user"):
|
|
94
|
+
raise APIValidationError({"type": ["Must be group or user."]})
|
|
95
|
+
(pk,) = _ints([request.query_params.get("id", "")]) or (0,)
|
|
96
|
+
try:
|
|
97
|
+
return Response(service.principal_payload(request.user, PrincipalRef(kind, pk)))
|
|
98
|
+
except Http404 as exc:
|
|
99
|
+
raise NotFound(str(exc)) from exc
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
class PlanView(APIView):
|
|
103
|
+
"""Dry run: the operations a change set would perform, and the token to apply them with."""
|
|
104
|
+
|
|
105
|
+
permission_classes = [IsAuthenticated, WriteEnabled]
|
|
106
|
+
|
|
107
|
+
@_guard
|
|
108
|
+
def post(self, request):
|
|
109
|
+
service.check_edit(request.user)
|
|
110
|
+
data = _change_set(request)
|
|
111
|
+
snap, result, token = service.plan_for(request.user, data["changes"], data["edits"])
|
|
112
|
+
return Response(service.plan_json(snap, result, token))
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
class ApplyView(APIView):
|
|
116
|
+
"""Apply a change set in one transaction, if nothing changed since it was planned."""
|
|
117
|
+
|
|
118
|
+
permission_classes = [IsAuthenticated, WriteEnabled]
|
|
119
|
+
|
|
120
|
+
@_guard
|
|
121
|
+
def post(self, request):
|
|
122
|
+
service.check_edit(request.user)
|
|
123
|
+
data = _change_set(request)
|
|
124
|
+
if not data.get("token"):
|
|
125
|
+
raise APIValidationError({"token": ["Plan the change set first and send the token it returned."]})
|
|
126
|
+
with transaction.atomic():
|
|
127
|
+
# Lock the permission table for the plan-and-write, so two applies cannot interleave.
|
|
128
|
+
loader.lock_permissions()
|
|
129
|
+
snap, result, token = service.plan_for(request.user, data["changes"], data["edits"])
|
|
130
|
+
if token != data["token"]:
|
|
131
|
+
return Response(
|
|
132
|
+
{"detail": "The permissions changed since this plan was made. Reload and review again."},
|
|
133
|
+
status=status.HTTP_409_CONFLICT,
|
|
134
|
+
)
|
|
135
|
+
written = apply_plan(result, request.user)
|
|
136
|
+
body = service.plan_json(snap, result, token)
|
|
137
|
+
body["written"] = written
|
|
138
|
+
return Response(body)
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
class ImportView(APIView):
|
|
142
|
+
"""Read an exported YAML file and return the cell changes that would make it true. Nothing is written."""
|
|
143
|
+
|
|
144
|
+
permission_classes = [IsAuthenticated, WriteEnabled]
|
|
145
|
+
|
|
146
|
+
@_guard
|
|
147
|
+
def post(self, request):
|
|
148
|
+
service.check_edit(request.user)
|
|
149
|
+
serializer = ImportSerializer(data=request.data)
|
|
150
|
+
serializer.is_valid(raise_exception=True)
|
|
151
|
+
try:
|
|
152
|
+
doc = yaml_io.load(serializer.validated_data["yaml"])
|
|
153
|
+
except ValueError as exc:
|
|
154
|
+
raise APIValidationError({"yaml": [str(exc)]}) from exc
|
|
155
|
+
return Response(service.import_for(request.user, doc))
|