# KBAC: Can this person act on that resource? Relationship-based authorization with the AuthZEN API

> Create a Knowledge-Based Access Control (KBAC) policy and execute authZEN-compliant authorization queries. This example demonstrates evaluation (can X do Y to Z?) and search operations (who can? what can? which resources?).

**Category:** KBAC  
**API:** KBAC  
**Tags:** KBAC Policy, authZEN, Authorization, Evaluation, Action Search, Resource Search, Subject Search, Access Control
**Last Updated:** 2026-07-14
**OpenAPI Endpoints:** /capture/v1/nodes, /capture/v1/relationships, /configs/v1/authorization-policies, /access/v1/evaluation, /access/v1/search/action, /access/v1/search/resource, /access/v1/search/subject
**Related Guides:** /guides/guide-authzen, /guides/guide-dynamic-authz, /guides/guide-sandbox

## Summary

This example demonstrates KBAC (Knowledge-Based Access Control) using the authZEN standard API:

Policy logic: A Person can perform CAN_DRIVE on a Car if they have a DRIVES relationship to that Car in the graph.

authZEN operations demonstrated:
1. Evaluation: "Can knightrider drive kitt?" -> true; "Can knightrider drive cadillacv16?" -> false
2. Action Search: "What actions can knightrider perform on kitt?" -> ["CAN_DRIVE"]
3. Resource Search: "Which cars can knightrider drive?" -> ["kitt"]
4. Subject Search: "Who can drive kitt?" -> ["knightrider"]

