Skip to content
This repository has been archived by the owner on Mar 21, 2024. It is now read-only.

Tenant Token #89

Merged
merged 40 commits into from
Mar 9, 2022
Merged

Tenant Token #89

merged 40 commits into from
Mar 9, 2022

Conversation

gmourier
Copy link
Member

@gmourier gmourier commented Nov 3, 2021

Summary

A Tenant token is generated by the user code to be used by an end-user when making search queries.

It allows users to have multi-tenant indexes and thus restricts access to documents depending on the end-user making the search request.

A Tenant Token is a JWT containing the information necessary for Meilisearch to verify it and extract permission/rules to apply it to the end user's search.

Key Points

  • Tenant tokens are JWTs generated on the user side by using Meilisearch SDKs or their custom code. Tenant tokens are not stored nor retrievable on the Meilisearch side.
  • Tenant tokens contain rules that ensure that a Tenant token holder (e.g. an end-user) only has access to documents matching rules chosen at the tenant token creation.
  • Tenant tokens are signed from a Meilisearch API key resource on the user's code.
  • Tenant tokens must not be signed by the master key.
  • Tenant tokens cannot be more permissive than the signing API key.
  • Tenant tokens must be signed by an API Key having the search action defined.
  • Tenant tokens can have different rules for each index accessible by the signing API key. These rules are described in the searchRules JSON object.
  • The only rule available in the searchRules object is the search parameter filter.
  • Tenant tokens are sent to Meilisearch via the Authorization header like any API Keys or the master key.
  • When Meilisearch receives a search query emitted with a Tenant token, the tenant token is decoded, then the searchRules are applied for the search request before the search parameters.

Motivation

Tenant tokens are introduced to solve multi-tenant indexes use-case.

Multi-Tenant Indexes Definition: It is an index that stores documents that may belong to different tenants. In our case, a tenant within an index can be a user or a company, etc. In general, the data of one tenant should not be accessible by other tenants.

Users today need to set up workarounds to have multi-tenant indexes. They have to use server code to implement the access restriction logic before requesting Meilisearch. It isn't easy to maintain, to implement, and the performance is not optimal because the frontend code does not communicate directly with Meilisearch.


Rendered

@gmourier gmourier added Ready For Review Feature specification must be reviewed. Q4:2021 labels Nov 3, 2021
@gmourier gmourier changed the title Scoped API Keys Multi-Tenant Scoped API Keys Nov 3, 2021
curquiza
curquiza previously approved these changes Nov 11, 2021
Copy link
Member

@curquiza curquiza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice spec! 💪

This should be read by the whole integration team since there is a crucial implementation on their side regarding the user experience 👍

@gmourier
Copy link
Member Author

Nice spec! 💪

This should be read by the whole integration team since there is a crucial implementation on their side regarding the user experience 👍

Thanks @curquiza! Ping @meilisearch/integration-team ⚡️

Copy link
Contributor

@bidoubiwa bidoubiwa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can a user be restricted to access a field?

text/0089-scoped-api-keys.md Outdated Show resolved Hide resolved
text/0089-scoped-api-keys.md Outdated Show resolved Hide resolved
text/0089-scoped-api-keys.md Outdated Show resolved Hide resolved
text/0089-scoped-api-keys.md Outdated Show resolved Hide resolved
text/0089-scoped-api-keys.md Outdated Show resolved Hide resolved
text/0089-scoped-api-keys.md Outdated Show resolved Hide resolved
text/0089-scoped-api-keys.md Outdated Show resolved Hide resolved
text/0089-scoped-api-keys.md Outdated Show resolved Hide resolved
text/0089-scoped-api-keys.md Outdated Show resolved Hide resolved
text/0089-scoped-api-keys.md Outdated Show resolved Hide resolved
@curquiza curquiza requested a review from alallema November 15, 2021 13:24
bidoubiwa
bidoubiwa previously approved these changes Nov 25, 2021
Copy link
Contributor

@bidoubiwa bidoubiwa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A part for the naming part that we already discussed :') the rest is very good to me 🔥

@bidoubiwa

This comment has been minimized.

@irevoire

This comment has been minimized.

@alallema

This comment has been minimized.

@gmourier

This comment has been minimized.

@bidoubiwa

This comment has been minimized.

@MarinPostma

This comment has been minimized.

@gmourier

This comment has been minimized.

@bidoubiwa

This comment has been minimized.

@dichotommy

This comment has been minimized.

@MarinPostma

This comment has been minimized.

@gmourier

This comment has been minimized.

@qdequele

This comment has been minimized.

@gmourier

This comment has been minimized.

