# Security in CI

Who may read, start, cancel and configure what (IAM), what is audited, and how runs are kept from reaching machines and secrets they should not.

## IAM actions

CI is checked per repository: run, log, artifact, environment and repository-variable actions are
evaluated on `rn:ews::<organization id>:ci:repository/<repository id>`, never on a single run.
Organization-wide things are evaluated on `rn:ews::<organization id>:ci:*`: listing runs across
repositories, runners, runner groups, runner pools, organization variables, and checking or
converting a workflow file.

(The table of IAM actions is generated on the web page.)
- `ci:GetRunLogs` and `ci:DownloadArtifact` are sensitive: build output can carry anything a step
  printed. The read-only policies leave them out, and every request is recorded in the audit log,
  allowed or refused.
- `ci:ManageRunners` on a repository issues registration tokens for that repository only; runner
  groups, moving and disabling runners need it on `ci:*`.
- `ci:CreateRunnerPool` also needs `autoscaling:CreateLaunchTemplate`,
  `autoscaling:CreateAutoScalingGroup` and `ec2:RunInstances`.
- `ci:ReviewDeployments` is not enough to approve a deployment: the environment must list you as a
  reviewer.
- `ci:CreateIdToken` is granted by no policy. A job's `permissions: id-token: write` and its
  environment's rules decide; the action names the audit entry of every token issued.
- Committing a workflow file is a push: `git:PushRepository`.

## Audit

Every write through the API that reaches its permission check is recorded in the audit log, allowed
or denied: cancel, re-run, manual start, runner and group changes, pools, variables, environments
and reviews. Every read of logs or an artifact is recorded too, allowed or refused. A request
refused earlier, for
an id that is not valid or a body that does not parse, is not. Every OIDC token issued, and every
refused one, is recorded as `ci:CreateIdToken`. See [Audit log](/docs/audit-log).

## What a run can reach

- A run acts as its repository's run identity, which works on that repository only and publishes
  only to the registry repositories of its own name (see
  [What runs on your machines](what-runs-on-your-machines.md)). Its clone token can only read; a
  GitHub-syntax job's token can do what the job's `permissions:` allow (see
  [Call the GitHub API from a job](call-the-github-api-from-a-job.md)).
- Secrets are judged against the person who started the run. A re-run keeps the original run's
  person: re-running someone else's run never hands it your secrets. A run that has no such person
  (an SSH push, a push to a pull request's branch, a pull request reopened by someone other than its
  author) gets no secrets: when it reads a secret that exists, it fails with "This run has no
  triggering IAM user, so no policy can be evaluated and secrets are withheld. …".
- A secret reaches a job only when the job names it, the secret is granted to `actions` for the
  repository, and the person who started the run may read it.
- An environment with reviewers holds its jobs until one approves; on your runners and runner
  pools such a job reaches no machine before then.

## Your own machines

There are no forks: whoever can push a branch decides what that branch's runs execute. A runner in
Default takes runs from any repository and any branch, pull requests included.

- Keep deploy or secret-manager credentials only on runners in a group that takes protected
  branches only.
- Prefer machines that take one job and are retired (`--ephemeral` for GitHub's runner) for
  runners that take unprotected branches, or runner pools with **Fresh machine per job**.
- The Deutsche Cloud agent on a Mac runs jobs natively, as root, next to your files; the agent's own
  credential never reaches a step.
- A registration token registers one machine within 15 minutes and is stored only as a hash.
  Labels it fixes cannot be widened by the machine, so a machine cannot call itself `deploy` to be
  sent deploy jobs.
- Disabling a runner revokes its credential at once.

## Related

- [Runners and runner groups](runners-and-groups.md)
- [Give a job a secret](give-a-job-a-secret.md)
