Примечание.
Пользовательские правила защиты развертывания в настоящее время находятся в public preview и подвергаются изменению.
About custom deployment protection rules
Вы можете включить собственные правила защиты для шлюза развертываний с помощью сторонних служб. Например, можно использовать такие службы, как Datadog, Honeycomb и ServiceNow, чтобы предоставить автоматические утверждения для развертываний в GitHub.
Custom deployment protection rules are powered by GitHub Apps and run based on webhooks and callbacks. Approval or rejection of a workflow job is based on consumption of the deployment_protection_rule
webhook. For more information, see События и полезные данные веб-перехватчика and Approving or rejecting deployments.
Once you have created a custom deployment protection rule and installed it on your repository, the custom deployment protection rule will automatically be available for all environments in the repository.
Using custom deployment protection rules to approve or reject deployments
Deployments to an environment can be approved or rejected based on the conditions defined in any external service like an approved ticket in an IT Service Management (ITSM) system, vulnerable scan result on dependencies, or stable health metrics of a cloud resource. The decision to approve or reject deployments is at the discretion of the integrating third-party application and the gating conditions you define in them. The following are a few use cases for which you can create a deployment protection rule.
- ITSM & Security Operations: you can check for service readiness by validating quality, security, and compliance processes that verify deployment readiness.
- Observability systems: you can consult monitoring or observability systems (Asset Performance Management Systems and logging aggregators, cloud resource health verification systems, etc.) for verifying the safety and deployment readiness.
- Code quality & testing tools: you can check for automated tests on CI builds which need to be deployed to an environment.
Alternatively, you can write your own protection rules for any of the above use cases or you can define any custom logic to safely approve or reject deployments from pre-production to production environments.
Creating a custom deployment protection rule with GitHub Apps
-
Create a GitHub App. For more information, see Регистрация приложения GitHub. Configure the GitHub App as follows.
- Optionally, in the Callback URL text field under "Identifying and authorizing users," enter the callback URL. For more information, see Сведения о URL-адресе обратного вызова авторизации пользователя.
- Under "Permissions," select Repository permissions.
- To the right of "Actions," click the drop down menu and select Access: Read-only.
- To the right of "Deployments," click the drop down menu and select Access: Read and write.
- Under "Subscribe to events," select Deployment protection rule.
-
Install the custom deployment protection rule in your repositories and enable it for use. For more information, see Configuring custom deployment protection rules.
Approving or rejecting deployments
Once a workflow reaches a job that references an environment that has the custom deployment protection rule enabled, GitHub sends a POST
request to a URL you configure containing the deployment_protection_rule
payload. You can write your deployment protection rule to automatically send REST API requests that approve or reject the deployment based on the deployment_protection_rule
payload. Configure your REST API requests as follows.
-
Validate the incoming
POST
request. For more information, see Проверка доставки веб-перехватчика. -
Use a JSON Web Token to authenticate as a GitHub App. For more information, see Проверка подлинности в качестве приложения GitHub.
-
Using the installation ID from the
deployment_protection_rule
webhook payload, generate an install token. For more information, see Сведения о проверке подлинности с помощью приложения GitHub.curl --request POST \ --url "http://api.github.com/app/installations/INSTALLATION_ID/ACCESS_TOKENS" \ --header "Accept: application/vnd.github+json" \ --header "Authorization: Bearer {jwt}" \ --header "Content-Type: application/json" \ --data \ '{ \ "repository_ids": [321], \ "permissions": { \ "deployments": "write" \ } \ }'
-
Optionally, to add a status report without taking any other action to GitHub, send a
POST
request to/repos/OWNER/REPO/actions/runs/RUN_ID/deployment_protection_rule
. In the request body, omit thestate
. For more information, see Конечные точки REST API для выполнения рабочих процессов. You can post a status report on the same deployment up to 10 times. Status reports support Markdown formatting and can be up to 1024 characters long. -
To approve or reject a request, send a
POST
request to/repos/OWNER/REPO/actions/runs/RUN_ID/deployment_protection_rule
. In the request body, set thestate
property to eitherapproved
orrejected
. For more information, see Конечные точки REST API для выполнения рабочих процессов. -
Optionally, request the status of an approval for a workflow run by sending a
GET
request to/repos/OWNER/REPOSITORY_ID/actions/runs/RUN_ID/approvals
. For more information, see Конечные точки REST API для выполнения рабочих процессов. -
Optionally, review the deployment on GitHub. For more information, see Reviewing deployments.
Publishing custom deployment protection rules in the GitHub Marketplace
You can publish your GitHub App to the GitHub Marketplace to allow developers to discover suitable protection rules and install it across their GitHub repositories. Or you can browse existing custom deployment protection rules to suit your needs. For more information, see Сведения о GitHub Marketplace для приложений and Размещение приложения на GitHub Marketplace.