You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ranger.apache.org by Sean Roberts <sr...@hortonworks.com> on 2017/04/03 12:46:37 UTC

Import policies via API

Ranger folks – Can you provide advice on importing policies via the API.

I imported via UI and am trying to replicate the actions via curl but it is not accepting it. The json is an export (attached)

curl –v -u admin:admin \
  -H Content-Type: application/json -X POST –d @ranger-policies.json \
  "http://localhost:6080/service/plugins/policies/importPoliciesFromFile?isOverride=true&serviceType=hdfs,hive"

* About to connect() to localhost port 6080 (#0)
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 6080 (#0)
* Server auth using Basic with user 'admin'
> POST /service/plugins/policies/importPoliciesFromFile?isOverride=true&serviceType=hdfs,hive HTTP/1.1
> Authorization: Basic YWRtaW46YWRtaW4=
> User-Agent: curl/7.29.0
> Host: localhost:6080
> Accept: */*
> Content-Type: application/json
> Content-Length: 4718
> Expect: 100-continue
>
< HTTP/1.1 100 Continue
< HTTP/1.1 404 Not Found
< Server: Apache-Coyote/1.1
< Set-Cookie: RANGERADMINSESSIONID=2CE00A4CA61EADCB0B491282E81608DE; Path=/; HttpOnly
< X-Frame-Options: DENY
< Content-Length: 0
< Date: Mon, 03 Apr 2017 12:45:17 GMT
< Connection: close
<
* Closing connection 0

--
Sean Roberts
Partner Engineering, EMEA
@seano


Re: Import policies via API

Posted by Sean Roberts <sr...@hortonworks.com>.
Ayub – Perfect. That works. Thanks! I also tried with ‘-F’ but had the wrong field name.

--
Sean Roberts
Partner Engineering, EMEA
@seano


From: Ayub Khan Pathan <ap...@hortonworks.com>
Date: Monday, 3 April 2017 at 15:21
To: "user@ranger.apache.org" <us...@ranger.apache.org>, Sean Roberts <sr...@hortonworks.com>
Subject: Re: Import policies via API

Hi Sean,

Can you try the exact below cmd?

curl -v -X POST -u "admin:admin" \
-H "Content-Type: multipart/form-data" \
-H "Content-Type: application/json" \
-F 'file=@Ranger_Policies_20170403_131421.json' \
http://ctr-e129-1487033772569-66527-01-000002.hwx.site:6080/service/plugins/policies/importPoliciesFromFile?isOverride=true&serviceType=hive


*   Trying 172.27.23.199...
* Connected to ctr-e129-1487033772569-66527-01-000002.hwx.site (172.27.23.199) port 6080 (#0)
* Server auth using Basic with user 'admin'
> POST /service/plugins/policies/importPoliciesFromFile?isOverride=true&serviceType=hive HTTP/1.1
> Host: ctr-e129-1487033772569-66527-01-000002.hwx.site:6080
> Authorization: Basic YWRtaW46YWRtaW4=
> User-Agent: curl/7.43.0
> Accept: */*
> Content-Length: 20050
> Expect: 100-continue
> Content-Type: multipart/form-data; boundary=------------------------054d9e8c1762dcd0
>
< HTTP/1.1 100 Continue
< HTTP/1.1 204 No Content
< Server: Apache-Coyote/1.1
< Set-Cookie: RANGERADMINSESSIONID=A063D293277437D074EFD2435967EF88; Path=/; HttpOnly
< WWW-Authenticate: Negotiate
< Set-Cookie: hadoop.auth=; Path=/; Domain=ctr-e129-1487033772569-66527-01-000002.hwx.site; Expires=Thu, 01-Jan-1970 00:00:00 GMT; HttpOnly
< X-Frame-Options: DENY
< Content-Type: application/json
< Date: Mon, 03 Apr 2017 13:15:53 GMT
<
* Connection #0 to host ctr-e129-1487033772569-66527-01-000002.hwx.site left intact

Regards
Ayub Khan

From: Sean Roberts <sr...@hortonworks.com>
Reply-To: "user@ranger.apache.org" <us...@ranger.apache.org>
Date: Monday, April 3, 2017 at 6:16 PM
To: "user@ranger.apache.org" <us...@ranger.apache.org>
Subject: Import policies via API

Ranger folks – Can you provide advice on importing policies via the API.

I imported via UI and am trying to replicate the actions via curl but it is not accepting it. The json is an export (attached)

curl –v -u admin:admin \
  -H Content-Type: application/json -X POST –d @ranger-policies.json \
  "http://localhost:6080/service/plugins/policies/importPoliciesFromFile?isOverride=true&serviceType=hdfs,hive"

* About to connect() to localhost port 6080 (#0)
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 6080 (#0)
* Server auth using Basic with user 'admin'
> POST /service/plugins/policies/importPoliciesFromFile?isOverride=true&serviceType=hdfs,hive HTTP/1.1
> Authorization: Basic YWRtaW46YWRtaW4=
> User-Agent: curl/7.29.0
> Host: localhost:6080
> Accept: */*
> Content-Type: application/json
> Content-Length: 4718
> Expect: 100-continue
>
< HTTP/1.1 100 Continue
< HTTP/1.1 404 Not Found
< Server: Apache-Coyote/1.1
< Set-Cookie: RANGERADMINSESSIONID=2CE00A4CA61EADCB0B491282E81608DE; Path=/; HttpOnly
< X-Frame-Options: DENY
< Content-Length: 0
< Date: Mon, 03 Apr 2017 12:45:17 GMT
< Connection: close
<
* Closing connection 0

--
Sean Roberts
Partner Engineering, EMEA
@seano


Re: Import policies via API

Posted by Ayub Khan Pathan <ap...@hortonworks.com>.
Hi Sean,

Can you try the exact below cmd?

curl -v -X POST -u "admin:admin" \
-H "Content-Type: multipart/form-data" \
-H "Content-Type: application/json" \
-F 'file=@Ranger_Policies_20170403_131421.json' \
http://ctr-e129-1487033772569-66527-01-000002.hwx.site:6080/service/plugins/policies/importPoliciesFromFile?isOverride=true&serviceType=hive


*   Trying 172.27.23.199...
* Connected to ctr-e129-1487033772569-66527-01-000002.hwx.site (172.27.23.199) port 6080 (#0)
* Server auth using Basic with user 'admin'
> POST /service/plugins/policies/importPoliciesFromFile?isOverride=true&serviceType=hive HTTP/1.1
> Host: ctr-e129-1487033772569-66527-01-000002.hwx.site:6080
> Authorization: Basic YWRtaW46YWRtaW4=
> User-Agent: curl/7.43.0
> Accept: */*
> Content-Length: 20050
> Expect: 100-continue
> Content-Type: multipart/form-data; boundary=------------------------054d9e8c1762dcd0
>
< HTTP/1.1 100 Continue
< HTTP/1.1 204 No Content
< Server: Apache-Coyote/1.1
< Set-Cookie: RANGERADMINSESSIONID=A063D293277437D074EFD2435967EF88; Path=/; HttpOnly
< WWW-Authenticate: Negotiate
< Set-Cookie: hadoop.auth=; Path=/; Domain=ctr-e129-1487033772569-66527-01-000002.hwx.site; Expires=Thu, 01-Jan-1970 00:00:00 GMT; HttpOnly
< X-Frame-Options: DENY
< Content-Type: application/json
< Date: Mon, 03 Apr 2017 13:15:53 GMT
<
* Connection #0 to host ctr-e129-1487033772569-66527-01-000002.hwx.site left intact

Regards
Ayub Khan

From: Sean Roberts <sr...@hortonworks.com>
Reply-To: "user@ranger.apache.org" <us...@ranger.apache.org>
Date: Monday, April 3, 2017 at 6:16 PM
To: "user@ranger.apache.org" <us...@ranger.apache.org>
Subject: Import policies via API

Ranger folks – Can you provide advice on importing policies via the API.

I imported via UI and am trying to replicate the actions via curl but it is not accepting it. The json is an export (attached)

curl –v -u admin:admin \
  -H Content-Type: application/json -X POST –d @ranger-policies.json \
  "http://localhost:6080/service/plugins/policies/importPoliciesFromFile?isOverride=true&serviceType=hdfs,hive"

* About to connect() to localhost port 6080 (#0)
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 6080 (#0)
* Server auth using Basic with user 'admin'
> POST /service/plugins/policies/importPoliciesFromFile?isOverride=true&serviceType=hdfs,hive HTTP/1.1
> Authorization: Basic YWRtaW46YWRtaW4=
> User-Agent: curl/7.29.0
> Host: localhost:6080
> Accept: */*
> Content-Type: application/json
> Content-Length: 4718
> Expect: 100-continue
>
< HTTP/1.1 100 Continue
< HTTP/1.1 404 Not Found
< Server: Apache-Coyote/1.1
< Set-Cookie: RANGERADMINSESSIONID=2CE00A4CA61EADCB0B491282E81608DE; Path=/; HttpOnly
< X-Frame-Options: DENY
< Content-Length: 0
< Date: Mon, 03 Apr 2017 12:45:17 GMT
< Connection: close
<
* Closing connection 0

--
Sean Roberts
Partner Engineering, EMEA
@seano


Re: Import policies via API

Posted by Bhavik Patel <bh...@gmail.com>.
Hi Robert,

Seems like you are hitting wrong curl command.

To import policies you have to pass data-file with "-F" and in header set
content type as multipart/form-data.
correct curl: curl -i -X POST -H "Content-Type: multipart/form-data" -F
'file=@/filePath/ranger-polices.json' -u admin:admin "
http://localhost:6080/service/plugins/policies/importPoliciesFromFile?isOverride=true
&serviceType=hdfs,hive"



Regard,
Bhavik Patel
+91-7208744109

On Mon, Apr 3, 2017 at 6:16 PM, Sean Roberts <sr...@hortonworks.com>
wrote:

> Ranger folks – Can you provide advice on importing policies via the API.
>
>
>
> I imported via UI and am trying to replicate the actions via curl but it
> is not accepting it. The json is an export (attached)
>
>
>
> curl –v -u admin:admin \
>
>   -H Content-Type: application/json -X POST –d @ranger-policies.json \
>
>   "http://localhost:6080/service/plugins/policies/importPoliciesFromFile?
> isOverride=true&serviceType=hdfs,hive"
>
>
>
> * About to connect() to localhost port 6080 (#0)
>
> *   Trying 127.0.0.1...
>
> * Connected to localhost (127.0.0.1) port 6080 (#0)
>
> * Server auth using Basic with user 'admin'
>
> > POST /service/plugins/policies/importPoliciesFromFile?
> isOverride=true&serviceType=hdfs,hive HTTP/1.1
>
> > Authorization: Basic YWRtaW46YWRtaW4=
>
> > User-Agent: curl/7.29.0
>
> > Host: localhost:6080
>
> > Accept: */*
>
> > Content-Type: application/json
>
> > Content-Length: 4718
>
> > Expect: 100-continue
>
> >
>
> < HTTP/1.1 100 Continue
>
> < HTTP/1.1 404 Not Found
>
> < Server: Apache-Coyote/1.1
>
> < Set-Cookie: RANGERADMINSESSIONID=2CE00A4CA61EADCB0B491282E81608DE;
> Path=/; HttpOnly
>
> < X-Frame-Options: DENY
>
> < Content-Length: 0
>
> < Date: Mon, 03 Apr 2017 12:45:17 GMT
>
> < Connection: close
>
> <
>
> * Closing connection 0
>
>
>
> --
>
> Sean Roberts
>
> Partner Engineering, EMEA
>
> @seano
>
>
>