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

Add --noninteractive flag to dcrwallet --create #2190

Open
alchemydc opened this issue Nov 8, 2022 · 8 comments
Open

Add --noninteractive flag to dcrwallet --create #2190

alchemydc opened this issue Nov 8, 2022 · 8 comments

Comments

@alchemydc
Copy link

Deploying voting nodes using automation tools is burdensome because of the assumption that there is an interactive session used to import wallets, particularly voting wallets.

Please add a --noninteractive flag to dcrwallet --create to ease this pain.

Thanks

@davecgh
Copy link
Member

davecgh commented Nov 8, 2022

I'm not sure if you're aware, but you can already feed it answers via stdin to automate it. For example, if you're trying to create a wallet from an existing seed, you could create an answers file like:

create_wallet_answers.txt

y
n
y
${WALLET_SEED}    (make this the real seed ofc)

Then use it like so:

$ dcrwallet --create <create_wallet_answers.txt

Alternatively, if you put it as part of a larger automation script, you could simply declare a variable and use that like so:

WALLET_CREATE_CONFIG="y
n
y
${WALLET_SEED}
"
# other setup things as desired...
echo "${WALLET_CREATE_CONFIG}" | dcrwallet --create

@alchemydc
Copy link
Author

Hey Dave,

Tried that, no dice.

dc@zd-decred-1:~$ ./decred/dcrwallet --create < answers.txt
Enter the private passphrase for your new wallet:
Confirm passphrase: Unable to create wallet: inappropriate ioctl for device
dc@zd-decred-1:~$ echo ${WALLET_CREATE_CONFIG} | ./decred/dcrwallet --create
Enter the private passphrase for your new wallet:
Confirm passphrase: Unable to create wallet: inappropriate ioctl for device

I got pretty far using expect, but am getting stuck detecting the prompt for the blank line that's required after putting in the seed phrase.

Any other ideas?

DC

@davecgh
Copy link
Member

davecgh commented Nov 8, 2022

I was going to suggest expect as an alternative for now as well. Try adding an additional \r after the seed to satisfy the requirement for the additional newline.

As far as the inappropriate ioctl for device (and similar tty-related errors), that error is typically the result of running without an interactive shell since it has to interact with the terminal in order to disable the password echo. Even when feeding it via stdin, it still disables the echo and hence still needs an interactive tty.

We were internally discussing ways to make automated configuration more robust and easier to deal with so that the aforementioned tty requirement is no longer necessary, but obviously that doesn't help for now, so, as mentioned above, I think expect should be a reasonable option for the time being.

@jrick
Copy link
Member

jrick commented Nov 9, 2022

The ioctl error should be fixed on the latest master branch now.

Let us know how well expect works for this now and if anything else seems necessary to make non-interactive wallet creation better. Another idea that we discussed is reading either a file or environment variable(s) containing all of the prompt answers, which would be more resilient and probably easier to understand than a list of just the answers without what each is being used for.

@alchemydc
Copy link
Author

Hey Josh,

I hit a wall with pexpect (via ansible) at the last step of wallet import, due to failing to properly detect the "prompt" that you answer with the blank line. I tried sending an extra \r or \r\n after the seed itself to no avail.

This works, up until the very last step. For now I'm working around the inability to create a wallet by dropping one on the filesystem, which isn't very elegant :( Appreciate anything we can do to make the process more automation friendly.

- name: Run dcrinstall headless
  ansible.builtin.expect:
    command: /tmp/dcrinstall
    timeout: 30
    echo: yes
    responses:
      Enter the private passphrase for your new wallet: "{{ decred_wallet_password }}"
      Confirm passphrase: "{{ decred_wallet_password }}"
      Do you want to add an additional layer of encryption for public data\? \(n\/no\/y\/yes\) \[no\]: "no"
      Do you have an existing wallet seed you want to use\? \(n\/no\/y\/yes\) \[no\]: "no"
      Once you have stored the seed in a safe and secure location, enter "OK" to continue: "ok"
      # oof what a rabbit hole
      #Do you have an existing wallet seed you want to use\? \(n\/no\/y\/yes\) \[no\]: "yes"
      #Enter existing wallet seed \(followed by a blank line\): "{{ decred_wallet_seed }}"
      #(.*): "\x04"
      #(<*): ""
      #(.*): ""
      #([\s\S]+): ''
      #([\s\S]+): "\x04"
      #.*: ''
      #(?=): ''
  become: true
  become_user: "{{ decred_user }}"

@davecgh
Copy link
Member

davecgh commented Nov 9, 2022

I agree things should be made more automation friendly. For now, another option, which is what I did in the simnet setup script is to create a config file with the password in it along with an environment variable that contains the answers and then use that config file along with piping the answers to the wallet when creating it.

That works because when there is a pass set in the config file, the create wizard questions change accordingly and the first one is Use the existing configured private passphrase for wallet encryption? which it answers y so there are no password prompts which avoids that tty error (which is now fixed on master as well).

@jrick
Copy link
Member

jrick commented Nov 9, 2022

We've addressed this in #2192. Give latest master another try, and use the hex seed instead of the seed words. That extra blank line needed after the seed prompt is gone now if you use a hex seed. Note that you'll need to update the expect prompt for the seed due to a wording change.

@alchemydc
Copy link
Author

alchemydc commented Nov 9, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants