Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/data-api-features.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ sidebar_position: 5

**Multi-tenancy**

- [ ] Tenant Id column
- [x] Tenant Id column
- [x] Schema per tenant
- [ ] Database per tenant

Expand Down
9 changes: 9 additions & 0 deletions docs/multitenancy/_category_.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{

"label": "Multitenancy",
"position": 149,
"link": {
"type": "generated-index",
"description": "Guide on how to use multi tenancy."
}
}
109 changes: 109 additions & 0 deletions docs/multitenancy/column-multitenancy.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
---
sidebar_position: 1
title: Column Based Multitenancy
description: Tutorial on how to configure column based multitenancy.
keywords:
- multi-tenancy

---

import siteConfig from '/docusaurus.config.js';
import CodeBlock from '@theme/CodeBlock';

# Column Based Multitenancy

One of the features of DB2Rest is using the rest api to serve multiple tenants from one database model, where via a filter a column value is matched.
This configuration resides in the authentication data source, where the tenant id column and a value are specified for each security role.
Users with a role specifying such a filter, will be able to access the data which has the tenant id column value matching with the value specified for that role.

## Auth Data Source

The security data source is kept separate from application properties. Currently only file based datasource is supported.
The absolute path of the data file can be specified with the `AUTH_DATA_SOURCE` configuration parameter.
An example to set auth data source is shown below:

```
$ export AUTH_DATA_SOURCE = `file://${user.home}/git/db2rest/auth/auth-sample.yml`
```

:::tip

The auth data source parameter must be prefixed with `file://` if the authentication data is sourced from a file.
In case the data is loaded from a remote location prefix it with `http` or `https`.
:::


## Auth Data Source file example

This example shows the configuration for column based multitenancy for a role named `airmax` where the tenant id column is `tenant_id` and the value is `15`.
The user `Tom` who has this `airmax` role, will be able to access data in the rows table `customer_data` where the `tenant_id` column has the value `15`.

```yaml config file example

name: db2rest-security

resourceRoles:
- resource: "/v1/rdbms/pgsqldb/**"
method: post
roles:
- role2
- airmax
- role4
- resource: "/v1/rdbms/pgsqldb/**"
method: get
roles:
- role2
- airmax
- role4
- resource: "/v1/rdbms/pgsqldb/**"
method: patch
roles:
- role2
- airmax
- role4
- resource: "/v1/rdbms/pgsqldb/**"
method: delete
roles:
- role2
- airmax
- role4

excludedResources:
- resource: "/v1/rdbms/northwind/**"
method: get
- resource: "/v1/rdbms/northwind/factor"
method: post
- resource: "/v1/rdbms/northwind/**"
method: put
- resource: "/v1/rdbms/northwind/**"
method: delete

users:
- username: admin
password: admin
roles: [role1,role6]
- username: root
password: 23456
roles: [role1,role4]
- username: tom
password: 32113
roles: [airmax]

apiKeys:
- key: apikey1
roles: [admin]
active: true
- key: apikey2
roles: [admin]
- key: apiKey3
roles: [user]
active: true

roleDataFilters:
- role: airmax
dbId: pgsqldb
table: customer_data
column: tenant_id
value: 15

```
3 changes: 1 addition & 2 deletions src/pages/roadmap.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ Updated: 05-November-2024

- [ ] UUID support
- [ ] Data Federation
- [ ] Multi-tenancy
- [ ] Documentation Deploy - AWS Lightsail
- [ ] Documentation Deploy - to Azure
- [ ] Document Metrics & health check
Expand Down Expand Up @@ -68,7 +67,7 @@ Updated: 05-November-2024


## Completed

- [x] Multi-tenancy
- [x] Support for MongoDB
- [x] Support for Oracle
- [x] Support Tembo
Expand Down