-
Notifications
You must be signed in to change notification settings - Fork 937
About sudo
detection
#852
Comments
It is muted, I am not seeing this in the non-root shell, but I see the error messages in the root shell running |
It's worth pointing out that systemd's journal is not the only issue from using The latter is especially easy to achieve on systems where sudoers are asked to enter their password every time |
Oops, somehow lost track of this one. @sambadevi - thanks for the bug report (a couple of months ago), and thanks for re-raising this, @vmivanov. It is much appreciated. @sambadevi - I assume you are still seeing this in the latest |
@bhilburn both, yes. Tested it a few minutes ago with I should mention, this error was reported for fedora 28. I tested on arch this time |
Okay, per your issue description and what @vmivanov is describing, I think it's important we address this ASAP. I wonder if there is actually is a 'safe' way to detect I'm genuinely asking, here - I don't know, hah. I wonder if @rjorgenson knows anything, here. |
@sambadevi that's ok, as the problem should be independent of your choice of distribution. Whether you see the error in logs is mostly dependent on the logging configuration, and chances are most systems will log and/or report any authentication errors by default. I can certainly observe this behaviour both on Gentoo and on Debian Testing. @bhilburn no problem, thanks for all your efforts - this theme is priceless! I forgot to mention that at the time of writing my comment, it refers to the Wrt the |
According to this serverfault answer you have special env vars set if you're sudo (copied from there):
|
@sambadevi The problem with this approach is that these environment variables are not persisted outside of the |
You can try this command : With -S flag, you provide a password from /dev/null ! I don’t see auth error on journalctl anymore. |
Did you try From |
@onaforeignshore yes, this is exactly what the script in if [[ $(print -P "%#") == '#' ]]; then
current_state="ROOT"
elif [[ -n "$SSH_CLIENT" || -n "$SSH_TTY" ]]; then
if sudo -n true 2>/dev/null; then
current_state="REMOTE_SUDO"
else
current_state="REMOTE"
fi
elif sudo -n true 2>/dev/null; then
current_state="SUDO"
fi So no, what you are referring to in the @gzugmeyer Interesting! But bear in mind the systemd journal is not the only concern here, in fact, I would say it's a lower priority issue. That said, having done a quick test of your snippet it does seem to partially resolve the issue. It correctly returns a value of
I would argue that using |
Thanks for weighing in, @gzugmeyer! It looks like that would be a solid fix if it weren't for the log flooding. So, I think @vmivanov has a great point, here:
The prompt indicating
To be honest, I personally don't think any of the three of these is useful, but am open to hearing other opinions. If people really like the current functionality, #1, then I would be okay leaving it in and (a) defaulting it to disabled (b) conditionalizing that code path out of execution otherwise. |
@bhilburn Since my prompt is always elevated (my user is in sudoers with the NOPASSWD flag), I don't have any use for this. I was just adding the state to solve the sudoers problem. |
@bhilburn seconded. Not really sure what the best approach would be for a Either way, it would be good to have it configurable so that it can be disabled if relying on a call to |
@bhilburn @dritter From everything I could tell, determining wether there is an active sudo session is not possible without calling the sudo command. I found this superuser article from like 8 years ago, but its been active pretty recently - https://superuser.com/questions/195781/sudo-is-there-a-command-to-check-if-i-have-sudo-and-or-how-much-time-is-left - There are many suggestions on how to do this, but they all require running sudo or already having root access. I'm not really sure of the use case for this personally, if I have to run something as sudo knowing wether or not I have a session isn't going to change the command I run or my behavior. But if this is needed functionality for something the best solution I was able to come up with was creating a wrapper script for sudo and tracking that within p9k. We'd create a sudo function that just calls the actual sudo with the arguments passed by the user and then tracks the time and return status of the sudo command. This probably wouldn't be trivial and might raise some eyebrows if we start hijacking user commands to do our stuff. Another far less effective solution would be checking the last 10(or some definable timeout value) minutes of command history for a sudo command, obviously this is not ideal and can easily result in false positives. I don't recommend it but that's the only other thing I could come up with. The final option is to leave this in as a configurable option(off by default) for the users who do have the use case for it and have mitigations in place for the results of doing this(a sudo call on every prompt draw). If anyone is looking for a quick fix for this you can add the below code to your .zshrc file and change your POWERLEVEL9K_LEFT_PROMPT_ELEMENTS entry for context to pcontext, same for the right prompt elements if you use context there. This was my emergency fix and is non-invasive to the powerlevel9k codebase. prompt_pcontext() {
local current_state="DEFAULT"
typeset -AH context_states
context_states=(
"ROOT" "yellow"
"SUDO" "yellow"
"DEFAULT" "yellow"
"REMOTE" "yellow"
"REMOTE_SUDO" "yellow"
)
local content=""
if [[ "$POWERLEVEL9K_ALWAYS_SHOW_CONTEXT" == true ]] || [[ "$(whoami)" != "$DEFAULT_USER" ]] || [[ -n "$SSH_CLIENT" || -n "$SSH_TTY" ]]; then
content="${POWERLEVEL9K_CONTEXT_TEMPLATE}"
elif [[ "$POWERLEVEL9K_ALWAYS_SHOW_USER" == true ]]; then
content="$(whoami)"
else
return
fi
if [[ $(print -P "%#") == '#' ]]; then
current_state="ROOT"
# elif [[ -n "$SSH_CLIENT" || -n "$SSH_TTY" ]]; then
# if sudo -n true 2>/dev/null; then
# current_state="REMOTE_SUDO"
# else
# current_state="REMOTE"
# fi
# elif sudo -n true 2>/dev/null; then
# current_state="SUDO"
fi
"$1_prompt_segment" "${0}_${current_state}" "$2" "$DEFAULT_COLOR" "${context_states[$current_state]}" "${content}"
} |
Came here to see if anyone else had encountered this as well. In any form of shared environment this "feature" is likely to end up getting unwanted attention from security, or in the worst case having your service terminated. Having the security team spammed by email or the IDS system go haywire because a blind sudo is issued every time you hit enter is not very pleasant for either party. I implemented the same fix as @rjorgenson and it would be nice if this was turned off by default to prevent unpleasantness for future users. |
@bhilburn This took me a while to track down. I consider this to be a pretty big problem since it set off security alerts and made me very concerned. The I think the correct approach is to use the I don't think that @vmivanov's objections are a problem. On my system (Ubuntu) they are exported: $ sudo -i -u docwhat
$ env | grep SUDO_
SUDO_COMMAND=/bin/zsh
SUDO_USER=docwhat
SUDO_UID=9009
SUDO_GID=9009 But even if they aren't exported, then I would argue that you have left the confines of Either way, calling |
I forgot to point out that They only show that you can run a command as root at the moment. It doesn't work for:
Checking for |
So, from my point of view we have an Issue with the |
Detecting if you can sudo to root with no password at moment was never the right check. I think the variable is very close to the intention. Sent with GitHawk |
@docwhat very elegant solution, I had not thought of the I still fail to see the usefulness of this feature but the solution does indeed appear to preserve original intent without the extra downsides. Wrt the |
The @docwhat solution solves the error of the |
Merged into master as part of #944! Will be in the v0.6.6 release. |
`sudo -n true` only checks that we _could_ use `sudo`, not if we are in a sudo session. closes Powerlevel9k#852
`sudo -n true` only checks that we _could_ use `sudo`, not if we are in a sudo session. closes Powerlevel9k#852
I just encountered an error message while using
next
System Information:
OS: Fedora 28
ZSH: 5.5.1
Used segments:
os_icon
context
dir
status
time
Steps to reproduce:
journalctl -f
as root to monitor the error messagenext
branchcd
orls
(any command will do)journalctl
The text was updated successfully, but these errors were encountered: