<?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: Modifying ACL/Saved Search permissions through REST API using Python in Splunk Dev</title>
    <link>https://community.splunk.com/t5/Splunk-Dev/Modifying-ACL-Saved-Search-permissions-through-REST-API-using/m-p/132806#M1882</link>
    <description>&lt;P&gt;By the way if you want to add multiple items (such as for permissions in the following example) use a comma delimited string format&lt;/P&gt;

&lt;P&gt;{ "sharing" : "app","owner":"nobody","perms.write":"admin,power,user" }&lt;/P&gt;</description>
    <pubDate>Mon, 03 Nov 2014 17:11:27 GMT</pubDate>
    <dc:creator>Flynt</dc:creator>
    <dc:date>2014-11-03T17:11:27Z</dc:date>
    <item>
      <title>Modifying ACL/Saved Search permissions through REST API using Python</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Modifying-ACL-Saved-Search-permissions-through-REST-API-using/m-p/132794#M1870</link>
      <description>&lt;P&gt;I'm attempting to modify a saved search's permissions through the Splunk Python SDK.  Unfortunately, it doesn't seem to be supported out of the box, so I'm trying to do it through the REST API.  I asked a previous question (modifying saved search permissions using the python sdk) which showed me how to do it in Java, but I'm having trouble translating that solution to Python.  I'm using the urllib2 module.  I've had some success with this, but I'm stuck:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;def modify_perms( ss ):
    service =   initSplunk()

    zen_config  =   get_config()
    url = "localhost:8089/servicesNS/%s/splenoss/saved/searches/%s/acl" % ("admin", ss)

    request =   urllib2.Request( url )        

    base64string    =   base64.encodestring("admin:changeme")

    request.add_header("Authorization", "Basic %s" % base64string)
    request.add_header("Referer", url ) 

    # Saved search access params
    jwargs  = { "sharing"       :   "app"                                        ,
                "modifiable"    :   "1"                                          ,
                "perms.read"    :   "*"                                          ,
                "perms.write"   :   ["admin" , "power"]                          ,
                #"perms"     :   {"read":["*"] , "write":["admin" , "power"]}    ,   
    }


    #response    =   urllib2.urlopen( request , **jwargs )
    response    =   urllib2.urlopen( request )
    print response.read()
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If I don't try to push anything to splunk, I get a response back, which has all of the permission settings.  However, once I do try to push jwargs, I get error messages about unexpected keywords.  I'm assuming that I'm not passing jwargs correctly, or the way I've built jwargs isn't correct.  What am I missing to get this to work in Python?&lt;/P&gt;</description>
      <pubDate>Mon, 07 Jul 2014 18:25:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Modifying-ACL-Saved-Search-permissions-through-REST-API-using/m-p/132794#M1870</guid>
      <dc:creator>erichar7</dc:creator>
      <dc:date>2014-07-07T18:25:52Z</dc:date>
    </item>
    <item>
      <title>Re: Modifying ACL/Saved Search permissions through REST API using Python</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Modifying-ACL-Saved-Search-permissions-through-REST-API-using/m-p/132795#M1871</link>
      <description>&lt;P&gt;I'm going to guess that the REST API is complaining about an unexpected &lt;CODE&gt;modifiable&lt;/CODE&gt; key. That's not writeable, but rather a calculated part of the response, telling the client if the permissions and sharing of the object allow the current user to modify the object. Setting that doesn't make sense, it's implicitly set of each user through the perms keys.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Jul 2014 00:22:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Modifying-ACL-Saved-Search-permissions-through-REST-API-using/m-p/132795#M1871</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-07-08T00:22:57Z</dc:date>
    </item>
    <item>
      <title>Re: Modifying ACL/Saved Search permissions through REST API using Python</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Modifying-ACL-Saved-Search-permissions-through-REST-API-using/m-p/132796#M1872</link>
      <description>&lt;P&gt;Yes, I do get an error about unexpected keys.  However, it complains no matter what I try to pass (if it's a valid key or not)&lt;/P&gt;</description>
      <pubDate>Tue, 08 Jul 2014 14:00:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Modifying-ACL-Saved-Search-permissions-through-REST-API-using/m-p/132796#M1872</guid>
      <dc:creator>erichar7</dc:creator>
      <dc:date>2014-07-08T14:00:35Z</dc:date>
    </item>
    <item>
      <title>Re: Modifying ACL/Saved Search permissions through REST API using Python</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Modifying-ACL-Saved-Search-permissions-through-REST-API-using/m-p/132797#M1873</link>
      <description>&lt;P&gt;Hmm. Here's a simplified excerpt of modifying the permissions from Python I've built a while back:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;import splunk.rest as rest
...
aclUrl = "/servicesNS/" + user + "/" + app + "/saved/searches/" + search + "/acl"
postArgs = {"perms.write": perms_write, "perms.read":  perms_read, "sharing": "app", "owner": entity.owner}
rest.simpleRequest(aclUrl, sessionKey=sessionKey, postargs=postArgs, method='POST', raiseAllErrors=True)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;CODE&gt;entity.owner&lt;/CODE&gt; is the owner of the search (from &lt;CODE&gt;splunk.entity.getEntity()&lt;/CODE&gt;), and &lt;CODE&gt;perms_write/perms_read&lt;/CODE&gt; are comma-separated strings of roles.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Jul 2014 14:33:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Modifying-ACL-Saved-Search-permissions-through-REST-API-using/m-p/132797#M1873</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-07-08T14:33:18Z</dc:date>
    </item>
    <item>
      <title>Re: Modifying ACL/Saved Search permissions through REST API using Python</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Modifying-ACL-Saved-Search-permissions-through-REST-API-using/m-p/132798#M1874</link>
      <description>&lt;P&gt;Is your perms.write array translated to "perms.write=admin,power" in the HTTP POST body?&lt;BR /&gt;
Additionally, you seem to be missing the owner.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Jul 2014 14:34:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Modifying-ACL-Saved-Search-permissions-through-REST-API-using/m-p/132798#M1874</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-07-08T14:34:08Z</dc:date>
    </item>
    <item>
      <title>Re: Modifying ACL/Saved Search permissions through REST API using Python</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Modifying-ACL-Saved-Search-permissions-through-REST-API-using/m-p/132799#M1875</link>
      <description>&lt;P&gt;there is no splunk.rest module, or splunklib.rest (or at least I can't find it)...what are you using here?&lt;/P&gt;

&lt;P&gt;Also, yes I'm missing "owner" in my args, but that's not important.  No matter what I put in my args, I always get back an error about unexpected keys&lt;/P&gt;</description>
      <pubDate>Wed, 09 Jul 2014 15:13:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Modifying-ACL-Saved-Search-permissions-through-REST-API-using/m-p/132799#M1875</guid>
      <dc:creator>erichar7</dc:creator>
      <dc:date>2014-07-09T15:13:02Z</dc:date>
    </item>
    <item>
      <title>Re: Modifying ACL/Saved Search permissions through REST API using Python</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Modifying-ACL-Saved-Search-permissions-through-REST-API-using/m-p/132800#M1876</link>
      <description>&lt;P&gt;Did you inspect your request to see what it actually sent as HTTP POST body? Coming from the other direction, did you use a basic client like curl to send a POST manually to validate the body you intend to send?&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;splunk.rest&lt;/CODE&gt; sits in &lt;CODE&gt;$SPLUNK_HOME/Python-2.7/Lib/site-packages/splunk/rest&lt;/CODE&gt; - part of the Splunk install itself.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Jul 2014 17:03:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Modifying-ACL-Saved-Search-permissions-through-REST-API-using/m-p/132800#M1876</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-07-09T17:03:53Z</dc:date>
    </item>
    <item>
      <title>Re: Modifying ACL/Saved Search permissions through REST API using Python</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Modifying-ACL-Saved-Search-permissions-through-REST-API-using/m-p/132801#M1877</link>
      <description>&lt;P&gt;Yes, I've inspected the request and it looks good.  If I do not unpack jwargs with **, I will get TypeError: unhashable type when I try to open the url.  If I try to build the request using **jwargs instead, it errors out before I can even try to open the url, I get an "unexpected keyword argument" on the first entry in jwargs&lt;/P&gt;

&lt;P&gt;Since I'm running Splunk on my Windows machine, I cannot test the curl command.  I also couldn't get the splunk.rest module to work correctly, I kept getting KeyError: "SPLUNK_HOME" (I'm guessing that variable doesn't exist with the Windows install)&lt;/P&gt;</description>
      <pubDate>Fri, 11 Jul 2014 14:57:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Modifying-ACL-Saved-Search-permissions-through-REST-API-using/m-p/132801#M1877</guid>
      <dc:creator>erichar7</dc:creator>
      <dc:date>2014-07-11T14:57:19Z</dc:date>
    </item>
    <item>
      <title>Re: Modifying ACL/Saved Search permissions through REST API using Python</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Modifying-ACL-Saved-Search-permissions-through-REST-API-using/m-p/132802#M1878</link>
      <description>&lt;P&gt;This is the content of my request via urllib2:&lt;/P&gt;

&lt;P&gt;print request.get_full_url()&lt;BR /&gt;
print request.get_method()&lt;/P&gt;

&lt;H2&gt;print request.get_data()&lt;/H2&gt;

&lt;P&gt;&lt;A href="https://localhost:8089/servicesNS/admin/splenoss/saved/searches/test/acl" target="_blank"&gt;https://localhost:8089/servicesNS/admin/splenoss/saved/searches/test/acl&lt;/A&gt;&lt;BR /&gt;
POST&lt;BR /&gt;
{'owner': 'admin', 'perms.write': ['admin', 'power'], 'sharing': 'app', 'perms.read': '*'}&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 17:02:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Modifying-ACL-Saved-Search-permissions-through-REST-API-using/m-p/132802#M1878</guid>
      <dc:creator>erichar7</dc:creator>
      <dc:date>2020-09-28T17:02:52Z</dc:date>
    </item>
    <item>
      <title>Re: Modifying ACL/Saved Search permissions through REST API using Python</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Modifying-ACL-Saved-Search-permissions-through-REST-API-using/m-p/132803#M1879</link>
      <description>&lt;P&gt;Replace the array for &lt;CODE&gt;perms.write&lt;/CODE&gt; with &lt;CODE&gt;"admin,power"&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;As for the &lt;CODE&gt;$SPLUNK_HOME&lt;/CODE&gt; environment variable on Windows, that's probably &lt;CODE&gt;C:\Program Files\Splunk&lt;/CODE&gt;. You can simply import &lt;CODE&gt;splunk.rest&lt;/CODE&gt; when called from within Splunk's own Python.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Jul 2014 15:54:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Modifying-ACL-Saved-Search-permissions-through-REST-API-using/m-p/132803#M1879</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-07-11T15:54:57Z</dc:date>
    </item>
    <item>
      <title>Re: Modifying ACL/Saved Search permissions through REST API using Python</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Modifying-ACL-Saved-Search-permissions-through-REST-API-using/m-p/132804#M1880</link>
      <description>&lt;P&gt;I replaced my perms.write with "admin,power" and I got the same results, I keep getting those unhashable type errors or unexpected keyword errors.&lt;/P&gt;

&lt;P&gt;As for splunk.rest, I can import that module just fine.  However, when I execute the Simple Request function, it returns errors related to SPLUNK_HOME, as if that variable doesn't exist.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Jul 2014 19:48:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Modifying-ACL-Saved-Search-permissions-through-REST-API-using/m-p/132804#M1880</guid>
      <dc:creator>erichar7</dc:creator>
      <dc:date>2014-07-11T19:48:43Z</dc:date>
    </item>
    <item>
      <title>Re: Modifying ACL/Saved Search permissions through REST API using Python</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Modifying-ACL-Saved-Search-permissions-through-REST-API-using/m-p/132805#M1881</link>
      <description>&lt;P&gt;There are a few changes that would need to be made here-&lt;/P&gt;

&lt;P&gt;First, when using urllib2 to post, you'll need to urlencode the data (&lt;A href="https://docs.python.org/2/howto/urllib2.html#data"&gt;https://docs.python.org/2/howto/urllib2.html#data&lt;/A&gt;)&lt;/P&gt;

&lt;P&gt;Secondly, base64.encodestring appears to be appending padding in some manner, you'll need to strip that out.&lt;/P&gt;

&lt;P&gt;Lastly, you'll have to add the content type in the header to use the urlencoded data.&lt;/P&gt;

&lt;P&gt;Something such as the following should work -&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;import urllib2
import base64
import urllib


    def modify_perms( ss ):
       url = "https://localhost:8089/servicesNS/%s/search/saved/searches/%s/acl" % ("admin", ss)
       request = urllib2.Request( url )
       base64string    =   base64.encodestring("admin:changeme").strip()
       request.add_header("Authorization", "Basic %s" % base64string)
       request.add_header("Referer", url )
       request.add_header("Content-Type", "application/x-www-form-urlencoded")
       kwargs = { "sharing" : "app","owner":"nobody" }
       response = urllib2.urlopen( request ,  urllib.urlencode(kwargs))
       print response.read()


    modify_perms("test")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This is for a search named test in the search app  changing the owner to "nobody" and sharing to "app".&lt;/P&gt;</description>
      <pubDate>Fri, 31 Oct 2014 17:33:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Modifying-ACL-Saved-Search-permissions-through-REST-API-using/m-p/132805#M1881</guid>
      <dc:creator>Flynt</dc:creator>
      <dc:date>2014-10-31T17:33:57Z</dc:date>
    </item>
    <item>
      <title>Re: Modifying ACL/Saved Search permissions through REST API using Python</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Modifying-ACL-Saved-Search-permissions-through-REST-API-using/m-p/132806#M1882</link>
      <description>&lt;P&gt;By the way if you want to add multiple items (such as for permissions in the following example) use a comma delimited string format&lt;/P&gt;

&lt;P&gt;{ "sharing" : "app","owner":"nobody","perms.write":"admin,power,user" }&lt;/P&gt;</description>
      <pubDate>Mon, 03 Nov 2014 17:11:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Modifying-ACL-Saved-Search-permissions-through-REST-API-using/m-p/132806#M1882</guid>
      <dc:creator>Flynt</dc:creator>
      <dc:date>2014-11-03T17:11:27Z</dc:date>
    </item>
    <item>
      <title>Re: Modifying ACL/Saved Search permissions through REST API using Python</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Modifying-ACL-Saved-Search-permissions-through-REST-API-using/m-p/132807#M1883</link>
      <description>&lt;P&gt;Can I ask if someone can explain me why you insert this part?&lt;/P&gt;

&lt;P&gt;request.add_header("Authorization", "Basic %s" % base64string)&lt;BR /&gt;
request.add_header("Referer", url )&lt;/P&gt;

&lt;P&gt;thank you &lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 18:57:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Modifying-ACL-Saved-Search-permissions-through-REST-API-using/m-p/132807#M1883</guid>
      <dc:creator>Federica_92</dc:creator>
      <dc:date>2020-09-28T18:57:07Z</dc:date>
    </item>
    <item>
      <title>Re: Modifying ACL/Saved Search permissions through REST API using Python</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Modifying-ACL-Saved-Search-permissions-through-REST-API-using/m-p/132808#M1884</link>
      <description>&lt;P&gt;Splunk allows for basic HTTP authentication as seen here - &lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/RESTUM/RESTusing#Supported_HTTP_methods"&gt;http://docs.splunk.com/Documentation/Splunk/latest/RESTUM/RESTusing#Supported_HTTP_methods&lt;/A&gt; . Also note the defining RFC for this method here - &lt;A href="http://www.rfc-base.org/txt/rfc-1945.txt"&gt;http://www.rfc-base.org/txt/rfc-1945.txt&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Authentication is necessary to access certain REST endpoints in Splunk (most of them actually). &lt;/P&gt;</description>
      <pubDate>Fri, 13 Feb 2015 17:31:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Modifying-ACL-Saved-Search-permissions-through-REST-API-using/m-p/132808#M1884</guid>
      <dc:creator>Flynt</dc:creator>
      <dc:date>2015-02-13T17:31:54Z</dc:date>
    </item>
    <item>
      <title>Re: Modifying ACL/Saved Search permissions through REST API using Python</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Modifying-ACL-Saved-Search-permissions-through-REST-API-using/m-p/132809#M1885</link>
      <description>&lt;P&gt;In Splunk 6.4.1, the URL is  &lt;A href="https://localhost:8089/servicesNS/admin/MYAPP/saved/searches/MYSEARCH/acl,Li"&gt;https://localhost:8089/servicesNS/admin/MYAPP/saved/searches/MYSEARCH/acl,Li&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jun 2016 19:29:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Modifying-ACL-Saved-Search-permissions-through-REST-API-using/m-p/132809#M1885</guid>
      <dc:creator>kiran_p</dc:creator>
      <dc:date>2016-06-23T19:29:04Z</dc:date>
    </item>
  </channel>
</rss>

