Skip to content

Commit 9e97332

Browse files
committed
Fix wildcard handling
1 parent d8aa0f9 commit 9e97332

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

docs/reference/rest-api/security/get-user-privileges.asciidoc

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
For the most up-to-date API details, refer to {api-es}/group/endpoint-security[Security APIs].
1212
--
1313

14-
Retrieves the <<security-privileges,security privileges>> for the logged in
14+
Retrieves the <<security-privileges,security privileges>> for the logged in
1515
user.
1616

1717
[[security-api-get-user-privileges-request]]
@@ -22,7 +22,7 @@ user.
2222
[[security-api-get-user-privileges-prereqs]]
2323
==== {api-prereq-title}
2424

25-
* All users can use this API, but only to determine their own privileges. To
25+
* All users can use this API, but only to determine their own privileges. To
2626
check the privileges of other users, you must use the run as feature. For
2727
more information, see <<run-as-privilege>>.
2828

@@ -57,6 +57,15 @@ GET /_security/user/_privileges
5757
"all"
5858
],
5959
"allow_restricted_indices" : true
60+
},
61+
{
62+
"names" : [
63+
"*::failures"
64+
],
65+
"privileges" : [
66+
"all"
67+
],
68+
"allow_restricted_indices" : true
6069
}
6170
],
6271
"applications" : [

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/permission/Role.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,19 @@ static SimpleRole buildFromRoleDescriptor(
433433
);
434434

435435
for (RoleDescriptor.IndicesPrivileges indexPrivilege : roleDescriptor.getIndicesPrivileges()) {
436+
if (Arrays.asList(indexPrivilege.getIndices()).contains("*")) {
437+
builder.add(
438+
fieldPermissionsCache.getFieldPermissions(
439+
new FieldPermissionsDefinition(indexPrivilege.getGrantedFields(), indexPrivilege.getDeniedFields())
440+
),
441+
indexPrivilege.getQuery() == null ? null : Collections.singleton(indexPrivilege.getQuery()),
442+
IndexPrivilege.get(Sets.newHashSet(indexPrivilege.getPrivileges())),
443+
indexPrivilege.allowRestrictedIndices(),
444+
// TODO properly handle this
445+
true,
446+
indexPrivilege.getIndices()
447+
);
448+
}
436449
builder.add(
437450
fieldPermissionsCache.getFieldPermissions(
438451
new FieldPermissionsDefinition(indexPrivilege.getGrantedFields(), indexPrivilege.getDeniedFields())
@@ -441,7 +454,7 @@ static SimpleRole buildFromRoleDescriptor(
441454
IndexPrivilege.get(Sets.newHashSet(indexPrivilege.getPrivileges())),
442455
indexPrivilege.allowRestrictedIndices(),
443456
// TODO properly handle this
444-
Arrays.asList(indexPrivilege.getIndices()).contains("*"),
457+
false,
445458
indexPrivilege.getIndices()
446459
);
447460
}

0 commit comments

Comments
 (0)