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

Remove principal + Allow updates to built-in users + Fix ccn/issues/66, ccn/issues/68 #44

Merged
merged 3 commits into from
Dec 14, 2016

Conversation

yuva29
Copy link
Contributor

@yuva29 yuva29 commented Dec 14, 2016

This PR addresses the following

  1. Removes Principal from local user management and authN workflow (everything is now string <username, group name>)

  2. Allows any update to built-in user (its treated like any other normal user except that DELETE is not allowed). Updated documentation here https://github.com/contiv/ccn_proxy/wiki/Local-User-Management-API

  3. Fixes https://github.com/contiv/ccn/issues/66, Fixes https://github.com/contiv/ccn/issues/67
    Signed-off-by: Yuva Shankar [email protected]

@yuva29 yuva29 changed the title Remove principal + Allow updates to built-in users + Fix ccn/issues/66 Remove principal + Allow updates to built-in users + Fix ccn/issues/66, ccn/issues/68 Dec 14, 2016
Copy link
Contributor

@rhim rhim left a comment

Choose a reason for hiding this comment

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

Mostly looks good, just a single concern on update of username. PTAL.

@@ -171,7 +150,7 @@ func (s *dbSuite) TestUpdateLocalUser(c *C) {
c.Assert(err, IsNil)

// change the username and update
user.LocalUser.Username = username + "_u"
user.Username = username + "_u"
Copy link
Contributor

Choose a reason for hiding this comment

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

since username is key, this should not be updatable. Only updatable fields should be disable, password, first/last name etc. So would this update silently drop the changed username?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch. Its a wrong use case. I'm changing it. Regarding the update logic, Update(username, newObj)==> deletes the record pointed by given username and adds newObj. https://github.com/contiv/ccn_proxy/pull/44/files#diff-d90b925ca5c4775e0b93a79d97cd12a7R118

the logic of dropping the username(if its getting updated) is pushed to the caller. https://github.com/contiv/ccn_proxy/pull/44/files#diff-e3696ffa263920e5e893b642474ab92cR276

As the library functions are called directly from test code(without going through helper) this new object will be updated with the new username. Let me know what you think of this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rhim Changed update() to overwrite rather delete+add. PTAL.

@@ -176,6 +176,7 @@ func adminOnly(handler func(*auth.Token, http.ResponseWriter, *http.Request)) fu
// convert token from string to Token type
token, err := auth.ParseToken(tokenStr)
if err != nil {
log.Infof("From here???")
Copy link
Contributor

Choose a reason for hiding this comment

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

what does this info msg mean?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed it. Added to debug one of the test failure.


// search the data store for old username
oldUser, err := GetLocalUser(username)
oldUser, err := GetLocalUser(user.Username)
Copy link
Contributor

Choose a reason for hiding this comment

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

see earlier comments. username should not be updatable, specifically since it might have authorizations against it.

@yuva29 yuva29 force-pushed the rm_principal branch 2 times, most recently from 1a06b71 to 8594315 Compare December 14, 2016 19:07
Copy link
Contributor

@rhim rhim left a comment

Choose a reason for hiding this comment

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

LGTM.

@yuva29 yuva29 merged commit 08b2bcf into contiv:master Dec 14, 2016
// return values:
// error: as returned by AddLocalUser, DeleteLocalUser
func UpdateLocalUser(username string, user *types.InternalLocalUser) error {
func UpdateLocalUser(username string, user *types.LocalUser) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

Whoa whoa whoa, I didn't notice this when this was first added... why are we deleting the user record and then replacing it with a completely new one instead of just doing a get + set? This is strictly an edge case, but because our datastore is not guaranteed to support transactions, we shouldn't be doing it this way.

What is the value of delete + create vs. updating in place?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah. I changed to overwrite now.

// 200 (fetch was successful)
// 404 (bad request; user not found)
// 200 (OK; fetch was successful)
// 404 (NotFound; bad request; user not found)
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment is a bit misleading: "bad request" has a very specific meaning in HTTP, and this is not a bad request according to that meaning. I'd delete those two words here

updatedUserObj.Principal.Role = role
func updateLocalUserInfo(username string, updateReq *types.LocalUser, actual *types.LocalUser) (int, []byte) {
updatedUserObj := &types.LocalUser{
// username == actual.Username
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the purpose of this comment? It doesn't seem to communicate anything different than the line below it... if it's legitimately trying to communicate something non-obvious, writing it as a normal sentence would be more clear

Role: updatedUserObj.Principal.Role.String(),
}
updatedUserObj.Password = ""
updatedUserObj.PasswordHash = []byte{}
Copy link
Contributor

Choose a reason for hiding this comment

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

Not a requested change but more of a general comment: we should probably have a Sanitize() function for preparing objects like this for display (hiding private fields and so on) instead of having to manually edit fields. It's easier to audit that every place we send data back to the user is calling Sanitize() than to inspect the whole callstack to make sure that certain fields were cleared out at some point, and it also gives us a central location to add fields to in the future.

dseevr pushed a commit to dseevr-dev/auth_proxy that referenced this pull request Dec 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants