Skip to main content

此版本的 GitHub Enterprise 已停止服务 2022-10-12. 即使针对重大安全问题,也不会发布补丁。 为了获得更好的性能、更高的安全性和新功能,请升级到最新版本的 GitHub Enterprise。 如需升级帮助,请联系 GitHub Enterprise 支持

Enforcing policies for GitHub Actions in your enterprise

You can enforce policies for GitHub Actions within your enterprise's organizations, or allow policies to be set in each organization.

Who can use this feature

Enterprise owners can enforce policies for GitHub Actions in an enterprise.

About policies for GitHub Actions in your enterprise

GitHub Actions helps members of your enterprise automate software development workflows on GitHub Enterprise Server. For more information, see "Understanding GitHub Actions."

If you enable GitHub Actions, any organization on your GitHub Enterprise Server instance can use GitHub Actions. You can enforce policies to control how members of your enterprise on GitHub Enterprise Server use GitHub Actions. By default, organization owners can manage how members use GitHub Actions. For more information, see "Disabling or limiting GitHub Actions for your organization."

Enforcing a policy to restrict the use of GitHub Actions in your enterprise

You can choose to disable GitHub Actions for all organizations in your enterprise, or only allow specific organizations. You can also limit the use of public actions , so that people can only use local actions that exist in your enterprise.

  1. 在 GitHub Enterprise Server 的右上角,单击� 的个人资料照片,然后单击“企业设置”。 GitHub Enterprise Server 上个人资料照片下拉菜单中的“企业设置”

  2. 在企业边� �中,单击 “策略”。 企业帐户边� �中的“策略”选项卡

  3. 在“ 策略”下,单击“操作”。

  4. Under "Policies", select your options.

    如果选择 允许选择操作,则允许企业内的操作,并且还有允许其他特定操作的其他选项。 有关详细信息,请参阅“允许选择操作来运行”。

    本地到企业的操作

    Note: To enable access to public actions, you must first configure your GitHub Enterprise Server instance to connect to GitHub.com. For more information, see "Enabling automatic access to GitHub.com actions using GitHub Connect."

    Enable, disable, or limits actions for this enterprise account

  5. Click Save.

允许选择操作以运行

如果选择 允许选择操作,则允许本地操作,并且还允许其他特定操作的其他选项:

  • 允许 GitHub 创建的操作: 可以允许工作流使用 GitHub 创建的所有操作。 GitHub 创建的操作位于 actionsgithub 组织中。 有关详细信息,请参阅 actionsgithub 组织。

  • 允许经过验证的创建者执行的 Marketplace 操作:如果已启用 GitHub Connect 并配置了 GitHub Actions,则此选项可用。 有关详细信息,请参阅“使用 GitHub Connect 启用对 GitHub.com 操作的自动访问。”可以允许工作流使用由经过验证的创建者创建的所有 GitHub Marketplace 操作。 如果 GitHub 验证该操作的创建者为合作伙伴组织, 徽� 将显示在 GitHub Marketplace 中的操作旁边。

  • 允许指定的操作:可以限制工作流使用特定组织和存储库中的操作。

    若要限制对操作的特定� �记或提交 SHA 的访问,请使用工作流中使用的相同语法来选择操作。

    • 对于操作,语法为 <OWNER>/<REPO>@<TAG OR SHA>。 例如,使用 actions/javascript-action@v1.0.1 选择� �记或使用 actions/javascript-action@172239021f7ba04fe7327647b213799853a9eb89 选择 SHA。 有关详细信息,请参阅“查找和自定义操作”。

    可以使用 * 通配符来匹配模式。 例如,若要允许以 space-org 开头的组织中的所有操作,可以指定 space-org*/*。 若要允许以 octocat 开头的存储库中的所有操作,可以使用 */octocat**@*。 有关使用 * 通配符的详细信息,请参阅“GitHub 操作的工作流语法”。

此过程演示如何将特定操作添� 到允许列表。

  1. 在 GitHub Enterprise Server 的右上角,单击� 的个人资料照片,然后单击“企业设置”。 GitHub Enterprise Server 上个人资料照片下拉菜单中的“企业设置”

  2. 在企业边� �中,单击 “策略”。 企业帐户边� �中的“策略”选项卡

  3. 在“ 策略”下,单击“操作”。

  4. Under "Policies", select 允许选择操作 and add your required actions to the list.

    Add actions to the allow list

