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

v2http: allow empty role for GET '/users' #5265

Merged
merged 1 commit into from
May 6, 2016
Merged

Conversation

gyuho
Copy link
Contributor

@gyuho gyuho commented May 4, 2016

Fix #5246.

@gyuho gyuho changed the title etcdserver/auth: error for non-existing roles [wip] etcdserver/auth: error for non-existing roles May 4, 2016
@gyuho gyuho changed the title [wip] etcdserver/auth: error for non-existing roles v2http: allow empty role for GET '/users' May 4, 2016
@gyuho
Copy link
Contributor Author

gyuho commented May 4, 2016

Previous:

./bin/etcdctl user add root:a
# auth: created user root

curl -L -X PUT  http://127.0.0.1:2379/v2/auth/users/root -d '{"user": "root", "grant": ["foo"]}'
# auth: updated user root

curl -L -u root http://127.0.0.1:2379/v2/auth/users
# {"message":"auth: Role foo does not exist."}

Now it returns "role":"":

./bin/etcdctl user add root:a
# User root created

curl -L -X PUT  http://127.0.0.1:2379/v2/auth/users/root -d '{"user": "root", "grant": ["foo"]}'
# auth: updated user root

curl -L -u root http://127.0.0.1:2379/v2/auth/users
# Enter host password for user 'root':
# {"users":[{"user":"root","roles":[{"role":"","permissions":{"kv":{"read":null,"write":null}}},{"role":"root","permissions":{"kv":{"read":["/*"],"write":["/*"]}}}]}]}

# server side
2016-05-04 13:58:53.028400 W | v2http: GetRole foo error (auth: Role foo does not exist.)

/cc @xiang90 @heyitsanthony

Please review.

Thanks.

writeError(w, r, err)
return
if err != nil { // in case, role does not exist
plog.Warningf("GetRole %s error (%v)", roleName, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

should this continue instead of falling through and appending an empty role?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, will fix. Thanks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just fixed. PTAL. Thanks.

Copy link
Contributor

Choose a reason for hiding this comment

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

i guess we should just remove the warning. this is nothing actually... etcd-users can assign a non-existing role to a user.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, will remove.

@gyuho gyuho force-pushed the fix_5246 branch 2 times, most recently from 3c1c0a8 to 5d358a3 Compare May 4, 2016 21:36
@heyitsanthony
Copy link
Contributor

lgtm, deferring to @xiang90

@@ -116,6 +116,29 @@ func TestV2CurlIssue5182(t *testing.T) {
}
}

func TestV2CurlIssue5246(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

this test does not really belong here. we should add a test in client_auth_test.go. e2e test is to ensure the correctness of etcdctl/etcd interaction, not to ensure the correctness of the server itself.

@gyuho
Copy link
Contributor Author

gyuho commented May 4, 2016

@xiang90 I moved the test into v2http pkg. PTAL. Thanks.

@gyuho
Copy link
Contributor Author

gyuho commented May 6, 2016

@xiang90 Now test only tests the baseUser handler (mock auth store change was needed as well).

PTAL

t.Fatal(err)
}
for _, u := range uc.Users {
if u.User == "root" {
Copy link
Contributor

Choose a reason for hiding this comment

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

first we need to ensure the user root does exist.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

first we need to ensure the user root does exist.

Can you explain more? Current output is:

{"users":[{"user":"root","roles":[{"role":"root","permissions":{"kv":{"read":["/"],"write":["/"]}}}]}]}

I thought we want to return empty role just for the non-existing foo?

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 nvm. You said does exist... :) Will fix.

Copy link
Contributor

Choose a reason for hiding this comment

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

this test does not ensure user root exist. it only fails if root exists and foo exists. it should also fail if root does not exist.

@gyuho
Copy link
Contributor Author

gyuho commented May 6, 2016

All addressed. PTAL.

t.Fatal(err)
}
rootExist := false
for _, u := range uc.Users {
Copy link
Contributor

Choose a reason for hiding this comment

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

just remove this range. get user root directly.

Copy link
Contributor

Choose a reason for hiding this comment

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

if len(us.Users) != 1 {t.fatal(...)}

u := us.Users[0]
if u.User != "root" {t.fatal()}
...

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 will fix.

@gyuho gyuho force-pushed the fix_5246 branch 2 times, most recently from 02ba10a to 433b25c Compare May 6, 2016 18:14
@gyuho
Copy link
Contributor Author

gyuho commented May 6, 2016

@xiang90 Actually, we can't check the user number because we use that mockStore for other tests, so AllUsers method returns 3 users now... https://github.com/coreos/etcd/blob/master/etcdserver/api/v2http/client_auth_test.go#L46

@xiang90
Copy link
Contributor

xiang90 commented May 6, 2016

@xiang90 Actually, we can't check the user number because we use that mockStore for other tests, so AllUsers method returns 3 users now...

Can we fix it? I do not really care about that 3 actually. I should just get the user out of the users and do what we need to do instead of ranging over every users. That makes the code more readable.

@gyuho
Copy link
Contributor Author

gyuho commented May 6, 2016

@xiang90 We can have another type of mock store for this test, or remove test cases using those 3 users. Which one do we prefer?

@xiang90
Copy link
Contributor

xiang90 commented May 6, 2016

@gyuho Which one is simpler. Or just keep the 3 there but get the root user out of them.

@gyuho
Copy link
Contributor Author

gyuho commented May 6, 2016

@xiang90 I fixed the AllUsers for mock store to make it work for our new test. Works now.

PTAL.

Thanks!

@xiang90
Copy link
Contributor

xiang90 commented May 6, 2016

LGTM

@gyuho
Copy link
Contributor Author

gyuho commented May 6, 2016

Thanks. Merging in greens.

@gyuho gyuho merged commit d17aaae into etcd-io:master May 6, 2016
@gyuho gyuho deleted the fix_5246 branch May 6, 2016 18:58
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.

None yet

3 participants