splunk-sdk-python icon indicating copy to clipboard operation
splunk-sdk-python copied to clipboard

Don't override Authorization header or make token auth optional

Open sullivanmatt opened this issue 11 years ago • 3 comments

In my fairly large environment, we need to be able to accept REST API requests from any IP on the Internet. Instead of opening up the entirety of our Splunk API to 0.0.0.0/0, we instead front the requests with an nginx reverse proxy with a whitelist of allowed API users (which simply does a lookup in an htpasswd file).

This actually works quite well for most of our applications, but unfortunately is incompatible with the Splunk SDK for Python. It seems that in all cases, the SDK prefers to get and use an auth token. And this probably does make sense as a default behavior - my guess is that checking the user/pass on each request isn't particularly efficient. But there are cases (and we're one of them!) where this is needed.

Anyway, this wouldn't be a big issue if I could just pass in an Authorization header, but unfortunately Splunk nukes any Authorization headers that don't start with 'Splunk': https://github.com/splunk/splunk-sdk-python/blob/ac660726d92f9c41784f33fb451e67921e21527c/splunklib/binding.py#L516

In my opinion, it should only add 'Splunk' if the Authorization header doesn't already have 'Basic' present.

If I make a PR to change this behavior, would such a modification be acceptable? In the future, I think the SDK could also benefit from simply having an option which disables using token auth on every request - I doubt I'm the first or last person to run into this issue.

Thanks!

sullivanmatt avatar Aug 20 '15 18:08 sullivanmatt

FYI @shakeelmohamed @itay

sullivanmatt avatar Aug 20 '15 18:08 sullivanmatt

@sullivanmatt apologies for the delay in getting back to you.

First of all, the answer is yes - we would definitely be open to fixing it. We actually have a similar request on the Ruby SDK as well.

Second - there is one complication to consider, however, and that is how to deal with the new cookie-based authentication we just added. Namely, if you pass in a Basic Auth header, we should skip all login methods, etc so that we don't get a cookie.

Let us know if you need any other pointers - we're happy to help in guiding the PR, but don't have time to make the change ourselves at the moment due to some other higher priority work.

itay avatar Aug 24 '15 17:08 itay

@itay PR made: https://github.com/splunk/splunk-sdk-python/pull/118

sullivanmatt avatar Aug 24 '15 21:08 sullivanmatt