# How the ghtier assessment works

For a person, or an agent, who wants to review the assessment before running it. Start with:

```bash
node verify.mjs          # or: node verify.mjs --json
```

`verify.mjs` reads the files next to it and checks the safety claims below against their source,
with the line numbers each claim rests on. It runs nothing and makes no network call. If a claim
fails, do not run the assessment until you know why.

## What it is

`assess.mjs` checks one GitHub organization against the ghtier checklist, lists who holds Tier 0 and
Tier 1 access, and follows attack paths: who can reach that access, through which steps, and which
change cuts the most paths. `azure.mjs` optionally adds what the organization's GitHub Actions can
do in Azure through OIDC. Both run on your machine, with your own read access, and write their
results to the folder you run them from.

## Safety: what runs, and where data goes

| | |
|---|---|
| Programs started | `gh` (only `gh api --method GET` and `gh auth status`), `jq` and `zizmor`. `azure.mjs` starts only `az` (`az rest --method get` and `az account show`). Never a shell. |
| Changes made | None. No POST, PUT, PATCH or DELETE, and no GraphQL (which has mutations). |
| Network | GitHub's API through `gh`, and Azure through `az`, with your login. One more request: the public data files (checklist and tiers), by default from `https://ghtier.com/data/`. Nothing about your organization is in that request. With `--checks ./checklist.json` (local files) there is no such request at all. |
| What ghtier receives | Nothing. There is no upload, telemetry or call home. |
| Your token | Read hidden if you paste it, kept in memory, and given to `gh` as `GH_TOKEN`. Never written to a file or printed. |
| Files written | `ghtier-assessment-<org>.json`, `ghtier-report-<org>.html`, and with `--full-graph` `ghtier-graph-<org>.json`, in the current folder. zizmor gets a temporary copy of the workflow files, deleted afterwards. `azure.mjs` writes `cloud-trust-<tenant>.json`. |
| The report | Its Content-Security-Policy blocks every network request, so opening it sends nothing. |

Trust boundaries:

- **The checklist is data, not code.** Each check is a list of API paths and a jq rule from
  `checklist.json`. Paths must stay inside the organization (its endpoints, its repositories, its
  `.github` repository), and jq runs with only `PATH`, so a rule cannot read your token.
- **zizmor** runs offline, with only `PATH` and a temporary `HOME`.
- **Pinning.** `--pin SHA256SUMS` refuses any data file whose SHA-256 is not listed. Every file read
  is also recorded, with its hash, under `sources` in the assessment file.
- **Azure URLs** are checked against an allow list (Microsoft Graph and Azure Resource Manager)
  before each call.

## The files

| File | Role |
|---|---|
| `assess.mjs` | The runner. Node 18 or newer, no packages. |
| `azure.mjs` | The optional Azure collector. |
| `report.html` | The report template the runner fills in. |
| `verify.mjs` | Checks the claims on this page. |
| `SKILL.md` | Instructions for an agent that runs the assessment. |
| `SHA256SUMS` | Hashes of these files and of the data files. |

The data files come from `https://ghtier.com/data/` and are generated from the ghtier repository's
`data/` folder: `checklist.json` (checks), `permissions.json`, `roles.json`, `scopes.json` and
`keys-policies.json` (tiers), `reach-rules.json` (attack path rules), `cloud-tiers.json`,
`assess-scores.json` and `inventory-kinds.json`.

## How a run works

1. **Credential.** A read-only fine-grained token (`GH_TOKEN`, or pasted), or `--gh-login`.
2. **Data.** The data files are loaded and hashed.
3. **Scope.** In a terminal, a start screen chooses the parts: checks, inventory, attack paths,
   workflow files, zizmor, Azure.
4. **Checks.** For each checklist item with a check: the GET calls it names, then its jq rule gives
   pass, fail, partial or review.
5. **Inventory.** Owners, organization roles, installed Apps, outside collaborators, deploy keys,
   secrets, runners and ruleset bypass lists, each tiered with the site data.
6. **Attack paths.** A graph is built from what was read: people, teams, roles, repositories,
   secrets, workflow jobs, environments, OIDC subjects and (with `--cloud`) cloud identities. Every
   edge is one rule from `reach-rules.json`, with the API response it came from as evidence. A
   search from every Tier 0 and Tier 1 node backwards finds, for each person, credential, member and
   "anyone on GitHub", the shortest chain to the highest tier it reaches. Then it tests which single
   change removes the most chains to Tier 0.
7. **Scores.** A posture score from the checklist results and a security score from the attack
   paths, by the rules in `assess-scores.json`. The run records what each collection the security
   score builds on saw (`reach.coverage.collections`: complete, empty, unsupported, partial, denied,
   failed or skipped). A starting point counts only when what it needs was read in full, or what
   was read already reaches Tier 0. When a starting point is left out, or checks holding more than
   a tenth of the posture weight could not be read, the score keeps its number and the report shows
   "insufficient coverage" instead of the grade.
8. **Output.** The assessment file and the report.

## How results are decided

- **Tiers** come only from what a grant allows: the site's tier for each permission, role, scope,
  key and policy, and `cloud-tiers.json` for Azure. No label, tag or custom property the
  organization sets changes a tier.
- **Each step of a path** cites its rule, and each rule cites GitHub's or Microsoft's docs, a
  documented strange finding, or a written judgement. The report links every step to its rule.
