API version: 0.3.0

---

# Access model

```json graph-example
[
  {"id":"user","type":"User","data":{"name":"User"}},
  {"id":"group","type":"Group","data":{"name":"Group"}},
  {"id":"data1","type":"Data","data":{"name":"Data 1"}},
  {"id":"data2","type":"Data","data":{"name":"Data 2"}},
  {"id":"isInGroup","type":"IS_IN_GROUP","start":"user","end":"group"},
  {"id":"owns","type":"OWNS","start":"group","end":"data1"},
  {"id":"hasReadAccess","type":"HAS_READ_ACCESS","start":"group","end":"data2"}
]
```

Ember Nexus uses a **graph based access model** with optional attributes for more nuanced access.
This means that individual users are not assigned a global role, but instead receive **explicit ownership or access to
specific elements**.

These permissions are **applied recursively**, i.e. if you own some element, then you also own all the element's
children:

```json graph-example
[
  {"id":"user","type":"User","data":{"name":"User"}},
  {"id":"data1","type":"Data","data":{"name":"Data 1"}},
  {"id":"data2","type":"Data","data":{"name":"Data 2"}},
  {"id":"data3","type":"Data","data":{"name":"Data 3"}},
  {"id":"owns1","type":"OWNS","start":"user","end":"data1"},
  {"id":"owns2","type":"OWNS","start":"data1","end":"data2"},
  {"id":"owns3","type":"OWNS","start":"data2","end":"data3"}
]
```

As ownership and access data are stored inside the same graph as relations, the access model is explicit, can be queried
separately, and becomes a natural part of your data.

Access is split between individual access operations (read, create, update, delete and search) for quite granular
permissions, as well as "ownership" (OWNS), which grants the owner full access.

The details are split into several pages:

- [Access to nodes and relations](/reference/access-model/access-to-elements.md): which access reading, changing and
  deleting nodes and relations needs, and which status code is answered if it is missing.
- [Handing out access](/reference/access-model/handing-out-access.md): pointer relations and grant relations, who may
  share an element or add users to a group, with a verified table of cases.
- [Conditional access](/reference/access-model/conditional-access.md): limiting access by label, parent label, state or
  creator.
- [Transfer of ownership](/reference/access-model/transfer-of-ownership.md) and the
  [anonymous user](/reference/access-model/anonymous-user.md).

### How access is determined

For a user being able to interact with some element at all, an access path between the user and element must exist.\
If no path can be found, or the element to be accessed is completely isolated, then the API responds to the user as if
the element does not exist (404 error codes etc.):

```json graph-example
[
  {"id":"user","type":"User","data":{"name":"User"}},
  {"id":"data","type":"Data","data":{"name":"Data"}}
]
```

Within a single specific path, the lowest overall access wins, e.g. in the following example `HAS_READ_ACCESS` is the
lowest common access permission across the path, therefore the user only has read access:

```json graph-example
[
  {"id":"user","type":"User","data":{"name":"User"}},
  {"id":"data1","type":"Data","data":{"name":"Data 1"}},
  {"id":"data2","type":"Data","data":{"name":"Data 2"}},
  {"id":"hasReadAccess","type":"HAS_READ_ACCESS","start":"user","end":"data1"},
  {"id":"owns","type":"OWNS","start":"data1","end":"data2"}
]
```

When multiple parallel paths exist, the path with the highest access wins. In the following example, a full `OWNS`-path
exists, therefore lower access operations are ignored:

```json graph-example
[
  {"id":"user","type":"User","data":{"name":"User"}},
  {"id":"data1","type":"Data","data":{"name":"Data 1"}},
  {"id":"data2","type":"Data","data":{"name":"Data 2"}},
  {"id":"hasReadAccess","type":"HAS_READ_ACCESS","start":"user","end":"data1"},
  {"id":"owns1","type":"OWNS","start":"user","end":"data1"},
  {"id":"owns2","type":"OWNS","start":"data1","end":"data2"}
]
```

### Groups for delegating access

Instead of giving many users direct access to some element, a group can be used to delegate access.

This will look then like this:

```json graph-example
[
  {"id":"user1","type":"User","data":{"name":"User 1"}},
  {"id":"user2","type":"User","data":{"name":"User 2"}},
  {"id":"group","type":"Group","data":{"name":"Group"}},
  {"id":"data","type":"Data","data":{"name":"Data"}},
  {"id":"isInGroup1","type":"IS_IN_GROUP","start":"user1","end":"group"},
  {"id":"isInGroup2","type":"IS_IN_GROUP","start":"user2","end":"group"},
  {"id":"owns","type":"OWNS","start":"group","end":"data"}
]
```

To model more complex situations, a group can also be part of another group:

```json graph-example
[
  {"id":"user","type":"User","data":{"name":"User"}},
  {"id":"group1","type":"Group","data":{"name":"Group 1"}},
  {"id":"group2","type":"Group","data":{"name":"Group 2"}},
  {"id":"data","type":"Data","data":{"name":"Data"}},
  {"id":"isInGroup1","type":"IS_IN_GROUP","start":"user","end":"group1"},
  {"id":"isInGroup2","type":"IS_IN_GROUP","start":"group1","end":"group2"},
  {"id":"owns","type":"OWNS","start":"group2","end":"data"}
]
```

