Caddy: skip prompts if stdin is closed or no tty

Created on 13 Jun 2018  Â·  4Comments  Â·  Source: caddyserver/caddy

1. What version of Caddy are you using (caddy -version)?

Caddy 0.11.0

… and really HEAD.

2. What are you trying to do?

  • Run caddy in my CI to test a plugin, but with a closed stdin.
  • Run caddy, and the console is no TTY.

3. What is your entire Caddyfile?

bind 0.0.0.0:<random port>

Just a minimal Caddyfile to get to the prompt. I know I could run this with a two-liner *:<random port>\nroot /…/….

4. How did you run Caddy (give the full command and describe the execution environment)?

For example, with a closed stdin:

<&- ./caddy -conf /etc/Caddyfile

5. Please paste any relevant HTTP request(s) here.

—

6. What did you expect to see?

Caddy doing its thing.

7. What did you see instead (give full error messages and/or log)?

Activating privacy features...

Your sites will be served over HTTPS automatically using Let's Encrypt.
By continuing, you agree to the Let's Encrypt Subscriber Agreement at:
  https://letsencrypt…
Please enter your email address to signify agreement and to be notified
in case of issues. You can leave it blank, but we don't recommend it.
  Email address: 2018/06/13 16:57:53 reading email address: read /dev/stdin: resource temporarily unavailable

8. How can someone who is starting from scratch reproduce the bug as minimally as possible?

See commands above.

9. What's going on?

Caddy does not check if stdin is open and available. It assumes the operator is at the keyboard and able to answer questions.

10. Panic, drinks, or what else?

Do something like this before any and all prompts:

    if f, err := os.Stdin.Stat(); err != nil {
        return // no questions will be answered
    } else {
        if !(f.Mode()&os.ModeCharDevice) {
            return // no dice either
        }
    }
    // Swell, ask away.

… or similar; I improvised the code above and didn't really check it.

good first issue

Most helpful comment

We actually have to check also if os.ModeCharDevice works well on windows and with Cygwin just in case.

All 4 comments

@wmark Would you like to create a PR?

I won't have time for this.

It should be easy enough for someone new to Caddy or even Go, with rudimentary knowledge of how Linux works.


From my notes:

  • Support for providing a configuration to caddy from stdin could've been discontinued recently. If so, then the CL might contain another example of how to detect what kind of input is on stdin. If not, then the safeguards there could be expanded to address this issue.

We actually have to check also if os.ModeCharDevice works well on windows and with Cygwin just in case.

Looking at the code there is a flag allowPrompts that is used to skip prompts. I wonder if it's a good idea to use an unattended config instead of this?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jgsqware picture jgsqware  Â·  3Comments

klaasel picture klaasel  Â·  3Comments

mikolysz picture mikolysz  Â·  3Comments

kilpatty picture kilpatty  Â·  3Comments

whs picture whs  Â·  3Comments