Skip to content

Commit b811d11

Browse files
slobodanadamovicabdonpijpelinkywangd
authored
[DOC] Document role restriction for API keys (elastic#97027) (elastic#97145)
This PR adds API documentation for role restriction and workflows which are introduced in elastic#96744 and elastic#96215. --------- Co-authored-by: Abdon Pijpelink <[email protected]> Co-authored-by: Yang Wang <[email protected]>
1 parent 90a3c5c commit b811d11

File tree

7 files changed

+108
-9
lines changed

7 files changed

+108
-9
lines changed

x-pack/docs/en/rest-api/security/bulk-update-api-keys.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ You can assign new privileges by specifying them in this parameter.
5555
To remove assigned privileges, supply the `role_descriptors` parameter as an empty object `{}`.
5656
If an API key has no assigned privileges, it inherits the owner user's full permissions.
5757
The snapshot of the owner's permissions is always updated, whether you supply the `role_descriptors` parameter or not.
58-
The structure of a role descriptor is the same as the request for the <<security-api-put-role, create or update roles API>>.
58+
The structure of a role descriptor is the same as the request for the <<api-key-role-descriptors, create API keys API>>.
5959

6060
`metadata`::
6161
(Optional, object) Arbitrary, nested metadata to associate with the API keys.

x-pack/docs/en/rest-api/security/create-api-keys.asciidoc

Lines changed: 71 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ then the API key will have a _point in time snapshot of permissions of the
5656
authenticated user_. If you supply role descriptors then the resultant permissions
5757
would be an intersection of API keys permissions and authenticated user's permissions
5858
thereby limiting the access scope for API keys.
59-
The structure of role descriptor is the same as the request for create role API.
60-
For more details, see <<security-api-put-role, create or update roles API>>.
6159
+
6260
--
6361
NOTE: Due to the way in which this permission intersection is calculated, it is not
@@ -67,6 +65,49 @@ role descriptor with no privileges. The derived API key can be used for
6765
authentication; it will not have authority to call {es} APIs.
6866

6967
--
68+
+
69+
`applications`::: (list) A list of application privilege entries.
70+
`application` (required):::: (string) The name of the application to which this entry applies
71+
`privileges` (required):::: (list) A list of strings, where each element is the name of an application
72+
privilege or action.
73+
`resources` (required):::: (list) A list resources to which the privileges are applied.
74+
75+
`cluster`::: (list) A list of cluster privileges. These privileges define the
76+
cluster level actions that API keys are able to execute.
77+
78+
`global`::: (object) An object defining global privileges. A global privilege is
79+
a form of cluster privilege that is request-aware. Support for global privileges
80+
is currently limited to the management of application privileges.
81+
This field is optional.
82+
83+
`indices`::: (list) A list of indices permissions entries.
84+
`field_security`:::: (object) The document fields that the API keys have
85+
read access to. For more information, see
86+
<<field-and-document-access-control>>.
87+
`names` (required):::: (list) A list of indices (or index name patterns) to which the
88+
permissions in this entry apply.
89+
`privileges`(required):::: (list) The index level privileges that the API keys
90+
have on the specified indices.
91+
`query`:::: A search query that defines the documents the API keys have
92+
read access to. A document within the specified indices must match this query in
93+
order for it to be accessible by the API keys.
94+
95+
`metadata`::: (object) Optional meta-data. Within the `metadata` object, keys
96+
that begin with `_` are reserved for system usage.
97+
98+
`restriction`::: (object) Optional restriction for when the role descriptor is allowed to be effective. For more information, see
99+
<<role-restriction>>.
100+
`workflows`:::: (list) A list of workflows to which the API key is restricted.
101+
For a full list see <<workflows-restriction>>.
102+
+
103+
--
104+
NOTE: In order to use role restriction, an API key must be created with a *single role descriptor*.
105+
--
106+
+
107+
108+
`run_as`::: (list) A list of users that the API keys can impersonate.
109+
For more information, see
110+
<<run-as-privilege>>.
70111

71112
`expiration`::
72113
(Optional, string) Expiration time for the API key. By default, API keys never
@@ -92,7 +133,7 @@ POST /_security/api_key
92133
"role_descriptors": { <2>
93134
"role-a": {
94135
"cluster": ["all"],
95-
"index": [
136+
"indices": [
96137
{
97138
"names": ["index-a*"],
98139
"privileges": ["read"]
@@ -101,7 +142,7 @@ POST /_security/api_key
101142
},
102143
"role-b": {
103144
"cluster": ["all"],
104-
"index": [
145+
"indices": [
105146
{
106147
"names": ["index-b*"],
107148
"privileges": ["all"]
@@ -170,3 +211,29 @@ echo -n "VuaCfGcBCdbkQm-e5aOx:ui2lp2axTNmsyakw9tvNnw" | base64 <1>
170211
----
171212
<1> Use `-n` so that the `echo` command doesn't print the trailing newline
172213
character
214+
215+
//tag::create-api-key-with-role-restriction-example[]
216+
The following example creates an API key with a <<role-restriction, restriction>> to the `search_application_query` workflow,
217+
which allows to call only <<search-application-search, Search Application Search API>>:
218+
219+
[source,console]
220+
----
221+
POST /_security/api_key
222+
{
223+
"name": "my-restricted-api-key",
224+
"role_descriptors": {
225+
"my-restricted-role-descriptor": {
226+
"indices": [
227+
{
228+
"names": ["my-search-app"],
229+
"privileges": ["read"]
230+
}
231+
],
232+
"restriction": {
233+
"workflows": ["search_application_query"]
234+
}
235+
}
236+
}
237+
}
238+
----
239+
//end::create-api-key-with-role-restriction-example[]

x-pack/docs/en/rest-api/security/create-roles.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,4 +140,4 @@ POST /_security/role/cli_or_drivers_minimal
140140
]
141141
}
142142
--------------------------------------------------
143-
// end::sql-queries-permission[]
143+
// end::sql-queries-permission[]

x-pack/docs/en/rest-api/security/grant-api-keys.asciidoc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ key. This parameter is optional. When it is not specified or is an empty array,
7575
the API key has a point in time snapshot of permissions of the specified user or
7676
access token. If you supply role descriptors, the resultant permissions are an
7777
intersection of API keys permissions and the permissions of the user or access
78-
token. The structure of role descriptor is the same as the request for create
79-
role API. For more details, see <<security-api-put-role>>.
78+
token. The structure of a role descriptor is the same as the request for <<api-key-role-descriptors, create API keys API>>.
8079

8180
`metadata`:::
8281
(Optional, object) Arbitrary metadata that you want to associate with the API key.

x-pack/docs/en/rest-api/security/update-api-key.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ You can assign new privileges by specifying them in this parameter.
5959
To remove assigned privileges, you can supply an empty `role_descriptors` parameter, i.e., an empty object `{}`.
6060
If an API key has no assigned privileges, it inherits the owner user's full permissions.
6161
The snapshot of the owner's permissions is always updated, whether you supply the `role_descriptors` parameter or not.
62-
The structure of a role descriptor is the same as the request for the <<security-api-put-role, create or update roles API>>.
62+
The structure of a role descriptor is the same as the request for the <<api-key-role-descriptors, create API keys API>>.
6363

6464
`metadata`::
6565
(Optional, object) Arbitrary metadata that you want to associate with the API key.

x-pack/docs/en/security/authorization/overview.asciidoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ include::built-in-roles.asciidoc[]
7878

7979
include::managing-roles.asciidoc[]
8080

81+
include::role-restriction.asciidoc[]
82+
8183
include::privileges.asciidoc[]
8284

8385
include::document-level-security.asciidoc[]
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
[role="xpack"]
2+
[[role-restriction]]
3+
=== Role restriction
4+
5+
Role restriction can be used to specify conditions under which a role should be effective.
6+
When conditions are not met, the role will be disabled, which will result in access being denied.
7+
Not specifying restriction means the role is not restricted and thus always effective.
8+
This is the default behaviour.
9+
10+
--
11+
NOTE: Currently, the role restriction is only supported for <<security-api-create-api-key, API keys>>,
12+
with limitation that the API key can only have a single role descriptor.
13+
--
14+
15+
[[workflows-restriction]]
16+
==== Workflows
17+
18+
Workflows allow to restrict the role to be effective exclusively when calling certain REST APIs.
19+
Calling a REST API that is not allowed by a workflow, will result in the role being disabled.
20+
The below section lists workflows that you can restrict the role to:
21+
22+
`search_application_query`::: This workflow restricts the role to the <<search-application-search, Search Application Search API>> only.
23+
24+
--
25+
NOTE: Workflow names are case-sensitive.
26+
--
27+
28+
[discrete]
29+
==== Examples
30+
31+
include::../../rest-api/security/create-api-keys.asciidoc[tag=create-api-key-with-role-restriction-example]

0 commit comments

Comments
 (0)