You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@hawq.apache.org by linwen <gi...@git.apache.org> on 2016/12/16 03:41:25 UTC

[GitHub] incubator-hawq pull request #1052: HAWQ-1004. Implement calling Ranger REST ...

GitHub user linwen opened a pull request:

    https://github.com/apache/incubator-hawq/pull/1052

    HAWQ-1004. Implement calling Ranger REST Service using libcurl for pr\u2026

    Please review, thanks! 

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/linwen/incubator-hawq hawq_1004

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/incubator-hawq/pull/1052.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #1052
    
----
commit 6589f1cdc6ebc4b7f7245fa076c28ec55daf3383
Author: Wen Lin <wl...@pivotal.io>
Date:   2016-12-16T03:35:33Z

    HAWQ-1004. Implement calling Ranger REST Service using libcurl for privilege check.

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-hawq issue #1052: HAWQ-1004. Implement calling Ranger REST Service...

Posted by stanlyxiang <gi...@git.apache.org>.
Github user stanlyxiang commented on the issue:

    https://github.com/apache/incubator-hawq/pull/1052
  
    +1 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-hawq pull request #1052: HAWQ-1004. Implement calling Ranger REST ...

Posted by linwen <gi...@git.apache.org>.
Github user linwen commented on a diff in the pull request:

    https://github.com/apache/incubator-hawq/pull/1052#discussion_r93160802
  
    --- Diff: src/backend/libpq/rangerrest.c ---
    @@ -0,0 +1,551 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *   http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing,
    + * software distributed under the License is distributed on an
    + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    + * KIND, either express or implied.  See the License for the
    + * specific language governing permissions and limitations
    + * under the License.
    + */
    +
    +/*-------------------------------------------------------------------------
    + *
    + * rangerrest.c
    + *	routines to interact with Ranger REST API
    + *
    + *-------------------------------------------------------------------------
    + */
    +#include "postgres.h"
    +
    +#include <json-c/json.h>
    +
    +#include "utils/acl.h"
    +#include "utils/guc.h"
    +#include "utils/rangerrest.h"
    +
    +/*
    + * Internal buffer for libcurl context
    + */
    +typedef struct curl_context_t
    +{
    +    CURL* curl_handle;
    +
    +    char curl_error_buffer[CURL_ERROR_SIZE];
    +
    +    int curl_still_running;
    +
    +    struct
    +    {
    +        char* buffer;
    +        int size;
    +    } response;
    +
    +    char* last_http_reponse;
    +} curl_context_t;
    +typedef curl_context_t* CURL_HANDLE;
    +
    +RangerACLResult parse_ranger_response(char* buffer)
    +{
    +    Assert(buffer != NULL);
    +    if (strlen(buffer) == 0)
    +        return RANGERCHECK_UNKNOWN;
    +
    +    elog(LOG, "read from Ranger Restful API: %s", buffer);
    +
    +    struct json_object *response = json_tokener_parse(buffer);
    +    struct json_object *accessObj = json_object_object_get(response, "access");
    +
    +    int arraylen = json_object_array_length(accessObj);
    +    elog(LOG, "Array Length: %dn",arraylen);
    +
    +    json_object * jvalue;
    +    json_object * jallow;
    +    json_bool result;
    +    // here should return which table's acl check failed in future.
    +    for (int i=0; i< arraylen; i++){
    +      jvalue = json_object_array_get_idx(accessObj, i);
    +      jallow = json_object_object_get(jvalue, "allowed");
    +      result = json_object_get_boolean(jallow);
    +      if(result != 1){
    +        return RANGERCHECK_NO_PRIV;
    +      }
    +    }
    +    return RANGERCHECK_OK;
    +
    +}
    +
    +/*
    + * A mapping from AclObjectKind to string
    + */
    +char* AclObjectKindStr[] =
    +{
    +    "table",             /* pg_class */
    +    "sequence",          /* pg_sequence */
    +    "database",          /* pg_database */
    +    "function",          /* pg_proc */
    +    "operator",          /* pg_operator */
    +    "type",              /* pg_type */
    +    "language",          /* pg_language */
    +    "namespace",         /* pg_namespace */
    +    "oplass",            /* pg_opclass */
    +    "conversion",        /* pg_conversion */
    +    "tablespace",        /* pg_tablespace */
    +    "filespace",         /* pg_filespace */
    +    "filesystem",        /* pg_filesystem */
    +    "fdw",               /* pg_foreign_data_wrapper */
    +    "foreign_server",    /* pg_foreign_server */
    +    "protocol",          /* pg_extprotocol */
    +    "none"               /* MUST BE LAST */
    +};
    +
    +/*
    + * args: List of RangerRequestJsonArgs
    + */
    +json_object *create_ranger_request_json_batch(List *args)
    +{
    +  json_object *juser = NULL;
    +  json_object *jaccess = json_object_new_array();
    +  json_object *jrequest = json_object_new_object();
    +  char *user = NULL;
    +  ListCell *arg;
    +  
    +  foreach(arg, args)
    +  {
    +    RangerRequestJsonArgs *arg_ptr = (RangerRequestJsonArgs *) lfirst(arg);
    +    if (user == NULL)
    +    {
    +      user = arg_ptr->user;
    +      juser = json_object_new_string(user);
    +    }
    +    AclObjectKind kind = arg_ptr->kind;
    +    char* object = arg_ptr->object;
    +    char* how = arg_ptr->how;
    --- End diff --
    
    Yes. We just leave it there, will modify it later. 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-hawq pull request #1052: HAWQ-1004. Implement calling Ranger REST ...

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/incubator-hawq/pull/1052


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-hawq issue #1052: HAWQ-1004. Implement calling Ranger REST Service...

Posted by zhangh43 <gi...@git.apache.org>.
Github user zhangh43 commented on the issue:

    https://github.com/apache/incubator-hawq/pull/1052
  
    +1


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-hawq pull request #1052: HAWQ-1004. Implement calling Ranger REST ...

Posted by denalex <gi...@git.apache.org>.
Github user denalex commented on a diff in the pull request:

    https://github.com/apache/incubator-hawq/pull/1052#discussion_r92857693
  
    --- Diff: src/backend/libpq/rangerrest.c ---
    @@ -0,0 +1,551 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *   http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing,
    + * software distributed under the License is distributed on an
    + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    + * KIND, either express or implied.  See the License for the
    + * specific language governing permissions and limitations
    + * under the License.
    + */
    +
    +/*-------------------------------------------------------------------------
    + *
    + * rangerrest.c
    + *	routines to interact with Ranger REST API
    + *
    + *-------------------------------------------------------------------------
    + */
    +#include "postgres.h"
    +
    +#include <json-c/json.h>
    +
    +#include "utils/acl.h"
    +#include "utils/guc.h"
    +#include "utils/rangerrest.h"
    +
    +/*
    + * Internal buffer for libcurl context
    + */
    +typedef struct curl_context_t
    +{
    +    CURL* curl_handle;
    +
    +    char curl_error_buffer[CURL_ERROR_SIZE];
    +
    +    int curl_still_running;
    +
    +    struct
    +    {
    +        char* buffer;
    +        int size;
    +    } response;
    +
    +    char* last_http_reponse;
    +} curl_context_t;
    +typedef curl_context_t* CURL_HANDLE;
    +
    +RangerACLResult parse_ranger_response(char* buffer)
    +{
    +    Assert(buffer != NULL);
    +    if (strlen(buffer) == 0)
    +        return RANGERCHECK_UNKNOWN;
    +
    +    elog(LOG, "read from Ranger Restful API: %s", buffer);
    +
    +    struct json_object *response = json_tokener_parse(buffer);
    +    struct json_object *accessObj = json_object_object_get(response, "access");
    +
    +    int arraylen = json_object_array_length(accessObj);
    +    elog(LOG, "Array Length: %dn",arraylen);
    +
    +    json_object * jvalue;
    +    json_object * jallow;
    +    json_bool result;
    +    // here should return which table's acl check failed in future.
    +    for (int i=0; i< arraylen; i++){
    +      jvalue = json_object_array_get_idx(accessObj, i);
    +      jallow = json_object_object_get(jvalue, "allowed");
    +      result = json_object_get_boolean(jallow);
    +      if(result != 1){
    +        return RANGERCHECK_NO_PRIV;
    +      }
    +    }
    +    return RANGERCHECK_OK;
    +
    +}
    +
    +/*
    + * A mapping from AclObjectKind to string
    + */
    +char* AclObjectKindStr[] =
    +{
    +    "table",             /* pg_class */
    +    "sequence",          /* pg_sequence */
    +    "database",          /* pg_database */
    +    "function",          /* pg_proc */
    +    "operator",          /* pg_operator */
    +    "type",              /* pg_type */
    +    "language",          /* pg_language */
    +    "namespace",         /* pg_namespace */
    +    "oplass",            /* pg_opclass */
    +    "conversion",        /* pg_conversion */
    +    "tablespace",        /* pg_tablespace */
    +    "filespace",         /* pg_filespace */
    +    "filesystem",        /* pg_filesystem */
    +    "fdw",               /* pg_foreign_data_wrapper */
    +    "foreign_server",    /* pg_foreign_server */
    +    "protocol",          /* pg_extprotocol */
    +    "none"               /* MUST BE LAST */
    +};
    +
    +/*
    + * args: List of RangerRequestJsonArgs
    + */
    +json_object *create_ranger_request_json_batch(List *args)
    +{
    +  json_object *juser = NULL;
    +  json_object *jaccess = json_object_new_array();
    +  json_object *jrequest = json_object_new_object();
    +  char *user = NULL;
    +  ListCell *arg;
    +  
    +  foreach(arg, args)
    +  {
    +    RangerRequestJsonArgs *arg_ptr = (RangerRequestJsonArgs *) lfirst(arg);
    +    if (user == NULL)
    +    {
    +      user = arg_ptr->user;
    +      juser = json_object_new_string(user);
    +    }
    +    AclObjectKind kind = arg_ptr->kind;
    +    char* object = arg_ptr->object;
    +    char* how = arg_ptr->how;
    --- End diff --
    
    we are not supporting "how" in RPS


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---