-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
caddyauth: Fix hash-password broken terminal state on SIGINT #3416
Conversation
d1936ac
to
d775959
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for jumping on this!
The change to stderr is not necessary -- redirections should be with stdout by default, unless your terminal is messed up. Interactive prompts definitely need to be on stdout.
d775959
to
c26575b
Compare
Big note: this PR now also moves the /cc @lucaslorentz this is relevant to you. You'll need to add |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for reworking the TrapSignals calls.
The stderr thing is a bit weird but I'll let it slide since this is kind of a dusty corner of the code base that I don't expect will be used much anyway... and I guess it makes sense... sigh I hate shells.
That's a python lib, it specifically recommends using stderr if the stdout output is useful, which is the case here.
The stderr thing is a bit weird but I'll let it slide since this is kind of a dusty corner of the code base that I don't expect will be used much anyway... and I guess it makes sense... sigh I hate shells.
The getpass module is actually part of the Python stdlib: https://docs.python.org/3/library/getpass.html. The module docs say it defaults to /dev/tty, and falls back to stderr, so that's something that could get added in a following PR. This might be better than using stderr 100% of the time.
|
@0az if you want to make a PR for that, that'd be great. I feel out of my depth here, I just wanted to fix the terminal state getting clobbered. |
If you run
caddy hash-password
then hit^C
to interrupt, the terminal would get stuck in a broken state. Not good.This fixes that by storing the state before starting to read passwords (which modifies the terminal state) and restores it if
SIGINT
is caught.This also has the side-effect of avoiding the default cleanup handling from Caddy which prints out some log lines that aren't helpful in this situation, e.g.:
And also, I changed the prompts to be printed to STDERR instead of STDOUT, so now you can do
caddy hash-password > hashed.txt
and it works as expected./cc @0az FYI