<?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 Python SDK - getting username and password (without hard coding) in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Python-SDK-getting-username-and-password-without-hard-coding/m-p/529523#M149557</link>
    <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;I'm trying to get the username and password of the user calling a python script from the search bar in the Splunk UI. I need this to log into smtp to send an email (smtp.login(username,&amp;nbsp;password)).&lt;/P&gt;&lt;P&gt;I need to make use of SCPv2, so the&lt;/P&gt;&lt;P&gt;&amp;nbsp;results,dummyresults,settings = splunk.Intersplunk.getOrganizedResults()&amp;nbsp;&lt;/P&gt;&lt;P&gt;route is not an option. I can get the&amp;nbsp;authenticated session connection via the self object&amp;nbsp;(self.service). I though I should be able to get the username and password using "storage_passwords", however when I use that and output the username and password to the logger, I see the following:&lt;/P&gt;&lt;P&gt;Username:Windows_Usage``splunk_cred_sep``2 Password:``splunk_cred_sep``S``splunk_cred_sep``P``splunk_cred_sep``L``splunk_cred_sep``U``splunk_cred_sep``N``splunk_cred_sep``K``splunk_cred_sep``&lt;/P&gt;&lt;P&gt;It looks like the username and password is encrypted in some way? If I try to use those credentials, I get a "[HTTP 401] Client is not authenticated" error. Looking at the capabilities o the user, I see that "list_storage_passwords" is included.&lt;/P&gt;&lt;P&gt;Any ideas on how I can get the username and password? If I hardcode the username and password everything works, but I do not like to have passwords in script files.&lt;/P&gt;</description>
    <pubDate>Mon, 16 Nov 2020 12:41:15 GMT</pubDate>
    <dc:creator>BernardEAI</dc:creator>
    <dc:date>2020-11-16T12:41:15Z</dc:date>
    <item>
      <title>Python SDK - getting username and password (without hard coding)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Python-SDK-getting-username-and-password-without-hard-coding/m-p/529523#M149557</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;I'm trying to get the username and password of the user calling a python script from the search bar in the Splunk UI. I need this to log into smtp to send an email (smtp.login(username,&amp;nbsp;password)).&lt;/P&gt;&lt;P&gt;I need to make use of SCPv2, so the&lt;/P&gt;&lt;P&gt;&amp;nbsp;results,dummyresults,settings = splunk.Intersplunk.getOrganizedResults()&amp;nbsp;&lt;/P&gt;&lt;P&gt;route is not an option. I can get the&amp;nbsp;authenticated session connection via the self object&amp;nbsp;(self.service). I though I should be able to get the username and password using "storage_passwords", however when I use that and output the username and password to the logger, I see the following:&lt;/P&gt;&lt;P&gt;Username:Windows_Usage``splunk_cred_sep``2 Password:``splunk_cred_sep``S``splunk_cred_sep``P``splunk_cred_sep``L``splunk_cred_sep``U``splunk_cred_sep``N``splunk_cred_sep``K``splunk_cred_sep``&lt;/P&gt;&lt;P&gt;It looks like the username and password is encrypted in some way? If I try to use those credentials, I get a "[HTTP 401] Client is not authenticated" error. Looking at the capabilities o the user, I see that "list_storage_passwords" is included.&lt;/P&gt;&lt;P&gt;Any ideas on how I can get the username and password? If I hardcode the username and password everything works, but I do not like to have passwords in script files.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Nov 2020 12:41:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Python-SDK-getting-username-and-password-without-hard-coding/m-p/529523#M149557</guid>
      <dc:creator>BernardEAI</dc:creator>
      <dc:date>2020-11-16T12:41:15Z</dc:date>
    </item>
    <item>
      <title>Re: Python SDK - getting username and password (without hard coding)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Python-SDK-getting-username-and-password-without-hard-coding/m-p/529531#M149560</link>
      <description>&lt;P&gt;I assume you tried something like this to get the output?&lt;/P&gt;&lt;LI-CODE lang="python"&gt;args = {'token': 'your_session_key'}
