Splunk Dev

Assigning multiple roles to user with Python

datamann119
Engager

I'm writing Python script that assigns multiple roles to a user, but having difficulty understanding what the  'roles' data structure needs to look like. According to the REST documentation for authentication/users/{name}:

To assign multiple roles, pass in each role using a separate roles parameter value.
For example, -d roles="role1", -d roles="role2".

In Postman, I can successfully construct a request with multiple 'roles' parameters to produce the result I want, which is to assign multiple roles to the user.  In Python, my code looks like this:

 

(response, content) = h.request(HOST + URL + OUTPUT_MODE, 'POST', headers=HEADERS,                          body=urllib.parse.urlencode({'roles':'admin','roles':'user'}))

 

But the end result is that the user is only assigned the 'user' role, presumably because the 'body' data structure ends up being a dictionary with a single key: {'roles':'user'}

Anybody know what is the right Python data structure to pass to urlencode so that I can add multiple roles to the user in a single POST?

Labels (2)
0 Karma

jcraumer
Explorer

Hurricane Labs did a sample demo regarding changing user permissions with a dashboard and custom endpoints.  

https://hurricanelabs.com/splunk-tutorials/splunk-custom-endpoints-part-3-posting-the-data/

I think the endpoint posting is included in part three, video 7 & 8, about cleaning and posting the data to python.  This is a good example demo as it needed to be slightly updated in certain parts to work correctly making it a nice tutorial with some trouble shooting involved.  

Aside from that aspect it shows the required format that can be used to send a user name with multiple roles assigned to update the Splunk ACL backend.  

Hopefully this helps solve your issue.

 

 

0 Karma
Get Updates on the Splunk Community!

Combine Multiline Logs into a Single Event with SOCK - a Guide for Advanced Users

This article is the continuation of the “Combine multiline logs into a single event with SOCK - a step-by-step ...

Everything Community at .conf24!

You may have seen mention of the .conf Community Zone 'round these parts and found yourself wondering what ...

Index This | I’m short for "configuration file.” What am I?

May 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with a Special ...