【问题标题】:Docker-Machine do not work with Google Cloud service accountDocker-Machine 不适用于 Google Cloud 服务帐户
【发布时间】:2017-11-10 16:18:11
【问题描述】:

我使用服务帐户创建一个 google 计算实例

gcloud --project my-proj compute instances create test1 \
--image-family "debian-9" --image-project "debian-cloud" \
--machine-type "g1-small" --network "default" --maintenance-policy "MIGRATE" \
--service-account "gke-build-robot@myproj-184015.iam.gserviceaccount.com" \
--scopes "https://www.googleapis.com/auth/cloud-platform" \
--tags "gitlab-runner" \
--boot-disk-size "10" --boot-disk-type "pd-standard" --boot-disk-device-name "$RESOURCE_NAME" \
--metadata register_token=mytoken,config_bucket=gitlab_config,runner_name=test1,gitlab_uri=myuri,runner_tags=backend \
--metadata-from-file "startup-script=startup-scripts/prepare-runner.sh"

通过 ssh 登录到实例:gcloud compute --project "myproj" ssh --zone "europe-west1-b" "gitlab-shared-runner-pool"

安装和配置 docker 机器后。我尝试创建实例:

     docker-machine create --driver google --google-project myproj test2
    Running pre-create checks...
    (test2) Check that the project exists
    (test2) Check if the instance already exists
    Creating machine...
    (test2) Generating SSH Key
    (test2) Creating host...
    (test2) Opening firewall ports
    (test2) Creating instance
    (test2) Waiting for Instance
Error creating machine: Error in driver during machine creation: Operation error: {EXTERNAL_RESOURCE_NOT_FOUND  The resource '1045904521672-compute@developer.gserviceaccount.com' of type 'serviceAccount' was not found. []}

1045904521672-compute@developer.gserviceaccount.com 是我的默认帐户。 我不明白为什么使用它。因为激活的是 gke-build-robot@myproj-184015.iam.gserviceaccount.com

gcloud config list
[core]
account = gke-build-robot@myproj-184015.iam.gserviceaccount.com
disable_usage_reporting = True
project = novaposhta-184015
Your active configuration is: [default]

 gcloud auth list
                      Credentialed Accounts
ACTIVE  ACCOUNT
*       gke-build-robot@myproj-184015.iam.gserviceaccount.com

谁能解释一下,我做错了什么?

【问题讨论】:

  • 我使用的是 0.12 版本的 docker 机器。 0.13版本不行,总是返回segmentation failed。
  • 我看到 $GOOGLE_APPLICATION_CREDENTIALS 是空的。我不明白,gcloud 凭据存储在哪里
  • 完整的脚本可以在这里找到github.com/GrigorievNick/gitlab-runner-gce

标签: docker docker-machine google-compute-engine


【解决方案1】:

有双重问题。

  • 首先,docker-machine 不能使用特定的服务帐户,至少在 0.12 和 0.13 版本中。
  • Docker+Machine google驱动只有scope参数,无法获取具体参数。
    因此,安装 docker+machine 的实例在指定的sa 下工作正常。 但是使用 docker+machine 创建的实例,必须有默认服务帐号
    在调试期间,我将其关闭。
    结果我遇到了这个错误。

【讨论】:

    【解决方案2】:

    类似的问题 (bosh-google-cpi-release issue 144) 以某种方式暗示了

    此错误消息不清楚,特别是因为还需要在清单中指定的凭据可能完全与另一个帐户相关联。

    bosh-google-cpi-release 的默认 service_account 设置为“default”,如果它不是由 bosh 清单主动设置的,那么每当您使用 service_scopes 而不是 service_account 时都会发生这种情况。

    虽然您没有使用bosh-google-cpi-release,但最后一句话让我仔细检查了gcloud reference page,尤其是gcloud compute instance create

    服务帐户是附加到实例的身份。其访问令牌可以通过实例元数据服务器访问,并用于对实例上的应用程序进行身份验证。
    该帐户可以是电子邮件地址,也可以是与服务帐户对应的别名。您可以使用“default”别名明确指定 Compute Engine 默认服务帐号。

    如果未提供,实例将获取项目的默认服务帐号。

    就好像您的服务帐户被忽略或不正确(并回退到项目默认帐户)

    请参阅“Creating and Enabling Service Accounts for Instances”以仔细检查其值:

    通常,服务帐户的电子邮件来自服务帐户 ID,格式为:

    [SERVICE-ACCOUNT-NAME]@[PROJECT_ID].iam.gserviceaccount.com
    

    或者试试setting first the service scope and account

    【讨论】:

    • 此服务帐户工作正常。由于公司政策原因,我更改了它的名称。我不想为我的默认服务帐户创建别名。我想使用带有特定机器的 docker 机器。错误消息只是显示 docker+machine 使用未指定的帐户,而是默认帐户。我把它关了一段时间。因为我注意到它已就地使用,我想使用特定帐户,而不是默认帐户。
    • 我不需要将服务帐户设置为实例。 gcloud 计算实例描述 gitlab-shared-runner-pool -> serviceAccounts:-电子邮件:gke-build-robot@myproj-184015.iam.gserviceaccount.com 范围:-googleapis.com/auth/cloud-platform gce 前景的一切都很好,但出于某种原因docker+machine 想使用默认服务帐号。
    • @user2870704 是的,这确实是问题所在。我认为明确强制使用服务帐户会改善这种情况。
    • 这无济于事。如何使用“默认”别名明确指定 Compute Engine 默认服务帐户。我需要创建名称为default 的sa?
    • 好吧,我的 UI 不工作。但我正在使用 gcloud ctl 重新启用 API。还有这个帮助。
    猜你喜欢
    • 2015-01-14
    • 1970-01-01
    • 2022-11-08
    • 2020-07-11
    • 1970-01-01
    • 2012-12-02
    • 2016-03-15
    • 1970-01-01
    • 2018-12-15
    相关资源
    最近更新 更多