You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: learn/security/master_api_keys.md
+43-22Lines changed: 43 additions & 22 deletions
Original file line number
Diff line number
Diff line change
@@ -82,52 +82,66 @@ Exposing your master key can give malicious users complete control over your Mei
82
82
83
83
Meilisearch gives you fine-grained control over which users can access which indexes, endpoints, and routes. When protecting your instance with a master key, you can ensure only authorized users can carry out sensitive tasks such as adding documents or altering index settings.
84
84
85
-
The master key is the only key with access to the [`/keys` route](/reference/api/keys.md). This route allows you to [create](#creating-an-api-key), [update](#updating-an-api-key), [list](#listing-api-keys), and [delete](#deleting-an-api-key) API keys.
85
+
You can access the [`/keys` route](/reference/api/keys.md) using the master key or an API key with access to the `keys.get`, `keys.create`, `keys.update`, or `keys.delete` actions. This`/keys` route allows you to [create](#creating-an-api-key), [update](#updating-an-api-key), [list](#listing-api-keys), and [delete](#deleting-an-api-key) API keys.
86
86
87
87
Though the default API keys are usually enough to manage the security needs of most applications, this might not be the case when dealing with privacy-sensitive data. In these situations, the fine-grained control offered by the `/keys` endpoint allows you to clearly decide who can access what information and for how long.
88
88
89
+
The [`key`](/reference/api/keys.md#key) field is generated by hashing the master key and the [`uid`](/reference/api/keys.md#uid). As a result, `key` values are deterministic between instances sharing the same configuration. Since the `key` field depends on the master key, it is not propagated to dumps and snapshots. If a malicious user ever gets access to your dumps or snapshots, they will not have access to your instance's API keys.
90
+
91
+
It is, therefore, possible to determine the value of the `key` field by using the following command:
This is also useful in continuous deployment processes as you know the value of the `key` field in advance.
98
+
89
99
### Updating an API key
90
100
91
-
You can freely update an API key at any time, even after it expires. This includes editing the indexes, endpoints, and routes it can access, as well as its description and expiry date.
101
+
You can only update the `name` and `description` of an API key, even after it expires.
92
102
93
-
We can update the `Default Search API Key`so regular users cannot perform search operations in our `patient_medical_records` index:
103
+
For example, we can update the `Default Search API Key`and change its description:
To update an API key, you must use the [update API key endpoint](/reference/api/keys.md#update-a-key) which can only be accessed with the master key.
125
+
To update an API key, you must use the [update API key endpoint](/reference/api/keys.md#update-a-key), which can only be accessed with the master key or an API key with the `keys.update` action.
114
126
115
-
Meilisearch supports partial updates with the `PATCH` route. This means your payload only needs to contain the data you want to update—in this case, `indexes`.
127
+
Meilisearch supports partial updates with the `PATCH` route. This means your payload only needs to contain the data you want to update—in this case, `description`.
116
128
117
129
### Creating an API key
118
130
119
-
You can create API keys by using the [create key endpoint](/reference/api/keys.md#create-a-key). This endpoint is always protected and can only be accessed with the master key.
131
+
You can create API keys by using the [create key endpoint](/reference/api/keys.md#create-a-key). This endpoint is always protected and can only be accessed with the master key or an API key with the `keys.create` action.
120
132
121
-
Since we have altered the permissions in our default search key, we need to create a new API key so authorized users can search through out `patient_medical_records` index:
133
+
Let's create a new API key so authorized users can search through out `patient_medical_records` index:
122
134
123
135
<CodeSamplesid="security_guide_create_key_1" />
124
136
125
137
All [`/keys` endpoints](/reference/api/keys.md) are synchronous, so your key will be generated immediately:
@@ -146,9 +160,9 @@ It is good practice to always set an expiry date when creating a new API key. If
146
160
147
161
You can use the [list keys endpoint](/reference/api/keys.md) to obtain information on any active key in your Meilisearch instance. This is useful when you need an overview of existing keys and their permissions.
148
162
149
-
[`GET /keys`](/reference/api/keys.md#get-all-keys) returns a full list of all existing keys.**Expired keys will appear in the response, but deleted keys will not**. As with creating, deleting, and updating API keys, you need the master key to access this endpoint.
163
+
By default, [`GET /keys`](/reference/api/keys.md#get-all-keys) returns the 20 most recently created keys. You can change this using the [`limit`](/reference/api/keys.md#get-all-keys) query parameter. **Expired keys will appear in the response, but deleted keys will not**. As with creating, deleting, and updating API keys, you either need the master key or an API key with the `keys.get` action to access this endpoint.
150
164
151
-
[`GET /keys/{key}`](/reference/api/keys.md#get-one-key) returns information on a single key. `{key}` should be replaced with the full `key` value obtained during key creation.
165
+
[`GET /keys/{key_or_uid}`](/reference/api/keys.md#get-one-key) returns information on a single key. `{key_or_uid}` should be replaced with the full `key` or `uid` value obtained during key creation.
152
166
153
167
We can query our instance to confirm which active keys can search our `patient_medical_records` index:
154
168
@@ -158,34 +172,40 @@ We can query our instance to confirm which active keys can search our `patient_m
158
172
{
159
173
"results": [
160
174
{
161
-
"description": "Default Search API Key (Use it to search from the frontend code)",
@@ -196,7 +216,10 @@ We can query our instance to confirm which active keys can search our `patient_m
196
216
"createdAt": "2022-01-01T10:00:00Z",
197
217
"updatedAt": "2022-01-01T10:00:00Z"
198
218
}
199
-
]
219
+
],
220
+
"offset":0,
221
+
"limit":20,
222
+
"total":3
200
223
}
201
224
```
202
225
@@ -212,8 +235,6 @@ If we accidentally exposed our `Search patient records key`, we can delete it to
212
235
213
236
Once a key is past its `expiresAt` date, using it for API authorization will return an error. Expired keys will still be returned by the [list keys endpoint](/reference/api/keys.md#get-all-keys).
214
237
215
-
If you must continue using an expired key, you may use the [update key endpoint](/reference/api/keys.md#update-a-key) to set a new `expiresAt` date and effectively reactivate it.
216
-
217
238
## Changing the master key
218
239
219
240
To change the master key, first terminate your Meilisearch instance. Then relaunch it, [supplying a new value for the master key](#protecting-a-meilisearch-instance).
Copy file name to clipboardExpand all lines: reference/api/error_codes.md
+16Lines changed: 16 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -165,6 +165,22 @@ The requested task does not exist. Please ensure that you are using the correct
165
165
166
166
The `minWordSizeForTypos` object is invalid. The value for both `oneTypo` and `twoTypos` should be between `0` and `255`, and `twoTypos` should be greater or equal to `oneTypo`.
167
167
168
+
### `immutable_field`
169
+
170
+
The field you are trying to modify is immutable.
171
+
172
+
### `api_key_already_exists`
173
+
174
+
A key with this `uid` already exists.
175
+
176
+
### `invalid_api_key_uid`
177
+
178
+
The given `uid` is invalid. The `uid` must follow the [uuid v4](https://www.sohamkamani.com/uuid-versions-explained) format.
179
+
180
+
### `invalid_api_key_name`
181
+
182
+
The given `name` is invalid. It should either be a string or `null`.
183
+
168
184
### `invalid_task_status`
169
185
170
186
The requested task status is invalid. Please use one of [these four possible values](/learn/advanced/asynchronous_operations.md#task-status).
0 commit comments