简体   繁体   English

Rundeck 4.0.0 - 使用 ssh 执行远程节点命令

[英]Rundeck 4.0.0 - Remote node command execution using ssh

I am having an issue with the most basic of Rundeck functions - namely, running a command over ssh on a remote node.我在使用最基本的 Rundeck 功能时遇到问题 - 即在远程节点上通过 ssh 运行命令。 I have generated a rsa key and added it via the Key Storage function.我已经生成了一个 rsa 密钥并通过Key Storage功能添加了它。 I have also created a yaml file for node definitions:我还为节点定义创建了一个 yaml 文件:

root@rundeck:/var/lib/rundeck# cat nodes.yml

mynode:
  nodename: mynode
  hostname: mynode
  description: 'Some description'
  ssh-authentication: privateKey            # added - unsure if really required
  ssh-keypath: /var/lib/rundeck/.ssh/id_rsa # added - unsure if really required
  username: rundeck
  osFamily: linux

The node is showing up correctly and command line ssh works just fine:该节点显示正确,命令行 ssh 工作正常:

root@rundeck:/var/lib/rundeck/.ssh# ssh -i id_rsa rundeck@mynode date
Mon Apr  4 16:19:33 UTC 2022

The project settings are as below:项目设置如下:

#Mon Apr 04 16:23:36 UTC 2022
#edit below
project.description=someproject
project.disable.executions=false
project.disable.schedule=false
project.execution.history.cleanup.batch=500
project.execution.history.cleanup.enabled=false
project.execution.history.cleanup.retention.days=60
project.execution.history.cleanup.retention.minimum=50
project.execution.history.cleanup.schedule=0 0 0 1/1 * ? *
project.jobs.gui.groupExpandLevel=1
project.label=somelabel
project.name=someproject
project.nodeCache.enabled=true
project.nodeCache.firstLoadSynch=true
project.output.allowUnsanitized=false
project.ssh-authentication=privateKey
project.ssh-command-timeout=0
project.ssh-connect-timeout=0
project.ssh-key-storage-path=keys/project/someproject/rundeck_id_rsa
resources.source.1.config.file=/var/lib/rundeck/nodes.yml
resources.source.1.config.format=resourceyaml
resources.source.1.config.requireFileExists=true
resources.source.1.config.writeable=true
resources.source.1.type=file
service.FileCopier.default.provider=jsch-scp
service.NodeExecutor.default.provider=jsch-ssh

Yet, when I try and run a Command from the UI, it fails:然而,当我尝试从 UI 运行Command时,它失败了:

