Skip to content

Add manage-application-privileges conditional cluster privilege#32116

Merged
tvernum merged 3 commits intoelastic:security-app-privsfrom
tvernum:app-priv/conditional-priv-api
Jul 19, 2018
Merged

Add manage-application-privileges conditional cluster privilege#32116
tvernum merged 3 commits intoelastic:security-app-privsfrom
tvernum:app-priv/conditional-priv-api

Conversation

@tvernum
Copy link
Copy Markdown
Contributor

@tvernum tvernum commented Jul 17, 2018

This includes support in the Roles API and for storing in the security index.

Traditional, action-name cluster privileges are still described by a cluster: []
element in the JSON, while conditional privileges are described in a policy: {}
element (the name is subject to change).

For the roles API, and builtin roles providers (native + file) the only supported
conditional privilege is ManageApplicationPrivileges represented in JSON as:

"application" : { "manage" : { "applications" : [ "my-app",  "app-*" ] } }

which restricts the use of the Get/Put/Delete Privileges actions to those that act upon the specified application names ("my-app", "app-*")

This includes support in the Roles API and for storing in the security
index.
@tvernum tvernum added review :Security/Authorization Roles, Privileges, DLS/FLS, RBAC/ABAC labels Jul 17, 2018
@tvernum tvernum requested a review from jaymode July 17, 2018 07:42
@elasticmachine
Copy link
Copy Markdown
Collaborator

Pinging @elastic/es-security

Copy link
Copy Markdown
Member

@jaymode jaymode left a comment

Choose a reason for hiding this comment

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

This looks pretty good. I left some thoughts

applicationPrivs.add(convertApplicationPrivilege(rd.getName(), i, applicationPrivileges[i]));
}


Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: unneeded new line

}

/**
* Read a list of privileges from the parser. The parse should be positioned at the
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

s/parse/parser

public static List<ConditionalClusterPrivilege> parse(XContentParser parser) throws IOException {
List<ConditionalClusterPrivilege> privileges = new ArrayList<>();

if (parser.currentToken() == null) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this goes against the javadocs for the method and is lenient. currentToken should be start object here

public static class ManageApplicationPrivileges implements ConditionalClusterPrivilege {

private static final ClusterPrivilege PRIVILEGE = ClusterPrivilege.get(
Collections.singleton("cluster:admin/xpack/security/privilege/*")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

seeing this here make me think we need to add application in the action names. What do you think?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think this is a bigger question.
At the moment the classes, endpoints and action-names all simply refer to "privilege". When I wrote them, I had the thought that perhaps in the future we might include support for cluster & index privileges in the GET API.
I'm less convinced that's a great idea now - but if we want to rename the actions, then we should probably rename it all.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

it looks like application is not required so I am ok either way. I will leave the naming up to you


@Override
public boolean test(TransportRequest request) {
if (request instanceof GetPrivilegesRequest) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I wonder if we should have a interface like UserRequest that returns a String[] of the application names? This simplifies the code here a bit

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

👍

if (parser.currentToken() == XContentParser.Token.START_OBJECT) {
parser.nextToken();
}
expectedToken(parser.currentToken(), parser, XContentParser.Token.FIELD_NAME);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I wonder if we can be stricter here around the state of the parser?

final PutRoleRequest original = buildRandomRequest();

final BytesStreamOutput out = new BytesStreamOutput();
final Version version = randomFrom(Version.V_5_6_10, Version.V_6_0_0, Version.V_6_1_2, Version.V_6_2_4, Version.V_6_3_0);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think VersionUtils#randomVersionBetween is a better choice here

auditTrail.accessGranted(authentication, action, request, permission.names());
}


Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

extraneous newline

Copy link
Copy Markdown
Member

@jaymode jaymode left a comment

Choose a reason for hiding this comment

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

LGTM

import java.util.Collection;

/**
* Interface implemented by all Requests that managed application privileges
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

s/managed/manage


final byte[] bytes = out.toByteArray();
try (XContentParser parser = xContent.createParser(NamedXContentRegistry.EMPTY, THROW_UNSUPPORTED_OPERATION, bytes)) {
assertThat( parser.nextToken(), equalTo(XContentParser.Token.START_OBJECT));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: remove space before parser

@tvernum
Copy link
Copy Markdown
Contributor Author

tvernum commented Jul 19, 2018

run gradle build tests
(The tests failed because the HasPrivieges API doesn't support the body being in a source param, which it should, but not in this PR)

@tvernum tvernum merged commit 69a42b3 into elastic:security-app-privs Jul 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Security/Authorization Roles, Privileges, DLS/FLS, RBAC/ABAC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants