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

Restic crashes when reading password via stdin #2203

Closed
Ppjet6 opened this issue Mar 8, 2019 · 1 comment · Fixed by #2221

Comments

@Ppjet6
Copy link

@Ppjet6 Ppjet6 commented Mar 8, 2019

Output of restic version

restic 0.9.4 (v0.9.4-37-g7b8d1dc0) compiled with go1.12 on linux/amd64

Expected behavior

Repository gets created with specified password.

Actual behavior

Restic crashes with the following:

read password from stdin
read password from stdin
EOF
ReadFull
main.readPassword
        cmd/restic/global.go:281
main.ReadPassword
        cmd/restic/global.go:317
main.ReadPasswordTwice
        cmd/restic/global.go:339
main.runInit
        cmd/restic/cmd_init.go:36
main.glob..func11
        cmd/restic/cmd_init.go:18
github.com/spf13/cobra.(*Command).execute
        vendor/github.com/spf13/cobra/command.go:762
github.com/spf13/cobra.(*Command).ExecuteC
        vendor/github.com/spf13/cobra/command.go:852
github.com/spf13/cobra.(*Command).Execute
        vendor/github.com/spf13/cobra/command.go:800
main.main
        cmd/restic/main.go:86
runtime.main
        /usr/lib/go/src/runtime/proc.go:200
runtime.goexit
        /usr/lib/go/src/runtime/asm_amd64.s:1337
unable to read password
main.ReadPassword
        cmd/restic/global.go:322
main.ReadPasswordTwice
        cmd/restic/global.go:339
main.runInit
        cmd/restic/cmd_init.go:36
main.glob..func11
        cmd/restic/cmd_init.go:18
github.com/spf13/cobra.(*Command).execute
        vendor/github.com/spf13/cobra/command.go:762
github.com/spf13/cobra.(*Command).ExecuteC
        vendor/github.com/spf13/cobra/command.go:852
github.com/spf13/cobra.(*Command).Execute
        vendor/github.com/spf13/cobra/command.go:800
main.main
        cmd/restic/main.go:86
runtime.main
        /usr/lib/go/src/runtime/proc.go:200
runtime.goexit
        /usr/lib/go/src/runtime/asm_amd64.s:1337

Steps to reproduce the behavior

  1. echo "a" | restic -r foo init

Do you have any idea what may have caused this?

No

I'm not entirely fond of having to drop passwords in a file, which is why I prefer to use stdin when possible. I would use environment variables, but it's not possible to specify the new key via env var when doing restic key add for example, as far as I know.

Thanks for your time :)

pschultz added a commit to classmarkets/restic that referenced this issue Mar 26, 2019
Reading the password from non-terminal stdin used io.ReadFull with a
byte slice of length 1000.

We are now using a Scanner to read one line of input, independent of its
length.

Additionally, if stdin is not a terminal, the password is read only
once instead of twice (in an effort to detect typos).

Fixes restic#2203
pschultz added a commit to classmarkets/restic that referenced this issue Mar 26, 2019
Reading the password from non-terminal stdin used io.ReadFull with a
byte slice of length 1000.

We are now using a Scanner to read one line of input, independent of its
length.

Additionally, if stdin is not a terminal, the password is read only
once instead of twice (in an effort to detect typos).

Fixes restic#2203
@pschultz pschultz mentioned this issue Mar 26, 2019
5 of 7 tasks complete
pschultz added a commit to classmarkets/restic that referenced this issue Mar 26, 2019
Reading the password from non-terminal stdin used io.ReadFull with a
byte slice of length 1000.

We are now using a Scanner to read one line of input, independent of its
length.

Additionally, if stdin is not a terminal, the password is read only
once instead of twice (in an effort to detect typos).

Fixes restic#2203
@fd0

This comment has been minimized.

Copy link
Member

@fd0 fd0 commented Apr 13, 2019

Thanks for the report! I think this is a bug and we should fix this, users expect that it works. There's a (less known) workaround using shell magic (<( cmd )):

$ restic -r /tmp/repo --password-file <(echo foo) init
created restic repository b22ca0564d at /tmp/repo
[...]
pschultz added a commit to classmarkets/restic that referenced this issue Apr 15, 2019
Reading the password from non-terminal stdin used io.ReadFull with a
byte slice of length 1000.

We are now using a Scanner to read one line of input, independent of its
length.

Additionally, if stdin is not a terminal, the password is read only
once instead of twice (in an effort to detect typos).

Fixes restic#2203

Signed-off-by: Peter Schultz <peter.schultz@classmarkets.com>
@fd0 fd0 closed this in #2221 Apr 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.