<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Retrieve Credentials from Splunk for a Custom Alert Action - Client is not authenticated in Splunk Dev</title>
    <link>https://community.splunk.com/t5/Splunk-Dev/Retrieve-Credentials-from-Splunk-for-a-Custom-Alert-Action/m-p/318005#M4383</link>
    <description>&lt;P&gt;That looks like the session key passed is not valid.&lt;/P&gt;

&lt;P&gt;Could you print everything Splunk is passing to stdin?&lt;/P&gt;</description>
    <pubDate>Mon, 04 Dec 2017 10:59:24 GMT</pubDate>
    <dc:creator>damien_chillet</dc:creator>
    <dc:date>2017-12-04T10:59:24Z</dc:date>
    <item>
      <title>Retrieve Credentials from Splunk for a Custom Alert Action - Client is not authenticated</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Retrieve-Credentials-from-Splunk-for-a-Custom-Alert-Action/m-p/318004#M4382</link>
      <description>&lt;P&gt;Currently using Splunk 6.2.3&lt;/P&gt;

&lt;P&gt;I have a python script that is being executed as part of a Custom Alert Action. This script retrieves credentials (for our internal tickets system) that are stored in a Splunk App I set up. &lt;/P&gt;

&lt;P&gt;I have been following this blog post for the setup of my script: &lt;A href="https://www.splunk.com/blog/2011/03/15/storing-encrypted-credentials.html"&gt;https://www.splunk.com/blog/2011/03/15/storing-encrypted-credentials.html&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;NOTE: I chose to have it send me an email with the error message instead of having to go check a log file, so the sendErrorEmail is something I defined.&lt;/P&gt;

&lt;P&gt;However, when my script runs, i keep getting the error: "Could not get My_App credentials from splunk. Error: [HTTP 401] Client is not authenticated"&lt;/P&gt;

&lt;P&gt;Below is my script code. Any idea what I'm doing wrong or if there is something I'm missing?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;def getCredentials(sessionKey):
    myapp = 'My_App'

    #Trims off "sessionKey=" from readline
    #Even if I remove this line, my script doesn't work
    sessionKey = sessionKey[11:]

    try:
        # list all credentials
        entities = entity.getEntities(['admin', 'passwords'], namespace=myapp, owner='nobody', sessionKey=sessionKey) 
    except Exception, e:
        html = "sessionKey == " + sessionKey + "&amp;lt;br&amp;gt;&amp;amp;lt;br/&amp;amp;gt;Could not get %s credentials from splunk. Error: %s" % (myapp, str(e))
        text = "Could not get %s credentials from splunk. Error: %s" % (myapp, str(e))
        sendErrorEmail(html, text);
        raise Exception("Could not get %s credentials from splunk. Error: %s" % (myapp, str(e)))

    # return first set of credentials
    for i, c in entities.items(): 
        return c['username'], c['clear_password']
    html = "No credentials have been found"
    text = "No credentials have been found"
    sendErrorEmail(html, text);
    raise Exception("No credentials have been found")  

def main(): 
sessionKey = sys.stdin.readline().strip()
    if sessionKey == "":
        html = 'No sessionKey'
        text = 'No sessionKey'
        sendErrorEmail(html, text)

    username, password = getCredentials(sessionKey)
    credentials = [username, password]
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 01 Dec 2017 21:46:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Retrieve-Credentials-from-Splunk-for-a-Custom-Alert-Action/m-p/318004#M4382</guid>
      <dc:creator>celestekiyoko</dc:creator>
      <dc:date>2017-12-01T21:46:58Z</dc:date>
    </item>
    <item>
      <title>Re: Retrieve Credentials from Splunk for a Custom Alert Action - Client is not authenticated</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Retrieve-Credentials-from-Splunk-for-a-Custom-Alert-Action/m-p/318005#M4383</link>
      <description>&lt;P&gt;That looks like the session key passed is not valid.&lt;/P&gt;

