【问题标题】:sshd AuthorizedKeysCommand throws status 127sshd AuthorizedKeysCommand 抛出状态 127
【发布时间】:2018-01-30 04:35:42
【问题描述】:

我正在尝试构建一个 ssh 服务以允许推/拉到 phabricator 存储库。我已经对所有服务进行了 docker 化,目前遇到了一个奇怪的错误,无法执行 ssh 所需的身份验证脚本。

docker 镜像同时运行 php-fpmsshd 服务,其理念是将 ssh 与必要的 php 脚本结合起来。

特别是,我有以下 /etc/ssh/sshd_config:

AuthorizedKeysCommand /usr/libexec/phabricator-ssh-hook.sh
AuthorizedKeysCommandUser git
AllowUsers git

Port 2222
Protocol 2
PermitRootLogin no
AllowAgentForwarding no
AllowTcpForwarding no
PrintMotd no
#PrintLastLog no
PasswordAuthentication no
ChallengeResponseAuthentication no
AuthorizedKeysFile none

PidFile /var/run/sshd-phabricator.pid

(附带说明,当我启动 sshd 时,PrintLastLog 会抛出一个错误,我认为这不相关,但可能是??)

当我手动运行时

su - git -c "/srv/phabricator/scripts/ssh/ssh-auth.php git",我可以成功执行脚本了。

但是,当我在调试模式 (/usr/sbin/sshd -d -d -d) 下检查 sshd 日志时,我收到以下错误:

...other stuff...
debug3: monitor_read: checking request 22
debug3: mm_answer_keyallowed entering
debug3: mm_answer_keyallowed: key_from_blob: 0x5564c1f473c0
debug3: subprocess: AuthorizedKeysCommand command "/usr/libexec/phabricator-ssh-hook.sh git" running as git
debug1: temporarily_use_uid: 1000/1000 (e=0/0)
debug1: restore_uid: 0/0
debug3: subprocess: AuthorizedKeysCommand pid 885
debug1: temporarily_use_uid: 1000/1000 (e=0/0)
debug2: key not found
AuthorizedKeysCommand /usr/libexec/phabricator-ssh-hook.sh git failed, status 127
debug1: restore_uid: 0/0
Failed publickey for git from some.ip.address.here port 58378 ssh2: ED25519 SHA256:GBGS4ag9s8msV3XsuojlIoqATF63tvXU3t5GIUN0eYY
debug3: mm_answer_keyallowed: key 0x5564c1f473c0 is not allowed
debug3: mm_request_send entering: type 23
debug2: userauth_pubkey: authenticated 0 pkalg ssh-ed25519 [preauth]
debug3: userauth_finish: failure partial=0 next methods="publickey" [preauth]
debug3: send packet: type 51 [preauth]
Connection closed by 24.5.151.66 port 58378 [preauth]
debug1: do_cleanup [preauth]
debug1: monitor_read_log: child log fd closed
debug3: mm_request_receive entering
debug1: do_cleanup
debug1: Killing privsep child 884

编辑:似乎 /usr/libexec/phabricator-ssh-hook.sh 确实执行了,但它执行的脚本 /srv/phabricator/bin/ssh-auth 可能会失败。该文件(phabricator 目录)实际上位于主机卷上。我想知道这是否是导致这些 status 127 问题的原因。

我读到当从 PATH 中找不到给定命令并且它不是内置 shell 命令(或找不到脚本使用的库)时,/bin/sh 返回状态 127。

话虽如此,我可以手动执行脚本,所以状态 127 似乎不太可能与此有关。

请注意,我也可以作为git 用户执行。

docker 容器版本信息:

Linux version 4.11.9-1-ARCH (builduser@tobias) (gcc version 7.1.1 20170621 (GCC) ) #1 SMP PREEMPT Wed Jul 5 18:23:08 CEST 2017

我们将不胜感激。

编辑

码头工人版本

Client:
 Version:      17.06.0-ce
 API version:  1.30
 Go version:   go1.8.3
 Git commit:   3dfb8343
 Built:        Wed Jul 26 18:03:33 2017
 OS/Arch:      linux/amd64