@gmourier gmourier changed the title Multi-Tenant Scoped API Keys Tenant Token Dec 13, 2021
@gmourier
Copy link
Member Author

The specification has been updated to use the term Tenant Token. Thanks to all for your suggestions and feedback. 🧱

text/0089-tenant-token.md Outdated Show resolved Hide resolved
text/0089-tenant-token.md Outdated Show resolved Hide resolved
text/0089-tenant-token.md Outdated Show resolved Hide resolved
text/0089-tenant-token.md Outdated Show resolved Hide resolved
text/0089-tenant-token.md Outdated Show resolved Hide resolved
gmourier and others added 6 commits March 7, 2022 12:14
Co-authored-by: Many <legendre.maxime.isn@gmail.com>
Co-authored-by: Bruno Casali <brunoocasali@gmail.com>
Co-authored-by: cvermand <33010418+bidoubiwa@users.noreply.github.com>
@gmourier gmourier force-pushed the scoped-api-keys branch 3 times, most recently from 3fa785e to c593d54 Compare March 7, 2022 12:03
@gmourier
Copy link
Member Author

gmourier commented Mar 7, 2022

Light reorganization of the specification and fix of some typos.

I removed the pseudo-JS code because it doesn't bring much to the specification. SDKs and documentation are much better for this since they are presenting working code and I want to avoid managing 2 base codes.

I need 2 approval reviews to merge this specification. If one person from the @meilisearch/integration-team and one person from the @meilisearch/docs-team can take a look at it, it will be really appreciated 🙏

Thanks to everyone for your work and feedback on this iteration. ❤️

Copy link
Member

@brunoocasali brunoocasali left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job @gmourier and team! 🎉 🌮

bors bot added a commit to meilisearch/meilisearch-php that referenced this pull request Mar 7, 2022
297: Adding generateTenantToken method to the client r=alallema a=alallema

## Tenant tokens

Introduction of the new method `generateTenantToken`  in order to facilitate the generation of the tenant token.

Related to:
- this issue: meilisearch/meilisearch#1991
- this spec: meilisearch/specifications#89


Co-authored-by: alallema <amelie@meilisearch.com>
Co-authored-by: Amélie <alallema@users.noreply.github.com>
@gmourier gmourier mentioned this pull request Mar 9, 2022
1 task
Copy link
Member

@curquiza curquiza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💪

@gmourier gmourier merged commit c4fa372 into develop Mar 9, 2022
@gmourier gmourier deleted the scoped-api-keys branch March 9, 2022 17:55
gmourier added a commit that referenced this pull request Mar 9, 2022
* init specification

* update filename

* update typo

* rephrase motivation

* rename master occurences by main

* replace mention of main by master

* Update text/0089-scoped-api-keys.md

Co-authored-by: cvermand <33010418+bidoubiwa@users.noreply.github.com>

* replace client code by frontend or backend

* Update text/0089-scoped-api-keys.md

Co-authored-by: cvermand <33010418+bidoubiwa@users.noreply.github.com>

* Update text/0089-scoped-api-keys.md

Co-authored-by: cvermand <33010418+bidoubiwa@users.noreply.github.com>

* Update text/0089-scoped-api-keys.md

Co-authored-by: cvermand <33010418+bidoubiwa@users.noreply.github.com>

* update javascript code sample for generateScopedApiKey method

* Rename Scoped API Key to Tenant Token

* Apply suggestions from code review

Co-authored-by: cvermand <33010418+bidoubiwa@users.noreply.github.com>

* precise message from reviews

* Add JWT part

* Rename specification file

* Update specification texts

* Add examples for indexesPolicy

* Update indexesPolicy examples texts

* Update indexesPolicy examples texts

* Update indexesPolicy examples texts

* Add a multi-tenant definition and tenant examples for MeiliSearch

* Update text/0089-tenant-tokens.md

Co-authored-by: Tommy <68053732+dichotommy@users.noreply.github.com>

* Update text/0089-tenant-tokens.md

Co-authored-by: Tommy <68053732+dichotommy@users.noreply.github.com>

* Add array format for indexesPolicy and rename iss to apiKeyPrefix

* update indexesPolicy formats example

* rename indexesPolicy to searchRules and add supported JWT signatures

* Rephrase searchRules explanations

* Update text/0089-tenant-tokens.md

Co-authored-by: cvermand <33010418+bidoubiwa@users.noreply.github.com>

* Update text/0089-tenant-tokens.md

Co-authored-by: cvermand <33010418+bidoubiwa@users.noreply.github.com>

* Update text/0089-tenant-tokens.md

Co-authored-by: cvermand <33010418+bidoubiwa@users.noreply.github.com>

