netbox-secrets 2.4.2__tar.gz → 3.0.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_secrets-2.4.2 → netbox_secrets-3.0.0}/MANIFEST.in +0 -1
- netbox_secrets-3.0.0/PKG-INFO +89 -0
- netbox_secrets-3.0.0/README.md +58 -0
- {netbox_secrets-2.4.2 → netbox_secrets-3.0.0}/netbox_secrets/__init__.py +2 -2
- netbox_secrets-3.0.0/netbox_secrets/api/serializers.py +2 -0
- netbox_secrets-3.0.0/netbox_secrets/api/serializers_/keys.py +152 -0
- netbox_secrets-3.0.0/netbox_secrets/api/serializers_/nested.py +21 -0
- netbox_secrets-3.0.0/netbox_secrets/api/serializers_/secrets.py +128 -0
- netbox_secrets-3.0.0/netbox_secrets/api/urls.py +22 -0
- netbox_secrets-3.0.0/netbox_secrets/api/views.py +777 -0
- netbox_secrets-3.0.0/netbox_secrets/constants.py +35 -0
- netbox_secrets-3.0.0/netbox_secrets/filtersets.py +98 -0
- netbox_secrets-3.0.0/netbox_secrets/forms/bulk_edit.py +29 -0
- netbox_secrets-3.0.0/netbox_secrets/forms/bulk_import.py +25 -0
- netbox_secrets-3.0.0/netbox_secrets/forms/filterset.py +53 -0
- netbox_secrets-3.0.0/netbox_secrets/forms/model_forms.py +256 -0
- netbox_secrets-3.0.0/netbox_secrets/graphql/filters.py +51 -0
- netbox_secrets-3.0.0/netbox_secrets/graphql/types.py +36 -0
- netbox_secrets-3.0.0/netbox_secrets/migrations/0009_secret_owner_secretrole_level_secretrole_lft_and_more.py +95 -0
- netbox_secrets-3.0.0/netbox_secrets/migrations/0010_secret_role_rebuild.py +23 -0
- netbox_secrets-3.0.0/netbox_secrets/models/__init__.py +23 -0
- netbox_secrets-3.0.0/netbox_secrets/models/keys.py +380 -0
- netbox_secrets-3.0.0/netbox_secrets/models/secrets.py +329 -0
- {netbox_secrets-2.4.2 → netbox_secrets-3.0.0}/netbox_secrets/navigation.py +10 -7
- netbox_secrets-3.0.0/netbox_secrets/querysets.py +26 -0
- {netbox_secrets-2.4.2 → netbox_secrets-3.0.0}/netbox_secrets/signals.py +1 -1
- {netbox_secrets-2.4.2 → netbox_secrets-3.0.0}/netbox_secrets/tables.py +33 -59
- {netbox_secrets-2.4.2 → netbox_secrets-3.0.0}/netbox_secrets/templates/netbox_secrets/inc/private_key_modal.html +8 -9
- netbox_secrets-3.0.0/netbox_secrets/templates/netbox_secrets/inc/secrets_inline_js.html +474 -0
- {netbox_secrets-2.4.2 → netbox_secrets-3.0.0}/netbox_secrets/templates/netbox_secrets/secret_edit.html +1 -0
- netbox_secrets-3.0.0/netbox_secrets/templates/netbox_secrets/secretrole.html +67 -0
- {netbox_secrets-2.4.2 → netbox_secrets-3.0.0}/netbox_secrets/templates/netbox_secrets/userkey.html +5 -4
- {netbox_secrets-2.4.2 → netbox_secrets-3.0.0}/netbox_secrets/templates/netbox_secrets/userkey_edit.html +1 -6
- {netbox_secrets-2.4.2 → netbox_secrets-3.0.0}/netbox_secrets/templates/netbox_secrets/userkey_list.html +1 -1
- netbox_secrets-3.0.0/netbox_secrets/tests/__init__.py +0 -0
- netbox_secrets-3.0.0/netbox_secrets/tests/test_api.py +741 -0
- netbox_secrets-3.0.0/netbox_secrets/tests/test_filters.py +108 -0
- netbox_secrets-3.0.0/netbox_secrets/tests/test_forms.py +187 -0
- netbox_secrets-3.0.0/netbox_secrets/tests/test_models.py +309 -0
- netbox_secrets-3.0.0/netbox_secrets/tests/test_signals.py +42 -0
- netbox_secrets-3.0.0/netbox_secrets/tests/test_utils.py +238 -0
- netbox_secrets-3.0.0/netbox_secrets/tests/test_views.py +338 -0
- {netbox_secrets-2.4.2 → netbox_secrets-3.0.0}/netbox_secrets/urls.py +3 -6
- netbox_secrets-3.0.0/netbox_secrets/utils/helpers.py +24 -0
- {netbox_secrets-2.4.2 → netbox_secrets-3.0.0}/netbox_secrets/views.py +100 -91
- netbox_secrets-3.0.0/netbox_secrets.egg-info/PKG-INFO +89 -0
- {netbox_secrets-2.4.2 → netbox_secrets-3.0.0}/netbox_secrets.egg-info/SOURCES.txt +11 -3
- {netbox_secrets-2.4.2 → netbox_secrets-3.0.0}/setup.py +1 -1
- netbox_secrets-2.4.2/PKG-INFO +0 -171
- netbox_secrets-2.4.2/README.md +0 -140
- netbox_secrets-2.4.2/netbox_secrets/api/serializers.py +0 -244
- netbox_secrets-2.4.2/netbox_secrets/api/urls.py +0 -18
- netbox_secrets-2.4.2/netbox_secrets/api/views.py +0 -417
- netbox_secrets-2.4.2/netbox_secrets/constants.py +0 -26
- netbox_secrets-2.4.2/netbox_secrets/filtersets.py +0 -112
- netbox_secrets-2.4.2/netbox_secrets/forms/bulk_edit.py +0 -37
- netbox_secrets-2.4.2/netbox_secrets/forms/bulk_import.py +0 -16
- netbox_secrets-2.4.2/netbox_secrets/forms/filterset.py +0 -46
- netbox_secrets-2.4.2/netbox_secrets/forms/model_forms.py +0 -146
- netbox_secrets-2.4.2/netbox_secrets/graphql/filters.py +0 -38
- netbox_secrets-2.4.2/netbox_secrets/graphql/types.py +0 -33
- netbox_secrets-2.4.2/netbox_secrets/models/__init__.py +0 -1
- netbox_secrets-2.4.2/netbox_secrets/models/secrets.py +0 -400
- netbox_secrets-2.4.2/netbox_secrets/querysets.py +0 -10
- netbox_secrets-2.4.2/netbox_secrets/static/netbox_secrets/secrets.js +0 -10
- netbox_secrets-2.4.2/netbox_secrets/static/netbox_secrets/secrets.js.map +0 -7
- netbox_secrets-2.4.2/netbox_secrets/templates/netbox_secrets/secretrole.html +0 -49
- netbox_secrets-2.4.2/netbox_secrets/tests/test_api.py +0 -284
- netbox_secrets-2.4.2/netbox_secrets/tests/test_filters.py +0 -102
- netbox_secrets-2.4.2/netbox_secrets/tests/test_form.py +0 -32
- netbox_secrets-2.4.2/netbox_secrets/tests/test_models.py +0 -172
- netbox_secrets-2.4.2/netbox_secrets/tests/test_views.py +0 -110
- netbox_secrets-2.4.2/netbox_secrets/utils/helpers.py +0 -15
- netbox_secrets-2.4.2/netbox_secrets.egg-info/PKG-INFO +0 -171
- {netbox_secrets-2.4.2 → netbox_secrets-3.0.0}/LICENSE.md +0 -0
- {netbox_secrets-2.4.2 → netbox_secrets-3.0.0}/netbox_secrets/api/__init__.py +0 -0
- {netbox_secrets-2.4.2/netbox_secrets/migrations → netbox_secrets-3.0.0/netbox_secrets/api/serializers_}/__init__.py +0 -0
- {netbox_secrets-2.4.2 → netbox_secrets-3.0.0}/netbox_secrets/exceptions.py +0 -0
- {netbox_secrets-2.4.2 → netbox_secrets-3.0.0}/netbox_secrets/forms/__init__.py +0 -0
- {netbox_secrets-2.4.2 → netbox_secrets-3.0.0}/netbox_secrets/graphql/__init__.py +0 -0
- {netbox_secrets-2.4.2 → netbox_secrets-3.0.0}/netbox_secrets/graphql/schema.py +0 -0
- {netbox_secrets-2.4.2 → netbox_secrets-3.0.0}/netbox_secrets/hashers.py +0 -0
- {netbox_secrets-2.4.2 → netbox_secrets-3.0.0}/netbox_secrets/migrations/0001_initial.py +0 -0
- {netbox_secrets-2.4.2 → netbox_secrets-3.0.0}/netbox_secrets/migrations/0002_populate_userkeys.py +0 -0
- {netbox_secrets-2.4.2 → netbox_secrets-3.0.0}/netbox_secrets/migrations/0003_populate_secretroles.py +0 -0
- {netbox_secrets-2.4.2 → netbox_secrets-3.0.0}/netbox_secrets/migrations/0004_populate_secrets.py +0 -0
- {netbox_secrets-2.4.2 → netbox_secrets-3.0.0}/netbox_secrets/migrations/0005_alter_secret_custom_field_data_and_more.py +0 -0
- {netbox_secrets-2.4.2 → netbox_secrets-3.0.0}/netbox_secrets/migrations/0006_alter_userkey_created_alter_userkey_last_updated.py +0 -0
- {netbox_secrets-2.4.2 → netbox_secrets-3.0.0}/netbox_secrets/migrations/0007_secret__object_repr_secret_comments_and_more.py +0 -0
- {netbox_secrets-2.4.2 → netbox_secrets-3.0.0}/netbox_secrets/migrations/0008_userkey_custom_field_data_userkey_tags.py +0 -0
- {netbox_secrets-2.4.2/netbox_secrets/tests → netbox_secrets-3.0.0/netbox_secrets/migrations}/__init__.py +0 -0
- {netbox_secrets-2.4.2 → netbox_secrets-3.0.0}/netbox_secrets/template_content.py +0 -0
- {netbox_secrets-2.4.2 → netbox_secrets-3.0.0}/netbox_secrets/templates/netbox_secrets/activate_keys.html +0 -0
- {netbox_secrets-2.4.2 → netbox_secrets-3.0.0}/netbox_secrets/templates/netbox_secrets/inc/secret_actions.html +0 -0
- {netbox_secrets-2.4.2 → netbox_secrets-3.0.0}/netbox_secrets/templates/netbox_secrets/inc/secret_add_button.html +0 -0
- {netbox_secrets-2.4.2 → netbox_secrets-3.0.0}/netbox_secrets/templates/netbox_secrets/inc/secrets_panel.html +0 -0
- {netbox_secrets-2.4.2 → netbox_secrets-3.0.0}/netbox_secrets/templates/netbox_secrets/secret.html +0 -0
- {netbox_secrets-2.4.2 → netbox_secrets-3.0.0}/netbox_secrets/tests/constants.py +0 -0
- {netbox_secrets-2.4.2 → netbox_secrets-3.0.0}/netbox_secrets/utils/__init__.py +0 -0
- {netbox_secrets-2.4.2 → netbox_secrets-3.0.0}/netbox_secrets/utils/crypto.py +0 -0
- {netbox_secrets-2.4.2 → netbox_secrets-3.0.0}/netbox_secrets/utils/hashers.py +0 -0
- {netbox_secrets-2.4.2 → netbox_secrets-3.0.0}/netbox_secrets.egg-info/dependency_links.txt +0 -0
- {netbox_secrets-2.4.2 → netbox_secrets-3.0.0}/netbox_secrets.egg-info/not-zip-safe +0 -0
- {netbox_secrets-2.4.2 → netbox_secrets-3.0.0}/netbox_secrets.egg-info/requires.txt +0 -0
- {netbox_secrets-2.4.2 → netbox_secrets-3.0.0}/netbox_secrets.egg-info/top_level.txt +0 -0
- {netbox_secrets-2.4.2 → netbox_secrets-3.0.0}/pyproject.toml +0 -0
- {netbox_secrets-2.4.2 → netbox_secrets-3.0.0}/requirements.txt +0 -0
- {netbox_secrets-2.4.2 → netbox_secrets-3.0.0}/setup.cfg +0 -0
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: netbox-secrets
|
|
3
|
+
Version: 3.0.0
|
|
4
|
+
Summary: Enhance your secret management with encrypted storage and flexible, user-friendly features.
|
|
5
|
+
Home-page: https://github.com/Onemind-Services-LLC/netbox-secrets/
|
|
6
|
+
Author: Abhimanyu Saharan
|
|
7
|
+
Author-email: asaharan@onemindservices.com
|
|
8
|
+
Maintainer: Prince Kumar
|
|
9
|
+
Maintainer-email: pkumar@onemindservices.com
|
|
10
|
+
License: Apache 2.0
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Requires-Python: >=3.10
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
License-File: LICENSE.md
|
|
17
|
+
Requires-Dist: pycryptodome==3.23.0
|
|
18
|
+
Dynamic: author
|
|
19
|
+
Dynamic: author-email
|
|
20
|
+
Dynamic: classifier
|
|
21
|
+
Dynamic: description
|
|
22
|
+
Dynamic: description-content-type
|
|
23
|
+
Dynamic: home-page
|
|
24
|
+
Dynamic: license
|
|
25
|
+
Dynamic: license-file
|
|
26
|
+
Dynamic: maintainer
|
|
27
|
+
Dynamic: maintainer-email
|
|
28
|
+
Dynamic: requires-dist
|
|
29
|
+
Dynamic: requires-python
|
|
30
|
+
Dynamic: summary
|
|
31
|
+
|
|
32
|
+
# NetBox Secrets
|
|
33
|
+
|
|
34
|
+
NetBox Secrets is a NetBox plugin for securely storing and managing secrets (passwords, API keys, tokens, certificates, etc.)
|
|
35
|
+
with end-to-end encryption. Secrets are encrypted at rest and can be assigned to any supported NetBox object.
|
|
36
|
+
|
|
37
|
+
## Highlights
|
|
38
|
+
- Public-key (RSA) based master key distribution
|
|
39
|
+
- AES-256 encryption for secret values
|
|
40
|
+
- Session-key workflow for encryption/decryption
|
|
41
|
+
- Flexible secret assignment to NetBox objects
|
|
42
|
+
- Secret roles for organization and access control
|
|
43
|
+
- REST API + GraphQL integration
|
|
44
|
+
|
|
45
|
+
## Compatibility
|
|
46
|
+
|
|
47
|
+
| NetBox Version | Plugin Version |
|
|
48
|
+
|----------------|----------------|
|
|
49
|
+
| 3.3.x | 1.4.x - 1.5.x |
|
|
50
|
+
| 3.4.x | 1.6.x - 1.7.x |
|
|
51
|
+
| 3.5.x | 1.8.x |
|
|
52
|
+
| 3.6.x | 1.9.x |
|
|
53
|
+
| 3.7.x | 1.10.x |
|
|
54
|
+
| 4.0.x | 2.0.x |
|
|
55
|
+
| 4.1.x | 2.1.x |
|
|
56
|
+
| 4.2.x | 2.2.x |
|
|
57
|
+
| 4.3.x | 2.3.x |
|
|
58
|
+
| 4.4.x | 2.4.x |
|
|
59
|
+
| 4.5.x | 3.0.x |
|
|
60
|
+
|
|
61
|
+
## Quickstart
|
|
62
|
+
- Setup (installation + configuration): [docs/installation.md](docs/installation.md)
|
|
63
|
+
- Then create your first User Key in the UI
|
|
64
|
+
|
|
65
|
+
## Documentation
|
|
66
|
+
- Setup: [docs/installation.md](docs/installation.md)
|
|
67
|
+
- Usage: [docs/usage.md](docs/usage.md)
|
|
68
|
+
- API: [docs/api.md](docs/api.md)
|
|
69
|
+
- Cryptography: [docs/cryptography.md](docs/cryptography.md)
|
|
70
|
+
- Permissions: [docs/permissions.md](docs/permissions.md)
|
|
71
|
+
- Troubleshooting: [docs/troubleshooting.md](docs/troubleshooting.md)
|
|
72
|
+
|
|
73
|
+
## Release Notes
|
|
74
|
+
- Release notes are maintained in GitHub for each version.
|
|
75
|
+
|
|
76
|
+
## Deprecations & Migration
|
|
77
|
+
- Legacy API endpoints supported until NetBox v4.6: [docs/api.md](docs/api.md)
|
|
78
|
+
|
|
79
|
+
## Legacy Migration
|
|
80
|
+
Legacy guidance for netbox-secretstore migrations is available here:
|
|
81
|
+
[docs/legacy-migration.md](docs/legacy-migration.md)
|
|
82
|
+
|
|
83
|
+
## Support
|
|
84
|
+
- Issues and feature requests: open a ticket in your internal tracker or this repository's issue tracker.
|
|
85
|
+
- Security concerns: see `SECURITY.md`.
|
|
86
|
+
|
|
87
|
+
## License
|
|
88
|
+
|
|
89
|
+
See `LICENSE.md`.
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# NetBox Secrets
|
|
2
|
+
|
|
3
|
+
NetBox Secrets is a NetBox plugin for securely storing and managing secrets (passwords, API keys, tokens, certificates, etc.)
|
|
4
|
+
with end-to-end encryption. Secrets are encrypted at rest and can be assigned to any supported NetBox object.
|
|
5
|
+
|
|
6
|
+
## Highlights
|
|
7
|
+
- Public-key (RSA) based master key distribution
|
|
8
|
+
- AES-256 encryption for secret values
|
|
9
|
+
- Session-key workflow for encryption/decryption
|
|
10
|
+
- Flexible secret assignment to NetBox objects
|
|
11
|
+
- Secret roles for organization and access control
|
|
12
|
+
- REST API + GraphQL integration
|
|
13
|
+
|
|
14
|
+
## Compatibility
|
|
15
|
+
|
|
16
|
+
| NetBox Version | Plugin Version |
|
|
17
|
+
|----------------|----------------|
|
|
18
|
+
| 3.3.x | 1.4.x - 1.5.x |
|
|
19
|
+
| 3.4.x | 1.6.x - 1.7.x |
|
|
20
|
+
| 3.5.x | 1.8.x |
|
|
21
|
+
| 3.6.x | 1.9.x |
|
|
22
|
+
| 3.7.x | 1.10.x |
|
|
23
|
+
| 4.0.x | 2.0.x |
|
|
24
|
+
| 4.1.x | 2.1.x |
|
|
25
|
+
| 4.2.x | 2.2.x |
|
|
26
|
+
| 4.3.x | 2.3.x |
|
|
27
|
+
| 4.4.x | 2.4.x |
|
|
28
|
+
| 4.5.x | 3.0.x |
|
|
29
|
+
|
|
30
|
+
## Quickstart
|
|
31
|
+
- Setup (installation + configuration): [docs/installation.md](docs/installation.md)
|
|
32
|
+
- Then create your first User Key in the UI
|
|
33
|
+
|
|
34
|
+
## Documentation
|
|
35
|
+
- Setup: [docs/installation.md](docs/installation.md)
|
|
36
|
+
- Usage: [docs/usage.md](docs/usage.md)
|
|
37
|
+
- API: [docs/api.md](docs/api.md)
|
|
38
|
+
- Cryptography: [docs/cryptography.md](docs/cryptography.md)
|
|
39
|
+
- Permissions: [docs/permissions.md](docs/permissions.md)
|
|
40
|
+
- Troubleshooting: [docs/troubleshooting.md](docs/troubleshooting.md)
|
|
41
|
+
|
|
42
|
+
## Release Notes
|
|
43
|
+
- Release notes are maintained in GitHub for each version.
|
|
44
|
+
|
|
45
|
+
## Deprecations & Migration
|
|
46
|
+
- Legacy API endpoints supported until NetBox v4.6: [docs/api.md](docs/api.md)
|
|
47
|
+
|
|
48
|
+
## Legacy Migration
|
|
49
|
+
Legacy guidance for netbox-secretstore migrations is available here:
|
|
50
|
+
[docs/legacy-migration.md](docs/legacy-migration.md)
|
|
51
|
+
|
|
52
|
+
## Support
|
|
53
|
+
- Issues and feature requests: open a ticket in your internal tracker or this repository's issue tracker.
|
|
54
|
+
- Security concerns: see `SECURITY.md`.
|
|
55
|
+
|
|
56
|
+
## License
|
|
57
|
+
|
|
58
|
+
See `LICENSE.md`.
|
|
@@ -13,8 +13,8 @@ class NetBoxSecrets(PluginConfig):
|
|
|
13
13
|
author = metadata.get('Author')
|
|
14
14
|
author_email = metadata.get('Author-email')
|
|
15
15
|
base_url = 'secrets'
|
|
16
|
-
min_version = '4.
|
|
17
|
-
max_version = '4.
|
|
16
|
+
min_version = '4.5.0'
|
|
17
|
+
max_version = '4.5.99'
|
|
18
18
|
required_settings = []
|
|
19
19
|
default_settings = {
|
|
20
20
|
'apps': ['dcim.device', 'virtualization.virtualmachine'],
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import base64
|
|
2
|
+
|
|
3
|
+
from drf_spectacular.types import OpenApiTypes
|
|
4
|
+
from drf_spectacular.utils import extend_schema_field
|
|
5
|
+
from rest_framework import serializers
|
|
6
|
+
|
|
7
|
+
from netbox.api.serializers import NetBoxModelSerializer
|
|
8
|
+
from netbox_secrets.models import *
|
|
9
|
+
from users.api.serializers import UserSerializer
|
|
10
|
+
|
|
11
|
+
__all__ = [
|
|
12
|
+
'ActivateUserKeySerializer',
|
|
13
|
+
'SessionKeyCreateSerializer',
|
|
14
|
+
'SessionKeySerializer',
|
|
15
|
+
'UserKeySerializer',
|
|
16
|
+
]
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class UserKeySerializer(NetBoxModelSerializer):
|
|
20
|
+
"""
|
|
21
|
+
Serializer for UserKey model.
|
|
22
|
+
|
|
23
|
+
Handles serialization of user encryption keys, including public/private key pairs.
|
|
24
|
+
The private key is write-only and never returned in responses.
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
user = UserSerializer(nested=True, required=False)
|
|
28
|
+
public_key = serializers.CharField(help_text="RSA public key in PEM format")
|
|
29
|
+
private_key = serializers.CharField(
|
|
30
|
+
write_only=True, required=False, help_text="RSA private key in PEM format (write-only, used for activation)"
|
|
31
|
+
)
|
|
32
|
+
is_active = serializers.BooleanField(
|
|
33
|
+
read_only=True, help_text="Whether this key has been activated with the master key"
|
|
34
|
+
)
|
|
35
|
+
is_filled = serializers.BooleanField(read_only=True, help_text="Whether this key has a public key configured")
|
|
36
|
+
|
|
37
|
+
class Meta:
|
|
38
|
+
model = UserKey
|
|
39
|
+
fields = [
|
|
40
|
+
'id',
|
|
41
|
+
'url',
|
|
42
|
+
'display_url',
|
|
43
|
+
'display',
|
|
44
|
+
'user',
|
|
45
|
+
'public_key',
|
|
46
|
+
'private_key',
|
|
47
|
+
'is_active',
|
|
48
|
+
'is_filled',
|
|
49
|
+
'created',
|
|
50
|
+
'last_updated',
|
|
51
|
+
'tags',
|
|
52
|
+
'custom_fields',
|
|
53
|
+
]
|
|
54
|
+
brief_fields = ('id', 'display', 'url')
|
|
55
|
+
|
|
56
|
+
def create(self, validated_data):
|
|
57
|
+
# Ignore private_key (used only for activation workflows)
|
|
58
|
+
validated_data.pop('private_key', None)
|
|
59
|
+
|
|
60
|
+
request = self.context.get('request')
|
|
61
|
+
if request and request.user and request.user.is_authenticated:
|
|
62
|
+
validated_data.setdefault('user', request.user)
|
|
63
|
+
|
|
64
|
+
return super().create(validated_data)
|
|
65
|
+
|
|
66
|
+
def update(self, instance, validated_data):
|
|
67
|
+
# Ignore private_key (used only for activation workflows)
|
|
68
|
+
validated_data.pop('private_key', None)
|
|
69
|
+
validated_data.pop('user', None)
|
|
70
|
+
return super().update(instance, validated_data)
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
class SessionKeySerializer(serializers.ModelSerializer):
|
|
74
|
+
"""
|
|
75
|
+
Serializer for SessionKey model.
|
|
76
|
+
|
|
77
|
+
Represents temporary session keys used for encrypting/decrypting secrets.
|
|
78
|
+
The actual session key value is only included in responses when explicitly
|
|
79
|
+
provided via context (e.g., after creation).
|
|
80
|
+
"""
|
|
81
|
+
|
|
82
|
+
userkey = UserKeySerializer(nested=True, read_only=True)
|
|
83
|
+
session_key = serializers.SerializerMethodField(
|
|
84
|
+
read_only=True, help_text="Base64-encoded session key (only returned on creation)"
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
class Meta:
|
|
88
|
+
model = SessionKey
|
|
89
|
+
fields = [
|
|
90
|
+
'id',
|
|
91
|
+
'userkey',
|
|
92
|
+
'session_key',
|
|
93
|
+
'created',
|
|
94
|
+
]
|
|
95
|
+
brief_fields = ('id', 'display', 'url')
|
|
96
|
+
|
|
97
|
+
@extend_schema_field(OpenApiTypes.STR)
|
|
98
|
+
def get_session_key(self, obj):
|
|
99
|
+
"""Return session key from context if available (e.g., after creation)."""
|
|
100
|
+
context_key = self.context.get('session_key')
|
|
101
|
+
if context_key:
|
|
102
|
+
return context_key
|
|
103
|
+
key = getattr(obj, 'key', None)
|
|
104
|
+
if key:
|
|
105
|
+
return base64.b64encode(key).decode('utf-8')
|
|
106
|
+
return None
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
class SessionKeyCreateSerializer(serializers.ModelSerializer):
|
|
110
|
+
"""
|
|
111
|
+
Serializer for creating session keys.
|
|
112
|
+
|
|
113
|
+
Requires the user's private key to derive the session key.
|
|
114
|
+
Optionally preserves existing session key instead of creating a new one.
|
|
115
|
+
"""
|
|
116
|
+
|
|
117
|
+
private_key = serializers.CharField(
|
|
118
|
+
write_only=True, required=True, help_text="User's RSA private key in PEM format"
|
|
119
|
+
)
|
|
120
|
+
preserve_key = serializers.BooleanField(
|
|
121
|
+
default=False,
|
|
122
|
+
write_only=True,
|
|
123
|
+
required=False,
|
|
124
|
+
help_text="If true, preserve existing session key instead of creating new one",
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
class Meta:
|
|
128
|
+
model = SessionKey
|
|
129
|
+
fields = ['private_key', 'preserve_key']
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
class ActivateUserKeySerializer(serializers.Serializer):
|
|
133
|
+
"""Serializer for activating user keys."""
|
|
134
|
+
|
|
135
|
+
private_key = serializers.CharField(
|
|
136
|
+
required=True,
|
|
137
|
+
write_only=True,
|
|
138
|
+
help_text="Administrator's RSA private key in PEM format for deriving master key",
|
|
139
|
+
min_length=1,
|
|
140
|
+
trim_whitespace=True,
|
|
141
|
+
)
|
|
142
|
+
user_key_ids = serializers.ListField(
|
|
143
|
+
child=serializers.IntegerField(min_value=1),
|
|
144
|
+
required=True,
|
|
145
|
+
help_text="List of UserKey IDs to activate",
|
|
146
|
+
min_length=1,
|
|
147
|
+
max_length=100,
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
def validate_user_key_ids(self, value):
|
|
151
|
+
"""Remove duplicates while preserving order."""
|
|
152
|
+
return list(dict.fromkeys(value))
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
from drf_spectacular.utils import extend_schema_serializer
|
|
2
|
+
from rest_framework import serializers
|
|
3
|
+
|
|
4
|
+
from netbox.api.serializers import WritableNestedSerializer
|
|
5
|
+
from netbox_secrets import models
|
|
6
|
+
|
|
7
|
+
__all__ = [
|
|
8
|
+
'NestedSecretRoleSerializer',
|
|
9
|
+
]
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@extend_schema_serializer(
|
|
13
|
+
exclude_fields=('secret_count',),
|
|
14
|
+
)
|
|
15
|
+
class NestedSecretRoleSerializer(WritableNestedSerializer):
|
|
16
|
+
secret_count = serializers.IntegerField(read_only=True)
|
|
17
|
+
_depth = serializers.IntegerField(source='level', read_only=True)
|
|
18
|
+
|
|
19
|
+
class Meta:
|
|
20
|
+
model = models.SecretRole
|
|
21
|
+
fields = ['id', 'url', 'display_url', 'display', 'name', 'slug', 'secret_count', '_depth']
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
from drf_spectacular.utils import extend_schema_field
|
|
2
|
+
from rest_framework import serializers
|
|
3
|
+
|
|
4
|
+
from core.models import ObjectType
|
|
5
|
+
from netbox.api.fields import ContentTypeField
|
|
6
|
+
from netbox.api.gfk_fields import GFKSerializerField
|
|
7
|
+
from netbox.api.serializers import NestedGroupModelSerializer, PrimaryModelSerializer
|
|
8
|
+
from netbox_secrets.constants import SECRET_ASSIGNABLE_MODELS
|
|
9
|
+
from netbox_secrets.models import *
|
|
10
|
+
from utilities.api import get_serializer_for_model
|
|
11
|
+
from .nested import NestedSecretRoleSerializer
|
|
12
|
+
|
|
13
|
+
__all__ = [
|
|
14
|
+
'SecretRoleSerializer',
|
|
15
|
+
'SecretSerializer',
|
|
16
|
+
]
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class SecretRoleSerializer(NestedGroupModelSerializer):
|
|
20
|
+
parent = NestedSecretRoleSerializer(required=False, allow_null=True)
|
|
21
|
+
secret_count = serializers.IntegerField(read_only=True, default=0)
|
|
22
|
+
|
|
23
|
+
class Meta:
|
|
24
|
+
model = SecretRole
|
|
25
|
+
fields = [
|
|
26
|
+
'id',
|
|
27
|
+
'url',
|
|
28
|
+
'display_url',
|
|
29
|
+
'display',
|
|
30
|
+
'name',
|
|
31
|
+
'slug',
|
|
32
|
+
'parent',
|
|
33
|
+
'description',
|
|
34
|
+
'tags',
|
|
35
|
+
'custom_fields',
|
|
36
|
+
'created',
|
|
37
|
+
'last_updated',
|
|
38
|
+
'secret_count',
|
|
39
|
+
'owner',
|
|
40
|
+
'comments',
|
|
41
|
+
'_depth',
|
|
42
|
+
]
|
|
43
|
+
brief_fields = ('id', 'url', 'display', 'name', 'slug', 'description', 'secret_count', '_depth')
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class SecretSerializer(PrimaryModelSerializer):
|
|
47
|
+
role = SecretRoleSerializer(nested=True, required=False)
|
|
48
|
+
assigned_object_type = ContentTypeField(queryset=ObjectType.objects.filter(SECRET_ASSIGNABLE_MODELS))
|
|
49
|
+
assigned_object = GFKSerializerField(read_only=True)
|
|
50
|
+
plaintext = serializers.CharField(required=False, help_text="Plaintext secret value (encrypted at rest)")
|
|
51
|
+
hash = serializers.CharField(read_only=True, help_text="SHA-256 hash for validation (read-only)")
|
|
52
|
+
|
|
53
|
+
class Meta:
|
|
54
|
+
model = Secret
|
|
55
|
+
fields = [
|
|
56
|
+
'id',
|
|
57
|
+
'url',
|
|
58
|
+
'display',
|
|
59
|
+
'assigned_object_type',
|
|
60
|
+
'assigned_object_id',
|
|
61
|
+
'assigned_object',
|
|
62
|
+
'role',
|
|
63
|
+
'name',
|
|
64
|
+
'plaintext',
|
|
65
|
+
'hash',
|
|
66
|
+
'description',
|
|
67
|
+
'comments',
|
|
68
|
+
'tags',
|
|
69
|
+
'custom_fields',
|
|
70
|
+
'created',
|
|
71
|
+
'last_updated',
|
|
72
|
+
]
|
|
73
|
+
validators = []
|
|
74
|
+
brief_fields = ('id', 'display', 'name', 'url')
|
|
75
|
+
|
|
76
|
+
@extend_schema_field(serializers.JSONField(allow_null=True))
|
|
77
|
+
def get_assigned_object(self, obj):
|
|
78
|
+
"""
|
|
79
|
+
Serialize the assigned object using its model-specific serializer.
|
|
80
|
+
|
|
81
|
+
Returns:
|
|
82
|
+
Nested serialized representation of the assigned object, or None
|
|
83
|
+
"""
|
|
84
|
+
if obj.assigned_object is None:
|
|
85
|
+
return None
|
|
86
|
+
|
|
87
|
+
serializer = get_serializer_for_model(obj.assigned_object)
|
|
88
|
+
context = {'request': self.context.get('request')}
|
|
89
|
+
return serializer(obj.assigned_object, nested=True, context=context).data
|
|
90
|
+
|
|
91
|
+
def validate(self, data):
|
|
92
|
+
"""
|
|
93
|
+
Validate and encrypt plaintext data.
|
|
94
|
+
|
|
95
|
+
If plaintext is provided and a master key is available in context,
|
|
96
|
+
encrypts the plaintext and stores the ciphertext and hash.
|
|
97
|
+
|
|
98
|
+
Args:
|
|
99
|
+
data: Validated data dictionary
|
|
100
|
+
|
|
101
|
+
Returns:
|
|
102
|
+
Validated data with ciphertext and hash added
|
|
103
|
+
|
|
104
|
+
Raises:
|
|
105
|
+
ValidationError: If plaintext provided but no master key in context
|
|
106
|
+
"""
|
|
107
|
+
plaintext = data.get('plaintext')
|
|
108
|
+
|
|
109
|
+
if plaintext:
|
|
110
|
+
master_key = self.context.get('master_key')
|
|
111
|
+
|
|
112
|
+
if master_key is None:
|
|
113
|
+
raise serializers.ValidationError(
|
|
114
|
+
{'plaintext': 'Cannot encrypt secret: master key not available in context'}
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
# Create temporary Secret instance for encryption
|
|
118
|
+
secret = Secret(plaintext=plaintext)
|
|
119
|
+
secret.encrypt(master_key)
|
|
120
|
+
|
|
121
|
+
# Store encrypted data
|
|
122
|
+
data['ciphertext'] = secret.ciphertext
|
|
123
|
+
data['hash'] = secret.hash
|
|
124
|
+
|
|
125
|
+
# Remove plaintext from data as it's now encrypted
|
|
126
|
+
data.pop('plaintext', None)
|
|
127
|
+
|
|
128
|
+
return super().validate(data)
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
from netbox.api.routers import NetBoxRouter
|
|
2
|
+
from . import views
|
|
3
|
+
|
|
4
|
+
router = NetBoxRouter()
|
|
5
|
+
router.APIRootView = views.SecretsRootView
|
|
6
|
+
|
|
7
|
+
# Key management endpoints
|
|
8
|
+
router.register('user-keys', views.UserKeyViewSet)
|
|
9
|
+
router.register('session-key', views.SessionKeyViewSet)
|
|
10
|
+
|
|
11
|
+
# Secret management endpoints
|
|
12
|
+
router.register('secret-roles', views.SecretRoleViewSet)
|
|
13
|
+
router.register('secrets', views.SecretViewSet)
|
|
14
|
+
|
|
15
|
+
# Utility endpoints
|
|
16
|
+
router.register('generate-rsa-key-pair', views.GenerateRSAKeyPairView, basename='generate-rsa-key-pair')
|
|
17
|
+
|
|
18
|
+
# Deprecated endpoints remain supported until NetBox v4.6 for backward compatibility.
|
|
19
|
+
router.register('session-keys', views.LegacySessionKeyViewSet, basename='session-keys')
|
|
20
|
+
router.register('activate-user-key', views.LegacyActivateUserKeyViewSet, basename='activate-user-key')
|
|
21
|
+
|
|
22
|
+
urlpatterns = router.urls
|