Server:
 Version:      17.06.0-ce
 API version:  1.30 (minimum version 1.12)
 Go version:   go1.8.3
 Git commit:   02c1d87617
 Built:        Wed Jul 26 20:03:39 2017
 OS/Arch:      linux/amd64
 Experimental: false

码头工人信息

Containers: 10
 Running: 10
 Paused: 0
 Stopped: 0
Images: 147
Server Version: 17.06.0-ce
Storage Driver: overlay2
 Backing Filesystem: extfs
 Supports d_type: true
 Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins: 
 Volume: local
 Network: bridge host macvlan null overlay
 Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: cfb82a876ecc11b5ca0977d1733adbe58599088a
runc version: 2d41c047c83e09a6d61d464906feb2a2f3c52aa4
init version: 949e6fa
Security Options:
 seccomp
  Profile: default
Kernel Version: 4.11.9-1-ARCH
Operating System: Arch Linux
OSType: linux
Architecture: x86_64
CPUs: 4
Total Memory: 7.631GiB
Name: <host-name>
ID: KYNR:4YHS:T4C2:URUY:GIB5:KCNF:DCNC:JLUT:DYO3:D5P7:VVOD:C2YV
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Experimental: false
Insecure Registries:
 127.0.0.0/8
Live Restore Enabled: false

【问题讨论】:

  • 发布 Dockerfile,docker versiondocker info
  • @user2915097 已更新,虽然 Dockerfile 相当大,我宁愿不公开发布。
  • secure.phabricator.com/book/phabricator/article/… "脚本本身和脚本所在的父目录都必须是root所有,并且脚本必须有755的权限。如果不这样做,sshd会拒绝执行钩子。”你检查了吗?
  • @ephemient 是的,我已经使用相关权限保护了文件。我已经多次梳理了该文档。这正在成为一个非常令人沮丧的问题......
  • 也许我可以做一些调试,或者我可以找到一些脚本来充实status 127 错误?

标签: docker ssh openssh phabricator sshd


【解决方案1】:

我也在为此苦苦挣扎。最终,我在执行phabricator-ssh-hook.sh时发现php不在PATH中。就我而言,它安装在/usr/local/bin(FreeBSD 默认)中,所以我添加了:

export PATH="/usr/local/bin:$PATH"

phabricator-ssh-hook.sh的最后一行之前。

【讨论】:

  • 我不记得我做了什么,但我最终让它工作了。这似乎是一个有效的解决方案,所以我会将其标记为已回答。
  • 在我的情况下,我需要将/usr/bin添加到路径中以便/usr/bin/env也可以执行,或者将/opt/bitnami/phabricator/bin/ssh-auth的shebang从#!/usr/bin/env php直接更改为#!/opt/bitnami/php/bin/php
【解决方案2】:

我遇到了类似的问题,但在 docker 容器中没有。上面 ehemient 的这条评论为我解决了这个问题:https://secure.phabricator.com/book/phabricator/article/diffusion_hosting/ 脚本本身和脚本所在的父目录都必须由 root 拥有,并且脚本必须具有 755 权限。如果你不这样做,sshd 将拒绝执行钩子。”你检查了吗?

【讨论】:

    【解决方案3】:

    我能够使用以下配置来实现此功能

    AuthorizedKeysCommand /bin/sh /etc/ssh/auth.sh %u %f %k
    AuthorizedKeysCommandUser root
    

    直接运行脚本时它正在抛出

    May 13 17:22:11 ip-10-0-0-100 sshd[5833]: error: AuthorizedKeysCommand /etc/ssh/auth.sh user failed, status 127
    

    直接调用/bin/sh后,成功了!

    【讨论】:

    • 这个答案解决了我的问题,但确保在 auth.sh 中有一个 shebang 行也同样有效。
    【解决方案4】:

    我的脚本指定了#!/bin/bash,但 bash 不可用。我不得不把它改成#!/bin/sh

    【讨论】:

      猜你喜欢
      • 2018-07-27
      • 1970-01-01
      • 2022-08-15
      • 1970-01-01
      • 1970-01-01
      • 2018-03-01
      • 1970-01-01
      • 2022-08-23
      • 2019-06-08
      相关资源
      最近更新 更多