-
Notifications
You must be signed in to change notification settings - Fork 25.3k
WIldcard IndicesPermissions don't cover .security #36765
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
Closed
albertzaharovits
wants to merge
26
commits into
elastic:master
from
albertzaharovits:strict_privilege_take_3
Closed
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
fa07a97
Names
albertzaharovits c12fa0e
getting there
albertzaharovits 59ff695
HashCode and trimms
albertzaharovits 536640d
HasPrivilege
albertzaharovits 4ee6cbd
Husling
albertzaharovits ac9ec5a
ReservedRolesStore
albertzaharovits 52e7c2a
Merge branch 'master' into strict_privilege_take_3
albertzaharovits c806970
Trimming
albertzaharovits c7f7f2b
AuthorizedIndices remove hack + tests
albertzaharovits f77fff1
More tests and checkstyle
albertzaharovits 2e92793
Javadoc and renames
albertzaharovits 6750306
two comments
albertzaharovits b6ea0b3
import static
albertzaharovits 527a22e
import static
albertzaharovits 82577ba
Merge branch 'backup_security_index' into strict_privilege_take_3
albertzaharovits 4340bcc
Merge branch 'backup_security_index' into strict_privilege_take_3
albertzaharovits 2a3f38d
Fix check
albertzaharovits aadd062
Implicit authorize monitoring passthrough
albertzaharovits d63577d
import static
albertzaharovits 7759040
Merge branch 'backup_security_index' into strict_privilege_take_3
albertzaharovits eaa4eb2
Merge branch 'master' into strict_privilege_take_3
albertzaharovits ee7e2c2
review nits
albertzaharovits d6191cf
Compilation minor error
albertzaharovits 55aefb6
Merge branch 'master' into strict_privilege_take_3
albertzaharovits 9f6c739
RoleDescriptor allow_restricted_indices
albertzaharovits e50ebfc
Mapping
albertzaharovits 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -428,6 +428,7 @@ private static RoleDescriptor.IndicesPrivileges parseIndex(String roleName, XCon | |
String[] privileges = null; | ||
String[] grantedFields = null; | ||
String[] deniedFields = null; | ||
boolean allow_restricted_indices = false; | ||
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { | ||
if (token == XContentParser.Token.FIELD_NAME) { | ||
currentFieldName = parser.currentName(); | ||
|
@@ -444,6 +445,13 @@ private static RoleDescriptor.IndicesPrivileges parseIndex(String roleName, XCon | |
throw new ElasticsearchParseException("failed to parse indices privileges for role [{}]. expected field [{}] " + | ||
"value to be a string or an array of strings, but found [{}] instead", roleName, currentFieldName, token); | ||
} | ||
} else if (Fields.ALLOW_RESTRICTED_INDICES.match(currentFieldName, parser.getDeprecationHandler())) { | ||
if (token == XContentParser.Token.VALUE_BOOLEAN) { | ||
allow_restricted_indices = parser.booleanValue(); | ||
} else { | ||
throw new ElasticsearchParseException("failed to parse indices privileges for role [{}]. expected field [{}] " + | ||
"value to be a boolean, but found [{}] instead", roleName, currentFieldName, token); | ||
} | ||
} else if (Fields.QUERY.match(currentFieldName, parser.getDeprecationHandler())) { | ||
if (token == XContentParser.Token.START_OBJECT) { | ||
XContentBuilder builder = JsonXContent.contentBuilder(); | ||
|
@@ -543,6 +551,7 @@ private static RoleDescriptor.IndicesPrivileges parseIndex(String roleName, XCon | |
.grantedFields(grantedFields) | ||
.deniedFields(deniedFields) | ||
.query(query) | ||
.allowRestrictedIndices(allow_restricted_indices) | ||
.build(); | ||
} | ||
|
||
|
@@ -590,6 +599,10 @@ public static class IndicesPrivileges implements ToXContentObject, Writeable { | |
private String[] grantedFields = null; | ||
private String[] deniedFields = null; | ||
private BytesReference query; | ||
// by default certain restricted indices are exempted when granting privileges, as they should generally be hidden for ordinary | ||
// users. Setting this flag eliminates this special status, and any index name pattern in the permission will cover restricted | ||
// indices as well. | ||
private boolean allow_restricted_indices = false; | ||
|
||
private IndicesPrivileges() { | ||
} | ||
|
@@ -600,6 +613,11 @@ public IndicesPrivileges(StreamInput in) throws IOException { | |
this.deniedFields = in.readOptionalStringArray(); | ||
this.privileges = in.readStringArray(); | ||
this.query = in.readOptionalBytesReference(); | ||
if (in.getVersion().onOrAfter(Version.V_6_7_0)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is right for the end-goal when we backport this to 6.7, but it will cause BWC to fail when it is merged to |
||
allow_restricted_indices = in.readBoolean(); | ||
} else { | ||
allow_restricted_indices = false; | ||
} | ||
} | ||
|
||
@Override | ||
|
@@ -609,6 +627,9 @@ public void writeTo(StreamOutput out) throws IOException { | |
out.writeOptionalStringArray(deniedFields); | ||
out.writeStringArray(privileges); | ||
out.writeOptionalBytesReference(query); | ||
if (out.getVersion().onOrAfter(Version.V_6_7_0)) { | ||
out.writeBoolean(allow_restricted_indices); | ||
} | ||
} | ||
|
||
public static Builder builder() { | ||
|
@@ -646,6 +667,10 @@ public boolean isUsingFieldLevelSecurity() { | |
return hasDeniedFields() || hasGrantedFields(); | ||
} | ||
|
||
public boolean allowsRestrictedIndices() { | ||
return allow_restricted_indices; | ||
} | ||
|
||
private boolean hasDeniedFields() { | ||
return deniedFields != null && deniedFields.length > 0; | ||
} | ||
|
@@ -666,6 +691,7 @@ private boolean hasGrantedFields() { | |
public String toString() { | ||
StringBuilder sb = new StringBuilder("IndicesPrivileges["); | ||
sb.append("indices=[").append(Strings.arrayToCommaDelimitedString(indices)); | ||
sb.append("], allows_restricted_indices=[").append(allow_restricted_indices); | ||
sb.append("], privileges=[").append(Strings.arrayToCommaDelimitedString(privileges)); | ||
sb.append("], "); | ||
if (grantedFields != null || deniedFields != null) { | ||
|
@@ -702,6 +728,7 @@ public boolean equals(Object o) { | |
IndicesPrivileges that = (IndicesPrivileges) o; | ||
|
||
if (!Arrays.equals(indices, that.indices)) return false; | ||
if (allow_restricted_indices != that.allow_restricted_indices) return false; | ||
if (!Arrays.equals(privileges, that.privileges)) return false; | ||
if (!Arrays.equals(grantedFields, that.grantedFields)) return false; | ||
if (!Arrays.equals(deniedFields, that.deniedFields)) return false; | ||
|
@@ -711,6 +738,7 @@ public boolean equals(Object o) { | |
@Override | ||
public int hashCode() { | ||
int result = Arrays.hashCode(indices); | ||
result = 31 * result + (allow_restricted_indices ? 1 : 0); | ||
result = 31 * result + Arrays.hashCode(privileges); | ||
result = 31 * result + Arrays.hashCode(grantedFields); | ||
result = 31 * result + Arrays.hashCode(deniedFields); | ||
|
@@ -736,6 +764,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws | |
if (query != null) { | ||
builder.field("query", query.utf8ToString()); | ||
} | ||
builder.field(RoleDescriptor.Fields.ALLOW_RESTRICTED_INDICES.getPreferredName(), allow_restricted_indices); | ||
return builder.endObject(); | ||
} | ||
|
||
|
@@ -774,6 +803,11 @@ public Builder query(@Nullable String query) { | |
return query(query == null ? null : new BytesArray(query)); | ||
} | ||
|
||
public Builder allowRestrictedIndices(boolean allow) { | ||
indicesPrivileges.allow_restricted_indices = allow; | ||
return this; | ||
} | ||
|
||
public Builder query(@Nullable BytesReference query) { | ||
if (query == null) { | ||
indicesPrivileges.query = null; | ||
|
@@ -954,6 +988,7 @@ public interface Fields { | |
ParseField APPLICATIONS = new ParseField("applications"); | ||
ParseField RUN_AS = new ParseField("run_as"); | ||
ParseField NAMES = new ParseField("names"); | ||
ParseField ALLOW_RESTRICTED_INDICES = new ParseField("allow_restricted_indices"); | ||
ParseField RESOURCES = new ParseField("resources"); | ||
ParseField QUERY = new ParseField("query"); | ||
ParseField PRIVILEGES = new ParseField("privileges"); | ||
|
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be
camelCase
notsnake_case