Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
WIP, multi-tenancy design
天舟5476185389a3
diff --git a/docs/design/multi-tenancy.md b/docs/design/multi-tenancy.mdindex ae43e88ad5..b34bdc7232 100644--- a/docs/design/multi-tenancy.md+++ b/docs/design/multi-tenancy.md@@ -26,49 +26,80 @@ This is quite an advanced feature and to our knowledege, none existing database### New models-1. **Tenant**, a tenant could be a SaaS customer name (e.g. ACME), a region name (e.g. us-west).-1. **Tenant Set**, a group of related tenants. e.g. a group of SaaS customers (e.g. CompanyFoo, CompanyBar), a group of regions (e.g. us-west, us-east, asia-pacific). A tenant must belong to one and one tenant set.+1. **Tenant**, a tenant usually represents a customer (e.g. ACME), a region name (e.g. us-west).+1. **Tenant Tag**, a tenant tag represents a property of the tenant. e.g it could represent the geo-location, like us-west, us-east, asia-pacific. It could also represent the release track, like beta, stable.+1. **Tenant Tag Set**, a group of related tenant tags. We can group tags like us-west, us-east, asia-pacific into a tenant tag set "region".-### Relationship with other models+A tenant can associate multiple tenant tags, but it can associate at most 1 tenant tag from a particular tenant tag set.-1. A workspace can have multiple tenant sets. In other words, tenant set is at the top level of the workspace. Another design option is to make tenant set under Project.+### Where to put the new models- #### Pros of putting under workspace+**Tenant Tag** and **Tenant Tag Set** are under workspace, only Workspace Owner or DBA can mutable them.- 1. Reduce duplication. e.g. for a tenant set representing regions, it's more likely to have a single set of regions. Putting under project would require each project to re-define regions.- 1. Easy to enforce workspace wide policy since tenant set is globally shared.+**Tenant** on the other hand are under project, only Project Owner can mutable them.- #### Cons of putting under workspace+The reason for this design is we think there should be a standard set of tenant tag/tag set defined at the workspace level such+as the region list, the release track list. While the actual tenant is business logic specific, which should be managed by+the individual project.- 1. Less flexibility. e.g. Only a particular project needs a set of tenants. This requires project owner to contact workspace owner to create the tenant set.- 1. May cause workspace to maintain a large list of tenant set, each only serves a single project.+### How tenant is used- #### We choose to put under workspace because+A database can associate at most a single tenant. The association works in the similar way as we associate a database with a project.- 1. We expect most customers won't use Bytebase to manage a lot of projects in the first couple years and they mostly have homogeneous environments.- 1. Customer can launch a separate Bytebase instance to mimic the project-level tenant set.- 1. Per workspace is a simplier solution, and it's easier for us to add per-project tenant set later than the other way around.--1. An instance can be associated with multiple tenants as long as the tenants come from different tenant set(e.g. dbfoo can have tenant _ACME_ and tenant _US-WEST_ at the same time, but can't have _US-WEST_, _US-EAST_ at the same time). If an instance has tenants, all its databases inherit the same tenants.--1. If an instance does NOT have tenant set, then a database can be associated with multiple tenants as long as the tenants come from different tenant set(e.g. dbfoo can have tenant _ACME_ and tenant _US-WEST_ at the same time, but can't have _US-WEST_, _US-EAST_ at the same time)+We did consider to associate the tenant on the instance level, that will ease the association, since all databases from the+instance will automatically inherit the tenant info. On the other hand, this approach can't deal with the case that an+instance may host multiple databases, each serving a particular tenant.### Permissions-1. Workspace Owner and DBA can CRUD tenant and tenant set. Anyone can view the exisiting tenant and tenant set.+1. Workspace Owner and DBA can CRUD tenant tag set and tenant tag. Workspace Developer can only view tenant tag set and tenant tag.-1. Project Owner can bind/unbind the tenant with the project's owning databases.+1. Project Owner can CRUD tenant. Project Developer can only view tenant.++1. Project Owner can associate/de-associate a single tenant to/from a database.### User Story-A Bytebase customer runs a multi-region shopify like SaaS service. It currently operates in 3 regions, _US West_, _US East_, _Asia Pasific_ and has 2 customers _Company A_ and _Company B_. It also has a test customer _Company Test_ which is used as a canary to receive change first. The Bytebase customer has established 2 environments, Test and Prod. _Company A_ and _Company B_ only run in Prod and have provisioned separate db for each (customer, region) pair, thus 6 total shop databases. Company Test only runs Test and just provisions a single shop db.+A Bytebase customer runs a multi-region shopify like SaaS service. It currently operates in 3 regions, _US West_, _US East_, _Asia Pacific_ and has 2 customers _Company A_ and _Company B_. It also has a test customer _Company Test_ which is used as a canary to receive change first. The Bytebase customer has established 2 environments, Test and Prod. Below is the database list matrix:++| Company | Region | Test | Prod |+| ------------ | ------------ | ------------------- | ------------------- |+| Company A | US West | db-a-uswest-test | db-a-uswest-prod |+| | US East | db-a-useast-test | db-a-useast-prod |+| | Asia Pacific | db-a-asia-test | db-a-asia-prod |+| Company B | US West | db-b-uswest-test | db-b-uswest-prod |+| | US East | db-b-useast-test | db-b-useast-prod |+| | Asia Pacific | db-b-asia-test | db-b-asia-prod |+| Company Test | US West | db-test-uswest-test | db-test-uswest-prod |++Workspace Owner or DBA creates 2 tenant tag set:++- _ReleaseTrack_, including _beta_, _stable_.+- _Region_, including _us-west_, _us-east_, _asia-pacific_.++| Tag Set | |+| ------------- | ------------------------------ |+| Release Track | beta, stable |+| Region | us-west, us-east, asia-pacific |++The Bytebaes user creates a project called _minishop_, and under that project, there are several stategy to construct+the tenant:++Strategy 1, group by release track:++- Tenants: beta, stable. Each assigning the beta, stable tag respectively++Strategy 2, group by region++- Tenants: us-west, us-east, asia-pacific. Each assigning the us-west, us-east, asia-pacific tag respectively++Strategy 3, group by company++- Tenants: companyA, companyB, companyTest. companyA and companyB assigning stable tag, companyTest assiging beta tag.-1. Workspace Owner or DBA creates 2 set of tenants:+Strategy 4, group by company, region- 1. 1 tenant set called _Customer_, including _CompanyA_, _CompanyB_.- 1. 1 tenant set called _Region_, including _us-west_, _us-east_, _asia-pacific_.+- Tenants: companyA-us-west, companyA-us-east, companyB-us-west, companyB-us-east, companyTest-us-west-1. Project owner bind _Customer_, _Region_ tenant to the correponding _Company A_, _Company B_ shop database in each region. Project owner do NOT bind any tenant to that _Company Test_ single shop database.-1. When rolling a new schema change, project member selects the applicable databases for each environment. For Test environment, there is only a single shop database for _Text Company_, so that is selected. For Prod environment, project member can select multiple databases and she can use tenant filter to quickly select databases.-1. In the generated pipeline, it has 2 stages, the 1st stage contains a single task to apply the schema change to the shop db for _Company A_. The 2nd stage contains multiple tasks each representing a change to a particular database.-1. UI should be able to view the schema change progress group by the tenant sets. Initially, we only support to group by a single tenant set. i.e. support GROUP BY _Customer_, or GROUP BY _Region_. But do NOT support GROUP BY _Customer_, _Region_.+UI should provide way to select databases based on the tenant filter. UI should also present information group by tenant (e.g+to view the change progress by tenant)