service = client.connect(**args)

for storage_password in service.storage_passwords:
    if storage_password.username == username and storage_password.realm == 'your_app':
        clear_pw = storage_password.content.clear_password&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;That works in my case. I've seen something like your output when analysing passwords/secrets that I used when coding using the Splunk Add-on Builder but it's been a long time so not sure if it's related.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Nov 2020 13:11:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Python-SDK-getting-username-and-password-without-hard-coding/m-p/529531#M149560</guid>
      <dc:creator>Patrick_Peeters</dc:creator>
      <dc:date>2020-11-16T13:11:59Z</dc:date>
    </item>
    <item>
      <title>Re: Python SDK - getting username and password (without hard coding)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Python-SDK-getting-username-and-password-without-hard-coding/m-p/529540#M149564</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/33390"&gt;@Patrick_Peeters&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the feedback. Correct, I used something very close to your code:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;storage_passwords=self.service.storage_passwords
for storage_password in service.storage_passwords:
    if storage_password.username == username and storage_password.realm == 'your_app':
        clear_pw = storage_password.content.clear_password&lt;/LI-CODE&gt;&lt;P&gt;Incidentally, how do you get the session key? I do not need the key since the&amp;nbsp;&lt;SPAN&gt;search command already gives me an authenticated session connection via the self object. However I can't seem to get the value of sessionKey from the self object. If I could get the session key there would be another route to get the password.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Nov 2020 14:01:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Python-SDK-getting-username-and-password-without-hard-coding/m-p/529540#M149564</guid>
      <dc:creator>BernardEAI</dc:creator>
      <dc:date>2020-11-16T14:01:26Z</dc:date>
    </item>
    <item>
      <title>Re: Python SDK - getting username and password (without hard coding)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Python-SDK-getting-username-and-password-without-hard-coding/m-p/529641#M149601</link>
      <description>&lt;P&gt;I got it by importing the Script class and using the following line:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from splunklib.modularinput import Script, Scheme, Argument, Event
session_key = self._input_definition.metadata["session_key"]&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 16 Nov 2020 22:04:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Python-SDK-getting-username-and-password-without-hard-coding/m-p/529641#M149601</guid>
      <dc:creator>Patrick_Peeters</dc:creator>
      <dc:date>2020-11-16T22:04:54Z</dc:date>
    </item>
    <item>
      <title>Re: Python SDK - getting username and password (without hard coding)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Python-SDK-getting-username-and-password-without-hard-coding/m-p/529686#M149623</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/33390"&gt;@Patrick_Peeters&lt;/a&gt;&amp;nbsp; I have determined that those passwords are encrypted, and for some reason they are not decrypted correctly.&lt;/P&gt;&lt;P&gt;I have now added my own username and password to a passwords.conf file in my app/local folder. I can now see that username and password if I run&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;storage_passwords=self.service.storage_passwords
  for credential in storage_passwords:
            usercreds = {'username':credential.content.get('username'),'password':credential.content.get('clear_password')}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Initially the passwords I added were not encrypted, which is not very secure. I managed to generate an encrypted passwords by using an API call:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;curl -k -u admin:&amp;lt;admin_password&amp;gt; https://&amp;lt;splunk_host&amp;gt;:8089/servicesNS/nobody/&amp;lt;app_name&amp;gt;/storage/passwords -d name=&amp;lt;username&amp;gt; -d password=&amp;lt;password&amp;gt;&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 17 Nov 2020 11:13:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Python-SDK-getting-username-and-password-without-hard-coding/m-p/529686#M149623</guid>
      <dc:creator>BernardEAI</dc:creator>
      <dc:date>2020-11-17T11:13:42Z</dc:date>
    </item>
  </channel>
</rss>

