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

Improvements to authenticated JSON-RPC permissions checking #1144

Merged
merged 6 commits into from Jun 25, 2020

Conversation

macfarla
Copy link
Contributor

Exit early when checking user permissions, ie if matching permission is found, don't keep checking.
Also reordered permissions produced by JsonRpcMethod to be in descending order of granularity
Added unit test for : permission

See #1118

@macfarla macfarla requested a review from jframe June 25, 2020 02:27
Copy link
Contributor

@mark-terry mark-terry left a comment

Choose a reason for hiding this comment

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

Comments.

@@ -69,7 +69,7 @@ public void shouldReturnFalseWhenNetworkIsNotListening() {
@Test
public void getPermissions() {
List<String> permissions = method.getPermissions();
assertThat(permissions).containsExactlyInAnyOrder("net:*", "net:listening", "*:*");
assertThat(permissions).containsExactly("*:*", "net:*", "net:listening");
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the reason for this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it just made sense to have the items in order of granularity from widest to narrowest

Copy link
Contributor Author

@macfarla macfarla Jun 25, 2020

Choose a reason for hiding this comment

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

also if the permissions are checked in that order then the log.debug messages will make sense

Signed-off-by: Sally MacFarlane <sally.macfarlane@consensys.net>
@@ -53,6 +53,10 @@ public static boolean isPermitted(
foundMatchingPermission.set(true);
}
});
// exit if a matching permission was found, no need to keep checking
if (foundMatchingPermission.get()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

The more I read this code the more I think setting a flag async is not ideal...

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 don't love it either but it's not simple to change so it's not going to happen as part of this PR

Signed-off-by: Sally MacFarlane <sally.macfarlane@consensys.net>
@macfarla macfarla merged commit 06e35a5 into hyperledger:master Jun 25, 2020
@macfarla macfarla deleted the permissions-check-1118 branch June 25, 2020 23:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants