-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Add 'create_doc' index privilege #45806
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
bizybot
merged 21 commits into
elastic:master
from
bizybot:append-only-indices-privilege
Oct 7, 2019
Merged
Changes from 19 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
e2a0a5b
Append only index privilege
6066680
precommit errors
460deae
fix test
8d5fceb
fix test
9b3987d
follow the conventions naming an action
0d32057
fix test
20707d3
fix test
99c2492
check the auto generated timestamp against the constant IndexRequest.…
e2ddaad
use constants
d644dc1
Merge branch 'master' into append-only-indices-privilege
7cab8e9
split into individual test cases
f4dd373
Merge branch 'master' into append-only-indices-privilege
dca6df0
'create_docs' as index privilege name instead of append-only
931823d
address review comment - use create_doc
9829bd4
address review comment
b080a38
Merge branch 'master' into append-only-indices-privilege
3927063
remove the logic to determine effective op_type
9e79797
remove unused import
635ccaa
add test case for bulk with create op_type
e55225a
address review comments
f15e735
Merge branch 'master' into append-only-indices-privilege
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
112 changes: 112 additions & 0 deletions
112
...n/security/src/test/java/org/elasticsearch/integration/CreateDocsIndexPrivilegeTests.java
This file contains hidden or 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,112 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License; | ||
| * you may not use this file except in compliance with the Elastic License. | ||
| */ | ||
|
|
||
| package org.elasticsearch.integration; | ||
|
|
||
| import org.elasticsearch.client.Request; | ||
| import org.elasticsearch.common.settings.SecureString; | ||
| import org.elasticsearch.xpack.core.security.authc.support.Hasher; | ||
| import org.junit.Before; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| public class CreateDocsIndexPrivilegeTests extends AbstractPrivilegeTestCase { | ||
| private static final String INDEX_NAME = "index-1"; | ||
| private static final String CREATE_DOC_USER = "create_doc_user"; | ||
| private String jsonDoc = "{ \"name\" : \"elasticsearch\", \"body\": \"foo bar\" }"; | ||
| private static final String ROLES = | ||
| "all_indices_role:\n" + | ||
| " indices:\n" + | ||
| " - names: '*'\n" + | ||
| " privileges: [ all ]\n" + | ||
| "create_doc_role:\n" + | ||
| " indices:\n" + | ||
| " - names: '*'\n" + | ||
| " privileges: [ create_doc ]\n"; | ||
|
|
||
| private static final String USERS_ROLES = | ||
| "all_indices_role:admin\n" + | ||
| "create_doc_role:" + CREATE_DOC_USER + "\n"; | ||
|
|
||
| @Override | ||
| protected boolean addMockHttpTransport() { | ||
| return false; // enable http | ||
| } | ||
|
|
||
| @Override | ||
| protected String configRoles() { | ||
| return super.configRoles() + "\n" + ROLES; | ||
| } | ||
|
|
||
| @Override | ||
| protected String configUsers() { | ||
| final String usersPasswdHashed = new String(Hasher.resolve( | ||
| randomFrom("pbkdf2", "pbkdf2_1000", "bcrypt", "bcrypt9")).hash(new SecureString("passwd".toCharArray()))); | ||
|
|
||
| return super.configUsers() + | ||
| "admin:" + usersPasswdHashed + "\n" + | ||
| CREATE_DOC_USER + ":" + usersPasswdHashed + "\n"; | ||
| } | ||
|
|
||
| @Override | ||
| protected String configUsersRoles() { | ||
| return super.configUsersRoles() + USERS_ROLES; | ||
| } | ||
|
|
||
| @Before | ||
| public void insertBaseDocumentsAsAdmin() throws Exception { | ||
| Request request = new Request("PUT", "/" + INDEX_NAME + "/_doc/1"); | ||
| request.setJsonEntity(jsonDoc); | ||
| request.addParameter("refresh", "true"); | ||
| assertAccessIsAllowed("admin", request); | ||
| } | ||
|
|
||
| public void testCreateDocUserCanIndexNewDocumentsWithAutoGeneratedId() throws IOException { | ||
| assertAccessIsAllowed(CREATE_DOC_USER, "POST", "/" + INDEX_NAME + "/_doc", "{ \"foo\" : \"bar\" }"); | ||
| } | ||
|
|
||
| public void testCreateDocUserCanIndexNewDocumentsWithExternalIdAndOpTypeIsCreate() throws IOException { | ||
| assertAccessIsAllowed(CREATE_DOC_USER, randomFrom("PUT", "POST"), "/" + INDEX_NAME + "/_doc/2?op_type=create", "{ \"foo\" : " + | ||
| "\"bar\" }"); | ||
| } | ||
|
|
||
| public void testCreateDocUserIsDeniedToIndexNewDocumentsWithExternalIdAndOpTypeIsIndex() throws IOException { | ||
| assertAccessIsDenied(CREATE_DOC_USER, randomFrom("PUT", "POST"), "/" + INDEX_NAME + "/_doc/3", "{ \"foo\" : \"bar\" }"); | ||
| } | ||
|
|
||
| public void testCreateDocUserIsDeniedToIndexUpdatesToExistingDocument() throws IOException { | ||
| assertAccessIsDenied(CREATE_DOC_USER, "POST", "/" + INDEX_NAME + "/_doc/1/_update", "{ \"doc\" : { \"foo\" : \"baz\" } }"); | ||
| assertAccessIsDenied(CREATE_DOC_USER, "PUT", "/" + INDEX_NAME + "/_doc/1", "{ \"foo\" : \"baz\" }"); | ||
| } | ||
|
|
||
| public void testCreateDocUserCanIndexNewDocumentsWithAutoGeneratedIdUsingBulkApi() throws IOException { | ||
| assertAccessIsAllowed(CREATE_DOC_USER, randomFrom("PUT", "POST"), | ||
| "/" + INDEX_NAME + "/_bulk", "{ \"index\" : { } }\n{ \"foo\" : \"bar\" }\n"); | ||
| } | ||
|
|
||
| public void testCreateDocUserCanIndexNewDocumentsWithAutoGeneratedIdAndOpTypeCreateUsingBulkApi() throws IOException { | ||
| assertAccessIsAllowed(CREATE_DOC_USER, randomFrom("PUT", "POST"), | ||
| "/" + INDEX_NAME + "/_bulk", "{ \"create\" : { } }\n{ \"foo\" : \"bar\" }\n"); | ||
| } | ||
|
|
||
| public void testCreateDocUserCanIndexNewDocumentsWithExternalIdAndOpTypeIsCreateUsingBulkApi() throws IOException { | ||
| assertAccessIsAllowed(CREATE_DOC_USER, randomFrom("PUT", "POST"), | ||
| "/" + INDEX_NAME + "/_bulk", "{ \"create\" : { \"_id\" : \"4\" } }\n{ \"foo\" : \"bar\" }\n"); | ||
| } | ||
|
|
||
| public void testCreateDocUserIsDeniedToIndexNewDocumentsWithExternalIdAndOpTypeIsIndexUsingBulkApi() throws IOException { | ||
| assertBodyHasAccessIsDenied(CREATE_DOC_USER, randomFrom("PUT", "POST"), | ||
| "/" + INDEX_NAME + "/_bulk", "{ \"index\" : { \"_id\" : \"5\" } }\n{ \"foo\" : \"bar\" }\n"); | ||
| } | ||
|
|
||
| public void testCreateDocUserIsDeniedToIndexUpdatesToExistingDocumentUsingBulkApi() throws IOException { | ||
| assertBodyHasAccessIsDenied(CREATE_DOC_USER, randomFrom("PUT", "POST"), | ||
| "/" + INDEX_NAME + "/_bulk", "{ \"index\" : { \"_id\" : \"1\" } }\n{ \"doc\" : {\"foo\" : \"bazbaz\"} }\n"); | ||
| assertBodyHasAccessIsDenied(CREATE_DOC_USER, randomFrom("PUT", "POST"), | ||
| "/" + INDEX_NAME + "/_bulk", "{ \"update\" : { \"_id\" : \"1\" } }\n{ \"doc\" : {\"foo\" : \"bazbaz\"} }\n"); | ||
| } | ||
|
|
||
| } |
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.