-
Notifications
You must be signed in to change notification settings - Fork 25.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reject defining workflows restriction via file and Role API (#96304)
This PR rejects file and API based role definitions that include workflows restriction. Specifying `restriction` (in file or via API) will be rejected during parsing of a `RoleDescriptor` and reported as a parsing error. Currently, only API keys are supporting roles to be restricted to a set of workflows. Relates to #96215
- Loading branch information
1 parent
48c6547
commit 77a80b0
Showing
9 changed files
with
232 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
...stTest/java/org/elasticsearch/xpack/security/role/RoleWithWorkflowsRestrictionRestIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.security.role; | ||
|
||
import org.apache.http.client.methods.HttpPost; | ||
import org.apache.http.client.methods.HttpPut; | ||
import org.elasticsearch.client.Request; | ||
import org.elasticsearch.client.Response; | ||
import org.elasticsearch.client.ResponseException; | ||
import org.elasticsearch.xpack.security.SecurityOnTrialLicenseRestTestCase; | ||
|
||
import java.io.IOException; | ||
|
||
import static org.hamcrest.Matchers.containsString; | ||
|
||
public class RoleWithWorkflowsRestrictionRestIT extends SecurityOnTrialLicenseRestTestCase { | ||
|
||
public void testCreateRoleWithWorkflowsRestrictionFail() { | ||
Request createRoleRequest = new Request(HttpPut.METHOD_NAME, "/_security/role/role_with_restriction"); | ||
createRoleRequest.setJsonEntity(""" | ||
{ | ||
"cluster": ["all"], | ||
"indices": [ | ||
{ | ||
"names": ["index-a"], | ||
"privileges": ["all"] | ||
} | ||
], | ||
"restriction":{ | ||
"workflows": ["foo", "bar"] | ||
} | ||
}"""); | ||
|
||
ResponseException e = expectThrows(ResponseException.class, () -> adminClient().performRequest(createRoleRequest)); | ||
assertEquals(400, e.getResponse().getStatusLine().getStatusCode()); | ||
assertThat(e.getMessage(), containsString("failed to parse role [role_with_restriction]. unexpected field [restriction]")); | ||
} | ||
|
||
public void testUpdateRoleWithWorkflowsRestrictionFail() throws IOException { | ||
Request createRoleRequest = new Request(HttpPut.METHOD_NAME, "/_security/role/my_role"); | ||
createRoleRequest.setJsonEntity(""" | ||
{ | ||
"cluster": ["all"], | ||
"indices": [ | ||
{ | ||
"names": ["index-a"], | ||
"privileges": ["all"] | ||
} | ||
] | ||
}"""); | ||
Response createRoleResponse = adminClient().performRequest(createRoleRequest); | ||
assertOK(createRoleResponse); | ||
|
||
Request updateRoleRequest = new Request(HttpPost.METHOD_NAME, "/_security/role/my_role"); | ||
updateRoleRequest.setJsonEntity(""" | ||
{ | ||
"cluster": ["all"], | ||
"indices": [ | ||
{ | ||
"names": ["index-*"], | ||
"privileges": ["all"] | ||
} | ||
], | ||
"restriction":{ | ||
"workflows": ["foo", "bar"] | ||
} | ||
}"""); | ||
|
||
ResponseException e = expectThrows(ResponseException.class, () -> adminClient().performRequest(updateRoleRequest)); | ||
assertEquals(400, e.getResponse().getStatusLine().getStatusCode()); | ||
assertThat(e.getMessage(), containsString("failed to parse role [my_role]. unexpected field [restriction]")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters