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

Ansible 2.0 does not allow special chars in SUDO password #13240

Closed
ThomasSteinbach opened this issue Nov 20, 2015 · 8 comments
Closed

Ansible 2.0 does not allow special chars in SUDO password #13240

ThomasSteinbach opened this issue Nov 20, 2015 · 8 comments
Labels
bug This issue/PR relates to a bug. pending_action
Milestone

Comments

@ThomasSteinbach
Copy link
Contributor

I have a Playbook which is configured with become: true started it with the option --ask-become-pass. When it asks for the SUDO password, I entered a password with many special chars, like k§=aI$nt

With this (example) password I get the following error:

fatal: [serverxxxxx]: FAILED! => {"failed": true, "msg": "ERROR! the field 'become_pass' has an invalid value (k§=aI$nt), and could not be converted to an string. Error was: 'ascii' codec can't decode byte 0xc2 in position 1: ordinal not in range(128)"}

In Ansible 1.9.4 I had no problems with sudo: yes and --ask-sudo-password.

@bcoca bcoca added this to the v2 milestone Nov 20, 2015
@chrrrles
Copy link
Contributor

Proposing this as a fix -- https://github.com/ansible/ansible/pull/13257/files
@bcoca @jimi-c @abadger comments?

@ThomasSteinbach
Copy link
Contributor Author

I can confirm this pull request would solve the issue for me.
Also the failing password would not be printed on the command line, like it was before the fix. I see this as a critical security issue, as others could get a look at the 'rejected' password on the screen.
thanx @chrrrles

@jimi-c
Copy link
Member

jimi-c commented Nov 24, 2015

@ThomasSteinbach / @chrrrles I'm ok with the patch above, with the one caveat that it should be using to_unicode() from ansible.utils.unicode instead of the try/except method (which is how we typically used to deal with this kind of issue).

@ThomasSteinbach
Copy link
Contributor Author

@chrrrles Could we please re-open this issue, as recent changes reverted the error? Even with to_unicode() Ansible fails with parsing a password like k§=aI$nt. There is just a new error:

UnicodeEncodeError: 'ascii' codec can't encode character u'\xa7' in position 1: ordinal not in range(128)

The working implementation for me is

if attribute.isa == 'string':
  try:
    value = to_unicode(value)
  except UnicodeDecodeError:
    value = binary_type(value)

However @jimi-c , you said that the try/except way is not the best. Did you know a working alternative? What does it mean to use binary_type for every string?

@abadger
Copy link
Contributor

abadger commented Dec 10, 2015

@ThomasSteinbach Could you give me the full traceback?

The code you're showing me as fixing this is definitely incorrect as it translates the value into either a text type (unicode) or a bytes type (str) depending on whether a UnicodeDecodeError (which should never happen with the default params to to_unicode()).

@abadger abadger reopened this Dec 10, 2015
@abadger
Copy link
Contributor

abadger commented Dec 10, 2015

@ThomasSteinbach reproduced... looking further.

@abadger
Copy link
Contributor

abadger commented Dec 10, 2015

Okay, that should fix this issue. Pushed to both devel and the stable-2.0 branch.

@ThomasSteinbach
Copy link
Contributor Author

Thank you @abadger , I couldn't reproduce the issue on my working machine, which confuses me a lot. I planned to check it again at home on my laptop, where issue arose. However you have fixed the issue. Great.

@ansibot ansibot added bug This issue/PR relates to a bug. and removed bug_report labels Mar 7, 2018
@ansible ansible locked and limited conversation to collaborators Apr 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug This issue/PR relates to a bug. pending_action
Projects
None yet
Development

No branches or pull requests

6 participants