Skip to content

Commit e5f9313

Browse files
committed
MB-68154: Fix auditing of JWT settings
JWT settings are stored in Erlang maps. They are JSON-encoded using jiffy (which can handle maps). However, they were passed as Erlang maps to ns_audit. ns_audit uses ejson for encoding and can't handle Erlang maps. Pass the jiffy-encoded JSON settings directly to ns_audit. Enable auditing in jwt_tests to exercise this path. Change-Id: I43af8f03f5c0850046810b5d3ce26cc21941b02a Reviewed-on: https://review.couchbase.org/c/ns_server/+/232478 Tested-by: Neelima Premsankar <[email protected]> Well-Formed: Build Bot <[email protected]> Reviewed-by: Peter Searby <[email protected]>
1 parent 85ee5b6 commit e5f9313

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

apps/ns_server/src/menelaus_web_jwt.erl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,8 @@ validate_and_store_settings(Props, Req) ->
464464
{ok, _} ->
465465
RestFormat = storage_to_rest_format(Settings),
466466
EncodedSettings = encode_response(RestFormat),
467-
ns_audit:settings(Req, modify_jwt, [{jwt_settings, RestFormat}]),
467+
ns_audit:settings(Req, modify_jwt, [{jwt_settings,
468+
{json, EncodedSettings}}]),
468469
_ = sync_with_node(),
469470
menelaus_util:reply(Req, EncodedSettings, 200,
470471
[{"Content-Type", "application/json"}]);

cluster_tests/testsets/jwt_tests.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ def setup(self):
117117
testlib.set_config_key(self.cluster,
118118
"{jwt_cache, jwks_cooldown_interval_ms}",
119119
1000)
120+
121+
audit_payload = {"auditdEnabled": "true"}
122+
testlib.post_succ(self.cluster, "/settings/audit", data=audit_payload)
123+
120124
# Disabled by default
121125
testlib.get_fail(self.cluster, self.endpoint, expected_code=404)
122126

@@ -129,6 +133,9 @@ def teardown(self):
129133
testlib.delete_succ(self.cluster, self.endpoint)
130134
testlib.get_fail(self.cluster, self.endpoint, expected_code=404)
131135

136+
audit_payload = {"auditdEnabled": "false"}
137+
testlib.post_succ(self.cluster, "/settings/audit", data=audit_payload)
138+
132139
# Clean up all test users
133140
for username in self.external_users:
134141
testlib.delete_succ(

0 commit comments

Comments
 (0)