&lt;P&gt;Could you print everything Splunk is passing to stdin?&lt;/P&gt;</description>
      <pubDate>Mon, 04 Dec 2017 10:59:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Retrieve-Credentials-from-Splunk-for-a-Custom-Alert-Action/m-p/318005#M4383</guid>
      <dc:creator>damien_chillet</dc:creator>
      <dc:date>2017-12-04T10:59:24Z</dc:date>
    </item>
    <item>
      <title>Re: Retrieve Credentials from Splunk for a Custom Alert Action - Client is not authenticated</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Retrieve-Credentials-from-Splunk-for-a-Custom-Alert-Action/m-p/318006#M4384</link>
      <description>&lt;P&gt;Are you sure that &lt;CODE&gt;Alert actions&lt;/CODE&gt; is showing under Settings in Splunk Web? Because as far as I know Custom Alert action introduced since Splunk 6.3 so it will not work in Splunk 6.2.3&lt;/P&gt;

&lt;P&gt;If you are running Splunk 6.3 or higher then you will able to fetch &lt;CODE&gt;session_key&lt;/CODE&gt; from payload. Please refer example script &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.6.3/AdvancedDev/ModAlertsBasicExample"&gt;http://docs.splunk.com/Documentation/Splunk/6.6.3/AdvancedDev/ModAlertsBasicExample&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Dec 2017 11:30:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Retrieve-Credentials-from-Splunk-for-a-Custom-Alert-Action/m-p/318006#M4384</guid>
      <dc:creator>harsmarvania57</dc:creator>
      <dc:date>2017-12-04T11:30:17Z</dc:date>
    </item>
    <item>
      <title>Re: Retrieve Credentials from Splunk for a Custom Alert Action - Client is not authenticated</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Retrieve-Credentials-from-Splunk-for-a-Custom-Alert-Action/m-p/318007#M4385</link>
      <description>&lt;P&gt;Here are some patterns depending on what you are doing.&lt;BR /&gt;
&lt;A href="http://www.georgestarcher.com/splunk-stored-encrypted-credentials/"&gt;http://www.georgestarcher.com/splunk-stored-encrypted-credentials/&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Honestly though you are better off using the Add-On builder to make your alert actions so you get all the supporting code.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Dec 2017 16:26:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Retrieve-Credentials-from-Splunk-for-a-Custom-Alert-Action/m-p/318007#M4385</guid>
      <dc:creator>starcher</dc:creator>
      <dc:date>2017-12-04T16:26:45Z</dc:date>
    </item>
    <item>
      <title>Re: Retrieve Credentials from Splunk for a Custom Alert Action - Client is not authenticated</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Retrieve-Credentials-from-Splunk-for-a-Custom-Alert-Action/m-p/318008#M4386</link>
      <description>&lt;P&gt;The custom alert action is relatively new, but even in older versions of Splunk, "Run a script" has been an option for alerts. That's what I am using to execute my script.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Dec 2017 18:36:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Retrieve-Credentials-from-Splunk-for-a-Custom-Alert-Action/m-p/318008#M4386</guid>
      <dc:creator>celestekiyoko</dc:creator>
      <dc:date>2017-12-04T18:36:37Z</dc:date>
    </item>
    <item>
      <title>Re: Retrieve Credentials from Splunk for a Custom Alert Action - Client is not authenticated</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Retrieve-Credentials-from-Splunk-for-a-Custom-Alert-Action/m-p/318009#M4387</link>
      <description>&lt;P&gt;That was my guess too, but I can't figure out what it's not liking about my session key.&lt;/P&gt;

&lt;P&gt;sys.stdin.readline().strip() gives the following:&lt;BR /&gt;
&lt;EM&gt;sessionKey=JcAM%5EMTPFZxlMfZgKthwNjbsqneDpCyUYh4Tf_sM4BviMnfgPXV86NsdIKlpFNQqFQxakLQWC9EbkNPSZTPuioEcTg34EopEcsSn8dhjWIZHTZRcEUCh%5EDSectftoLS4FXcgDHo5bCMjKo&lt;/EM&gt;&lt;/P&gt;

&lt;P&gt;sessionKey = sessionKey[11:] makes it the following:&lt;BR /&gt;
&lt;EM&gt;JcAM%5EMTPFZxlMfZgKthwNjbsqneDpCyUYh4Tf_sM4BviMnfgPXV86NsdIKlpFNQqFQxakLQWC9EbkNPSZTPuioEcTg34EopEcsSn8dhjWIZHTZRcEUCh%5EDSectftoLS4FXcgDHo5bCMjKo&lt;/EM&gt;&lt;/P&gt;

