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

etcdserver: do not allow creating empty role #10907

Merged
merged 1 commit into from
Jul 25, 2019

Conversation

spzala
Copy link
Member

@spzala spzala commented Jul 19, 2019

Like user, we should not allow creating empty role.

Related #10905

@jingyih
Copy link
Contributor

jingyih commented Jul 19, 2019

Might be a good chance to add more description to the APIs? For example:

etcd/auth/store.go

Lines 114 to 115 in 828225c

// UserAdd adds a new user
UserAdd(r *pb.AuthUserAddRequest) (*pb.AuthUserAddResponse, error)

etcd/auth/store.go

Lines 132 to 133 in 828225c

// RoleAdd adds a new role
RoleAdd(r *pb.AuthRoleAddRequest) (*pb.AuthRoleAddResponse, error)

@spzala
Copy link
Member Author

spzala commented Jul 19, 2019

Might be a good chance to add more description to the APIs? For example:

etcd/auth/store.go

Lines 114 to 115 in 828225c

// UserAdd adds a new user
UserAdd(r *pb.AuthUserAddRequest) (*pb.AuthUserAddResponse, error)

etcd/auth/store.go

Lines 132 to 133 in 828225c

// RoleAdd adds a new role
RoleAdd(r *pb.AuthRoleAddRequest) (*pb.AuthRoleAddResponse, error)

Thanks @jingyih I updated the commit, does that look OK?

@jingyih
Copy link
Contributor

jingyih commented Jul 20, 2019

Thanks @jingyih I updated the commit, does that look OK?

Thanks for adding more description.

I understand the existing pattern is to check for empty user name during apply. Have we considered moving the check prior to sending request to Raft, so the request fails faster?
cc @mitake

@spzala
Copy link
Member Author

spzala commented Jul 20, 2019

Thanks @jingyih I updated the commit, does that look OK?

Thanks for adding more description.

I understand the existing pattern is to check for empty user name during apply. Have we considered moving the check prior to sending request to Raft, so the request fails faster?
cc @mitake

@jingyih np and thank you! I initially and naturally thought of doing so i.e. to return error in etcdctl role_command and clientv3/auth but as you noticed I have tried following how user name is being handled currently. Let's wait on comment from @mitake

@jingyih
Copy link
Contributor

jingyih commented Jul 20, 2019

Sounds good.

On the server side this can also be done earlier:

func (as *AuthServer) RoleAdd(ctx context.Context, r *pb.AuthRoleAddRequest) (*pb.AuthRoleAddResponse, error) {

@spzala
Copy link
Member Author

spzala commented Jul 21, 2019

OK, that sounds great. Thanks @jingyih

@mitake
Copy link
Contributor

mitake commented Jul 21, 2019

@spzala @jingyih thanks for doing this! I think the error checking should be in the state machine layer as implemented in this PR because it is more defensive than checking in the API layer. Even if something in the API layer is broken by the future change, the state machine layer can deny it. I think it is safer.
Also operations of role creation doesn't happen so much (unlike reading/writing keys). The overhead passing the log entry to the Raft layer wouldn't be a problem.
However it can potentially change the behavior of existing clusters which have empty roles (although such a situation isn't good). Probably writing it to the changelog would be user friendly, I think.

@spzala
Copy link
Member Author

spzala commented Jul 21, 2019

@mitake hello, thank you so much for the quick comment!! Agree, I don't see a real good reason to create empty role besides playing with it or accident. For courtesy writing to changelog sounds good too. I will defer to @jingyih for a decision.

@jingyih
Copy link
Contributor

jingyih commented Jul 21, 2019

@mitake Thanks for the explanation. It makes sense to me.

@spzala I agree we should document the change. What is the current behavior when user try to create a role with empty name? Reading from the bug report, it looks like server will crash, and client will get an error with code = Unavailable. With this PR, client will get an error with code = InvalidArgument. Is my understanding correct?

@spzala
Copy link
Member Author

spzala commented Jul 21, 2019

@jingyih yup, you understood it correct! I guess this will go in the CHANGELOG-3.4, should I update it under this PR or as a follow up once this gets merged? Thanks!

@jingyih
Copy link
Contributor

jingyih commented Jul 23, 2019

I think either is fine. Maybe simply push a commit to update the change log?

Copy link
Contributor

@jingyih jingyih left a comment

Choose a reason for hiding this comment

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

lgtm after nits.

auth/store.go Outdated
@@ -796,6 +797,11 @@ func (as *authStore) RoleDelete(r *pb.AuthRoleDeleteRequest) (*pb.AuthRoleDelete
}

func (as *authStore) RoleAdd(r *pb.AuthRoleAddRequest) (*pb.AuthRoleAddResponse, error) {

Copy link
Contributor

Choose a reason for hiding this comment

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

remove the leading empty line?

Copy link
Member Author

Choose a reason for hiding this comment

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

Agree. Thanks!

@spzala spzala force-pushed the emptyrole10905 branch 2 times, most recently from b7a6554 to 90f410b Compare July 23, 2019 04:11
@spzala
Copy link
Member Author

spzala commented Jul 23, 2019

Thanks @jingyih I have also updated the changelog!

@spzala
Copy link
Member Author

spzala commented Jul 23, 2019

/cc @xiang90

@codecov-io
Copy link

codecov-io commented Jul 23, 2019

Codecov Report

Merging #10907 into master will increase coverage by 0.05%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #10907      +/-   ##
==========================================
+ Coverage   63.25%   63.31%   +0.05%     
==========================================
  Files         400      400              
  Lines       37687    37689       +2     
==========================================
+ Hits        23839    23861      +22     
+ Misses      12252    12232      -20     
  Partials     1596     1596
Impacted Files Coverage Δ
etcdserver/api/v3rpc/util.go 51.61% <ø> (ø) ⬆️
etcdserver/api/v3rpc/rpctypes/error.go 90.47% <ø> (ø) ⬆️
auth/store.go 45.59% <100%> (+0.13%) ⬆️
client/client.go 68.3% <0%> (-5.23%) ⬇️
clientv3/leasing/cache.go 87.22% <0%> (-4.45%) ⬇️
clientv3/auth.go 59.74% <0%> (-2.6%) ⬇️
clientv3/balancer/balancer.go 84.12% <0%> (-2.39%) ⬇️
clientv3/leasing/kv.go 89.03% <0%> (-2.33%) ⬇️
clientv3/op.go 72.5% <0%> (-1.25%) ⬇️
clientv3/balancer/grpc1.7-health.go 58.43% <0%> (-0.88%) ⬇️
... and 15 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d137fa9...1cef112. Read the comment docs.

Like user, we should not allow creating empty role.

Related etcd-io#10905
@spzala
Copy link
Member Author

spzala commented Jul 25, 2019

@jingyih there was a merge conflict on changelog which I have fixed now. Please take a look now. It will be great if we can merge this one after your final review, considering we may have few more updates on changelog due to 3.4 release, to avoid any further conflicts :-). Thanks!

@jingyih
Copy link
Contributor

jingyih commented Jul 25, 2019

lgtm. Thanks for fixing this.

@jingyih jingyih merged commit 425b654 into etcd-io:master Jul 25, 2019
@spzala
Copy link
Member Author

spzala commented Jul 25, 2019

@jingyih yrw, thank you so much for the quick review!!

@spzala spzala deleted the emptyrole10905 branch September 13, 2019 17:18
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.

4 participants