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

Run hb_report under hacluster #742

Merged
merged 3 commits into from
Feb 19, 2021

Conversation

liangxin1300
Copy link
Collaborator

@liangxin1300 liangxin1300 commented Feb 5, 2021

Problem

It didn't work if run hb_report or crm cluster copy under hacluster user, which was required from Hawk

Solution

  • Change function bootstrap.configure_local_ssh_key and bootstrap.swap_public_ssh_key to accept non-root user parameter; That is, for common user, bootstrap process also setup password-less among cluster nodes

  • Assign /usr/bin/sh to hacluster's login shell, otherwise, it's impossible to run command remotely

  • On interactive mode, behavior about changing hacluster's login shell and setup ssh access will be asked for confirm

  • For runtime existing cluster, need to use ssh stage to setup password-less access for hacluster

    • on init node, run crm cluster init ssh -y
    • on join node, run crm cluster join ssh -c <init node> -y
  • For runtime existing cluster, /etc/corosync/corosync.conf and /etc/sysconfig/sbd might has 400 mod, which will cause Permission denied exceptions when running hb_report under hacluster, Dev: utils: change default file mod as 644 for str2file function #747 try to resolve this, but not works for runtime existing cluster, to avoid that, before running hb_report under hacluster:

    • Run chmod 644 /etc/corosync/corosync.conf
    • Run chmod 644 /etc/sysconfig/sbd

Test rpm link: https://build.opensuse.org/package/show/home:XinLiang:branches:crmsh_testing7/crmsh

@liangxin1300 liangxin1300 force-pushed the 20210205_hb_report branch 3 times, most recently from 3ce64f9 to 6e5b30e Compare February 7, 2021 08:27
@liangxin1300 liangxin1300 changed the title [WIP] 20210205 hb report Run hb_report under hacluster Feb 7, 2021
Copy link
Contributor

@MalloZup MalloZup left a comment

Choose a reason for hiding this comment

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

seems good to me but not familiar with crmsh codebase

Copy link
Contributor

@arbulu89 arbulu89 left a comment

Choose a reason for hiding this comment

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

@liangxin1300 Added some comments about the code.
About the purpose of the changes, I cannot really judge without knowing what are the consequences of changing the hacluster user bash option

private_key = "{}/.ssh/id_rsa".format(home_dir)
public_key = "{}/.ssh/id_rsa.pub".format(home_dir)
authorized_file = "{}/.ssh/authorized_keys".format(home_dir)
return private_key, public_key, authorized_file
Copy link
Contributor

Choose a reason for hiding this comment

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

I wouldn't return a 3 elements list here. This is a potential issue if for some reason you check the return data, as you will need to change all the places where the method is used.
Better to return a dictionary or specific object, so you can use just the needed elements

Copy link
Contributor

Choose a reason for hiding this comment

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

yop valid point

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks @arbulu89 , already changed!

@@ -1134,22 +1133,59 @@ def init_ssh():
Configure passwordless SSH.
"""
utils.start_service("sshd.service", enable=True)
configure_local_ssh_key()
for user in ["root", "hacluster"]:
Copy link
Contributor

Choose a reason for hiding this comment

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

This ["root", "hacluster"] list looks something that should go in a constant, as it is repeated later

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Changed

if not os.path.exists(private_key):
status("Generating SSH key for {}".format(user))
cmd = "ssh-keygen -q -f {} -C 'Cluster Internal on {}' -N ''".format(private_key, utils.this_node())
if user != "root":
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe adding the next code in a method is a good idea:

if user != "root":
  cmd = utils.add_su(cmd, user)

It is reused in different places

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Already put it into add_su function

@liangxin1300 liangxin1300 force-pushed the 20210205_hb_report branch 2 times, most recently from c5acd09 to 01e3bbc Compare February 10, 2021 03:34
Copy link
Member

@gao-yan gao-yan left a comment

Choose a reason for hiding this comment

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

It generally looks good to me. Thanks for the nice work, @liangxin1300!

Only one nitpick.

crmsh/bootstrap.py Outdated Show resolved Hide resolved
@gao-yan
Copy link
Member

gao-yan commented Feb 10, 2021

  • For runtime existing cluster, need to use ssh stage to setup password-less access for hacluster

    • on init node, run crm cluster init ssh -y
    • on join node, run crm cluster join ssh -c <init node> -y

Probably it could be a further improvement. To make it as friendly as possible, given that there's an existing cluster, it'd be great to only require running such an ssh stage on any of the nodes, which takes care of all the nodes.

  • For runtime existing cluster, /etc/corosync/corosync.conf and /etc/sysconfig/sbd might has 400 mod, which will cause Permission denied exceptions when running hb_report under hacluster, Dev: utils: change default file mod as 644 for str2file function #747 try to resolve this, but not works for runtime existing cluster, to avoid that, before running hb_report under hacluster:

    • Run chmod 644 /etc/corosync/corosync.conf
    • Run chmod 644 /etc/sysconfig/sbd

Also to make it as easy as possible for users, I'm thinking probably ssh stage running for an existing cluster should as well fix the permissions of any theses existing files?

@liangxin1300
Copy link
Collaborator Author

  • For runtime existing cluster, need to use ssh stage to setup password-less access for hacluster

    • on init node, run crm cluster init ssh -y
    • on join node, run crm cluster join ssh -c <init node> -y

Probably it could be a further improvement. To make it as friendly as possible, given that there's an existing cluster, it'd be great to only require running such an ssh stage on any of the nodes, which takes care of all the nodes.

Good suggestion! Thanks @gao-yan

  • For runtime existing cluster, /etc/corosync/corosync.conf and /etc/sysconfig/sbd might has 400 mod, which will cause Permission denied exceptions when running hb_report under hacluster, Dev: utils: change default file mod as 644 for str2file function #747 try to resolve this, but not works for runtime existing cluster, to avoid that, before running hb_report under hacluster:

    • Run chmod 644 /etc/corosync/corosync.conf
    • Run chmod 644 /etc/sysconfig/sbd

Also to make it as easy as possible for users, I'm thinking probably ssh stage running for an existing cluster should as well fix the permissions of any theses existing files?

I agree that will be more convenient for this whole issue.
But ssh key and the permissions changing are two kinds of things for crmsh, is that proper to put them together in ssh stage?

@gao-yan
Copy link
Member

gao-yan commented Feb 17, 2021

  • For runtime existing cluster, /etc/corosync/corosync.conf and /etc/sysconfig/sbd might has 400 mod, which will cause Permission denied exceptions when running hb_report under hacluster, Dev: utils: change default file mod as 644 for str2file function #747 try to resolve this, but not works for runtime existing cluster, to avoid that, before running hb_report under hacluster:

    • Run chmod 644 /etc/corosync/corosync.conf
    • Run chmod 644 /etc/sysconfig/sbd

Also to make it as easy as possible for users, I'm thinking probably ssh stage running for an existing cluster should as well fix the permissions of any theses existing files?

I agree that will be more convenient for this whole issue.
But ssh key and the permissions changing are two kinds of things for crmsh, is that proper to put them together in ssh stage?

Technically, no :-) As we can see, the "breaking" changes of hawk will bring users much inconvenience requiring them to re-run ssh stage. I was thinking combing this into ssh stage would make their lives a bit easier :-) But of course, we could either add this step also into update note / TID ...

@liangxin1300
Copy link
Collaborator Author

  • For runtime existing cluster, /etc/corosync/corosync.conf and /etc/sysconfig/sbd might has 400 mod, which will cause Permission denied exceptions when running hb_report under hacluster, Dev: utils: change default file mod as 644 for str2file function #747 try to resolve this, but not works for runtime existing cluster, to avoid that, before running hb_report under hacluster:

    • Run chmod 644 /etc/corosync/corosync.conf
    • Run chmod 644 /etc/sysconfig/sbd

Also to make it as easy as possible for users, I'm thinking probably ssh stage running for an existing cluster should as well fix the permissions of any theses existing files?

I agree that will be more convenient for this whole issue.
But ssh key and the permissions changing are two kinds of things for crmsh, is that proper to put them together in ssh stage?

Technically, no :-) As we can see, the "breaking" changes of hawk will bring users much inconvenience requiring them to re-run ssh stage. I was thinking combing this into ssh stage would make their lives a bit easier :-) But of course, we could either add this step also into update note / TID ...

@arbulu89 , How do you think about this?

@liangxin1300
Copy link
Collaborator Author

liangxin1300 commented Feb 18, 2021

  • For runtime existing cluster, need to use ssh stage to setup password-less access for hacluster

    • on init node, run crm cluster init ssh -y
    • on join node, run crm cluster join ssh -c <init node> -y

Probably it could be a further improvement. To make it as friendly as possible, given that there's an existing cluster, it'd be great to only require running such an ssh stage on any of the nodes, which takes care of all the nodes.

Good suggestion! Thanks @gao-yan

@gao-yan After estimating, I think this change might be big and might break compatibility and bring regression.
So I suggest keep this unchanged and try to clarify these steps in update note

Copy link
Contributor

@arbulu89 arbulu89 left a comment

Choose a reason for hiding this comment

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

@liangxin1300
I see correct the code changes. But I'm talking about python code itself.
As commented, I don't have that much context about the change, so I would wait until @gao-yan approval to move forward

return re.search("{}:.*:/sbin/nologin".format(user), f.read())


def configure_local_ssh_key(user="root"):
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this configure_local_ssh_key method has become too big and complex.
We could split the logic in different submethods

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks @arbulu89
I moved the change shell codes into change_user_shell function
And I will adjust UT codes later

@liangxin1300
Copy link
Collaborator Author

Loop #1033 here

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.

5 participants