<?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>question Re: How to create Ranger policy on HDFS path via REST API? in Archives of Support Questions (Read Only)</title>
    <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/How-to-create-Ranger-policy-on-HDFS-path-via-REST-API/m-p/182622#M83208</link>
    <description>&lt;P&gt;Hi &lt;A href="https://community.hortonworks.com/questions/217726/how-to-create-ranger-policy-on-hdfs-path-via-rest.html#"&gt;@Marcel-Jan Krijgsman&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Looks like you are missing the "service" value. I get the same [3002] error if I copy-paste your command on my cluster, that error is gone when I add in the "service":"myservice" value (use an existing service, or you'll have to first create a new one).&lt;/P&gt;</description>
    <pubDate>Thu, 06 Sep 2018 16:03:20 GMT</pubDate>
    <dc:creator>JonathanSneep</dc:creator>
    <dc:date>2018-09-06T16:03:20Z</dc:date>
    <item>
      <title>How to create Ranger policy on HDFS path via REST API?</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/How-to-create-Ranger-policy-on-HDFS-path-via-REST-API/m-p/182621#M83207</link>
      <description>&lt;P&gt;I'm trying to roll out new Ranger policies for HDFS with the REST API, but I keep running into errors. We use the Ranger REST API via a Knox gateway, but all that has been proven to work. I was able to use the Ranger REST API to get info about existing policies via the REST API.&lt;/P&gt;&lt;P&gt;I use this command to create a simple policy:&lt;/P&gt;&lt;PRE&gt;curl -iv -u myaccount -H "Content-Type: application/json" -X POST &lt;A href="https://servername:6081/gateway/ui/ranger/service/public/v2/api/policy" target="_blank"&gt;https://servername:6081/gateway/ui/ranger/service/public/v2/api/policy&lt;/A&gt; -d '{ "policyName": "Test: testfile", "resourceName": "/data/test2", "description": "Added automatically via the Ranger REST API", "repositoryName": "ourrepository", "repositoryType": "hdfs", "isEnabled": "true", "isRecursive": "false", "isAuditEnabled": "true", "permMapList": [{ "groupList": ["developers"], "permList": ["Read", "Write", "Execute"] }] }'&lt;/PRE&gt;&lt;P&gt;And this is the message that I get:&lt;/P&gt;&lt;PRE&gt;{"statusCode":1,"msgDesc":"(0) Validation failure: error code[3002], reason[Internal error: missing field[service name]], field[service name], subfield[null], type[missing] "}&lt;/PRE&gt;&lt;P&gt;Any idea what's wrong with my JSON?&lt;/P&gt;</description>
      <pubDate>Thu, 06 Sep 2018 14:43:15 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/How-to-create-Ranger-policy-on-HDFS-path-via-REST-API/m-p/182621#M83207</guid>
      <dc:creator>marcel-jan</dc:creator>
      <dc:date>2018-09-06T14:43:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to create Ranger policy on HDFS path via REST API?</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/How-to-create-Ranger-policy-on-HDFS-path-via-REST-API/m-p/182622#M83208</link>
      <description>&lt;P&gt;Hi &lt;A href="https://community.hortonworks.com/questions/217726/how-to-create-ranger-policy-on-hdfs-path-via-rest.html#"&gt;@Marcel-Jan Krijgsman&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Looks like you are missing the "service" value. I get the same [3002] error if I copy-paste your command on my cluster, that error is gone when I add in the "service":"myservice" value (use an existing service, or you'll have to first create a new one).&lt;/P&gt;</description>
      <pubDate>Thu, 06 Sep 2018 16:03:20 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/How-to-create-Ranger-policy-on-HDFS-path-via-REST-API/m-p/182622#M83208</guid>
      <dc:creator>JonathanSneep</dc:creator>
      <dc:date>2018-09-06T16:03:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to create Ranger policy on HDFS path via REST API?</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/How-to-create-Ranger-policy-on-HDFS-path-via-REST-API/m-p/182623#M83209</link>
      <description>&lt;P&gt;I've added the service. Not sure if it just didn't work or that it was followed by a different issue.
&lt;/P&gt;&lt;PRE&gt; curl -iv -u myaccount -H "Content-Type: application/json"-X POST &lt;A href="https://servername:6081/gateway/ui/ranger/service/public/v2/api/policy" target="_blank"&gt;https://servername:6081/gateway/ui/ranger/service/public/v2/api/policy&lt;/A&gt; -d '{ "policyName": "Test: testfile", "service": "OPS_hadoop", "resourceName": "/data/test2", "description": "Added automatically via the Ranger REST API", "repositoryName": "OPS_hadoop", "repositoryType": "hdfs", "isEnabled": "true", "isRecursive": "false", "isAuditEnabled": "true", "permMapList": [{ "groupList": ["developers"], "permList": ["Read", "Write", "Execute"] }] }'&lt;/PRE&gt;&lt;P&gt;(In my code repositoryName and service are the same BTW).&lt;/P&gt;&lt;P&gt;I got a different error now.&lt;/P&gt;&lt;PRE&gt;{"statusCode":1,"msgDesc":"(0) Validation failure: error code[3025], reason[Invalid resources specified. hdfs policy must specify values for the following resources: [path] ], field[policy resources], subfield[missing mandatory], type[semantically incorrect] "}&lt;/PRE&gt;</description>
      <pubDate>Thu, 06 Sep 2018 18:30:43 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/How-to-create-Ranger-policy-on-HDFS-path-via-REST-API/m-p/182623#M83209</guid>
      <dc:creator>marcel-jan</dc:creator>
      <dc:date>2018-09-06T18:30:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to create Ranger policy on HDFS path via REST API?</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/How-to-create-Ranger-policy-on-HDFS-path-via-REST-API/m-p/182624#M83210</link>
      <description>&lt;P&gt;Hi &lt;A rel="user" href="https://community.cloudera.com/users/16354/marcel-jan.html" nodeid="16354"&gt;@Marcel-Jan Krijgsman&lt;/A&gt;&lt;BR /&gt;Ok, so it seems we are using the v1 API format while we should be using the v2 format, which is quite different.&lt;BR /&gt;I think, the easiest thing to avoid running into the next errors, is to first export the format from an existing policy as an example. Try exporting an existing one first and storing the json;&lt;/P&gt;&lt;PRE&gt;curl -k -iv -s -u user:pass -H "Content-Type: application/json" -X GET &lt;A href="http://myhost:6080/service/public/v2/api/policy/2" target="_blank"&gt;http://myhost:6080/service/public/v2/api/policy/2&lt;/A&gt; &amp;gt; /tmp/exampleformat&lt;/PRE&gt;&lt;P&gt;With the above, I simply changed the name, path, policyID, uuid value, and posted a new policy. &lt;/P&gt;&lt;P&gt;Then post it back like so;&lt;/P&gt;&lt;PRE&gt;curl -v -s -ik -u user:pass -H "Content-Type: application/json" -X POST &lt;A href="http://myhost:6080/service/public/v2/api/policy" target="_blank"&gt;http://myhost:6080/service/public/v2/api/policy&lt;/A&gt; -d @exampleformat&lt;/PRE&gt;&lt;P&gt;This gave me a HTTP/1.1 200 OK &amp;amp; the new policy was visible in the ranger web UI, with the expected config.&lt;BR /&gt;Let me know if that's clear. I can attach the exampleformat file I used in the above example if that helps.&lt;/P&gt;</description>
      <pubDate>Thu, 06 Sep 2018 20:49:11 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/How-to-create-Ranger-policy-on-HDFS-path-via-REST-API/m-p/182624#M83210</guid>
      <dc:creator>JonathanSneep</dc:creator>
      <dc:date>2018-09-06T20:49:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to create Ranger policy on HDFS path via REST API?</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/How-to-create-Ranger-policy-on-HDFS-path-via-REST-API/m-p/182625#M83211</link>
      <description>&lt;P&gt;&lt;A rel="user" href="https://community.cloudera.com/users/84313/jsneep.html" nodeid="84313"&gt;@Jonathan Sneep&lt;/A&gt; That worked!&lt;/P&gt;&lt;P&gt;I've edited the json a little. I removed the id and guid from it, but that was no problem. There's some more stuff that probably doesn't have to be in there. I'll try out some more stuff and report back here.&lt;/P&gt;</description>
      <pubDate>Thu, 06 Sep 2018 21:04:16 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/How-to-create-Ranger-policy-on-HDFS-path-via-REST-API/m-p/182625#M83211</guid>
      <dc:creator>marcel-jan</dc:creator>
      <dc:date>2018-09-06T21:04:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to create Ranger policy on HDFS path via REST API?</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/How-to-create-Ranger-policy-on-HDFS-path-via-REST-API/m-p/182626#M83212</link>
      <description>&lt;P&gt;So you can basically widdle it down to:&lt;/P&gt;&lt;PRE&gt;{"isEnabled":true,"service":"OPS_hadoop","name":"Test: /data/test2","policyType":0,"description":"Added automatically via the Ranger REST API","isAuditEnabled":true,"resources":{"path":{"values":["/data/test2"],"isExcludes":false,"isRecursive":true}},"policyItems":[{"accesses":[{"type":"read","isAllowed":true},{"type":"write","isAllowed":true},{"type":"execute","isAllowed":true}],"groups":["developers"],"conditions":[],"delegateAdmin":false}],"denyPolicyItems":[],"allowExceptions":[],"denyExceptions":[],"dataMaskPolicyItems":[],"rowFilterPolicyItems":[]}&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;And this also works.&lt;/P&gt;&lt;PRE&gt;curl -iv -u 203631 -H "Content-Type: application/json" -X POST &lt;A href="https://servername:6801/gateway/ui/ranger/service/public/v2/api/policy" target="_blank"&gt;https://servername:6801/gateway/ui/ranger/service/public/v2/api/policy&lt;/A&gt; -d '{"isEnabled":true,"service":"OPS_hadoop","name":"Test: /data/test2","policyType":0,"description":"Added automatically via the Ranger REST API","isAuditEnabled":true,"resources":{"path":{"values":["/data/test2"],"isExcludes":false,"isRecursive":true}},"policyItems":[{"accesses":[{"type":"read","isAllowed":true},{"type":"write","isAllowed":true},{"type":"execute","isAllowed":true}],"groups":["developers"],"conditions":[],"delegateAdmin":false}],"denyPolicyItems":[],"allowExceptions":[],"denyExceptions":[],"dataMaskPolicyItems":[],"rowFilterPolicyItems":[]}'&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;Which means I can write a couple of these commands to prepare for a rollout. Cool!&lt;/P&gt;</description>
      <pubDate>Thu, 06 Sep 2018 21:19:13 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/How-to-create-Ranger-policy-on-HDFS-path-via-REST-API/m-p/182626#M83212</guid>
      <dc:creator>marcel-jan</dc:creator>
      <dc:date>2018-09-06T21:19:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to create Ranger policy on HDFS path via REST API?</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/How-to-create-Ranger-policy-on-HDFS-path-via-REST-API/m-p/182627#M83213</link>
      <description>&lt;P&gt;Awesome, &lt;A rel="user" href="https://community.cloudera.com/users/16354/marcel-jan.html" nodeid="16354"&gt;@Marcel-Jan Krijgsman&lt;/A&gt;, glad we got it working &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; and thank you for sharing the trimmed result!&lt;/P&gt;</description>
      <pubDate>Thu, 06 Sep 2018 21:24:15 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/How-to-create-Ranger-policy-on-HDFS-path-via-REST-API/m-p/182627#M83213</guid>
      <dc:creator>JonathanSneep</dc:creator>
      <dc:date>2018-09-06T21:24:15Z</dc:date>
    </item>
  </channel>
</rss>

