Skip to content

Add explicit privilege prompt to improve sudo UX #138

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

Merged
merged 19 commits into from
Feb 6, 2018
Merged

Conversation

grayside
Copy link
Contributor

Fixes #134

This change identifies that we need to sudo and adjusts logging/spinning behaviors accordingly. Needs some more testing (e.g., with verbose) and a bit more smarts in sudo detection, hence the WIP flag. Also some UI issues around the asynchronous nature of the spinner.

I am pausing here for approach feedback.

Here's what it looks like when it operates as intended:

Paused for Input

screen shot 2018-01-29 at 1 12 27 pm

Success!

screen shot 2018-01-29 at 1 11 34 pm

@grayside grayside requested review from tekante and febbraro January 29, 2018 21:14
@febbraro
Copy link
Member

So I would simply say Administrative privileges needed and nothing about a password, since the Password prompt does that already. Look at this example, I ran rig dns twice. Once to get the initial prompt because I was unprivileged...

https://www.dropbox.com/s/m8twc771il6llhq/Screenshot%202018-01-29%2013.25.10.png?dl=0

And then once again, immediately, while I still had privs....

https://www.dropbox.com/s/vtx768cuhep9xk2/Screenshot%202018-01-29%2013.25.52.png?dl=0

It gave me "please enter your password" even though it just blasted right past it. Claiming privs needed is a good plan and it gives us the newline needed for an unobscured prompt. Claiming they are needed and blowing past it is really just a heads up and it is not confusing.

@grayside
Copy link
Contributor Author

Unfortunately here are some of the other results I'm getting, with a password needed:

screen shot 2018-01-29 at 1 42 48 pm
screen shot 2018-01-29 at 1 42 59 pm
screen shot 2018-01-29 at 1 43 25 pm

@grayside grayside changed the title [WIP] Add explicit privilege prompt to improve sudo UX Add explicit privilege prompt to improve sudo UX Jan 30, 2018
@grayside
Copy link
Contributor Author

Simplification helped tremendously. This is ready for final review.

I would appreciate if someone took it for a spin to confirm the timing issues are not still lurking.

My test has been:

./build/darwin/rig dns

@grayside grayside changed the base branch from master to develop January 31, 2018 04:08
@tekante
Copy link
Member

tekante commented Jan 31, 2018

Looks like it's working as intended. First run through didn't need password as I had recently used sudo, second time includes the password prompt.

privilege-prompt-test-results

util/logger.go Outdated
// This newline ensures the last status before escallation is preserved
// on-screen.
fmt.Println()
log.Spin("Evaluating administrative action...")
Copy link
Member

Choose a reason for hiding this comment

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

Just noting that things go by so quickly on my machine I never see the "Evaluating administrative action..." message.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wouldn't expect it to. I need the log.Spin() to start the spinner and the log.Warning() for the real message... let me test just using the same message for both, since that would avoid coder confusion.

util/slices.go Outdated

// IndexOfString is a general utility function that can find the index of a value
// present in a string slice. The second value is true if the item is found.
func IndexOfString(slice []string, value string) (int, bool) {
Copy link
Member

Choose a reason for hiding this comment

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

This is probably due to general newness to go and it's structures and syntax but it took me a while to realize that this was testing for the presence of an element in a collection of elements rather than the presence of a substring within a string. Probably baggage from character arrays and the concept of a slice of a string from Perl combined with previous indexOf type functions. I don't think it has to change I just thought I'd mention it.

This is relevant because commands of the form of util.Command("bash", "-c", fmt.Sprintf("echo 'nameserver %s' | sudo tee /etc/resolver/vm", bridgeIP)).Run() on 178 of dns.go would fail this check. It's not really an issue for Macs because that one is guaranteed to be proceeded by a command which will already trigger the Password prompt and stop the spinner (line 175 of dns.go). I think it might affect Linux however as the configureLinuxResolver function has no such preceding command.

I've attached an example of what this looks like on Linux.

privilege-prompt-test-results-linux

Copy link
Member

Choose a reason for hiding this comment

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

One potential avenue around this would be to import the strings package and change the conditional on line 7 to something like
if elem == value || strings.Contains(elem, value + " ") {

This appears to function properly for both mac and linux though it changes the nature of this function such that you'll probably want to rename it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's a convention with exec.Cmd that the tokens all be individual array elements. I see that subshell situations might be different. Will adjust.

@grayside
Copy link
Contributor Author

In addition to addressing CJ's feedback, I took the following steps:

  • Refactored Executor.ToString() to Executor.String() to be more in-line with Golang built-ins.
  • Added the privilege escalation prompt to more of our command execution methods.
  • When resuming the spinner, it now flashes "resuming operation", this is likely to be a flicker in many cases, but if the calling code doesn't do a good job of spinner management it may be confusing to see the spinning without context. I think this is a good idea, but could be convinced to leave it as an empty string.

@febbraro
Copy link
Member

febbraro commented Feb 1, 2018

I'm getting prompt overlap on rig stop

Using sudo -k first to remove privs

@febbraro
Copy link
Member

febbraro commented Feb 1, 2018

Prompt overlap is only when stopping a running machine. If I stop an already stopped machine, the prompt works fine.

@grayside
Copy link
Contributor Author

grayside commented Feb 6, 2018

I haven't found a way to crack the rig stop spinner yet. It appears that the route command does something unusual in how it interacts with newlines or the password prompt, and may require much deeper research. Is this change a sufficient improvement to move forward anyway?

Should I output an extra message on rig stop to provide instruction on dealing with the confusion?

@tekante
Copy link
Member

tekante commented Feb 6, 2018

I could go with proceeding if it is just the stop portion that overlap is wonky on. If it's something with route would an initial sudo cat /dev/null just so that the password gets prompted for alleviate that without causing ill effects?

@grayside
Copy link
Contributor Author

grayside commented Feb 6, 2018

cat /dev/null seems to have helped. Will need to research the implications of that trick.

@febbraro febbraro merged commit 41cad0c into develop Feb 6, 2018
@febbraro febbraro deleted the privilege-prompt branch February 6, 2018 23:26
@febbraro febbraro mentioned this pull request Feb 7, 2018
febbraro added a commit that referenced this pull request Feb 8, 2018
* Add explicit privilege prompt to improve sudo UX (#138)

* Explicitly prompt for privilege escallation

* Remove password prompt part of privilege message

* Expand sudo detection.

* Tidy up timing issues.

* Consolidate messaging and avoid newline in verbose.

* Cleanup ToString, sudo contains, cover more exec methods.

* Lint does not catch all of fmt.

* Remove unnecessary password prompt from networking cleanup.

* Remove color reset and cat /dev/null to clear route text.

* trying a different approach to requesting for admin privs (#144)
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