Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Git 生成期间的SSH转发仅适用于根用户_Git_Docker_Ssh_Bitbucket - Fatal编程技术网

Git 生成期间的SSH转发仅适用于根用户

Git 生成期间的SSH转发仅适用于根用户,git,docker,ssh,bitbucket,Git,Docker,Ssh,Bitbucket,下面是一个Dockerfile: # syntax=docker/dockerfile:1.0.0-experimental FROM debian:buster-slim as base # setup APT operation for noninteractive use # This avoids a bunch of warnings like # "debconf: unable to initialize frontend: Dialog" ENV DEBIAN_FRONTEND

下面是一个Dockerfile:

# syntax=docker/dockerfile:1.0.0-experimental
FROM debian:buster-slim as base

# setup APT operation for noninteractive use
# This avoids a bunch of warnings like
# "debconf: unable to initialize frontend: Dialog"
ENV DEBIAN_FRONTEND=noninteractive

# install requirements
RUN apt-get update \
    && apt-get upgrade -y \
    && apt-get install -y --no-install-recommends \
        git \
        openssh-client

# add a user
# RUN adduser --disabled-password app-user
# WORKDIR /home/app-user
# USER app-user

RUN mkdir --mode=0700 ~/.ssh
RUN printf "Host <bitbucket host>\n  StrictHostKeyChecking no\n  CheckHostIP no\n" >> ~/.ssh/config
RUN chmod 600 ~/.ssh/config
RUN --mount=type=ssh ssh-keyscan -t rsa <bitbucket host> >> ~/.ssh/known_hosts
RUN chmod 600 ~/.ssh/known_hosts

RUN --mount=type=ssh git clone --no-checkout 'ssh://git@<bitbucket host>/my/project.git'
#syntax=docker/dockerfile:1.0.0-1
来自debian:buster slim作为基础
#设置APT操作以供非交互使用
#这避免了像这样的一系列警告
#“debconf:无法初始化前端:对话框”
环境DEBIAN_前端=非交互
#安装要求
运行apt获取更新\
&&apt获得升级-y\
&&apt get install-y--不建议安装\
吉特\
openssh客户端
#添加用户
#运行adduser--禁用的密码应用程序用户
#WORKDIR/主页/应用程序用户
#用户应用程序用户
运行mkdir--mode=0700~/.ssh
运行printf“Host\n StrictHostKeyChecking no\n CheckHostIP no\n”>>~/.ssh/config
运行chmod 600~/.ssh/config
RUN--mount=type=ssh-ssh-keyscan-t rsa>>>~/.ssh/known\u主机
运行chmod 600~/.ssh/known_主机
运行--mount=type=ssh git clone--不签出'ssh://git@/我的/project.git'
我唯一删掉的是实际的bitbucket主机。现在,不起作用的是激活“添加用户”注释后的三个逗号。如果激活这三个命令,则生成将失败:

#20 [13/13] RUN --mount=type=ssh git clone --no-checkout 'ssh://git@bitbucke...
#20       digest: sha256:2ca1...
#20         name: "[13/13] RUN --mount=type=ssh git clone --no-checkout 'ssh://git@<bitbucket host>/my/project.git'"
#20      started: 2020-03-31 20:12:44.957895838 +0000 UTC
#20 0.648 Cloning into 'project'...
#20 1.170 git@<bitbucket host>: Permission denied (publickey).
#20 1.171 fatal: Could not read from remote repository.
#20 1.171 
#20 1.171 Please make sure you have the correct access rights
#20 1.171 and the repository exists.
#20    completed: 2020-03-31 20:12:46.235264455 +0000 UTC
#20     duration: 1.277368617s
#20        error: "executor failed running [/bin/sh -c git clone --no-checkout 'ssh://git@<bitbucket host>/my/project.git']: exit code: 128"

rpc error: code = Unknown desc = executor failed running [/bin/sh -c git clone --no-checkout 'ssh://git@<bitbucket host>/my/project.git']: exit code: 128
#20[13/13]运行--mount=type=ssh-git-clone--不签出'ssh://git@比特巴克。。。
#20摘要:sha256:2ca1。。。
#20名称:“[13/13]运行--mount=type=ssh git clone--无签出”ssh://git@/我的/project.git“
#20开始:2020-03-31 20:12:44.957895838+0000 UTC
#20 0.648克隆到“项目”。。。
#20 1.170吉特@:拒绝许可(公钥)。
#20 1.171致命:无法从远程存储库读取。
#20 1.171 
#20 1.171请确保您拥有正确的访问权限
#20 1.171和存储库存在。
#完成时间:2020-03-31 20:12:46.235264455+0000 UTC
#20时长:1.277368617秒
#20错误:“执行器无法运行[/bin/sh-c git clone--无签出”ssh://git@/my/project.git']:退出代码:128“
rpc错误:code=Unknown desc=executor无法运行[/bin/sh-c git clone--无签出'ssh://git@/my/project.git']:退出代码:128
这是Docker的一个bug吗?我是否遗漏了一个暗示,即这不应该以某种方式起作用?我是否需要在根帐户和新用户帐户之间设置额外的转发级别?git/ssh首先是如何与代理建立通信的?我检查了
/tmp
/run
,装载和环境,但找不到管道/套接字

显而易见的解决方法是克隆为root,然后在其上运行
chown-R
,但这似乎非常不合法。另外,我显然想了解发生了什么。

Buildkit指令将主机的ssh代理套接字重新安装到具有特定权限的容器中。默认值为root用户所有(uid=0,gid=0),其他用户无法读取(mode=0600)

您可以添加一个选项,使套接字归某个已知的非root用户所有:

#创建用户时,请指定其uid
运行adduser--禁用密码--uid 999应用程序用户
用户应用程序用户
#还指定uid作为装载选项
运行--mount=type=ssh,uid=999 ssh密钥扫描。。。
您还可以让其他用户访问套接字(这不是一个很大的安全问题,因为它只能在单个
RUN
命令的生命周期内访问,并且您可以控制它运行的内容)

RUN--mount=type=ssh,mode=0666 ssh-keyscan。。。

添加子选项
--mount=type=ssh,uid=1000
(匹配
应用程序用户的数字用户ID
)是否有效?看起来这会使非root用户无法访问转发代理套接字。我相信这就是答案,@DavidMaze。但是,我宁愿使用
模式
子选项。但我必须从18.09升级,因为该版本不理解这两个变体中的任何一个。