authZEN is an OpenID standard for authorization APIs (https://openid.net/specs/authorization-api-1_0-03.html).

Policy version note: the policy in this example uses "policy_version": "2.0-kbac". The same policy JSON is also accepted with "policy_version": "3.0-kbac" (identical schema, raw-Cypher semantics; do not reference $subject_id or external properties). Only 3.0-kbac additionally accepts USE graph.byName() routing and CALL { } subqueries for composite / data-residency IKGs - see resources authz-7 and authz-8.

## Use Case

Scenario: A car-sharing application needs to verify driving permissions.

Graph structure (the shared AuthZEN dataset):
- Person(knightrider) -[DRIVES]-> Car(kitt)
- Person(satchmo) -[DRIVES]-> Car(cadillacv16)
- Person(alice) -[DRIVES]-> Car(cadillacv16)
- Person(karel) -[HAS]-> Ticket(listek) -[FOR]-> Bus(harmonika)

Authorization questions the app can ask:
1. "Can knightrider drive kitt?" -> true (DRIVES relationship exists)
2. "Can knightrider drive cadillacv16?" -> false (no DRIVES relationship)
3. "What can knightrider do with kitt?" -> ["CAN_DRIVE"]
4. "Which cars can knightrider drive?" -> ["kitt"]
5. "Who can drive kitt?" -> ["knightrider"]

Use this pattern for: vehicle access, device permissions, resource sharing, any permission that follows from a relationship in the graph.

## Requirements

Prerequisites:
- ServiceAccount credentials: For creating policies (Bearer token)
- AppAgent credentials: For data ingestion and authorization queries (X-IK-ClientKey)

Required API access:
- POST /capture/v1/nodes/ and /capture/v1/relationships/ (graph data)
- POST /configs/v1/authorization-policies (create policy)
- POST /access/v1/evaluation (single authorization check)
- POST /access/v1/search/action (what actions are permitted?)
- POST /access/v1/search/resource (which resources can be accessed?)
- POST /access/v1/search/subject (who can access this resource?)

## Steps

Step 1: Ingest Authorization Graph Data
- Authentication: AppAgent credential (X-IK-ClientKey header)
- Action: POST Person (alice, knightrider, satchmo, karel), Car (kitt, cadillacv16), Bus, Ticket and Laptop nodes, then the DRIVES, OWNS, HAS and FOR relationships
- Result: Graph ready for authorization queries

Step 2: Create KBAC Policy
- Authentication: ServiceAccount credential (Bearer token)
- Action: POST a 2.0-kbac policy: subject type Person, action CAN_DRIVE, resource type Car, cypher MATCH (subject:Person)-[:DRIVES]->(resource:Car)
- Result: Policy ID returned

Step 3: Run authZEN Evaluation
- Authentication: AppAgent credential (X-IK-ClientKey header)
- Action: POST to /access/v1/evaluation with subject, action, resource
- Input: subject Person knightrider, action CAN_DRIVE, resource Car kitt -> {"decision": true}; resource Car cadillacv16 -> {"decision": false}

Step 4: Run authZEN Searches
- Authentication: AppAgent credential (X-IK-ClientKey header)
- Action Search (subject knightrider, resource kitt): {"results": [{"name": "CAN_DRIVE"}]}
- Resource Search (subject knightrider, action CAN_DRIVE, resource type Car): {"results": [{"type": "Car", "id": "kitt"}]}
- Subject Search (subject type Person, action CAN_DRIVE, resource kitt): {"results": [{"type": "Person", "id": "knightrider"}]}

Step 5: Cleanup
- Action: DELETE policy configuration

## Graph

The graph the example runs on: 9 nodes (4 Person, 2 Car, 1 Bus, 1 Ticket, 1 Laptop) and 8 relationships (DRIVES, HAS, FOR, OWNS). Hover a node for its properties, click it to highlight its neighbourhood.

- Person `alice` (identity): email=alice@email.com, given_name=Alice, last_name=Smith
- Person `knightrider` (identity): email=knightrider@demo.com, name=Michael Knight
- Person `satchmo` (identity): email=satchmo@demo.com, name=Louis Armstrong
- Person `karel` (identity): email=karel@demo.com, name=Karel Plihal
- Car `kitt`: manufacturer=pontiac, model=Firebird
- Car `cadillacv16`: manufacturer=Cadillac, model=V-16
- Bus `harmonika`: manufacturer=Ikarus, model=280
- Ticket `listek`
- Laptop `airbook-xyz`
- `knightrider` -[DRIVES]-> `kitt`
- `satchmo` -[DRIVES]-> `cadillacv16`
- `karel` -[HAS]-> `listek`
- `listek` -[FOR]-> `harmonika`
- `karel` -[OWNS]-> `airbook-xyz`
- `alice` -[OWNS]-> `airbook-xyz`
- `knightrider` -[OWNS]-> `kitt`
- `alice` -[DRIVES]-> `cadillacv16`

## Code Examples

### Step 1

Capture the nodes needed for this use case.

**POST https://eu.api.indykite.com/capture/v1/nodes/**

```json
{
  "nodes": [
    {
      "external_id": "alice",
      "is_identity": true,
      "type": "Person",
      "properties": [
        {
          "type": "email",
          "value": "alice@email.com"
        },
        {
          "type": "given_name",
          "value": "Alice"
        },
        {
          "type": "last_name",
          "value": "Smith"
        }
      ]
    },
    {
      "external_id": "knightrider",
      "type": "Person",
      "is_identity": true,
      "properties": [
        {
          "type": "email",
          "value": "knightrider@demo.com"
        },
        {
          "type": "name",
          "value": "Michael Knight"
        }
      ]
    },
    {
      "external_id": "satchmo",
      "type": "Person",
      "is_identity": true,
      "properties": [
        {
          "type": "email",
          "value": "satchmo@demo.com"
        },
        {
          "type": "name",
          "value": "Louis Armstrong"
        }
      ]
    },
    {
      "external_id": "karel",
      "type": "Person",
      "is_identity": true,
      "properties": [
        {
          "type": "email",
          "value": "karel@demo.com"
        },
        {
          "type": "name",
          "value": "Karel Plihal"
        }
      ]
    },
    {
      "external_id": "kitt",
      "type": "Car",
      "is_identity": false,
      "properties": [
        {
          "type": "manufacturer",
          "value": "pontiac"
        },
        {
          "type": "model",
          "value": "Firebird"
        }
      ]
    },
    {
      "external_id": "cadillacv16",
      "type": "Car",
      "is_identity": false,
      "properties": [
        {
          "type": "manufacturer",
          "value": "Cadillac"
        },
        {
          "type": "model",
          "value": "V-16"
        }
      ]
    },
    {
      "external_id": "harmonika",
      "type": "Bus",
      "is_identity": false,
      "properties": [
        {
          "type": "manufacturer",
          "value": "Ikarus"
        },
        {
          "type": "model",
          "value": "280"
        }
      ]
    },
    {
      "external_id": "listek",
      "type": "Ticket",
      "is_identity": false
    },
    {
      "external_id": "airbook-xyz",
      "type": "Laptop",
      "is_identity": false
    }
  ]
}
```


Capture the relationships needed for this use case.

**POST https://eu.api.indykite.com/capture/v1/relationships/**

```json
{
  "relationships": [
    {
      "source": {
        "external_id": "knightrider",
        "type": "Person"
      },
      "target": {
        "external_id": "kitt",
        "type": "Car"
      },
      "type": "DRIVES"
    },
    {
      "source": {
        "external_id": "satchmo",
        "type": "Person"
      },
      "target": {
        "external_id": "cadillacv16",
        "type": "Car"
      },
      "type": "DRIVES"
    },
    {
      "source": {
        "external_id": "karel",
        "type": "Person"
      },
      "target": {
        "external_id": "listek",
        "type": "Ticket"
      },
      "type": "HAS"
    },
    {
      "source": {
        "external_id": "listek",
        "type": "Ticket"
      },
      "target": {
        "external_id": "harmonika",
        "type": "Bus"
      },
      "type": "FOR"
    },
    {
      "source": {
        "external_id": "karel",
        "type": "Person"
      },
      "target": {
        "external_id": "airbook-xyz",
        "type": "Laptop"
      },
      "type": "OWNS"
    },
    {
      "source": {
        "external_id": "alice",
        "type": "Person"
      },
      "target": {
        "external_id": "airbook-xyz",
        "type": "Laptop"
      },
      "type": "OWNS"
    },
    {
      "source": {
        "external_id": "knightrider",
        "type": "Person"
      },
      "target": {
        "external_id": "kitt",
        "type": "Car"
      },
      "type": "OWNS"
    },
    {
      "source": {
        "external_id": "alice",
        "type": "Person"
      },
      "target": {
        "external_id": "cadillacv16",
        "type": "Car"
      },
      "type": "DRIVES"
    }
  ]
}
```

### Step 2

KBAC Policy which rules that a Person node can drive a car if the Person node has a relation DRIVES with a Car node.

**policy.json**

```json
{
  "meta": {
    "policy_version": "2.0-kbac"
  },
  "subject": {
    "type": "Person"
  },
  "actions": [
    "CAN_DRIVE"
  ],
  "resource": {
    "type": "Car"
  },
  "condition": {
    "cypher": "MATCH (subject:Person)-[:DRIVES]->(resource:Car)"
  }
}
```


Request to create the KBAC Policy configuration using REST.

**POST https://eu.api.indykite.com/configs/v1/authorization-policies**

```json
{
  "project_id": "your_project_gid",
  "description": "description of policy",
  "display_name": "policy name",
  "name": "policy-name",
  "policy": "{\"meta\":{\"policy_version\":\"2.0-kbac\"},\"subject\":{\"type\":\"Person\"},\"actions\":[\"CAN_DRIVE\"],\"resource\":{\"type\":\"Car\"},\"condition\":{\"cypher\":\"MATCH (subject:Person)-[:DRIVES]->(resource:Car)\"}}",
  "status": "ACTIVE",
  "tags": []
}
```


Request to create the KBAC Policy configuration using Python.

**policy_request.py**

```python

import http.client

conn = http.client.HTTPSConnection("eu.api.indykite.com")

payload = "{"description": "",
  "display_name": "",
  "name": "",
  "policy": "",
  "project_id": "",
  "status": "ACTIVE",
  "tags": [
    ""
  ]}"
headers = {
    'Content-Type': "application/json",
    'Authorization': "YOUR_SECRET_TOKEN"
}

conn.request("POST", "/configs/v1/authorization-policies", payload, headers)
res = conn.getresponse()
data = res.read()

```


Request to read the KBAC Policy configuration using REST.

**GET https://eu.api.indykite.com/configs/v1/authorization-policies/{id}**

```json
{
  "id": "your_policy_configuration_gid"
}
```


Request to read the KBAC Policy configuration using Python.

**policy_request.py**

```python

import http.client

conn = http.client.HTTPSConnection("eu.api.indykite.com")
headers = { 'Authorization': "YOUR_SECRET_TOKEN" }
conn.request("GET", "/configs/v1/authorization-policies/{{id}}", headers=headers)
res = conn.getresponse()
data = res.read()

```

### Step 3

Request to run a KBAC authZEN Evaluation - authorized.

**POST https://eu.api.indykite.com/access/v1/evaluation**

```json
{
  "subject": {
    "type": "Person",
    "id": "knightrider"
  },
  "resource": {
    "type": "Car",
    "id": "kitt"
  },
  "action": {
    "name": "CAN_DRIVE"
  }
}
```


Response to the KBAC authZEN Evaluation - authorized.

**Response 200**

```json
{
  "decision": true
}
```


Request to run a KBAC authZEN Evaluation - authorized.

**evaluation.py**

```python

import http.client

conn = http.client.HTTPSConnection("eu.api.indykite.com")

payload = "{
  	"subject": {"type": "Person",
        "id": "knightrider"}, 
    "resource": {"type": "Car",
        "id": "kitt"},
    "action": {"name": "CAN_DRIVE"}
}"

headers = {
    'Content-Type': "application/json",
    'X-IK-ClientKey': ""
}

conn.request("POST", "/access/v1/evaluation", payload, headers)

res = conn.getresponse()
data = res.read()

```


Request to run a KBAC authZEN Evaluation - not authorized.

**POST https://eu.api.indykite.com/access/v1/evaluation**

```json
{
  "subject": {
    "type": "Person",
    "id": "knightrider"
  },
  "resource": {
    "type": "Car",
    "id": "cadillacv16"
  },
  "action": {
    "name": "CAN_DRIVE"
  }
}
```


Response to the KBAC authZEN Evaluation - not authorized.

**Response 200**

```json
{
  "decision": false
}
```

### Step 4

Request to run a KBAC authZEN Action Search.

**POST https://eu.api.indykite.com/access/v1/search/action**

```json
{
  "subject": {
    "type": "Person",
    "id": "knightrider"
  },
  "resource": {
    "type": "Car",
    "id": "kitt"
  }
}
```


Response to the KBAC authZEN Action Search.

**Response 200**

```json
{
  "results": [
    {
      "name": "CAN_DRIVE"
    }
  ]
}
```


Request to run a KBAC authZEN Action Search using Python.

**action.py**

```python

import http.client

conn = http.client.HTTPSConnection("eu.api.indykite.com")

payload = "{
    "subject": {"type": "Person",
        "id": "knightrider"}, 
    "resource": {"type": "Car",
        "id": "kitt"}
}"

headers = {
    'Content-Type': "application/json",
    'X-IK-ClientKey': ""
}

conn.request("POST", "/access/v1/search/action", payload, headers)

res = conn.getresponse()
data = res.read()

```


Request to run a KBAC authZEN Resource Search.

**POST https://eu.api.indykite.com/access/v1/search/resource**

```json
{
  "subject": {
    "type": "Person",
    "id": "knightrider"
  },
  "resource": {
    "type": "Car"
  },
  "action": {
    "name": "CAN_DRIVE"
  }
}
```


Response to the KBAC authZEN Resource Search.

**Response 200**

```json
{
  "results": [
    {
      "type": "Car",
      "id": "kitt"
    }
  ]
}
```


Request to run a KBAC authZEN Resource Search using Python.

**resource.py**

```python

import http.client

conn = http.client.HTTPSConnection("eu.api.indykite.com")

payload = "{
    "subject": {"type": "Person",
        "id": "knightrider"},
    "resource": {"type": "Car"},
    "action": {"name": "CAN_DRIVE"}
}"

headers = {
    'Content-Type': "application/json",
    'X-IK-ClientKey': ""
}

conn.request("POST", "/access/v1/search/resource", payload, headers)

res = conn.getresponse()
data = res.read()

```


Request to run a KBAC authZEN Subject Search.

**POST https://eu.api.indykite.com/access/v1/search/subject**

```json
{
  "subject": {
    "type": "Person"
  },
  "resource": {
    "type": "Car",
    "id": "kitt"
  },
  "action": {
    "name": "CAN_DRIVE"
  }
}
```


Response to the KBAC authZEN Subject Search.

**Response 200**

```json
{
  "results": [
    {
      "type": "Person",
      "id": "knightrider"
    }
  ]
}
```


Request to run a KBAC authZEN Subject Search using Python.

**subject.py**

```python

import http.client

conn = http.client.HTTPSConnection("eu.api.indykite.com")

payload = "{
    "subject": {"type": "Person"},
    "resource": {"type": "Car",
        "id": "kitt"},
    "action": {"name": "CAN_DRIVE"}
}"

headers = {
    'Content-Type': "application/json",
    'X-IK-ClientKey': ""
}

conn.request("POST", "/access/v1/search/subject", payload, headers)

res = conn.getresponse()
data = res.read()

```

### Step 5

Delete the KBAC Policy.

**DELETE https://eu.api.indykite.com/configs/v1/authorization-policies/{id}**

```json
{
  "id": "your_policy_configuration_gid"
}
```


Request to delete the KBAC Policy.

**del.py**

```python

import http.client

conn = http.client.HTTPSConnection("eu.api.indykite.com")

headers = { 'Authorization': "Bearer ...", 'Content-Type': "application/json" }

conn.request("DELETE", "/configs/v1/authorization-policies/{id}", headers=headers)

res = conn.getresponse()
data = res.read()

```

## Common Errors

### 401: UNAUTHENTICATED

**Solution:** Check X-IK-ClientKey header contains valid AppAgent credentials

### 404: NOT_FOUND

**Solution:** Verify the policy exists and the subject/resource nodes exist in the IKG

---

Source: https://developer.indykite.com/resources/authz-1