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

etcdctl: handle empty key permission correctly #8514

Merged
merged 2 commits into from
Sep 13, 2017

Conversation

mitake
Copy link
Contributor

@mitake mitake commented Sep 7, 2017

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

Copy link
Contributor

@heyitsanthony heyitsanthony left a 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]
Copy link
Contributor

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:])

Copy link
Contributor Author

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.

@mitake
Copy link
Contributor Author

mitake commented Sep 11, 2017

@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 {
Copy link
Contributor

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 {?

Copy link
Contributor Author

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
@mitake
Copy link
Contributor Author

mitake commented Sep 13, 2017

@heyitsanthony @gyuho updated based on @gyuho 's latest comment, could you take a look?

Copy link
Contributor

@heyitsanthony heyitsanthony left a comment

Choose a reason for hiding this comment

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

lgtm thanks

@mitake
Copy link
Contributor Author

mitake commented Sep 13, 2017

@heyitsanthony thanks, I'm merging it.

@mitake mitake merged commit 1b85dad into etcd-io:master Sep 13, 2017
@mitake mitake deleted the empty-key-perm branch September 13, 2017 08:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

etcdctl role grant-permission --from-key '' is not effect
3 participants