Splunk Dev

Why is my python script suddenly writing "Authorization Failed: " statements to stdout

sideview
SplunkTrust
SplunkTrust

I updated to 8.2.2.1 and suddenly all of our unit test output is polluted with hundreds of Authorization Failed messages,  each coming from various calls to splunk.rest.simpleRequest.

The Authorization failures themselves are perfectly normal - many of our tests actually assert that ownership and permissions are set the right way, and testing that involves trying to do things with the wrong user and asserting that the thing fails.  

What's problematic is how formerly nice clean unit test output to the console or to stdout is now polluted with all this stuff about these normal failures.

for example,  picture dozens or hundreds of these:

Authorization Failed: b'{"success":false,"messages":[{"text":"It looks like your Splunk Enterprise\\nuser account does not have the correct capabilities to be able to post licenses.\\nReach out to your local Splunk admin(s) for help, and/or contact Sideview support\\nfor more detail."}]}

Curious if anyone has run into this or knows where the messages might be coming from.

Labels (2)
0 Karma
1 Solution

sideview
SplunkTrust
SplunkTrust

The answer was that some time between 8.2.21 and 8.2.1,   Splunk posted this change to their AuthorizationFailed class,  to have it log the error out.... as INFO.

here is python3.7/site-packages/splunk/rest/__init__.py

    # SPL-174568 - In case of authorization failures, we raise the
    # AuthorizationFailed exception but do not include the failure message.
    # Logging the authorization failure message so we have some info
    # to diagnose the scenarios why authorization failed.
    logger.info('Authorization Failed: %s' % serverContent)
    raise splunk.AuthorizationFailed(extendedMessages=uri)

And this would be harmless if all client code implemented a logger. But if you don't actually do anything with the "splunk.rest" logger.... (because why on earth would you)   then the default just goes to stdout.   D'oh.

So that's what bit us here.  Our unit test scripts dont implement any logging,  and any such python script that might trigger AuthorizationFailed will also suffer the same fate in its stdout.    

 

SOLUTION:

In your code that wants to use the splunk.rest stuff,   but doesn't want INFO's to spew out to stdout, add this:

restLogger = logging.getLogger('splunk.rest')
restLogger.setLevel(logging.ERROR)

 

ALTERNATIVE CLUMSY SOLUTION:
manually edit the __init__.py  to comment out that logger.info line.

 

 

View solution in original post

sideview
SplunkTrust
SplunkTrust

The answer was that some time between 8.2.21 and 8.2.1,   Splunk posted this change to their AuthorizationFailed class,  to have it log the error out.... as INFO.

here is python3.7/site-packages/splunk/rest/__init__.py

    # SPL-174568 - In case of authorization failures, we raise the
    # AuthorizationFailed exception but do not include the failure message.
    # Logging the authorization failure message so we have some info
    # to diagnose the scenarios why authorization failed.
    logger.info('Authorization Failed: %s' % serverContent)
    raise splunk.AuthorizationFailed(extendedMessages=uri)

And this would be harmless if all client code implemented a logger. But if you don't actually do anything with the "splunk.rest" logger.... (because why on earth would you)   then the default just goes to stdout.   D'oh.

So that's what bit us here.  Our unit test scripts dont implement any logging,  and any such python script that might trigger AuthorizationFailed will also suffer the same fate in its stdout.    

 

SOLUTION:

In your code that wants to use the splunk.rest stuff,   but doesn't want INFO's to spew out to stdout, add this:

restLogger = logging.getLogger('splunk.rest')
restLogger.setLevel(logging.ERROR)

 

ALTERNATIVE CLUMSY SOLUTION:
manually edit the __init__.py  to comment out that logger.info line.

 

 

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 ...