Skip to content

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
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
fa07a97
Names
albertzaharovits Dec 18, 2018
c12fa0e
getting there
albertzaharovits Dec 18, 2018
59ff695
HashCode and trimms
albertzaharovits Dec 18, 2018
536640d
HasPrivilege
albertzaharovits Dec 18, 2018
4ee6cbd
Husling
albertzaharovits Dec 18, 2018
ac9ec5a
ReservedRolesStore
albertzaharovits Dec 18, 2018
52e7c2a
Merge branch 'master' into strict_privilege_take_3
albertzaharovits Dec 18, 2018
c806970
Trimming
albertzaharovits Dec 18, 2018
c7f7f2b
AuthorizedIndices remove hack + tests
albertzaharovits Dec 19, 2018
f77fff1
More tests and checkstyle
albertzaharovits Dec 19, 2018
2e92793
Javadoc and renames
albertzaharovits Dec 19, 2018
6750306
two comments
albertzaharovits Dec 19, 2018
b6ea0b3
import static
albertzaharovits Dec 19, 2018
527a22e
import static
albertzaharovits Dec 19, 2018
82577ba
Merge branch 'backup_security_index' into strict_privilege_take_3
albertzaharovits Dec 20, 2018
4340bcc
Merge branch 'backup_security_index' into strict_privilege_take_3
albertzaharovits Dec 24, 2018
2a3f38d
Fix check
albertzaharovits Dec 25, 2018
aadd062
Implicit authorize monitoring passthrough
albertzaharovits Dec 25, 2018
d63577d
import static
albertzaharovits Dec 26, 2018
7759040
Merge branch 'backup_security_index' into strict_privilege_take_3
albertzaharovits Jan 8, 2019
eaa4eb2
Merge branch 'master' into strict_privilege_take_3
albertzaharovits Jan 9, 2019
ee7e2c2
review nits
albertzaharovits Jan 9, 2019
d6191cf
Compilation minor error
albertzaharovits Jan 9, 2019
55aefb6
Merge branch 'master' into strict_privilege_take_3
albertzaharovits Jan 15, 2019
9f6c739
RoleDescriptor allow_restricted_indices
albertzaharovits Jan 15, 2019
e50ebfc
Mapping
albertzaharovits Jan 15, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -543,6 +551,7 @@ private static RoleDescriptor.IndicesPrivileges parseIndex(String roleName, XCon
.grantedFields(grantedFields)
.deniedFields(deniedFields)
.query(query)
.allowRestrictedIndices(allow_restricted_indices)
.build();
}

Expand Down Expand Up @@ -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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be camelCase not snake_case


private IndicesPrivileges() {
}
Expand All @@ -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)) {
Copy link
Contributor

Choose a reason for hiding this comment

The 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 master as 6.7 won't be including the boolean field in the stream yet.
We typically commit it as V_7_0_0 and then update it to V6_7_0 at time of backport.

allow_restricted_indices = in.readBoolean();
} else {
allow_restricted_indices = false;
}
}

@Override
Expand All @@ -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() {
Expand Down Expand Up @@ -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;
}
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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();
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down
Loading