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

[crmsh-4.6] Fix: report: use ClusterShell for ssh (bsc#1220170) #1335

Merged

Conversation

nicholasyang2022
Copy link
Collaborator

The current ssh implementation in crm.report will use a wrong user when using root + ssh-agent + sudo.

This patch change to use try to ClusterShell first, providing consistent behavior with other parts of crmsh. And fallback to interactive authentication when ClusterShell does not work.

Copy link

codecov bot commented Feb 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 52.82%. Comparing base (58aa13d) to head (9510a00).

Additional details and impacted files
@@              Coverage Diff              @@
##           crmsh-4.6    #1335      +/-   ##
=============================================
- Coverage      52.82%   52.82%   -0.01%     
=============================================
  Files             79       79              
  Lines          24002    24002              
=============================================
- Hits           12679    12678       -1     
- Misses         11323    11324       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

nicholasyang2022 and others added 3 commits February 26, 2024 14:53
The current ssh implementation in crm.report will use a wrong user when
using root + ssh-agent + sudo.

This patch change to use try to ClusterShell first, providing consistent
behavior with other parts of crmsh. And fallback to interactive
authentication when ClusterShell does not work.
Reproducer:

1. /etc/ssh/sshd_config "PermitRootLogin yes" on both nodes

2. root@node-1 and root@node-2 are passwordless with the forwarded ssh
   key. That says, those nodes don't have root passwordless with their
   local root ssh key.

3. crm report hangs in the remote node trying to do the root
   passwordless ssh back to the main node to figure out the trace_ra
   directories
@@ -441,6 +432,31 @@ def load_context_attributes(context: Context) -> None:
context.cores_dir_list.extend([constants.COROSYNC_LIB] if os.path.isdir(constants.COROSYNC_LIB) else [])


def load_context_trace_dir_list(context: Context) -> None:
log_contents = ""
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to move these two comment lines (https://github.com/ClusterLabs/crmsh/blob/crmsh-4.6/crmsh/report/collect.py#L192-L193) into here to explain why need to do like this

cmd,
)
shell = crmsh.sh.LocalShell()
ret = shell.su_subprocess_run(None, cmd, tty=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the same code as line 264-275?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extracted as a function _interactive_ssh_run_as_root.

@nicholasyang2022 nicholasyang2022 marked this pull request as ready for review February 26, 2024 08:32
Copy link
Contributor

@zzhou1 zzhou1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM



def _interactive_ssh_run_as_root(host: str, ssh_user: str, cmd: str):
# cmd MUST be escaped to make sure it works as an arugment of ssh command
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this comment mean for "escaped", in this function scope?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cmd is concatenated to ssh as string. This string is firstly parsed by bash and later by ssh. This requires special characters in it to be escaped 2 times. And I am not sure how to write a general function to escape arguments for ssh. So for now, let the callers to escape it case by case.

@liangxin1300 liangxin1300 merged commit cf0a94f into ClusterLabs:crmsh-4.6 Feb 26, 2024
31 checks passed
@nicholasyang2022 nicholasyang2022 deleted the bsc_1220170_20240222 branch February 27, 2024 07:49
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 this pull request may close these issues.

3 participants