Skip to main content

向 GitHub API 进行身份验证

了解如何向 GitHub API 进行身份验证,以将 Actions Runner Controller 与 GitHub.com 配合使用。

法律通告

概述

可以使用 GitHub App 或 personal access token (classic) 向 GitHub API 验证 Actions Runner Controller (ARC)。

注意:对于企业级运行器,不能使用 GitHub App 进行身份验证。 有关详细信息,请参阅“使用组管理对自托管运行程序的访问”。

使用 GitHub App 对 ARC 进行身份验证

  1. 创建由组织拥有的 GitHub App。 有关详细信息,请参阅“注册 GitHub 应用”。 按如下所示配置 GitHub App。

    1. 对于“主页 URL”,请输入 https://github.com/actions/actions-runner-controller

    2. 在“权限”下,单击“存储库权限”。 然后使用下拉菜单选择以下访问权限。

      • 管理:读取和写入

        注意Administration: Read and write 仅在配置 Actions Runner Controller 以在存储库范围内注册时必需。 在组织范围内注册时,它不是必需的。

      • 元数据:只读

    3. 在“权限”下,单击“组织权限”。 然后使用下拉菜单选择以下访问权限。

      • 自托管运行器:读取和写入
  2. 创建 GitHub App 后,在 GitHub App 页面上,记下“应用 ID”的值。 稍后会用到此值。

  3. 在“私钥”下,单击“生成私钥”并保存 .pem 文件。 稍后会用到此密钥。

  4. 在页面左上角的菜单中,单击“安装应用”,然后单击组织旁边的“安装”,以在组织上安装应用 。

  5. 确认组织的安装权限后,记下应用安装 ID。 稍后将使用它。 可以在应用安装页上找到应用安装 ID,该页的 URL 格式如下:

    https://github.com/organizations/ORGANIZATION/settings/installations/INSTALLATION_ID

  6. 将应用 ID、安装 ID 以及前面步骤中下载的 .pem 私钥文件作为机密注册到 Kubernetes。

    若要使用 GitHub App 的值创建 Kubernetes 机密,请运行以下命令。

    注意:**** 在安装 gha-runner-scale-set 图表的同一命名空间中创建机密。 在此示例中,命名空间是 arc-runners,与快速入门文档对应。 有关详细信息,请参阅“操作运行器控制器快速入门”。

    Bash
    kubectl create secret generic pre-defined-secret \
       --namespace=arc-runners \
       --from-literal=github_app_id=123456 \
       --from-literal=github_app_installation_id=654321 \
       --from-literal=github_app_private_key='-----BEGIN RSA PRIVATE KEY-----********'
    

    然后在 values.yaml 文件的副本中使用 githubConfigSecret 属性,将机密名称作为引用传递。

    githubConfigSecret: pre-defined-secret
    

有关其他 Helm 配置选项,请参阅 ARC 存储库中的 values.yaml

使用 personal access token (classic) 对 ARC 进行身份验证

ARC 可以使用 personal access tokens (classic) 注册自托管运行器。

注意: 如果在企业级注册运行器,使用 personal access token (classic) 对 ARC 进行身份验证是唯一受支持的身份验证方法。

  1. 使用所需范围创建 personal access token (classic)。 根据你是在存储库、组织或企业级别注册运行器,所需的范围会有所不同。 若要详细了解如何创建 personal access token (classic),请参阅“管理个人访问令牌”。

    下面是 ARC 运行器所需的 personal access token 范围的列表。

    • 存储库运行器:repo
    • 组织运行器:admin:org
    • 企业运行器:manage_runners:enterprise
  2. 若要使用 personal access token (classic) 的值创建 Kubernetes 机密,请运行以下命令。

    注意:**** 在安装 gha-runner-scale-set 图表的同一命名空间中创建机密。 在此示例中,命名空间是 arc-runners,与快速入门文档对应。 有关详细信息,请参阅“操作运行器控制器快速入门”。

    Bash
    kubectl create secret generic pre-defined-secret \
       --namespace=arc-runners \
       --from-literal=github_token='YOUR-PAT'
    
  3. values.yaml 文件的副本中,将机密名称作为引用传递。

    githubConfigSecret: pre-defined-secret
    

    有关其他 Helm 配置选项,请参阅 ARC 存储库中的 values.yaml

部分内容改编自 Apache-2.0 许可证下的 https://github.com/actions/actions-runner-controller/

Copyright 2019 Moto Ishizawa

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.