-
Notifications
You must be signed in to change notification settings - Fork 891
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
Conversation
Signed-off-by: Sally MacFarlane <sally.macfarlane@consensys.net>
…missions-check-1118
…missions-check-1118
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.
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"); |
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.
What's the reason for this change?
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.
it just made sense to have the items in order of granularity from widest to narrowest
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.
also if the permissions are checked in that order then the log.debug messages will make sense
.../main/java/org/hyperledger/besu/ethereum/api/jsonrpc/authentication/AuthenticationUtils.java
Outdated
Show resolved
Hide resolved
.../src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/JsonRpcMethod.java
Show resolved
Hide resolved
.../main/java/org/hyperledger/besu/ethereum/api/jsonrpc/authentication/AuthenticationUtils.java
Outdated
Show resolved
Hide resolved
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()) { |
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.
The more I read this code the more I think setting a flag async is not ideal...
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.
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>
…missions-check-1118
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