Skip to content

Commit c75c6b5

Browse files
committed
[change] Hide senstive fields on shared objects from non-superuser
1 parent 2a4a863 commit c75c6b5

File tree

5 files changed

+63
-1
lines changed

5 files changed

+63
-1
lines changed

openwisp_controller/config/migrations/0060_update_groups_permissions.py renamed to openwisp_controller/config/migrations/0061_update_groups_permissions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
class Migration(migrations.Migration):
77
dependencies = [
8-
("config", "0059_zerotier_templates_ow_zt_to_global"),
8+
("config", "0060_cleanup_api_task_notification_types"),
99
]
1010

1111
operations = [

openwisp_controller/connection/admin.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class CredentialsAdmin(MultitenantAdminMixin, TimeReadonlyAdminMixin, admin.Mode
5757
"created",
5858
"modified",
5959
]
60+
sensitive_fields = ["params"]
6061

6162
def get_urls(self):
6263
options = getattr(self.model, "_meta")

openwisp_controller/connection/tests/test_admin.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,24 @@ def test_org_admin_view_shared_credentials(self):
156156
),
157157
)
158158

159+
def test_credential_admin_sensitive_fields(self):
160+
"""
161+
Sensitive fields for shared credentials should be hidden for non-superusers.
162+
"""
163+
org = self._get_org()
164+
shared_credentials = self._create_credentials(organization=None)
165+
org_credentials = self._create_credentials(organization=org)
166+
self._test_sensitive_fields_visibility_on_shared_and_org_objects(
167+
sensitive_fields=["params"],
168+
shared_obj_path=reverse(
169+
f"admin:{self.app_label}_credentials_change", args=(shared_credentials.id,)
170+
),
171+
org_obj_path=reverse(
172+
f"admin:{self.app_label}_credentials_change", args=(org_credentials.id,)
173+
),
174+
organization=org,
175+
)
176+
159177

160178
class TestCommandInlines(TestAdminMixin, CreateConnectionsMixin, TestCase):
161179
config_app_label = "config"

openwisp_controller/pki/admin.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
@admin.register(Ca)
1515
class CaAdmin(MultitenantAdminMixin, AbstractCaAdmin, VersionAdmin):
1616
history_latest_first = True
17+
sensitive_fields = [
18+
"private_key",
19+
]
1720

1821

1922
CaAdmin.fields.insert(2, "organization")
@@ -25,6 +28,9 @@ class CaAdmin(MultitenantAdminMixin, AbstractCaAdmin, VersionAdmin):
2528
@admin.register(Cert)
2629
class CertAdmin(MultitenantAdminMixin, AbstractCertAdmin, VersionAdmin):
2730
multitenant_shared_relations = ("ca",)
31+
sensitive_fields = [
32+
"private_key",
33+
]
2834
history_latest_first = True
2935

3036

openwisp_controller/pki/tests/test_admin.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,24 @@ def test_org_admin_view_shared_ca(self):
9999
path=reverse(f"admin:{self.app_label}_ca_change", args=[ca.pk]),
100100
)
101101

102+
def test_ca_admin_sensitive_fields(self):
103+
"""
104+
Sensitive fields for shared CA should be hidden for non-superusers.
105+
"""
106+
org = self._get_org()
107+
shared_ca = self._create_ca(organization=None)
108+
org_ca = self._create_ca(organization=org)
109+
self._test_sensitive_fields_visibility_on_shared_and_org_objects(
110+
sensitive_fields=["private_key"],
111+
shared_obj_path=reverse(
112+
f"admin:{self.app_label}_ca_change", args=(shared_ca.id,)
113+
),
114+
org_obj_path=reverse(
115+
f"admin:{self.app_label}_ca_change", args=(org_ca.id,)
116+
),
117+
organization=org,
118+
)
119+
102120
def test_cert_queryset(self):
103121
data = self._create_multitenancy_test_env(cert=True)
104122
self._test_multitenant_admin(
@@ -174,6 +192,25 @@ def test_org_admin_view_shared_cert(self):
174192
path=reverse(f"admin:{self.app_label}_cert_change", args=[shared_cert.pk]),
175193
)
176194

195+
def test_cert_admin_sensitive_fields(self):
196+
"""
197+
Sensitive fields for shared certificates should be hidden for non-superusers.
198+
"""
199+
org = self._get_org()
200+
shared_ca = self._create_ca(organization=None)
201+
shared_cert = self._create_cert(ca=shared_ca, organization=None)
202+
org_cert = self._create_cert(ca=shared_ca, organization=org)
203+
self._test_sensitive_fields_visibility_on_shared_and_org_objects(
204+
sensitive_fields=["private_key"],
205+
shared_obj_path=reverse(
206+
f"admin:{self.app_label}_cert_change", args=(shared_cert.id,)
207+
),
208+
org_obj_path=reverse(
209+
f"admin:{self.app_label}_cert_change", args=(org_cert.id,)
210+
),
211+
organization=org,
212+
)
213+
177214
def test_cert_changeform_200(self):
178215
org = self._create_org(name="test-org")
179216
self._create_operator(organizations=[org])

0 commit comments

Comments
 (0)