&lt;P&gt;I have tried passing it with the "sessionKey=" in the beginning and without it, and both times I still get the "could not authenticate" error.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Dec 2017 18:46:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Retrieve-Credentials-from-Splunk-for-a-Custom-Alert-Action/m-p/318009#M4387</guid>
      <dc:creator>celestekiyoko</dc:creator>
      <dc:date>2017-12-04T18:46:53Z</dc:date>
    </item>
    <item>
      <title>Re: Retrieve Credentials from Splunk for a Custom Alert Action - Client is not authenticated</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Retrieve-Credentials-from-Splunk-for-a-Custom-Alert-Action/m-p/318010#M4388</link>
      <description>&lt;P&gt;Hi Celeste, &lt;/P&gt;

&lt;P&gt;The blogpost you are basing your script on is quite old (2011), and in the current python SDK i'm using there is no &lt;CODE&gt;splunk.entity&lt;/CODE&gt; module.&lt;BR /&gt;
Which SDK version are you using?&lt;/P&gt;

&lt;P&gt;Here is how I manage to retrieve credentials using Python SDK version 1.6.2:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;service = client.Service(token=sessionKey)

# service.storage_passwords.create('test','damien','SPLUNK ANSWERS')

print service.storage_passwords.list(**{"search": "SPLUNK ANSWERS"})[0].content
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;For this example the output is as following:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;{'username': 'damien', 'encr_password': '$1$gfY5DWk=', 'realm': 'SPLUNK ANSWERS', 'clear_password': 'test', 'password': '********'}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Hope that helps!&lt;/P&gt;</description>
      <pubDate>Tue, 05 Dec 2017 11:36:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Retrieve-Credentials-from-Splunk-for-a-Custom-Alert-Action/m-p/318010#M4388</guid>
      <dc:creator>damien_chillet</dc:creator>
      <dc:date>2017-12-05T11:36:18Z</dc:date>
    </item>
    <item>
      <title>Re: Retrieve Credentials from Splunk for a Custom Alert Action - Client is not authenticated</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Retrieve-Credentials-from-Splunk-for-a-Custom-Alert-Action/m-p/318011#M4389</link>
      <description>&lt;P&gt;Maybe a bit late on this one, but it looks like your session key needs to be URL decoded.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Aug 2018 15:40:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Retrieve-Credentials-from-Splunk-for-a-Custom-Alert-Action/m-p/318011#M4389</guid>
      <dc:creator>dsommerville</dc:creator>
      <dc:date>2018-08-17T15:40:11Z</dc:date>
    </item>
    <item>
      <title>Re: Retrieve Credentials from Splunk for a Custom Alert Action - Client is not authenticated</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Retrieve-Credentials-from-Splunk-for-a-Custom-Alert-Action/m-p/529535#M4390</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/67425"&gt;@starcher&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for this hint. I followed your directions at&amp;nbsp;&lt;A href="http://www.georgestarcher.com/splunk-stored-encrypted-credentials/" rel="nofollow noopener noreferrer" target="_blank"&gt;http://www.georgestarcher.com/splunk-stored-encrypted-credentials/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;I'm getting the following result if I run:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;import sys
from splunklib.searchcommands import dispatch, GeneratingCommand, Configuration, Option, validators

@Configuration(streaming=False, local=True, type='reporting')
class GenerateAuthInfoCommand(GeneratingCommand):
    def generate(self):
        storage_passwords=self.service.storage_passwords
        for credential in storage_passwords:
            usercreds = {'username':credential.content.get('username'),'password':credential.content.get('clear_password')}
            yield usercreds
dispatch(GenerateAuthInfoCommand, sys.argv, sys.stdin, sys.stdout, __name__)&lt;/LI-CODE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="2020-11-16 15_19_45-Search _ Splunk 7.3.3.png" style="width: 999px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/11908iCC256C3E5CEFB246/image-size/large?v=v2&amp;amp;px=999" role="button" title="2020-11-16 15_19_45-Search _ Splunk 7.3.3.png" alt="2020-11-16 15_19_45-Search _ Splunk 7.3.3.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;None of these results look like something I can use as a username and password. I have tried authenticating with one of them, but no luck.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Nov 2020 13:21:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Retrieve-Credentials-from-Splunk-for-a-Custom-Alert-Action/m-p/529535#M4390</guid>
      <dc:creator>BernardEAI</dc:creator>
      <dc:date>2020-11-16T13:21:48Z</dc:date>
    </item>
  </channel>
</rss>

