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

Don't correctly parse contain @ ssh password #752

Open
SouthFox-D opened this issue Dec 28, 2023 · 3 comments · May be fixed by #783
Open

Don't correctly parse contain @ ssh password #752

SouthFox-D opened this issue Dec 28, 2023 · 3 comments · May be fixed by #783

Comments

@SouthFox-D
Copy link

version: testinfra-10.0.0

pytest --hosts=ssh://root:foo@[email protected] test.py -vvv

Captured log:

DEBUG testinfra:base.py:328 RUN CommandResult(backend=<testinfra.backend.ssh.SshBackend object at 0x7f1514287490>, exit_status=5, command=b"sshpass -p foo ssh -o User=root -o ConnectTimeout=10 -o ControlMaster=auto -o ControlPersist=60s [email protected] 'uname -s'", _stdout=b'', _stderr=b'Permission denied, please try again.\r\n')

@philpep
Copy link
Contributor

philpep commented Dec 28, 2023

Did you try to urlencode the password ? e.g.:

pytest --hosts 'ssh://root:foo%[email protected]' test.py -vvv

@SouthFox-D
Copy link
Author

Did you try to urlencode the password ? e.g.:

pytest --hosts 'ssh://root:foo%[email protected]' test.py -vvv

Thanks, it works, and it works in ansible as well.

But I'm handling passwords via environment variables, so I can't use urlencode anywhere (unless maintained separately).

Is it a good idea to use rspilt instead of spilt for parse_hostspec?

def parse_hostspec(hostspec: str) -> HostSpec:
name = hostspec
port = None
user = None
password = None
if "@" in name:
user, name = name.split("@", 1)

        if "@" in name:
            user, name = name.rsplit("@", 1)

@CarstenGrohmann
Copy link
Contributor

With rsplit(), colons are possible in the password without encoding, but not in the user name.

Since there is no general solution, I suggest to leave the code as it is and to extend the documentation with #783.

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

Successfully merging a pull request may close this issue.

3 participants