Skip to content

Commit bd27b42

Browse files
author
Shakeel Mohamed
committed
Fix: accessing /server/* endpoints doesn't 403 if namespace is set.
Ex: If namespace is set to `{'owner': 'admin', 'app': 'search'}`, then we don't want to access /servicesNS/admin/search/server/info. (This was the behavior before this change).
1 parent 50d7a92 commit bd27b42

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

splunklib/binding.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -857,7 +857,7 @@ def _abspath(self, path_segment,
857857
# endpoint. Otherwise, use /servicesNS with the specified
858858
# namespace. If only one of app and owner is specified, use
859859
# '-' for the other.
860-
if ns.app is None and ns.owner is None:
860+
if ns.app is None and ns.owner is None or path_segment.startswith("server"):
861861
return UrlEncoded("/services/%s" % path_segment, skip_encode=skip_encode)
862862

863863
oname = "nobody" if ns.owner is None else ns.owner

tests/test_service.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,22 @@ def test_info(self):
4545
for key in keys:
4646
self.assertTrue(key in info.keys())
4747

48+
def test_info_with_namespace(self):
49+
# Make sure we're not accessing /servicesNS/admin/search/server/info
50+
# instead of /services/server/info
51+
# Backup the values, which are probably set to None
52+
owner, app = self.service.namespace["owner"], self.service.namespace["app"]
53+
54+
self.service.namespace["owner"] = self.service.username
55+
self.service.namespace["app"] = "search"
56+
try:
57+
self.service.info
58+
except Exception as e:
59+
self.fail("Couldn't get the server info, probably got a 403! %s" % e.message)
60+
61+
self.service.namespace["owner"] = owner
62+
self.service.namespace["app"] = app
63+
4864
def test_without_namespace(self):
4965
service = client.connect(**self.opts.kwargs)
5066
service.apps.list()

0 commit comments

Comments
 (0)