* Rephrase explanations from suggestions

* Update scheme

* Update text/0089-tenant-tokens.md

Co-authored-by: Many <legendre.maxime.isn@gmail.com>

* Mention tenant token revoking

* Add precision on SDKs and Meilisearch role for Tenant Token

* Apply suggestions from code review

Co-authored-by: Bruno Casali <brunoocasali@gmail.com>
Co-authored-by: cvermand <33010418+bidoubiwa@users.noreply.github.com>

* Add Future Possibilities on tenant token formatting error

* Replace MeiliSearch by Meilisearch, fix typos, rephrase sentences and reorganize sections

Co-authored-by: cvermand <33010418+bidoubiwa@users.noreply.github.com>
Co-authored-by: Tommy <68053732+dichotommy@users.noreply.github.com>
Co-authored-by: Many <legendre.maxime.isn@gmail.com>
Co-authored-by: Bruno Casali <brunoocasali@gmail.com>
@gmourier gmourier added Implemented Feature specification has been implemented. and removed Ready For Review Feature specification must be reviewed. P1 labels Mar 10, 2022
gmourier added a commit that referenced this pull request Mar 14, 2022
* Search API (#118)

* Add specification the search API endpoints

* Add errors

* Add a future possibility about error code

* Replace spec id

* Fix typo

* Harmonize sentences

* Apply suggestions from code review

Co-authored-by: Clémentine Urquizar - curqui <clementine@meilisearch.com>

* Fix type definition by http verb for filter parameter

* fix typos

Co-authored-by: Clémentine Urquizar - curqui <clementine@meilisearch.com>

* Handle empty cell as `null` value for CSV format (#110)

* Add null value part and example

* Update text/0028-indexing-csv.md

Co-authored-by: Clément Renault <clement@meilisearch.com>

* Replace MeiliSearch by Meilisearch

Co-authored-by: Clément Renault <clement@meilisearch.com>

* Dumps (#105)

* Init dumps specification

* Apply suggestions from code review

Co-authored-by: Tamo <tamo@meilisearch.com>

* Describe CLI flags and error messages

* Apply suggestions from code review

Co-authored-by: Clémentine Urquizar - curqui <clementine@meilisearch.com>

* remove wrong statement

* Add dump creation as a task into future possibilities section

* Rename spec file and mentions technical aspects

Co-authored-by: Tamo <tamo@meilisearch.com>
Co-authored-by: Clémentine Urquizar - curqui <clementine@meilisearch.com>

* Remove the error on put/post documents when sending paylaod with 0 document object (#98)

* Add CLI flag/option to telemetry specification (#107)

* Add CLI analytics

* Add log_level

* use snake case

* Add backticks on examples

* Apply suggestions from code review

Co-authored-by: Tommy <68053732+dichotommy@users.noreply.github.com>

* Fix debounce-duration-sec parameter name

Co-authored-by: Tommy <68053732+dichotommy@users.noreply.github.com>

* Keys API - Update the error message for `expiresAt` (#114)

* update the wrong date message

* Change ISO-8601 by RFC 3339

* Update errors: backticks, example error message and placeholder var

Co-authored-by: Guillaume Mourier <guillaume@meilisearch.com>

* Dump support (#122)

* Add dump version support

* Fix titles numerotation, clear API endpoints definition, apply curquiza suggestion to gain one title level

* Update text/0105-dumps-api.md

Co-authored-by: Guillaume Mourier <guillaume@meilisearch.com>

Co-authored-by: Guillaume Mourier <guillaume@meilisearch.com>

* Tenant Token (#89)

* init specification

* update filename

* update typo

* rephrase motivation

* rename master occurences by main

* replace mention of main by master

* Update text/0089-scoped-api-keys.md

Co-authored-by: cvermand <33010418+bidoubiwa@users.noreply.github.com>

* replace client code by frontend or backend

* Update text/0089-scoped-api-keys.md

Co-authored-by: cvermand <33010418+bidoubiwa@users.noreply.github.com>

* Update text/0089-scoped-api-keys.md

Co-authored-by: cvermand <33010418+bidoubiwa@users.noreply.github.com>

* Update text/0089-scoped-api-keys.md

Co-authored-by: cvermand <33010418+bidoubiwa@users.noreply.github.com>

* update javascript code sample for generateScopedApiKey method

* Rename Scoped API Key to Tenant Token

* Apply suggestions from code review

Co-authored-by: cvermand <33010418+bidoubiwa@users.noreply.github.com>

* precise message from reviews

* Add JWT part

* Rename specification file

* Update specification texts

* Add examples for indexesPolicy

* Update indexesPolicy examples texts

* Update indexesPolicy examples texts

* Update indexesPolicy examples texts

* Add a multi-tenant definition and tenant examples for MeiliSearch

* Update text/0089-tenant-tokens.md

Co-authored-by: Tommy <68053732+dichotommy@users.noreply.github.com>

* Update text/0089-tenant-tokens.md

Co-authored-by: Tommy <68053732+dichotommy@users.noreply.github.com>

* Add array format for indexesPolicy and rename iss to apiKeyPrefix

* update indexesPolicy formats example

* rename indexesPolicy to searchRules and add supported JWT signatures

* Rephrase searchRules explanations

* Update text/0089-tenant-tokens.md

Co-authored-by: cvermand <33010418+bidoubiwa@users.noreply.github.com>

* Update text/0089-tenant-tokens.md

Co-authored-by: cvermand <33010418+bidoubiwa@users.noreply.github.com>

* Update text/0089-tenant-tokens.md

Co-authored-by: cvermand <33010418+bidoubiwa@users.noreply.github.com>

* Rephrase explanations from suggestions

* Update scheme

* Update text/0089-tenant-tokens.md

Co-authored-by: Many <legendre.maxime.isn@gmail.com>

* Mention tenant token revoking

* Add precision on SDKs and Meilisearch role for Tenant Token

* Apply suggestions from code review

Co-authored-by: Bruno Casali <brunoocasali@gmail.com>
Co-authored-by: cvermand <33010418+bidoubiwa@users.noreply.github.com>

* Add Future Possibilities on tenant token formatting error

* Replace MeiliSearch by Meilisearch, fix typos, rephrase sentences and reorganize sections

Co-authored-by: cvermand <33010418+bidoubiwa@users.noreply.github.com>
Co-authored-by: Tommy <68053732+dichotommy@users.noreply.github.com>
Co-authored-by: Many <legendre.maxime.isn@gmail.com>
Co-authored-by: Bruno Casali <brunoocasali@gmail.com>

* Auto-Batching (#96)

* init auto-batching specification

* replace file name

* Add content and explanations

* fix typo

* change wording

* Update auto-batching

* Mention batchUid identifier

* Update spec titles numerotation

* Separate consecutive tasks type

* Add a simple schema to represent the batchUid and tasks picking

* Apply suggestions from code review

Co-authored-by: Clémentine Urquizar - curqui <clementine@meilisearch.com>

* Update auto-batching spec with CLI flags explanations

* Modify Task API resource to display the batchUid

* Add the batchUid field to the Task API object description

* Fix parameter name

* Replaces MeiliSearch by Meilisearch, fix typos, rephrase sentences and reorganize section

* Rename --enable-autbatching to --enable-auto-batching

* Update text/0096-auto-batching.md

Co-authored-by: Clémentine Urquizar - curqui <clementine@meilisearch.com>

* Update text/0096-auto-batching.md

Co-authored-by: ad hoc <postma.marin@protonmail.com>

* Add precisions

* Rephrase debounce-duration-sec option

* Apply suggestions from code review

Co-authored-by: ad hoc <postma.marin@protonmail.com>

* Apply suggestions from code review

Co-authored-by: Tamo <irevoire@protonmail.ch>

Co-authored-by: Clémentine Urquizar - curqui <clementine@meilisearch.com>
Co-authored-by: ad hoc <postma.marin@protonmail.com>
Co-authored-by: Tamo <irevoire@protonmail.ch>

* Bump OAS to v0.26.0

Co-authored-by: Clémentine Urquizar - curqui <clementine@meilisearch.com>
Co-authored-by: Clément Renault <clement@meilisearch.com>
Co-authored-by: Tamo <tamo@meilisearch.com>
Co-authored-by: Tommy <68053732+dichotommy@users.noreply.github.com>
Co-authored-by: cvermand <33010418+bidoubiwa@users.noreply.github.com>
Co-authored-by: Many <legendre.maxime.isn@gmail.com>
Co-authored-by: Bruno Casali <brunoocasali@gmail.com>
Co-authored-by: ad hoc <postma.marin@protonmail.com>
Co-authored-by: Tamo <irevoire@protonmail.ch>
meili-bors bot added a commit to meilisearch/meilisearch-swift that referenced this pull request Apr 12, 2022
273: Feature/Tenant Token: Add a module which can generate tenant tokens r=bidoubiwa a=brunoocasali

Create the `generateTenantToken` following the specification meilisearch/specifications#89

Co-authored-by: Bruno Casali <brunoocasali@gmail.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Implemented Feature specification has been implemented. Q1:2022 v0.26
Projects
None yet
Development

Successfully merging this pull request may close these issues.