Enforcing a policy for artifact and log retention in your enterprise

GitHub Actions can store artifact and log files. For more information, see "Downloading workflow artifacts."

默认情况下,工作流程生成的构件和日志文件将保留 90 天,然后自动� 除。 可以将此保持期更改为 1 天或 400 天之间的任何时长。

自定义保留期时,它仅适用于新构件和日志文件,并且不追溯性地应用于现有对象。 对于托管的仓库和组织,最长保留期不能超过管理组织或企业设置的限制。

  1. 在 GitHub Enterprise Server 的右上角,单击� 的个人资料照片,然后单击“企业设置”。 GitHub Enterprise Server 上个人资料照片下拉菜单中的“企业设置”
  2. 在企业边� �中,单击 “策略”。 企业帐户边� �中的“策略”选项卡
  3. 在“ 策略”下,单击“操作”。
  4. 在“工件和日志保留”下,输入新值。
  5. 单击“保存”应用更改。

Enforcing a policy for fork pull requests in your enterprise

You can enforce policies to control how GitHub Actions behaves for your GitHub Enterprise Server instance when members of your enterprise run workflows from forks.

Enforcing a policy for fork pull requests in private repositories

如果依赖于使用专用存储库的分支,� 可以配置策略来控制用户如何在 pull_request 事件上运行工作流。 仅适用于专用和内部存储库,� 可以为� 的企业、组织或存储库配置这些策略设置。

If a policy is enabled for an enterprise, the policy can be selectively disabled in individual organizations or repositories. If a policy is disabled for an enterprise, individual organizations or repositories cannot enable it.

  • 从分支拉取请求运行工作流 - 允许用户使用具有只读权限、没有密� �访问权限的 GITHUB_TOKEN,从分支拉取请求运行工作流。
  • 从拉取请求向工作流发送写入令牌 - 允许来自分支的拉取请求使用具有写入权限的 GITHUB_TOKEN
  • 从拉取请求向工作流发送机密 - 使所有机密都可用于拉取请求。
  1. 在 GitHub Enterprise Server 的右上角,单击� 的个人资料照片,然后单击“企业设置”。 GitHub Enterprise Server 上个人资料照片下拉菜单中的“企业设置”
  2. 在企业边� �中,单击 “策略”。 企业帐户边� �中的“策略”选项卡
  3. 在“ 策略”下,单击“操作”。
  4. 在“复刻拉取请求工作流”下,选择选项。 例如:启用、禁用或限制此存储库的操作
  5. 单击“保存”以应用设置。

Enforcing a policy for workflow permissions in your enterprise

可以设置授予 GITHUB_TOKEN 的默认权限。 有关 GITHUB_TOKEN 的详细信息,请参阅“自动令牌身份验证”。 � 可以选择一组有限的权限作为默认项或应用权限设置。

You can set the default permissions for the GITHUB_TOKEN in the settings for your enterprise, organizations, or repositories. If you choose a restricted option as the default in your enterprise settings, this prevents the more permissive setting being chosen in the organization or repository settings.

任何拥有存储库写入权限的人都可以通过编辑工作流文件中的 permissions 键来修改授予 GITHUB_TOKEN 的权限,或者� �据需要添� 或� 除权限。 有关详细信息,请参阅 permissions

Configuring the default GITHUB_TOKEN permissions

  1. 在 GitHub Enterprise Server 的右上角,单击� 的个人资料照片,然后单击“企业设置”。 GitHub Enterprise Server 上个人资料照片下拉菜单中的“企业设置”

  2. 在企业边� �中,单击 “策略”。 企业帐户边� �中的“策略”选项卡

  3. 在“ 策略”下,单击“操作”。

  4. Under "Workflow permissions", choose whether you want the GITHUB_TOKEN to have read and write access for all scopes, or just read access for the contents scope.

    Set GITHUB_TOKEN permissions for this enterprise

  5. Click Save to apply the settings.