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

caddyauth: Fix hash-password broken terminal state on SIGINT #3416

Merged
merged 2 commits into from
May 21, 2020

Conversation

francislavoie
Copy link
Member

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.:

2020/05/15 14:52:47.348	INFO	shutting down	{"signal": "SIGINT"}
2020/05/15 14:52:47.349	ERROR	stopping admin endpoint	{"signal": "SIGINT", "error": "no admin server"}
2020/05/15 14:52:47.349	INFO	shutdown done	{"signal": "SIGINT"}

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

@francislavoie francislavoie added the bug 🐞 Something isn't working label May 15, 2020
@francislavoie francislavoie added this to the 2.1 milestone May 15, 2020
@francislavoie francislavoie requested a review from mholt May 15, 2020 15:42
@francislavoie francislavoie force-pushed the fix-hash-pwd branch 2 times, most recently from d1936ac to d775959 Compare May 15, 2020 15:56
Copy link
Member

@mholt mholt left a 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.

modules/caddyhttp/caddyauth/command.go Show resolved Hide resolved
modules/caddyhttp/caddyauth/command.go Show resolved Hide resolved
@mholt mholt added the under review 🧐 Review is pending before merging label May 15, 2020
@francislavoie
Copy link
Member Author

francislavoie commented May 18, 2020

Big note: this PR now also moves the caddy.TrapSignals() call to inside the subcommands that it's relevant for instead of at the start of Main(). This could be a breaking change for plugins that add long-running commands.

/cc @lucaslorentz this is relevant to you. You'll need to add caddy.TrapSignals() at the top of your cmdFunc function for the docker-proxy subcommand once this PR is merged.

@francislavoie francislavoie requested a review from mholt May 18, 2020 20:29
Copy link
Member

@mholt mholt left a 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.

@mholt mholt merged commit bb67e19 into caddyserver:master May 21, 2020
@mholt mholt removed the under review 🧐 Review is pending before merging label May 21, 2020
@francislavoie francislavoie deleted the fix-hash-pwd branch May 21, 2020 19:14
@0az
Copy link
Contributor

0az commented May 25, 2020 via email

@francislavoie
Copy link
Member Author

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐞 Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants