Skip to main content

Privacera Documentation

Add Tags with Ranger REST API

Prerequisite: Make sure the repo is created on Ranger for tags and Hive has the same tag service selected.

To add a tag using Rest API in Ranger, use the following steps:

  1. Create privacera_tags in the Ranger Tag Based Policy.

  2. Associate the privacera_tags to Hive service.

    vi atlas_tag_test.json
    
  3. Edit the JSON file shown below based on your specific table/tag information.

        {
          "op": "add_or_update",
          "serviceName": "dublin_hive",
          "tagVersion": 0,
          "tagDefinitions": {
            "0": {
              "name": "TEST_TAG",
              "source": "Atlas",
              "attributeDefs": [],
              "id": 0,
              "isEnabled": true
            }
          },
          "tags": {
            "0": {
              "type": "TEST_TAG",
              "owner": 0,
              "attributes": {},
              "id": 0,
              "isEnabled": true
            }
          },
          "serviceResources": [
            {
              "serviceName": "dublin_hive",
              "resourceElements": {
                "database": {
                  "values": [
                    "db_name"
                  ],
                  "isExcludes": false,
                  "isRecursive": false
                },
                "column": {
                  "values": [
                    "column_name"
                  ],
                  "isExcludes": false,
                  "isRecursive": false
                },
                "table": {
                  "values": [
                    "table_name"
                  ],
                  "isExcludes": false,
                  "isRecursive": false
                }
              },
              "id": 0,
              "isEnabled": true
            }
          ],
          "resourceToTagIds": {
            "0": [
              0
            ]
          }
        }
                

Update the following variables

  • serviceName

  • tagDefinitions[‘0’].name

  • tags[‘0’].type

  • serviceResources[0].serviceName

  • serviceResources[0].resourceElements[‘database’].values[0]

  • serviceResources[0].resourceElements[‘column’].values[0]

  • serviceResources[0].resourceElements[‘table’].values[0]

    curl -i -L -k -u admin:${RANGER_ADMIN_PASSWORD} \
    -H "Content-type: application/json" \
    -d @atlas_tag_test.json \
    -X PUT http://<RANGER_HOST>:6080/service/tags/importservicetags
    
  • Wait for a couple of minutes and run the following:

    select * from <database_name>.<table_name>