---
title: Actions trust rules
description: Let a GitHub Actions workflow of one repository read another repository with a short-lived token instead of a stored key, by a rule a person approves in advance. The rules can be written now; the token exchange is not available yet.
llms_section: "Admin"
llms_order: 68
llms_summary: "Read when a deploy or build workflow needs to read another private repository and you want to stop storing a GitHub App key or a personal access token as an Actions secret, or when `stamp repo trust` refuses a rule."
llms_full: true
---

# Actions trust rules

::: warning The token exchange is not available yet
You can write, list and remove rules today. **No token is issued yet:** this release of Stamp only stores the rules, and no workflow can call Stamp. The exchange arrives in a later release; this page will say how a workflow uses it then. A repository with no rule is not affected in any way.
:::

A deploy workflow often needs to read a second private repository: deployment configuration, shared scripts, a private module. The usual answer is a GitHub App private key or a personal access token stored as an Actions secret. That secret does not expire, and anything that can read it can use it.

With a trust rule, nothing is stored in the workflow's repository. GitHub gives every workflow run a signed statement of what it is: which repository, which environment, which ref, which event. A workflow will present that statement to Stamp, and Stamp will answer with a token only if a rule a person approved in advance matches it.

## What a rule grants

A rule is kept under the **target**, the repository to be read, and names the **source**, the repository whose workflows are trusted. A matching run will get a GitHub token that:

- reads the contents of the target repository only (`contents: read`: clone and fetch with full history, files, release downloads);
- cannot write anything, and cannot read any other repository;
- ends by itself within an hour.

A rule states:

| Part | Meaning |
| --- | --- |
| Source | The repository whose workflows are trusted. Stamp stores GitHub's own id of the repository and of its owner, not the name. If the source is renamed the rule still applies to it; if someone later creates another repository under the old name, the rule does not apply to that one. |
| Environment | The GitHub environment the workflow's job must run in (`environment: aws-prod` in the job). Required, see below. |
| Refs | 1 to 8 full refs the run may be on: `refs/heads/release/v*`, `refs/tags/v*`. `*` stays within one path segment, `**` crosses segments. A pattern must match the whole ref. |
| Events | What may start the run: `push`, `workflow_dispatch`, `schedule`, `release`. With an environment the default is `push` and `workflow_dispatch`. `pull_request` and `pull_request_target` are always refused: such a run executes what the author of a pull request wrote. |
| Workflow | Optional: only this workflow file of the source. |
| Budget | How many tokens the rule may issue in an hour (default 30). |

```
stamp repo trust add -R acme/deploy-secrets --from acme/app \
  --environment aws-prod --ref 'refs/heads/release/v*' --ref 'refs/tags/v*'
stamp repo trust list -R acme/deploy-secrets
stamp repo trust remove aws-prod -R acme/deploy-secrets
stamp repo trust log -R acme/deploy-secrets
```

`-R` is always the target. A rule is named after its environment unless you pass `--name`; adding a rule under an existing name changes that rule.

## Who can add one

Only a **person** who is both:

- an owner or admin of the Raft server, and
- an admin of the **target** repository on GitHub. Stamp reads this from GitHub with your own account at the moment you add the rule; the maintain role is not enough.

You must also be able to see the source repository on GitHub with the account you signed in to Stamp with. For a private source, your server's GitHub App must be installed on it as well; a public source is read either way. An agent can never add, change or remove a rule, whatever its role. If you are refused, ask an admin of the target repository who is an owner or admin of your server.

Anyone on the server can read the rules and their history.

Rules belong to the server that wrote them. If two servers cover the same target, each has its own rules and neither can read or change the other's. A rule counts only while its server's GitHub App covers the target; if the App is removed from the target, the rule stays listed as not in effect and can still be removed.

## The environment is required

GitHub lets a repository restrict an environment to chosen branches and tags and require reviewers for it. That makes the environment the strongest statement a run can make about itself: a job cannot claim `aws-prod` from a branch the environment does not admit.

When you add a rule, Stamp reads the source's environment from GitHub with your account:

- **The environment does not exist:** refused (`ACTIONS_TRUST_ENVIRONMENT_NOT_FOUND`). Create it on GitHub first.
- **The environment admits any branch or tag:** refused (`ACTIONS_TRUST_ENVIRONMENT_UNRESTRICTED`). Then anyone who can push a branch to the source could run a job in that environment, so the environment proves nothing. This includes an environment set to selected branches and tags whose patterns together admit every branch name, such as `*` with `**/*`, or `**` (and every tag name, when the rule names a tag). In GitHub's patterns `*` does not cross a `/`, so `*` alone admits only branches without a slash and counts as a restriction. Restrict it on GitHub (the repository's **Settings**, **Environments**, the environment, **Deployment branches and tags**, **Selected branches and tags**) and add the rule again. If you accept the environment as it is, pass `--allow-unrestricted-environment`; the rule and its history record that you did.
- **The environment's branches and tags do not include the rule's refs:** the rule is written, with the warning `ENVIRONMENT_BRANCH_POLICY_MISMATCH`. Stamp compares patterns as text, and an exact ref against the environment's patterns, so it cannot always tell; check both. A run on a ref the environment does not admit can never match the rule.
- **GitHub cannot be read:** refused, nothing is written, and you can run the same command again.

"Protected branches only" counts as a restriction: only a branch with a protection rule on GitHub can deploy. Stamp does not read what those rules restrict.

The environment's name is written exactly as GitHub shows it, in any letter case; Stamp stores GitHub's spelling. A name with a slash, or with a space at either end, is not accepted.

**These checks are made once, when the rule is added or changed.** If someone later loosens the environment on GitHub, the rule stays as it is. Whoever can change the source's environments can widen what the rule admits, so review the rule when the environment changes.

Keep three things in agreement: the rule's refs, the environment's branches and tags on GitHub, and, if the workflow also assumes a cloud role, that role's trust condition. Stamp checks the first two when the rule is written. The third is yours to check.

## The weaker form, without an environment

Some workflows have no environment. A rule without one is possible, but it is weaker: no environment limits which runs match, and Stamp checks only that the branch has a protection rule on GitHub. It is never what a missing flag means; you must ask for it:

```
stamp repo trust add -R acme/deploy-secrets --from acme/app \
  --no-environment --ref refs/heads/main --event push
```

It is accepted only when:

- it names exactly one branch, written in full and without a wildcard;
- the branch has a protection rule on GitHub when the rule is added. Stamp checks that one exists, not what it restricts: a rule that only forbids deleting the branch passes, and does not limit who can push to it. It is not checked again later, so removing the protection leaves the trust rule standing;
- the events are stated.

Every list marks such a rule as weaker. Prefer an environment.

## What is recorded

Every rule that is added, changed or removed leaves a record that cannot be edited: the rule before and after, who did it, the GitHub account whose admin role was read, whether an unrestricted environment was accepted, what GitHub said about the environment at that moment, and when. `stamp repo trust log -R OWNER/REPO` shows it.

The rules stay until you remove them. Rules and their history are deleted with the rest of a server's data when its GitHub App is uninstalled, see [Data retention and deletion](/data-retention/).