Important: For a user to be considered part of a group, there must exist a direct path of solely `IS_IN_GROUP`-relations
between the user and the group. Using `OWNS`- and `HAS_X_ACCESS`-relations between the user and the group has other
semantic meanings, and should be avoided unless explicitly required.

### Writing to group nodes

Being a member of a group (via `IS_IN_GROUP`) grants `READ`, `SEARCH` and `CREATE` access to the group node itself, but
not `UPDATE`, `DELETE` or `GOVERN` access. A group node can only be updated, deleted or shared by a user with an
explicit `OWNS` or `HAS_UPDATE_ACCESS`/`HAS_DELETE_ACCESS`/`HAS_GOVERN_ACCESS` relation to that group node, not by
virtue of membership alone. This does not mean that members can not use access which the group has been given: a
relation from the group to another element counts for every member, whatever the access type.

In the following example, the member can hand out access to `Data` through the group, because the group has been
granted `HAS_GOVERN_ACCESS` and `HAS_READ_ACCESS` to it. The member can not hand out access to the group itself:

```json graph-example
[
  {"id":"member","type":"User","data":{"name":"Member"}},
  {"id":"group","type":"Group","data":{"name":"Group"}},
  {"id":"data","type":"Data","data":{"name":"Data"}},
  {"id":"isInGroup","type":"IS_IN_GROUP","start":"member","end":"group"},
  {"id":"hasGovern","type":"HAS_GOVERN_ACCESS","start":"group","end":"data"},
  {"id":"hasRead","type":"HAS_READ_ACCESS","start":"group","end":"data"}
]
```

### Access operations

The following access operations exist:

- `OWNS`: Full permissions.
- `HAS_READ_ACCESS`: Only grants read permissions to the element. If you want to grant this access operation, you will
  likely want to grant `HAS_SEARCH_ACCESS` as well.
- `HAS_CREATE_ACCESS`: Grants the permission to create new child nodes underneath the element.
- `HAS_UPDATE_ACCESS`: Grants the permission to change the element.
- `HAS_DELETE_ACCESS`: Grants the permission to delete the element and its children.
- `HAS_SEARCH_ACCESS`: Grants the permission to search the element. Similar to `HAS_READ_ACCESS`, but explicitly
  relevant for search operations. Can not carry conditions, see
  [conditional access](/reference/access-model/conditional-access.md).
- `HAS_GOVERN_ACCESS`: Grants the permission to hand out and revoke access to the element, i.e. to create, change and
  delete `OWNS`, `IS_IN_GROUP` and `HAS_X_ACCESS` relations pointing to it, if the user holds the granted access
  themselves, see
  [pointer relations and grant relations](/reference/access-model/handing-out-access.md#pointer-relations-and-grant-relations).
  `OWNS` implies it,
  group membership alone does not.
- `HAS_EXECUTE_ACCESS`: Grants the permission to run an executable element, currently saved searches (type
  `SavedSearch`, see [saved searches](/guide/search/saved-searches.md)) through
  [`POST /search/<uuid>`](/api/post-saved-search.md).
  It is independent of read access: neither implies the other, so a query can be hidden from the users who may run it,
  or be readable without being runnable. Like the other access relations it is inherited through `OWNS` chains and
  groups and can carry conditions; `OWNS` includes it, group membership alone does not. It has no effect on other
  elements, is only checked by execution endpoints and is not part of the search index.

### Limitations and Exceptions

Regardless of access operations, overall permissions etc., there are a few element types and properties which can not be
accessed, read or changed. These are usually only relevant for the API itself, or are dangerous to be changed by any
user.

When user try to change these properties, relevant exceptions are being thrown and the current request is being
canceled.

Other properties like `createdAt` and `updatedAt` are automatically set by the API, and can not be changed by the user
as well.

Users always have full access to their own user element.

### Performance considerations

Permission lists, i.e. which users and groups have access to each element, are calculated and cached in the background.

Adding new users to a group does only update a few cache entries internally, while giving a user direct access to a big
tree of elements requires a somewhat expensive re-calculation of the whole tree. While this is done asynchronously in
the background, it should be avoided.

Therefore, you should always use a group as a proxy object for bigger trees you might want to share with others in the
future.

### Metadata and timing attacks

Note that even with all security measures in place, some data can still be accessed by other users:

- General graph structure, e.g. the types of nodes and relations present in the global graph, through the
  [`GET /graph-structure`](/api/get-graph-structure.md)
  endpoint.
- Timing data. Databases can and will act differently for elements which exist but need to be filtered out, as well as
  elements which are truly missing from the database. While these small differences are usually not enough to leak
  useful data, a persistent actor might be able to learn general patterns.

---

Home: [Ember Nexus API docs](/index.md)

Full site map: [llms.txt](/llms.txt)

Previous: [Migrating to version 0.2.0](/guide/migration/migrating-to-0-2-0.md)

Next: [Access to nodes and relations](/reference/access-model/access-to-elements.md)
