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

[collect] Using batch flag with password blocks requesting the ssh password #3839

Open
TrevorBenson opened this issue Nov 15, 2024 · 4 comments

Comments

@TrevorBenson
Copy link
Member

SOS Version: sos-4.7.2-3.el9.noarch

$ man sos-collect |grep -A1 -e '\-\-batch$' -e '\-\-password$'
       --batch
              Run in non-interactive mode. This will skip prompts for user input, with the exception of a prompt for the SSH password.
--
       --password
              Specifying this option will cause sos collect to prompt the user for an SSH password that will be used to connect to all nodes.

Using --batch --password leads to an unsupported operand type(s) for +: 'bool' and 'str' error:

[root@localhost ~]# sos collect --batch --password --ssh-user project-user --nodes 192.168.124.121

sos-collector (version 4.7.2)

This utility is used to collect sos reports from multiple nodes simultaneously.
Remote connections are made and/or maintained to those nodes via well-known
transport protocols such as SSH.

An archive of sos report tarballs collected from the nodes will be generated in
/var/tmp/sos.mwlhdiqu and may be provided to an appropriate support
representative.

The generated archive may contain data considered sensitive and its content
should be reviewed by the originating organization before being passed to any
third party.

No configuration changes will be made to the system running this utility or
remote systems that it connects to.


The following is a list of nodes to collect from:
	localhost
	192.168.124.121


Connecting to nodes...
[192.168.124.121:__init__] Unable to open remote session: unsupported operand type(s) for +: 'bool' and 'str'
Collection would only gather from localhost due to failure to either enumerate or connect to cluster nodes. Assuming single collection from localhost is not desired.
Aborting...

This was found while using a fix for nested sudo in PR #3838

jcastill added a commit to jcastill/sos that referenced this issue Nov 15, 2024
options

Using --batch --password together in sos-collect leads to an error:

Unable to open remote session:
unsupported operand type(s) for +: 'bool' and 'str'

Related: sosreport#3839

Signed-off-by: Jose Castillo <[email protected]>
@jcastill
Copy link
Member

I managed to reproduce and get a call trace:

Traceback (most recent call last):
  File "/usr/lib/python3.9/site-packages/sos/collector/sosnode.py", line 89, in __init__
    self._transport.connect(self._password)
  File "/usr/lib/python3.9/site-packages/sos/collector/transports/__init__.py", line 146, in connect
    if self._connect(password):
  File "/usr/lib/python3.9/site-packages/sos/collector/transports/control_persist.py", line 134, in _connect
    res.sendline(password)
  File "/usr/lib/python3.9/site-packages/pexpect/pty_spawn.py", line 578, in sendline
    return self.send(s + self.linesep)
TypeError: unsupported operand type(s) for +: 'bool' and 'str'
[192.168.124.134:__init__] Unable to open remote session: unsupported operand type(s) for +: 'bool' and 'str'

And send a PR with a possible fix.

jcastill added a commit to jcastill/sos that referenced this issue Nov 15, 2024
Using --batch --password together in sos-collect leads to an error:

Unable to open remote session:
unsupported operand type(s) for +: 'bool' and 'str'

This PR attempts to catch the combination of options as early as
possible and exit with an error message.

Related: sosreport#3839

Signed-off-by: Jose Castillo <[email protected]>
@TrevorBenson
Copy link
Member Author

@jcastill Given the man page output stating that --batch prevents any input, except requesting the ssh password, I believe they are intended to be a functional combination.

@jcastill
Copy link
Member

Ah, I see. Let me rework this then

@jcastill
Copy link
Member

I guess we either change the man page, or I change this:

https://github.com/sosreport/sos/blob/main/sos/collector/__init__.py#L796

       try:
            if ((self.opts.password or (self.opts.password_per_node and
                                        self.opts.primary))
                    and not self.opts.batch):
                self.log_debug('password specified, not using SSH keys')
                msg = ('Provide the SSH password for user '
                       f'{self.opts.ssh_user}: ')
                self.opts.password = getpass(prompt=msg)

But it's late here so I may be misreading the code above. I'll do some tests and do a force push, considering the man page the source of truth.

jcastill added a commit to jcastill/sos that referenced this issue Nov 15, 2024
Using --batch --password together in sos-collect leads to an error:

Unable to open remote session:
unsupported operand type(s) for +: 'bool' and 'str'

This PR removes the check for the batch option, enabling
the prompt for password as specified in the man page:

  --batch
      Run in non-interactive mode.
     This will skip prompts for user input,  with  the
     exception  of  a prompt for the SSH password.

Related: sosreport#3839

Signed-off-by: Jose Castillo <[email protected]>
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

2 participants