Skip to main content

Restricting network traffic to your enterprise with an IP allow list

You can restrict access to your enterprise and only allow access to your resources from specified IP addresses by using an IP allow list.

谁可以使用此功能?

Enterprise owners can configure IP allow lists.

About network traffic restrictions

By default, authorized users can access your enterprise's resources from any IP address. You can restrict access to your enterprise's private resources by configuring a list that allows or denies access from specific IP addresses. 例如,你可以只允许从你的办公网络的 IP 地址访问专用资源。

如果列表允许 IP 地址,则从该地址连接到 GitHub.com 的经过身份验证的用户可以访问专用资源。 如果用户的 IP 地址是不允许的,那么在从允许的地址进行连接之前,该用户无法访问专用资源。

配置 IP 允许列表后,该列表将确定用户是否可以使用以下任一身份验证方法通过 Web UI、API 或 Git 访问受保护的资源。

  • 使用 GitHub 身份验证或 SAML SSO 的用户名和密码
  • Personal access token
  • SSH 密钥

IP 允许列表适用于具有任何角色或访问权限的用户,包括企业和组织所有者、存储库管理员和外部协作者。

如果用户登录到 GitHub.com,则 IP 允许列表将确定用户是否可以访问组织的公共资源。 该列表不适用于对公共资源的匿名访问。

只有对组织拥有的存储库的访问权限由 IP 允许列表确定。 该列表不控制对 托管用户帐户 拥有的存储库或存储库分支的访问。

不需要直接从 GitHub 提取私有数据或组织数据的 GitHub Copilot 功能不受 IP 允许列表的限制,因为错误使用的唯一风险是 GitHub 自己的计算资源。

If your enterprise uses Enterprise Managed Users with Microsoft Entra ID (previously known as Azure AD) and OIDC, you can choose whether to use GitHub's IP allow list feature or to use the allow list restrictions for your identity provider (IdP). If your enterprise does not use Enterprise Managed Users with Azure and OIDC, you can use GitHub's allow list feature.

About GitHub's IP allow list

You can use GitHub's IP allow list to control access to your enterprise and assets owned by organizations in your enterprise.

您可以使用 CIDR 表示法批准访问单个 IP 地址或地址范围。 有关详细信息,请参阅维基百科上的”CIDR 表示法”。

要执行 IP 允许列表,必须先将 IP 地址添加到列表,然后启用 IP 允许列表。 在完成列表后,可以检查列表中任何已启用条目是否允许使用特定 IP 地址。

您必须先添加当前 IP 地址或匹配范围,然后才能启用 IP 允许列表。 启用允许列表时,您配置的 IP 地址将立即添加到企业中的组织允许列表中。 如果禁用允许列表,则地址将从组织允许列表中删除。

组织所有者可以向其组织的允许列表添加其他条目,但他们无法管理从企业帐户的允许列表继承的条目,企业所有者也无法管理添加到组织的允许列表的条目。有关详细信息,请参阅“管理组织允许的 IP 地址”。

您可以选择将为组织中安装的 GitHub Apps 配置的任何 IP 地址自动添加到允许列表中。 GitHub App 的创建者可以为其应用程序配置允许列表,指定应用程序运行的 IP 地址。 通过将允许列表继承到您的列表中,您可以避免申请中的连接请求被拒绝。 有关详细信息,请参阅“允许 GitHub 应用进行访问”。

About your IdP's allow list

If you are using Enterprise Managed Users with Entra ID and OIDC, you can use your IdP's allow list.

Using your IdP's allow list deactivates the GitHub IP allow list configurations for all organizations in your enterprise and deactivates the GraphQL APIs for enabling and managing IP allow lists.

By default, your IdP runs the CAP on the initial interactive SAML or OIDC sign-in to GitHub for any IP allow list configuration you choose.

The OIDC CAP only applies for requests to the API using a user token, such as an OAuth token for an OAuth app or a user access token for a GitHub App acting on behalf of a user. The OIDC CAP does not apply when a GitHub App uses an installation access token. For more information, see "关于使用 GitHub 应用进行身份验证" and "About support for your IdP's Conditional Access Policy."

