Skip to content
This repository has been archived by the owner on Jul 7, 2020. It is now read-only.

improve sudo, not fixing existing bugs yet ref T68510 #242

Merged
merged 6 commits into from
May 25, 2017
Merged

Conversation

satang500
Copy link
Contributor

  • only show sudo button to users who have access
  • sudo should not require logging in again, but should still require confirmation

Copy link
Contributor

@tedpearson tedpearson left a comment

Choose a reason for hiding this comment

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

I am extremely concerned about the security of this approach. I would recommend completely rethinking the design of this feature before proceeding.

}
if( inner != null && inner.isAdmin(user)) {
return true;
} else if (outer != null && outer.isAdmin(user)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

There's no need for an "else if" since you are returning from the "if" above.

@@ -111,6 +111,10 @@ public User authenticate(String username, String secret) {
return authentication.authenticate(username, secret);
}

public boolean isamdin(User user) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Incorrect spelling

Copy link
Contributor

Choose a reason for hiding this comment

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

What @tedpearson meant is camel case isAdmin is the convention

Copy link
Contributor

Choose a reason for hiding this comment

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

What i meant is that "amdin" is not a word.

} else {
alertify.error("Unknown token name " + tokenName);
return;
}
var username = $.trim(usernameInput.value);
var password = passwordInput.value;
passwordCache = passwordInput.value;
Copy link
Contributor

Choose a reason for hiding this comment

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

I would HIGHLY DISCOURAGE any attempt to save ldap passwords on the browser side. I recommend that we completely change our approach to something that does not involve the caching of passwords on the browser.

Copy link

@jhorwit2 jhorwit2 May 18, 2017

Choose a reason for hiding this comment

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

You should be using a secure https only cookie that cannot be accessed by js and that gets refreshed on every request so that it doesn't expire unless there is a period of inactivity greater than the ttl.

Choose a reason for hiding this comment

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

Ah, i see what this does. Yeah, caching in memory isn't great. It's visible in the call stack of anything in this require block.

Copy link
Contributor

@yuesong yuesong left a comment

Choose a reason for hiding this comment

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

Thanks. This is a good PR. Most comments are related to coding styles and possible simplification. End user functionality appears to be working properly.

The only thing that I didn't see is that sudo should timeout automatically after a short period of time, e.g. 15 minutes.

Merging master into this PR would make review easier.

var token = Cookies.get("token");
if(app.issudo(username, token)) {
app.sudoCb(false, true);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not move this block of code to the success handler of /update/settings a few lines below? They both use username and token cookies and handle sudo checkbox value and visibility.

@@ -111,6 +119,27 @@ function(
}
});
},
issudo: function(username, token) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd rename this function to isadmin to match endpoint name

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will change

app.sudoCb(false, true);
} else {
app.sudoCb(false, false);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of the explicit if/else, you can use response directly:

app.sudoCb(false, response == 'true')

or assign it to a variable called visible to make the code more self-documenting

data: {
username: username,
token: token,
sudo: Cookies.get("sudo"),
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 extra trailing ,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nice catch. will remove.

sudo:function() {
var sudoUrl = app.authprefix() + "/authentication/sudo";
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider refactor this function - I feel the way it mixes username/token validation and unsudo makes it less readable than it can be.

@@ -34,6 +35,7 @@

private static final Logger log = LoggerFactory.getLogger(PermissionsManager.class);

@VisibleForTesting
Copy link
Contributor

Choose a reason for hiding this comment

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

Unnecessary?

@@ -111,6 +111,10 @@ public User authenticate(String username, String secret) {
return authentication.authenticate(username, secret);
}

public boolean isamdin(User user) {
Copy link
Contributor

Choose a reason for hiding this comment

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

What @tedpearson meant is camel case isAdmin is the convention

public User getUser(String username) {
User user = authentication.getUser(username);
return user;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

return authentication.getUser(username);

builder = Response.ok(Boolean.toString(false));
} else {
builder = Response.ok(Boolean.toString(true));
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Just do:

builder = Response.ok(Boolean.toString(isadmin))

builder.header("Access-Control-Allow-Origin",
"http://" + uriInfo.getAbsolutePath().getHost() +
":" + configuration.webPort);
builder.header("Access-Control-Allow-Methods", "POST");
return builder.build();
} catch (Exception ex) {
log.warn("Internal error in sudo attempt for user {} with ssl {}", username, usingSSL, ex);
return Response.serverError().entity(ex.toString()).build();
// TODO: don't show "Accept out https certificate" and hydra.png
Copy link
Contributor

Choose a reason for hiding this comment

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

Why this TODO here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

mistakenly added will remove

@yuesong
Copy link
Contributor

yuesong commented May 24, 2017

Also please make sure any script that requires sudo privilege, such as fail-minion, still works.

@satang500
Copy link
Contributor Author

will keep the bug described in app.js as it is for now.

@yuesong
Copy link
Contributor

yuesong commented May 24, 2017

New changes look good to me. You should merge master to this PR (and resolve the web build files conflict and regenerate them with webpack -p as part of the merge).

@yuesong yuesong merged commit bba99d0 into master May 25, 2017
@yuesong yuesong deleted the sudoimp branch May 25, 2017 16:51
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants