Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

ranger policies custom report

ranger policies custom report

Expert Contributor

i want to pull report from Mysql (ranger db). report i need is what ever i see in ranger UI. list of policies and what permissions are assigned to users.

i'm using ranger 0.5, i knonw this is easy in new ranger 0.6 where we can download report from ranger ui

1 REPLY 1
Highlighted

Re: ranger policies custom report

Hi Raja,

In ranger 0.5 it is a lot more difficult to get the data from the db directly. What I have done in the past is use the Rest APIs to download the content and flatten out the data. You can get the rest apis from your browsers developer tool utilities. For example,

json curl

curl 'http://127.0.0.1:6080/service/plugins/policies?page=0&pageSize=25&startIndex=0&serviceType=hive&group=&_=1451414078895' -H 'Cookie: AMBARISESSIONID=bkhp0zgjk8be1a5hy438zyk7r; JSESSIONID=DACAF20F2DDF50BD05BFA82C37AE758F; clientTimeOffset=480' -H 'Accept-Encoding: gzip, deflate, sdch' -H 'Accept-Language: en-US,en;q=0.8' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36' -H 'Accept: application/json, text/javascript, */*; q=0.01' -H 'Referer: http://127.0.0.1:6080/index.html' -H 'X-Requested-With: XMLHttpRequest' -H 'Connection: keep-alive' --compressed

or xml curl

curl 'http://127.0.0.1:6080/service/plugins/policies?page=0&pageSize=25&startIndex=0&serviceType=hive&group=&_=1451414078895' -H 'Accept-Encoding: gzip, deflate, sdch' -H 'Accept-Language: en-US,en;q=0.8' -H 'Upgrade-Insecure-Requests: 1' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' -H 'Cookie: AMBARISESSIONID=bkhp0zgjk8be1a5hy438zyk7r; JSESSIONID=DACAF20F2DDF50BD05BFA82C37AE758F; clientTimeOffset=480' -H 'Connection: keep-alive' --compressed

If you change the serviceType= to other components you can get the reports from those components, etc.

Once you have the data you can use something like xpath to parse the data: Forexample,

Say I want all hive databases in all my policies

rangerPolicyList/policies/resources/entry[key='database']/value//values 

Say I want all users:  

/rangerPolicyList/policies/policyItems/users 

Say I want all groups:  

/rangerPolicyList/policies/policyItems/groups

Or you can use a parsing tool of your choice. Forexample, http://www.convertcsv.com/json-to-csv.htm to convert the json file to csv and import into excel.

In HDP version 2.5 you can download reports in Ranger to csv/excel.

10048-screen-shot-2016-12-02-at-40956-pm.png

Don't have an account?
Coming from Hortonworks? Activate your account here