【问题标题】:Why is openshift oc new-app not using the --source-secret I provided?为什么 openshift oc new-app 不使用我提供的 --source-secret?
【发布时间】:2017-12-15 19:59:46
【问题描述】:

我正在这样启动操作系统:

oc cluster up --public-hostname=julio-oc.10.238.41.233.nip.io

我还有一个私有 github 存储库,配置了部署密钥,只有一个微不足道的 Dockerfile

然后我将秘密添加如下:

oc secrets new-sshauth sleep-key-rsa --ssh-privatekey=/home/julio/.ssh/sleep-key_rsa

如果我尝试创建应用程序,它会失败:

> oc new-app --source-secret=sleep-key-rsa git@github-isl-01.ca.com:garju09/docker-sleep.git
error: Errors occurred while determining argument types:

git@github-isl-01.ca.com:garju09/docker-sleep.git as a Git repository URL:  Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

但如果我将密钥添加到 ssh 代理,它现在可以工作了:

> ssh-add ~/.ssh/sleep-key_rsa
Identity added: /home/julio/.ssh/sleep-key_rsa (/home/julio/.ssh/sleep-key_rsa)

> oc new-app --source-secret=sleep-key-rsa git@github-isl-01.ca.com:garju09/docker-sleep.git
--> Found Docker image 3fa8225 (2 weeks old) from Docker Hub for "centos:centos7"

    * An image stream will be created as "centos:centos7" that will track the source image
    * A Docker build using source code from git@github-isl-01.ca.com:garju09/docker-sleep.git will be created
      * The resulting image will be pushed to image stream "docker-sleep:latest"
      * Every time "centos:centos7" changes a new build will be triggered
      * WARNING: this source repository may require credentials.
                 Create a secret with your git credentials and use 'set build-secret' to assign it to the build config.
    * This image will be deployed in deployment config "docker-sleep"
    * The image does not expose any ports - if you want to load balance or send traffic to this component
      you will need to create a service with 'expose dc/docker-sleep --port=[port]' later
    * WARNING: Image "centos:centos7" runs as the 'root' user which may not be permitted by your cluster administrator

--> Creating resources ...
    imagestream "centos" created
    imagestream "docker-sleep" created
    buildconfig "docker-sleep" created
    deploymentconfig "docker-sleep" created
--> Success
    Build scheduled, use 'oc logs -f bc/docker-sleep' to track its progress.
    Run 'oc status' to view your app.

为什么new-app没有使用我指定的--source-secret

更新

> oc version
oc v3.7.0+7ed6862
kubernetes v1.7.6+a08f5eeb62
features: Basic-Auth GSSAPI Kerberos SPNEGO

Server https://127.0.0.1:8443
openshift v3.7.0+7ed6862
kubernetes v1.7.6+a08f5eeb62

我的主要信息来源是以下博客:https://blog.openshift.com/private-git-repositories-part-2a-repository-ssh-keys/

请注意,密钥上没有密码,我尝试了各种其他排列,包括以下。唯一适用于项目创建的是ssh-add。奇怪的是,创建项目后,我可以清空ssh-agent 并且操作系统构建没有问题:

oc secrets new-sshauth sleep-key-rsa --ssh-privatekey=/home/julio/.ssh/sleep-key_rsa
oc secrets link builder sleep-key-rsa
oc new-app --source-secret=sleep-key-rsa https://github-isl-01.ca.com/garju09/docker-sleep.git

但上述方法不起作用,因为 https 需要在我们的部署中进行身份验证。

oc secrets new-sshauth sleep-key-rsa --ssh-privatekey=/home/julio/.ssh/sleep-key_rsa
oc secrets link builder sleep-key-rsa
oc new-app git@github-isl-01.ca.com:garju09/docker-sleep.git

也失败了。

更新 2: 我创建了一个 github 存储库来复制问题并显示我正在使用的脚本:https://github.com/julio-garcia-fc/docker-sleep

如果你克隆它并拥有 oc 3.7,你应该能够运行 oc.sh 并且你会看到它失败。

【问题讨论】:

  • 您提到需要ssh-add 是因为oc new-app 正在将源代码下载到您的本地计算机以运行算法来确定如何构建它。如果您尝试进行 docker 类型构建,请提供参数 --strategy docker。如果您使用的是 S2I,请提供选项 --strategy source 并提供 S2I 构建器名称以与 repo 详细信息一起使用,即 <s2i-builder-image>~<repository-url>。这样oc new-app 不需要拉下 repo 来解决如何构建源代码。
  • 请注意目前 (3.6/3.7) 在 oc new-app 中存在一个错误,如果使用 --strategy source 并使用 --image-stream 作为 S2I 构建器名称,使用 --code 作为存储库 URL,它错误地仍在拉回购,并不必要地试图弄清楚如何构建。避免使用显式选项并使用<s2i-builder-image>~<repository-url> 形式的命令。

标签: github openshift openshift-origin


【解决方案1】:

您需要说明构建器服务帐户可以访问您的密钥。见:

以及该系列中的所有其他博客文章。

你需要的命令是:

oc secrets link builder sleep-key-rsa

【讨论】:

  • 谢谢格雷厄姆。我看过那个博客,这就是我所关注的。当您指定 --source-secret 时,您指示的命令似乎是多余的。它不能解决问题。
  • 能不能不使用--source-secret,试试博文中介绍的方法?甚至尝试使用 Web 控制台方法而不是命令行。我肯定知道博客文章中的方法有效,所以如果博客文章中的命令行和 Web 控制台方法都不起作用,那么就知道存在问题。您是否还确保 SSH 密钥上没有密码?
  • 我建议这样做的部分原因是,从记忆中我认为--source-secret 是出于不同的目的。也就是说,允许构建容器内部的秘密供构建步骤使用。不是为了拉下 Git 存储库开始。很确定--source-secret 在写博客文章时已经存在,但它不是必需的,所以为什么不使用。或者--source-secret当时不存在,不记得了。
  • 所以使用oc secrets new-sshauth,然后是oc secrets link builder,然后是oc set build-secret
  • 格雷厄姆,原谅我的无知。我对此很陌生,但在我看来,我陷入了先有鸡还是先有蛋的境地。据我所知,我需要运行 new-app 来获取构建配置,而构建配置是构建秘密适用的地方。不幸的是,新应用失败了,所以如果新应用失败,我看不到如何调用 build-secret。
猜你喜欢
  • 2020-08-20
  • 2020-07-01
  • 1970-01-01
  • 2019-06-12
  • 2019-04-14
  • 1970-01-01
  • 1970-01-01
  • 2020-08-20
  • 1970-01-01
相关资源
最近更新 更多