Failed: SSHProtocolFailure: invalid privatekey: [B@7d7d0b2d

What am I doing incorrectly, and how do I successfully run a command over ssh on a remote node?我做错了什么,如何在远程节点上通过 ssh 成功运行命令?

Your node definition needs the ssh-key-storage-path attribute pointing to the Rundeck user private key (created before on Rundeck Key Storage), also, the osFamily attribute must be set as unix (not linux , Rundeck only admits two values there: unix and windows ).您的节点定义需要ssh-key-storage-path属性指向 Rundeck 用户私钥(之前在 Rundeck 密钥存储上创建),此外, osFamily属性必须设置为unix (不是linux ,Rundeck 只允许有两个值: unixwindows )。

To add an SSH node follow these steps:要添加 SSH 节点,请执行以下步骤:

  1. If you're using a WAR-based installation execute: ssh-keygen -t rsa -b 4096 .如果您使用的是基于 WAR 的安装,请执行: ssh-keygen -t rsa -b 4096 That generates two keys (private and public) on the user .ssh directory (the user that launches Rundeck).这会在用户.ssh目录(启动 Rundeck 的用户)上生成两个密钥(私有和公共)。 If you're using an RPM/DEB installation these keys are already created on the /var/lib/rundeck path.如果您使用的是 RPM/DEB 安装,这些密钥已经在/var/lib/rundeck路径上创建。

  2. Go to the remote SSH node (the account that you want to connect from Rundeck), then add the Rundeck server user public key to the authorized_keys file.转到远程 SSH 节点(您要从 Rundeck 连接的帐户),然后将 Rundeck 服务器用户公钥添加到authorized_keys文件中。 Then you can test that connection with ssh user@xxx.xxx.xxx.xxx from the Rundeck server user account.然后,您可以从 Rundeck 服务器用户帐户使用ssh user@xxx.xxx.xxx.xxx测试该连接。

  3. Launch Rundeck and then add to the Rundeck keys storage the rundeck user private key (remember to include the first and the last line " -----BEGIN RSA PRIVATE KEY----- " and " -----END RSA PRIVATE KEY----- ") in my case I use this path keys/rundeck .启动 Rundeck,然后将rundeck用户私钥添加到 Rundeck 密钥存储中(请记住包括第一行和最后一行“ -----BEGIN RSA PRIVATE KEY----- ”和“ -----END RSA PRIVATE KEY----- ") 在我的情况下,我使用这个路径keys/rundeck

  4. Create a new Project and then create the resources.xml file with remote node information.创建一个新项目,然后使用远程节点信息创建resources.xml文件。 To generate that file just go to Project Settings > Edit Nodes > Click on the "Configure Nodes" button > Click on "Add Sources +" > Select "+ File" option > in the "Format" field select resourcexml and fill the path in "File Path" field (put the file name at the end, usually "resources.xml", also, select "Generate", "Include Server Node" and "Writeable" checkboxes and click on the "Save" button.要生成该文件,只需转到项目设置>编辑节点>单击“配置节点”按钮>单击“添加源+”>选择“+文件”选项>在“格式”字段中选择resourcexml并填写路径“文件路径”字段(将文件名放在末尾,通常是“resources.xml”,另外,选择“生成”、“包含服务器节点”和“可写”复选框,然后单击“保存”按钮。

  5. Now you can edit that file including the remote node, which in my case is "node00" (a Vagrant test image), on the key-storage-path attribute I used the same path created in step 3:现在您可以在key-storage-path属性上编辑该文件,包括远程节点,在我的例子中是“node00”(一个 Vagrant 测试图像),我使用了在步骤 3 中创建的相同路径:

<?xml version="1.0" encoding="UTF-8"?>
<project>
  <node name="hyperion" description="Rundeck server node" tags="" hostname="hyperion" osArch="amd64" osFamily="unix" osName="Linux" osVersion="4.15.0-66-generic" username="ruser"/>
  <node name="node00" description="Node 00" tags="" hostname="192.168.33.20" osArch="amd64" osFamily="unix" osName="Linux" osVersion="3.10.0-1062.4.1.el7.x86_64" username="vagrant" ssh-key-storage-path="keys/rundeck"/>
</project>
  1. On Rundeck GUI go to the sidebar and check your nodes on the "Nodes" section.在 Rundeck GUI 上,转到侧边栏并在“节点”部分检查您的节点。 Check . 检查

  2. Go to "Commands" (sidebar) and put the SSH remote node name as a filter and launch any command like this .转到“命令”(侧边栏)并将 SSH 远程节点名称作为过滤器并启动任何这样的命令。

You can follow an entire guide here .您可以在此处阅读完整指南。

Alternatively, you can re-generate the key pairs with the following command: ssh-keygen -p -f /var/lib/rundeck/.ssh/id_rsa -m pem .或者,您可以使用以下命令重新生成密钥对: ssh-keygen -p -f /var/lib/rundeck/.ssh/id_rsa -m pem

The keystorage save the private-key with crlf and this was the issue I recognize with version 4.2.1 .密钥crlf使用keystorage保存private-key ,这是我在4.2.1版本中认识到的问题。

Do a dirty fix for ssh-exec.sh :ssh-exec.sh做一个肮脏的修复:

echo "$RD_CONFIG_SSH_KEY_STORAGE_PATH" > "$SSH_KEY_STORAGE_PATH"

insert these lines:插入这些行:

sed -i 's/\r$//' "$SSH_KEY_STORAGE_PATH"

SSHOPTS="$SSHOPTS -i $SSH_KEY_STORAGE_PATH"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM