Repository Actions Policy
Definition of a Repository Actions Policy, the following properties are supported:
| Key | Value | Description | Notes |
|---|---|---|---|
| name | string | The name of this actions policy | Must be unique within the repository |
| enforcement | string | The enforcement status of this actions policy | active, disabled or evaluate, evaluate is only available with GitHub Enterprise |
| include_workflows | list[string] | List of workflow files or patterns targeted by the policy | ~ALL targets all workflows, e.g. .github/workflows/release.yml or .github/workflows/* |
| exclude_workflows | list[string] | List of workflow files or patterns excluded from the policy | ~ALL is not allowed |
| allowed_actors | list[AllowedActor] or null | Rule: the actors allowed to run the targeted workflows | null does not require the rule |
| allowed_events | list[string] or null | Rule: the events allowed to trigger the targeted workflows | e.g. push, pull_request or workflow_dispatch, null does not require the rule |
An actions policy, called workflow execution protection by GitHub, blocks the runs of the targeted workflows that it does not allow, see Controlling workflow execution.
Like rulesets, actions policies layer with the policies of the organization and the enterprise: a run must be allowed by all the policies that target its workflow. The policies of the organization are defined with the Organization Actions Policy.
A workflow pattern matches the path of a workflow file in the repository, an empty include_workflows targets all
the workflows that exclude_workflows does not exclude.
The rules of a policy that otterdog does not support, e.g. Require lockfile whose rule GitHub does not
publish in its API yet, are kept when otterdog updates the policy. A rule missing from the configuration, e.g. with
a default configuration predating it, is not managed either and keeps its current value, as does one of
include_workflows and exclude_workflows missing from the configuration while the other one is configured.
GitHub does not allow two policies with the same name in a repository. When otterdog adds a policy whose name is already used by a policy that the configuration does not know, e.g. created in the web UI, it updates that policy instead.
Jsonnet Function¶
The default values of an actions policy:
# Function to create a new repository actions policy with default settings.
local newRepoActionsPolicy(name) = {
name: name,
enforcement: "active",
# the workflows targeted by the policy, '~ALL' targets all workflows
include_workflows: ["~ALL"],
exclude_workflows: [],
# the rules of the policy, null does not require a rule
# the actors allowed to run the targeted workflows
allowed_actors: null,
# the events allowed to trigger the targeted workflows
allowed_events: null,
};
# Function to create a new organization actions policy with default settings.
local newOrgActionsPolicy(name) = newRepoActionsPolicy(name) {
include_repo_names: [],
exclude_repo_names: [],
protect_repo_names: false,
};
Validation rules¶
- setting
enforcementtoevaluatefor an organization on a nonenterpriseplan triggers an error - setting both
include_workflowsandexclude_workflowsto empty lists triggers an error, use~ALLto target all workflows - combining
~ALLwith other patterns ininclude_workflows, or using~ALLinexclude_workflowstriggers an error - setting an invalid allowed actor, e.g. an unknown role, triggers an error
- setting an event in
allowed_eventsthat otterdog does not know triggers a warning - setting
allowed_actorsorallowed_eventsto an empty list triggers a warning, as it blocks all the targeted workflows - a policy that does not require any rule triggers a warning, as it has no effect
Example usage¶
The following policy only allows the maintainers of the repository and the releng team to run its release
workflow: