Splunk Search

Receiving a '401 Unauthorized' error when querying the 'services/search/jobs' API

cymulate
Observer

Hi,

I'm working with .NET and using the 'services/search/jobs/' API.
After successfully connecting through the 'services/auth/logi'n API, I receive a SessionKey, which I add to the headers for subsequent requests as follows:

oRequest.Headers.Authorization = new AuthenticationHeaderValue("Splunk", connectionInfo.AccessToken);

When I received 401 error code after called 'services/search/jobs/' , I attempt to reconnect by calling 'services/auth/login' up to three times to retrieve a new session key and update the header accordingly.
Despite this, the session key sometimes remains unchanged (is this expected behavior?), and regardless of whether the token changes or not, I continue to receive the 401 Unauthorized error:

Response: '<?xml version="1.0" encoding="UTF-8"?>
<response>
<messages>
<msg type="WARN">call not properly authenticated</msg>
</messages>
</response>
'

Error from System.Net.Http: System.Net.Http.HttpRequestException: Response status code does not indicate success: 401 (Unauthorized).

The URL I'm using starts with https and the port is 8089.
Can you assist with this issue?

Labels (2)
0 Karma

yuanliu
SplunkTrust
SplunkTrust

Is it possible that the token you use is created for a user that does not have permission to list other people's jobs?

0 Karma

cymulate
Observer

How can I verify this? How do I grant a specific user permission for all jobs? Does the user require particular capabilities or roles to search for a job? I noticed that someitmes the user has successfully accessed the "/services/search/jobs" endpoint , but encountered issues when using the "/services/search/jobs/{searchid}" endpoint.
Sometimes I got Unauthorizedon "/services/search/jobs" and sometimes got  Unauthorized on "/services/search/jobs/{searchid}"

0 Karma

yuanliu
SplunkTrust
SplunkTrust

You can go into token management to find out which this token belongs to, then go into permissions and find out what permissions the user has.

To think, every user who can launch a search should be allowed to use /services/search/jobs endpoint.  So, that is highly abnormal.  Maybe first test that user in UI to see if it can launch job manager menu.  Meanwhile, a trivial user should not be allowed to see another user's search, so denying /services/search/jobs/<searchid> can be the result of "otherness".

Also, it is not clear what exactly context defines "sometimes".  If the behavior is inconsistent over time using the same token on the same endpoint, maybe it's time to call support.

0 Karma
Get Updates on the Splunk Community!

Enterprise Security Content Update (ESCU) | New Releases

In December, the Splunk Threat Research Team had 1 release of new security content via the Enterprise Security ...

Why am I not seeing the finding in Splunk Enterprise Security Analyst Queue?

(This is the first of a series of 2 blogs). Splunk Enterprise Security is a fantastic tool that offers robust ...

Index This | What are the 12 Days of Splunk-mas?

December 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...