- **Assumed steps.** A step the access used could not confirm is kept, marked assumed (shown as ⇢),
  and says why. It is never silently dropped or silently trusted.
- **A per-repository check passes** only when every repository was read and passed. One failure, one
  repository that could not be read or one left out by `--max-repos` makes it partial.
- **An outsider path into a job is confirmed** only when zizmor finds template injection in that job.
  A finding in another job of the same file, or in a file whose path several repositories share in
  imported results, confirms nothing; the step stays assumed.
- **A chain stops** at the first Tier 0 it reaches, at any length. The report folds chains longer than
  `maxSteps` in `reach-rules.json` (6) to their first and last two steps.
- **A fix removes reach** only when no path to Tier 0 is left at any length. A fix that leaves a longer path counts as making the chain longer. Only the
  150 changes on the most chains are tested, and the report says so when there were more.
- **Severity** of a checklist item is the highest tier of the attack techniques it stops, and Tier 0
  when its fix cuts a Tier 0 path in this organization.

## Assumptions and limits

Read these before trusting a result. Each assumed step in the report says which one applies.

- Anyone with Write is assumed able to change workflow files. Push rules on `.github/workflows`
  are not considered yet.
- An App with `contents: write` but not `workflows: write` pushes code but cannot change workflow
  files. It is assumed to start every push-triggered job without an environment on its repositories,
  as an assumed step: whether the job runs the pushed code depends on the workflow.
- Branch protection and rulesets are not considered for OIDC subjects of branches and tags: anyone
  who can push is assumed to produce them.
- A job whose environment is set by an expression is treated as unprotected.
- An App installed on selected repositories is assumed to reach all of them, since a token cannot
  list which.
- Which runner group serves a job's labels is not read.
- A reusable workflow in another repository is not read; it is assumed to ask for a token.
- When a repository's own settings cannot be read (OIDC subject format, default workflow token),
  the organization's are used.
- A workflow token with only `contents: write` can send `repository_dispatch`, which starts
  workflows from the default branch. This is not modeled yet.
- GitHub shows who can bypass a ruleset only to a token with write access to it, so with a read-only
  token those lists are reported as not read. Built-in repository role numbers in bypass lists are
  not documented by GitHub, so they are shown as numbers.
- Fine-grained personal access tokens can only be listed by a GitHub App, and classic tokens only in
  organizations with SAML SSO, so most tokens are not starting points.
- An SSO-authorized classic token is linked to its owner's repository roles (`repo`, or `public_repo` for
  public repositories) and organization roles (`admin:org`), not to its owner. Without `workflow` it
  pushes code but cannot add a workflow; on a repository the owner administers it keeps Admin, as an
  uncertain step, since an admin can add a deploy key. An SSH key gets Write at most. Approving
  deployments with a token, and other scopes, are not modeled yet.
- A custom organization role is tiered by its base repository role and the organization permissions
  it adds, the strongest of them, read from `customRolePermissions` in `roles.json` by API name. A name
  that file does not list is shown as not tiered, by name. Any organization role with Manage organization
  runners and runner groups gets an uncertain step to every self-hosted job, and a custom one with Manage
  custom organization roles an uncertain step to Admin on every repository, since it may edit itself.
  Editing custom repository roles and adding repositories to organization secrets are not linked: what
  they give depends on what each holder already has.
- A custom repository role counts as its base role, plus a step for each added permission that opens one:
  Bypass branch protections or Edit repository rules, and Manage environments, when the base role can
  push; Manage runners on any base, as an uncertain step to the repository's self-hosted jobs; Manage
  GitHub Actions general settings, when the base role can push and the repository does not already let
  Actions approve pull requests, as an uncertain step to approving its own pull request (the organization
  or enterprise may not let the repository turn that on). The rules in `reach-rules.json` list which
  permissions open each. An SSO token of such a holder takes the same steps with `repo` (`public_repo` on
  public repositories), and the approving one only with `workflow` too; an SSH key takes none.
- A repository admin gets the same uncertain step to the repository's self-hosted jobs, since an admin
  can register a runner there, and can always deploy to its environments, since an admin can change their
  protection. Adding required reviewers to an environment is therefore never counted as taking an admin
  off a path.
- A secret's value is never read, so every secret is treated the same (Tier 1).
- Per-repository checks and workflow files cover the most recently pushed repositories up to
  `--max-repos` (200 by default), and fewer when the API rate limit is low; the report says so.
- Members of enterprise teams are not read.

Everything that could not be read is listed in the report under "Not read" and "Missing access".

## Reproduce and test it

In the ghtier repository (the fixtures are not published with the runner). Nothing here needs a
GitHub or Azure account:

```bash
GHTIER_ASSESS_FIXTURES=scripts/fixtures/workflows-org.json \
  node skills/ghtier-assess/assess.mjs --org acme --checks public/data/checklist.json --yes
```

The fixture files are canned API responses for a made-up organization; the runner reads them
instead of calling `gh`. In the ghtier repository, `npm test` runs every test (including that each
claim on this page fails when the runner is changed to break it), and
`node assess.mjs --report-from ghtier-assessment-<org>.json` rebuilds a report without any call.

## For an agent reviewing this

1. Run `node verify.mjs --json` and read every claim and the lines it points to.
2. Read this page, then the lines of `assess.mjs` and `azure.mjs` that the claims name.
3. Run the runner on a fixture organization (above) to see what it does.
4. Only then run it on a real organization, with a read-only token, and tell the user what it will
   read before it starts.
