Skip to content
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

[HLRC] Put Role #36209

Merged
merged 27 commits into from
Dec 10, 2018
Merged

Conversation

albertzaharovits
Copy link
Contributor

This commit adds support for the put role API in the java high level rest client.

Related #29827
cc @elastic/es-security

@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-features

@@ -217,12 +217,12 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
builder.startObject();
builder.field(NAMES.getPreferredName(), indices);
builder.field(PRIVILEGES.getPreferredName(), privileges);
if (isUsingFieldLevelSecurity()) {
if (grantedFields != null || deniedFields != null) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Although the previous condition was correctly from the server logic stand point, it would hinder testing in IndicesPrivilegesTests.

PARSER.declareObject(constructorArg(), (parser, c) -> parser.map(), METADATA);
PARSER.declareObject(constructorArg(), (parser, c) -> parser.map(), TRANSIENT_METADATA);
PARSER.declareObject(optionalConstructorArg(), (parser, c) -> parser.map(), METADATA);
PARSER.declareObject(optionalConstructorArg(), (parser, c) -> parser.map(), TRANSIENT_METADATA);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Again this was correct judging by the server logic but XContentTests serialize and deserialize roles with null metadata and then test for equality.

Objects.requireNonNull(transientMetadata, "Transient metadata cannot be null. Pass an empty map instead.");
return this;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Transient metadata cannot be set in the builder, by the client, it is created only by the server.

}

@Override
public int hashCode() {
return Objects.hash(name, clusterPrivileges, globalApplicationPrivileges, indicesPrivileges, applicationResourcePrivileges,
runAsPrivilege, metadata, transientMetadata);
runAsPrivilege, metadata);
Copy link
Contributor Author

@albertzaharovits albertzaharovits Dec 4, 2018

Choose a reason for hiding this comment

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

transient metadata is a read only field when retrieving the Role and cannot be set on a put Role.
It should not matter in an equals because a user should be able to create a role that is equal to another one, except for the transient part over which it has no control (cannot set it himself)

Copy link
Member

Choose a reason for hiding this comment

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

Is a (retrieved) enabled role equal (for a client) to a disabled role ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In principle yes because the enabled status is included in the transientMetadata which is not counted by equals. In practice I don't know how the client could get hold of a disabled role (probably before disabling it).

Do you have some scenario in mind when you think transientMetadata would be something the client should touch?

Copy link
Member

Choose a reason for hiding this comment

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

In principle yes because the enabled status is included in the transientMetadata which is not counted by equals.

Yes, this is what we have now. My (poorly stated) stated question was whether we think it should be this way or not.

In practice I don't know how the client could get hold of a disabled role (probably before disabling it).

A role that has DLS/FLS for a user that was on platinum but is now on Gold maybe.

Do you have some scenario in mind when you think transientMetadata would be something the client should touch?

No not specifically. I was just wondering if the client should be able to distinguish between the same role being enabled or disabled by comparing the role objects

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is similar to the enabled flag on the user. I think the Role that is included in a PutRoleRequest should contain only fields that the client can change. transientMetadata is a field that is read only, and it is a compromise because the Role is also part of the GetRolesResponse . We can completely pull out transientMetadata from the Role and present it other way in the Get Roles API. GetRolesResponse would be having some sort of transientMetadata field. Do you see this preferable?

Copy link
Member

Choose a reason for hiding this comment

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

I think it's clearer.. I'm now circling back to our discussion regarding Role when I started with the GetRoles API and it's much clearer what you were saying back then. I probably should have done it in the get roles effort but it wasn't obvious at that point, sorry ❤️

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it's clearer too. I will make the change in this PR, instead of opening a new one, because Role was "synthetically" created and was expected to change as APIs suit it. But we need to get this PR in before 6.6 so as not to be breaking because it will change GetRolesResponse.
Sounds like a plan?

Copy link
Contributor

Choose a reason for hiding this comment

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

another approach that might help here is PutRoleRequest.Builder which implicitly uses Role.Builder but does not build the transient part to build Role.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bizybot I prefer to pass the Role to the PutRoleRequest and not take fields apart to call builder methods.

@@ -1023,18 +1019,63 @@ public void onFailure(Exception e) {
}
}

// TODO: move all calls to high-level REST client once APIs for adding new role exist
Copy link
Member

Choose a reason for hiding this comment

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

❤️

docs/java-rest/high-level/security/put-role.asciidoc Outdated Show resolved Hide resolved
Copy link
Contributor

@bizybot bizybot left a comment

Choose a reason for hiding this comment

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

Overall LGTM, left some comments.

@@ -49,7 +49,7 @@

// When categories change, adapting this field should suffice. Categories are NOT
// opaque "named_objects", we wish to maintain control over these namespaces
static final List<String> CATEGORIES = Collections.unmodifiableList(Arrays.asList("application"));
public static final List<String> CATEGORIES = Collections.unmodifiableList(Arrays.asList("application"));
Copy link
Contributor

Choose a reason for hiding this comment

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

Collections.singletonList if we do not have other categories for now.

@@ -329,6 +326,9 @@ public Role build() {
public static final String MANAGE_PIPELINE = "manage_pipeline";
public static final String MANAGE_CCR = "manage_ccr";
public static final String READ_CCR = "read_ccr";
public static final String[] ARRAY = new String[] { NONE, ALL, MONITOR, MONITOR_ML, MONITOR_WATCHER, MONITOR_ROLLUP, MANAGE,
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should rename this constant to something that represents the meaning.

@@ -349,6 +349,8 @@ public Role build() {
public static final String CREATE_INDEX = "create_index";
public static final String VIEW_INDEX_METADATA = "view_index_metadata";
public static final String MANAGE_FOLLOW_INDEX = "manage_follow_index";
public static final String[] ARRAY = new String[] { NONE, ALL, READ, READ_CROSS, CREATE, INDEX, DELETE, WRITE, MONITOR, MANAGE,
Copy link
Contributor

Choose a reason for hiding this comment

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

same here

}

@Override
public int hashCode() {
return Objects.hash(name, clusterPrivileges, globalApplicationPrivileges, indicesPrivileges, applicationResourcePrivileges,
runAsPrivilege, metadata, transientMetadata);
runAsPrivilege, metadata);
Copy link
Contributor

Choose a reason for hiding this comment

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

another approach that might help here is PutRoleRequest.Builder which implicitly uses Role.Builder but does not build the transient part to build Role.

if (role.getMetadata() != null) {
builder.field(Role.METADATA.getPreferredName(), role.getMetadata());
}
if (role.getTransientMetadata() != null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should not write this for PutRoleRequest.

@albertzaharovits
Copy link
Contributor Author

@jkakavas @bizybot Thanks for the eyes. I have made the change to pull out transientMetadata out of Role.
May you please review it again?

Copy link
Member

@jkakavas jkakavas left a comment

Choose a reason for hiding this comment

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

LGTM Albert, thanks for taking care of GetRolesResponse too.

Copy link
Contributor

@bizybot bizybot left a comment

Choose a reason for hiding this comment

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

LGTM, Thank you.

@albertzaharovits albertzaharovits merged commit dad6f1c into elastic:master Dec 10, 2018
@albertzaharovits albertzaharovits deleted the hlrc_put_role_2 branch December 10, 2018 10:24
albertzaharovits added a commit that referenced this pull request Dec 10, 2018
This commit adds support for the put role API in the
java high level rest client.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants