Skip to content

Organization Actions Policy

Definition of an Organization Actions Policy, the following properties are supported:

Key Value Description Notes
name string The name of this actions policy Must be unique within the organization
enforcement string The enforcement status of this actions policy active, disabled or evaluate, evaluate is only available with GitHub Enterprise
include_repo_names list[RepoNameMatcher] List of names or patterns to include matching repositories ~ALL targets all repositories, an empty list targets none
exclude_repo_names list[RepoNameMatcher] List of names or patterns to exclude matching repositories
protect_repo_names boolean If enabled, the targeted repositories can not be renamed
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. The policies of the enterprise are not managed by otterdog, the ones of a repository are defined with the Repository Actions Policy.

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 a key of the workflow or repository targeting missing from the configuration while another one is configured.

GitHub does not allow two policies with the same name. 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.

A policy that targets repositories by custom property or by id, which otterdog does not support, keeps this targeting when otterdog updates the policy, its include_repo_names, exclude_repo_names and protect_repo_names are not compared.

Jsonnet Function

orgs.newOrgActionsPolicy('<name>') {
  <key>: <value>
}

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 enforcement to evaluate for an organization on a non enterprise plan triggers an error
  • setting both include_workflows and exclude_workflows to empty lists triggers an error, use ~ALL to target all workflows
  • combining ~ALL with other patterns in include_workflows, or using ~ALL in exclude_workflows triggers an error
  • setting an invalid allowed actor, e.g. an unknown role, triggers an error
  • setting an event in allowed_events that otterdog does not know triggers a warning
  • setting allowed_actors or allowed_events to 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
  • an empty include_repo_names triggers a warning, as the policy does not apply to any repository
  • a pattern of include_repo_names or exclude_repo_names that does not match any repository triggers a warning
  • setting protect_repo_names while include_repo_names and exclude_repo_names are empty triggers a warning

Example usage

The following policy only allows workflows of the repositories of the organization to be triggered by pushes, pull requests and manual runs, e.g. it blocks pull_request_target:

orgs.newOrg('my-project', 'my-org') {
  actions_policies+: [
    orgs.newOrgActionsPolicy('events') {
      include_repo_names: [
        "~ALL"
      ],
      allowed_events: [
        "push",
        "pull_request",
        "workflow_dispatch"
      ],
    },
  ],
}

Open in the Playground