To ensure seamless use of the OIDC CAP while still applying the policy to OAuth tokens and user access tokens, you must copy all of the IP ranges from each GitHub App that your enterprise uses to your IdP policy.

Using GitHub's IP allow list

Enabling GitHub's IP allow list

  1. 在 GitHub 的右上角,选择个人资料照片,然后单击 你的组织”。
  2. 在组织旁边,单击“设置”。
  3. 在侧边栏的“安全性”部分中,单击“ 身份验证安全性”。
  4. If you're using Enterprise Managed Users with OIDC, under "IP allow list", select the IP allow list configuration dropdown menu and click GitHub.
  5. Under "IP allow list", select Enable IP allow list.
  6. Click Save.

Adding an allowed IP address

可以通过添加每个包含 IP 地址或地址范围的条目来创建 IP 允许列表。 在添加完条目后,可以检查列表中任何已启用条目是否允许使用特定 IP 地址。

对于企业中的组织拥有的专用资产,在列表限制对这些资产的访问权限之前,还必须启用允许的 IP 地址。

注意:GitHub 正在逐步推出对 IPv6 的支持。 随着 GitHub 服务继续添加 IPv6 支持,我们将开始识别 GitHub 用户的 IPv6 地址。 若要防止可能的访问中断,请确保将任何所需的 IPv6 地址添加到 IP 允许列表。

注意: 由于缓存的原因,添加或移除 IP 地址后可能需要几分钟才能完全生效。

  1. 在 GitHub 的右上角,单击你的个人资料照片,然后单击“你的企业”****。

  2. 在企业列表中,单击您想要查看的企业。

  3. 在页面左侧的企业帐户边栏中,单击 设置”。

  4. 在“ 设置”下,单击“身份验证安全性” 。

  5. 在“IP 允许列表”部分的底部,在“采用 CIDR 表示法的 IP 地址或范围”字段中,键入以 CIDR 表示法表示的 IP 地址或地址范围。

    IP 允许列表设置的屏幕截图。 标记为“采用 CIDR 表示法的 IP 地址或范围”的文本字段以橙色边框突出显示。

  6. (可选)在“IP 地址或范围的简短说明”字段中,输入允许的 IP 地址或范围的说明。

  7. 单击“添加”。

  8. (可选)检查列表中是否有任何已启用条目允许使用特定 IP 地址。 有关详细信息,请参阅“检查是否允许使用 IP 地址”。

Allowing access by GitHub Apps

如果您使用允许列表,还可以选择将为企业中安装的 GitHub Apps 配置的任何 IP 地址自动添加到允许列表中。

如果你在允许列表设置中选择“为已安装的 GitHub 应用程序启用 IP 允许列表配置”,则来自已安装 GitHub Apps 的 IP 地址将添加到你的允许列表中。 不管您的允许列表目前是否启用,都会发生这种情况。 如果您安装 GitHub App,然后该应用程序的创建者更改其允许列表中的地址,则允许列表会自动更新这些更改。

您可以通过查看描述字段来识别从 GitHub Apps 自动添加的 IP 地址。 这些 IP 地址的描述是:“由 NAME GitHub App管理”。 与手动添加的地址不同,您无法编辑、删除或禁用从 GitHub Apps 自动添加的 IP 地址。

注意: GitHub App IP 允许列表中的地址仅影响 GitHub App 安装提出的请求。 将 GitHub App 的 IP 地址自动添加到组织的允许列表中不允许访问从该 IP 地址连接的 GitHub Enterprise Cloud 用户。

若要详细了解如何为已创建的 GitHub App 创建允许列表,请参阅“管理 GitHub 应用程序允许的 IP 地址”。

为 GitHub Apps 启用自动添加 IP 地址:

  1. 在 GitHub 的右上角,单击你的个人资料照片,然后单击“你的企业”****。

  2. 在企业列表中,单击您想要查看的企业。

  3. 在页面左侧的企业帐户边栏中,单击 设置”。

  4. 在“ 设置”下,单击“身份验证安全性” 。

  5. 在“IP 允许列表”下,选择“为已安装的 GitHub 应用启用 IP 允许列表配置”。

    注意:如果将 Enterprise Managed Users 与 OIDC 配合使用,则只有将 GitHub 用于 IP 允许列表配置时,才允许 GitHub 应用进行访问。

  6. 单击“保存” 。

Editing an allowed IP address

可以在 IP 允许列表中编辑条目。 如果编辑已启用的条目,则更改会立即实施。

在编辑完条目后,可以检查在启用你的允许列表后,你的允许列表是否允许来自特定 IP 地址的连接。

  1. 在 GitHub 的右上角,单击你的个人资料照片,然后单击“你的企业”****。

  2. 在企业列表中,单击您想要查看的企业。

  3. 在页面左侧的企业帐户边栏中,单击 设置”。

  4. 在“ 设置”下,单击“身份验证安全性” 。

  5. 在“IP 允许列表”下,在你要编辑的条目旁边,单击“编辑”。

  6. 在“IP 地址”字段中,以 CIDR 表示法键入 IP 地址或地址范围。

  7. 在“说明”字段中,输入允许的 IP 地址或范围的说明。

  8. Click Update.

  9. (可选)检查列表中是否有任何已启用条目允许使用特定 IP 地址。 有关详细信息,请参阅“检查是否允许使用 IP 地址”。

Checking if an IP address is permitted

可以检查 IP 允许列表中是否有任何已启用条目允许使用特定 IP 地址(即使列表当前未启用)。

  1. 在 GitHub 的右上角,单击你的个人资料照片,然后单击“你的企业”****。

  2. 在企业列表中,单击您想要查看的企业。

  3. 在页面左侧的企业帐户边栏中,单击 设置”。

  4. 在“ 设置”下,单击“身份验证安全性” 。

  5. 在“IP 允许列表”部分的末尾,在“检查 IP 地址”下输入 IP 地址。

    “检查 IP 地址”文本字段的屏幕截图。

Deleting an allowed IP address

注意: 由于缓存的原因,添加或移除 IP 地址后可能需要几分钟才能完全生效。

  1. 在 GitHub 的右上角,单击你的个人资料照片,然后单击“你的企业”****。

  2. 在企业列表中,单击您想要查看的企业。

  3. 在页面左侧的企业帐户边栏中,单击 设置”。

  4. 在“ 设置”下,单击“身份验证安全性” 。

  5. 在“IP 允许列表”下,单击要删除的条目旁边的“删除”。

  6. 要永久删除该条目,请单击“是,删除此 IP 允许列表条目”。

Using your identity provider's allow list

Note: Using your IdP's allow list is only supported for Enterprise Managed Users with Entra ID and OIDC.

  1. 在 GitHub 的右上角,选择个人资料照片,然后单击 你的组织”。
  2. 在组织旁边,单击“设置”。
  3. 在侧边栏的“安全性”部分中,单击“ 身份验证安全性”。
  4. Under "IP allow list", select the IP allow list configuration dropdown menu and click Identity Provider.
  5. Optionally, to allow installed GitHub and OAuth apps to access your enterprise from any IP address, select Skip IdP check for applications.
  6. Click Save.

Using GitHub Actions with an IP allow list

警告:如果使用 IP 允许列表并且还想使用 GitHub Actions,则必须使用自托管的运行器,或 GitHub 托管的具有静态 IP 地址范围的大型运行器。 使用 Azure 专用网络时,必须使用来自 Azure 子网的 IP。 要减少所需的 IP 数,建议创建负载均衡器,以便为 GitHub 允许列表提供单一 IP 范围。 有关详细信息,请参阅“关于自托管运行程序”或“关于较大的运行器”。

若要允许自托管或大型托管运行器与 GitHub 通信,请将你的运行器的 IP 地址或 IP 地址范围添加到你为企业配置的 IP 允许列表中。

Using GitHub Pages with an IP allow list

如果使用自定义 GitHub Actions 工作流作为 GitHub Pages 网站的发布源,以允许运行器连接和生成站点,则必须为 IP 允许列表配置规则。

如果不使用自定义工作流,则在默认情况下,生成运行器将具有对 GitHub Pages 站点的存储库的访问权限。 有关发布源的详细信息,请参阅“为 GitHub Pages 站点配置发布源”。