-
Notifications
You must be signed in to change notification settings - Fork 9.8k
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
etcdctl: handle empty key permission correctly #8514
Conversation
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.
one nit about code duplication, but otherwise looks OK. Thanks!
rangeEnd, rerr := rangeEndFromPermFlags(args[2:]) | ||
if rerr != nil { | ||
ExitWithError(ExitBadArgs, rerr) | ||
key := args[2] |
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.
dedup code into shared function?
key, rangeEnd := permRange(args[2:])
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.
ok, I'll dedup them. Thanks for the comment.
2824811
to
496f5a7
Compare
@heyitsanthony updated based on your comment, could you take a look? |
// so the empty prefix which should be matched with every key must be like this ["\x00", <end>). | ||
key = "\x00" | ||
if rolePermPrefix || rolePermFromKey { | ||
if rolePermPrefix && rolePermFromKey { |
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.
This if rolePermPrefix && rolePermFromKey
block can be before if rolePermPrefix || rolePermFromKey {
?
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.
Yes, they should be swapped clearly... thanks for pointing out!
Current `etcdctl role grant-permission` doesn't handle an empty key ("") correctly. Because the range permissions are treated as BytesAffineInterval internally, just specifying the empty key as a beginning of range introduces an invalid permission which doesn't work and betray users' intuition. This commit fix the way of handling empty key as a prefix or from key in permission granting. Fix etcd-io#8494
496f5a7
to
e4c0e11
Compare
@heyitsanthony @gyuho updated based on @gyuho 's latest comment, could you take a look? |
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.
lgtm thanks
@heyitsanthony thanks, I'm merging it. |
Current
etcdctl role grant-permission
doesn't handle an empty key("") correctly. Because the range permissions are treated as
BytesAffineInterval internally, just specifying the empty key as a
beginning of range introduces an invalid permission which doesn't work
and betray users' intuition. This commit Fix the way of handling empty
key as a prefix or from key in permission granting.
Fix #8494
/cc @zyf0330 @heyitsanthony