About policies for GitHub Actions in your enterprise
GitHub Actions helps members of your enterprise automate software development workflows on GitHub Enterprise Cloud. For more information, see "Understanding GitHub Actions."
Any organization on GitHub.com can use GitHub Actions. You can enforce policies to control how members of your enterprise on GitHub Enterprise Cloud 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 and reusable workflows, so that people can only use local actions and reusable workflows that exist in your enterprise.
-
在 GitHub.com 的右上角,单击您的个人资料照片,然后单击 Your enterprises(您的企业)。
-
在企业列表中,单击您想要查看的企业。
-
在企业账户侧边栏中,单击 Policies(政策)。
-
在“ Policies(政策)”下,单击 Actions(操作)。
-
Under "Policies", select your options.
If you choose Allow enterprise, and select non-enterprise, actions and reusable workflows, actions and reusable workflows within your enterprise are allowed, and there are additional options for allowing other specific actions and reusable workflows. For more information, see "Allowing select actions and reusable workflows to run."
When you allow actions and reusable workflows from only in your enterprise, the policy blocks all access to actions authored by GitHub. For example, the
actions/checkout
action would not be accessible. -
Click Save.
允许所选操作 和可重启工作流程 运行
选择 Allow enterprise, and select non-enterprise, actions and reusable workflows 时,允许本地操作 和可重用工作流程 ,并且还有其他选项可用于允许其他特定操作 和可重用工作流程:
-
允许 GitHub 创建的操作: 您可以允许 GitHub 创建的所有操作用于工作流程。 GitHub 创建的操作位于
actions
和github
组织中。 更多信息请参阅actions
和github
组织。 -
允许已验证的创建者执行市场操作: 您可以允许工作流程使用由经过验证的创建者创建的所有 GitHub Marketplace 操作。 如果 GitHub 验证该操作的创建者为合作伙伴组织, 徽章将显示在 GitHub Marketplace 中的操作旁边。
-
允许指定的操作 和可重用工作流程: 可以将工作流程限制为使用特定组织和存储库中的操作 和可重用工作流程。
要限制对特定标记的访问或者操作 或可重用工作流程 的提交 SHA,请使用工作流中使用的相同语法来选择操作 或可重用工作流程。
- 对于操作,语法为
<OWNER>/<REPO>@<TAG OR SHA>
。 例如,使用actions/javascript-action@v1.0.1
选择标记,或使用actions/javascript-action@172239021f7ba04fe7327647b213799853a9eb89
选择 SHA。 更多信息请参阅“查找和自定义操作”。 - 对于可重用的工作流程,语法为
<OWNER>/<REPO>/<PATH>/<FILENAME>@<TAG OR SHA>
。 例如,octo-org/another-repo/.github/workflows/workflow.yml@v1
。 更多信息请参阅“重用工作流程”。
您可以使用
*
通配符来匹配模式。 例如,要允许以space-org
开头的组织中的所有操作 和可重用工作流程,可以指定space-org*/*
。 要允许以 octocat 开头的存储库中的所有操作 和可重用工作流程 ,可以使用*/octocat**@*
。 有关使用*
通配符的更多信息,请参阅“GitHub Actions 的工作流程语法”。注: 允许指定的操作 和可重用工作流程选项仅可用于具有 GitHub Free、GitHub Pro、组织的 GitHub Free 或 GitHub Team 计划的公共仓库。
- 对于操作,语法为
此过程演示如何将特定操作 和可重用工作流程 添加到允许列表中。
-
在 GitHub.com 的右上角,单击您的个人资料照片,然后单击 Your enterprises(您的企业)。
-
在企业列表中,单击您想要查看的企业。
-
在企业账户侧边栏中,单击 Policies(政策)。
-
在“ Policies(政策)”下,单击 Actions(操作)。
-
Under "Policies", select Allow enterprise, and select non-enterprise, actions and reusable workflows and add your required actions and reusable workflows to the 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 至 90 天。
-
对于私有 和内部 存储库:您可以将此保留期更改为 1 天或 400 天之间的任何保留期。
自定义保留期时,它仅适用于新构件和日志文件,并且不追溯性地应用于现有对象。 对于托管的仓库和组织,最长保留期不能超过管理组织或企业设置的限制。
-
在 GitHub.com 的右上角,单击您的个人资料照片,然后单击 Your enterprises(您的企业)。
-
在企业列表中,单击您想要查看的企业。
-
在企业账户侧边栏中,单击 Policies(政策)。
-
在“ Policies(政策)”下,单击 Actions(操作)。
-
Under Artifact and log retention, enter a new value.
-
单击 Save(保存)以应用更改。
Enforcing a policy for fork pull requests in your enterprise
You can enforce policies to control how GitHub Actions behaves for GitHub.com when members of your enterprise or outside collaborators run workflows from forks.
Enforcing a policy for approval of pull requests from outside collaborators
任何人都可以复刻公共仓库,然后提交建议更改仓库 GitHub Actions 工作流程的拉取请求。 虽然来自复刻的工作流程无法访问敏感数据(如密钥),但如果出于滥用目的进行修改,可能会让维护者感到烦恼。
为了帮助防止这种情况,某些外部贡献者向公共仓库提出的关于拉取请求的工作流程不会自动运行,可能需要先批准。 默认情况下,所有首次贡献者都需要批准才能运行工作流程。
注意:由 pull_request_target
事件触发的工作流程在基本分支的上下文中运行。 由于基本分支被视为受信任,因此无论审批设置如何,由这些事件触发的工作流程都将始终运行。
-
在 GitHub.com 的右上角,单击您的个人资料照片,然后单击 Your enterprises(您的企业)。
-
在企业列表中,单击您想要查看的企业。
-
在企业账户侧边栏中,单击 Policies(政策)。
-
在“ Policies(政策)”下,单击 Actions(操作)。
-
在 Fork pull request workflows from outside collaborators(从外部贡献者复刻拉取请求工作流程)下,选择您的选项。 选项按照从限制最少到限制最多的顺序列出。
-
单击 Save(保存)以应用设置。
有关批准此政策适用的工作流程运行的更多信息,请参阅“批准公共复刻中的工作流程运行”。
Enforcing a policy for fork pull requests in private repositories
如果您依赖于使用私有仓库的复刻,您可以配置策略来控制用户如何在 pull_request
事件上运行工作流程。 Available to private and internal repositories only, you can configure these policy settings for enterprises, organizations, or repositories.
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.
- Run workflows from fork pull requests(从复刻拉取请求运行工作流程) - 允许用户使用具有只读权限、没有密码访问权限的
GITHUB_TOKEN
从复刻拉取请求运行工作流程。 - Send write tokens to workflows from pull requests(从拉取请求向工作流程发送写入令牌) - 允许从复刻拉取请求以使用具有写入权限的
GITHUB_TOKEN
。 - Send secrets to workflows from pull requests(从拉取请求向工作流程发送密码) - 使所有密码可用于拉取请求。
-
在 GitHub.com 的右上角,单击您的个人资料照片,然后单击 Your enterprises(您的企业)。
-
在企业列表中,单击您想要查看的企业。
-
在企业账户侧边栏中,单击 Policies(政策)。
-
在“ Policies(政策)”下,单击 Actions(操作)。
-
在 Fork pull request workflows(复刻拉取请求工作流程)下,选择您的选项。 例如:
-
单击 Save(保存)以应用设置。
Enforcing a policy for workflow permissions in your enterprise
您可以设置授予 GITHUB_TOKEN
的默认权限。 For more information about the GITHUB_TOKEN
, see "Automatic token authentication." You can choose a restricted set of permissions as the default, or apply permissive settings.
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
By default, when you create a new enterprise, GITHUB_TOKEN
only has read access for the contents
scope.
-
在 GitHub.com 的右上角,单击您的个人资料照片,然后单击 Your enterprises(您的企业)。
-
在企业列表中,单击您想要查看的企业。
-
在企业账户侧边栏中,单击 Policies(政策)。
-
在“ Policies(政策)”下,单击 Actions(操作)。
-
Under "Workflow permissions", choose whether you want the
GITHUB_TOKEN
to have read and write access for all scopes, or just read access for thecontents
scope. -
Click Save to apply the settings.
Preventing GitHub Actions from creating or approving pull requests
You can choose to allow or prevent GitHub Actions workflows from creating or approving pull requests.
By default, when you create a new enterprise, workflows are not allowed to create or approve pull requests.
-
在 GitHub.com 的右上角,单击您的个人资料照片,然后单击 Your enterprises(您的企业)。
-
在企业列表中,单击您想要查看的企业。
-
在企业账户侧边栏中,单击 Policies(政策)。
-
在“ Policies(政策)”下,单击 Actions(操作)。
-
Under "Workflow permissions", use the Allow GitHub Actions to create and approve pull requests setting to configure whether
GITHUB_TOKEN
can create and approve pull requests. -
Click Save to apply the settings.