Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@ dependency-light and customer-neutral.
write permission. A Workspace whose policy declares
`permission_ceiling: "contents"` (since `0.16.0`) mints exactly
`contents: write` for the write tier and exactly `contents: read` for the
read tier, never an opt-in, so its tokens carry no Actions, Checks, issue,
membership, pull request or workflow permission. A mint without an explicit
read tier, never an installation opt-in, so its tokens carry no Actions,
issue, membership, pull request or workflow permission. Its only opt-in,
`checks_read: true` (since `0.17.0`, accepted only on a contents-ceiling
Workspace), adds exactly `checks: read` to its read tier outside the
policy's `conglomerate_hosts` repository; its write tier and every other
Workspace never gain it. A mint without an explicit
tier or a Workspace of the policy fails, and so does any set that asks for
a permission or level the installation has not accepted. A token of a GitHub Actions OIDC purpose is
limited to the purpose's one repository and its exact reviewed permission
Expand Down
14 changes: 10 additions & 4 deletions ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ its tier, and refuses a response with any other scope or any other repository:
becomes `issues: read`;
- a Workspace with `permission_ceiling: "contents"`: exactly
`contents: write` for the write tier and exactly `contents: read` for the
read tier, never an opt-in.
read tier, never an installation opt-in. With `checks_read: true` (since
`0.17.0`) its read tier is `contents: read` and `checks: read`, except on
the policy's `conglomerate_hosts` repository.

Before asking GitHub, the runtime refuses any set that asks for a permission
or level the installation has not accepted, any write tier for a Workspace
Expand Down Expand Up @@ -140,9 +142,13 @@ production applications host that pushes its applications' data, declares
tier of each grant, with one exception below, and each tier asks for
repository contents only:
`contents: write` or `contents: read`, plus GitHub's `metadata: read`, with no
opt-in whatever the installation accepted. Its tokens therefore carry no
permission for pull requests, issues, check runs, workflow runs, workflow
files or Organization membership (opening an issue in a public repository,
installation opt-in whatever the installation accepted. Its tokens therefore
carry no permission for pull requests, issues, workflow runs, workflow files
or Organization membership, and none for check runs unless the Workspace
declares `checks_read: true` (since `0.17.0`): then its read tier also reads
check runs, so an application host can verify a commit's checks before it
deploys it, while its write tier and the `conglomerate_hosts` repository stay
contents-only (opening an issue in a public repository,
above, is GitHub's exception for every token). `contents: write` stays GitHub's whole
contents permission: it pushes, force-pushes and deletes every unprotected
branch and creates tags, releases and `repository_dispatch` events, and a
Expand Down
65 changes: 61 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@ Since `0.16.0` a Workspace whose policy entry declares
repository contents only: `contents: write` for a `push`, `maintain` or
`admin` grant, `contents: read` for a `pull` or `triage` grant, and only
`contents: read` on the policy's `conglomerate_hosts` repository. Its tokens
never carry an Actions, Checks, issue, membership, pull request or workflow
permission. See
[Contents-only Workspaces](#contents-only-workspaces-permission_ceiling-contents).
never carry an Actions, issue, membership, pull request or workflow
permission, and no Checks permission unless it opts in: since `0.17.0` such a
Workspace can declare `checks_read: true`, and then its `pull` and `triage`
grants also ask for `checks: read`, so an application host can verify a
commit's check runs before it deploys it. See
[Contents-only Workspaces](#contents-only-workspaces-permission_ceiling-contents)
and [Reading check runs](#reading-check-runs-checks_read).

Since `0.13.0` the Cloudflare Worker adapter also serves short-lived GitHub
Actions runners: a job of an allowlisted Deployment Repo exchanges its GitHub
Expand Down Expand Up @@ -135,7 +139,11 @@ Workspace id + Workspace credential + repository (name or id)
`pull` or `triage`, and only `contents: read` on the policy's
`conglomerate_hosts` repository. It carries no permission for pull
requests, issues, check runs, GitHub Actions, workflow files or
Organization membership: in the live check GitHub refused it opening and
Organization membership, except that a Workspace with `checks_read: true`
(since `0.17.0`) adds `checks: read` to its `pull` and `triage` grants
outside that repository (see
[Reading check runs](#reading-check-runs-checks_read)). In the live check of
`0.16.0` GitHub refused a contents-ceiling token opening and
listing pull requests, opening an issue in a private repository, rerunning
and dispatching workflows, creating a check run and pushing a change to
`.github/workflows/`.
Expand Down Expand Up @@ -257,6 +265,10 @@ Schema v3 binds each Workspace to its GitHub Team and names no repositories:
`"contents"` every token carries repository contents only; see
[Contents-only Workspaces](#contents-only-workspaces-permission_ceiling-contents).
Any other value, including `null`, is rejected.
- `workspaces[].checks_read` is optional (since `0.17.0`). Its only value is
`true`, and only a Workspace with `permission_ceiling: "contents"` may
declare it; any other value or Workspace is rejected. See
[Reading check runs](#reading-check-runs-checks_read).
- `oidc` is optional (since `0.13.0`). It declares the purposes for which
GitHub Actions jobs of listed Deployment Repos may obtain a token; see
[The `oidc` purpose table](#the-oidc-purpose-table). Absent, the broker has
Expand Down Expand Up @@ -498,6 +510,51 @@ For such a Workspace:
there, and the mint refuses the write set for that repository before
GitHub is asked, should a gate ever select it.

#### Reading check runs (`checks_read`)

Since `0.17.0` a contents-ceiling Workspace can opt in to reading check runs.
An application host needs it to deploy a Module's commit only once that
commit's checks have passed: it reads
`GET /repos/{owner}/{repo}/commits/{sha}/check-runs` for the Module
repository, which a `contents: read` token cannot. The policy entry adds:

```json
{
"id": "example-apps-host",
"github_team_id": 4005,
"github_team_slug": "apps-host",
"credential_file": "/run/secrets/workspace-example-apps-host",
"permission_ceiling": "contents",
"checks_read": true
}
```

For such a Workspace:

- a `pull` or `triage` grant mints exactly `contents: read` and
`checks: read` (plus `metadata: read`);
- a `push`, `maintain` or `admin` grant still mints exactly
`contents: write`, so the repositories the host writes, such as its
applications' data repositories, gain nothing;
- on the policy's `conglomerate_hosts` repository every grant still mints
exactly `contents: read`, so a `push` grant lowered to the read tier there
gains nothing either;
- no write permission is added anywhere, and other Workspaces of the policy
mint exactly as before.

`checks: read` reveals check runs (names, status, conclusions and output
summaries) of repositories the Workspace can already read. It cannot create,
rerun or change a check run. The installation already holds `checks: read`
(the policy requires it), so an Organization accepts no new installation
permission; what it accepts is this wider read for that one Workspace, by
merging the opt-in into its reviewed policy.

`checks_read` is only `true` and only on a contents-ceiling Workspace; any
other value, or the key on another Workspace, is rejected and the broker
fails closed. A broker before `0.17.0` ignores the key, keeps minting
`contents: read` and the host's read of check runs is refused, so nothing is
deployed. Deploy `0.17.0` before relying on the opt-in.

`contents: write` is GitHub's whole permission for repository contents, and
the ceiling cannot narrow it further: GitHub has no installation permission
for one branch or for fast-forward pushes only. Such a token pushes,
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@lazurio/github-app-broker",
"version": "0.16.0",
"version": "0.17.0",
"private": true,
"license": "Apache-2.0",
"repository": {
Expand Down
26 changes: 22 additions & 4 deletions src/broker.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -204,20 +204,29 @@ function formatHostsSummary(hosts) {
* Offline summary of the parsed Team binding and of the exact permission set each access tier
* mints under this policy; no GitHub traffic and no secret. A policy whose Workspaces declare no
* permission ceiling prints exactly the two tier lines; a read ceiling adds the one set every
* grant of such a Workspace mints, a contents ceiling the two sets its write and read grants mint,
* and either adds a CEILING column. OIDC purposes, when declared, follow.
* grant of such a Workspace mints, a contents ceiling the two sets its write and read grants mint
* (the read set of a Workspace with `checks_read` on its own line, `contents+checks_read` in the
* column), and either adds a CEILING column. OIDC purposes, when declared, follow.
*/
export function formatPolicySummary(policy) {
const uncapped = policy.workspaces.find((workspace) => workspace.permission_ceiling === undefined);
const capped = policy.workspaces.find((workspace) => workspace.permission_ceiling === READ_CEILING);
const contentsOnly = policy.workspaces.find((workspace) => workspace.permission_ceiling === CONTENTS_CEILING);
const contentsChecks = policy.workspaces.find(
(workspace) => workspace.permission_ceiling === CONTENTS_CEILING && workspace.checks_read === true,
);
const contentsPlain = policy.workspaces.find(
(workspace) => workspace.permission_ceiling === CONTENTS_CEILING && workspace.checks_read !== true,
);
const ceilingColumn = capped !== undefined || contentsOnly !== undefined;
const header = ["WORKSPACE", "TEAM_ID", "TEAM_SLUG", ...(ceilingColumn ? ["CEILING"] : [])];
const rows = policy.workspaces.map((workspace) => [
workspace.id,
String(workspace.github_team_id),
workspace.github_team_slug ?? "-",
...(ceilingColumn ? [workspace.permission_ceiling ?? "-"] : []),
...(ceilingColumn
? [workspace.checks_read === true ? `${workspace.permission_ceiling}+checks_read` : (workspace.permission_ceiling ?? "-")]
: []),
]);
const widths = header.map((title, column) => Math.max(title.length, ...rows.map((row) => row[column].length)));
const line = (values) => values.map((value, column) => value.padEnd(widths[column])).join(" ").trimEnd();
Expand All @@ -235,7 +244,16 @@ export function formatPolicySummary(policy) {
...(contentsOnly
? [
`contents ceiling (push/maintain/admin grant of a CEILING contents Workspace) asks for: ${formatPermissions(tokenPermissions(policy, WRITE_ACCESS, contentsOnly))}`,
`contents ceiling (pull/triage grant of a CEILING contents Workspace) asks for: ${formatPermissions(tokenPermissions(policy, READ_ACCESS, contentsOnly))}`,
]
: []),
...(contentsPlain
? [
`contents ceiling (pull/triage grant of a CEILING contents Workspace) asks for: ${formatPermissions(tokenPermissions(policy, READ_ACCESS, contentsPlain))}`,
]
: []),
...(contentsChecks
? [
`contents ceiling with checks_read (pull/triage grant, not on the conglomerate_hosts repository) asks for: ${formatPermissions(tokenPermissions(policy, READ_ACCESS, contentsChecks))}`,
]
: []),
...(rows.length > 0 ? [line(header), ...rows.map(line)] : ["no Workspaces"]),
Expand Down
33 changes: 24 additions & 9 deletions src/core.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const RETIRED_POLICY_SCHEMA_V2 = "lazurio.github_app_broker.policy.v2";
const V3_MIGRATION =
"migrate to lazurio.github_app_broker.policy.v3 by deleting `repositories` and every `workspaces[].repository_ids`; the live Team grant is the scope";
const GITHUB_API_VERSION = "2026-03-10";
const USER_AGENT = "lazurio-github-app-broker/0.16.0";
const USER_AGENT = "lazurio-github-app-broker/0.17.0";
/** Upper bound for `policy check --live` Team repository pages (100 repositories per page). */
const MAX_TEAM_REPOSITORY_PAGES = 100;
const MAX_HOST_ADMISSION_PAGES = 10;
Expand Down Expand Up @@ -81,11 +81,13 @@ const PERMISSION_CEILINGS = Object.freeze([READ_CEILING, CONTENTS_CEILING]);

/**
* The two exact sets of a contents-ceiling Workspace (plus GitHub's automatic `metadata: read`).
* No opt-in reaches them, so such a token never carries an Actions, Checks, issue, membership,
* pull request or workflow permission.
* Neither installation opt-in reaches them, so such a token never carries an Actions, issue,
* membership, pull request or workflow permission. Its one Workspace opt-in, `checks_read: true`
* (since 0.17.0), adds `checks: read` to the read set only (see tokenPermissions).
*/
const CONTENTS_WRITE_TOKEN_PERMISSIONS = Object.freeze({ contents: "write" });
const CONTENTS_READ_TOKEN_PERMISSIONS = Object.freeze({ contents: "read" });
const CONTENTS_CHECKS_READ_TOKEN_PERMISSIONS = Object.freeze({ checks: "read", contents: "read" });

const PERMISSION_LEVELS = Object.freeze({ read: 1, write: 2 });

Expand All @@ -106,18 +108,24 @@ const PERMISSION_LEVELS = Object.freeze({ read: 1, write: 2 });
*
* A Workspace with `permission_ceiling: "contents"` keeps the tier the Team gate selects for its
* grant (see grantAccess) and asks for repository contents only, at that level: `contents: write`
* for the write tier and `contents: read` for the read tier. Neither opt-in reaches it, whatever
* the installation accepted.
* for the write tier and `contents: read` for the read tier. Neither installation opt-in reaches
* it, whatever the installation accepted. With `checks_read: true` (since 0.17.0) its read tier
* asks for `contents: read` and `checks: read`, so an application host can verify a commit's check
* runs before it deploys it. The write tier never gains it, and neither does the read tier on the
* policy's host key repository (`repositoryId`), where the Team gate lowers every grant of such a
* Workspace to the read tier, so a push grant there gains nothing either.
*/
export function tokenPermissions(policy, access, workspace) {
export function tokenPermissions(policy, access, workspace, repositoryId) {
if (!policy.workspaces.includes(workspace)) fail("token permissions need a Workspace of the policy");
const accepted = policy.installation_permissions;
const issues = accepted.issues === "write" ? { issues: "write" } : {};
let permissions;
if (workspace.permission_ceiling === CONTENTS_CEILING) {
if (access === WRITE_ACCESS) permissions = { ...CONTENTS_WRITE_TOKEN_PERMISSIONS };
else if (access === READ_ACCESS) permissions = { ...CONTENTS_READ_TOKEN_PERMISSIONS };
else fail("token access tier must be read or write");
else if (access === READ_ACCESS) {
const checks = workspace.checks_read === true && !isHostKeyRepository(policy, repositoryId);
permissions = { ...(checks ? CONTENTS_CHECKS_READ_TOKEN_PERMISSIONS : CONTENTS_READ_TOKEN_PERMISSIONS) };
} else fail("token access tier must be read or write");
} else if (access === WRITE_ACCESS) {
if (workspace.permission_ceiling === READ_CEILING) {
fail(`Workspace ${workspace.id} permission ceiling is read; it never mints the write tier`);
Expand Down Expand Up @@ -683,12 +691,19 @@ export function parsePolicy(raw) {
if (ceiling !== undefined && !PERMISSION_CEILINGS.includes(ceiling)) {
fail(`workspaces[${index}].permission_ceiling must be "${READ_CEILING}" or "${CONTENTS_CEILING}" when present`);
}
// Optional and absent by default (since 0.17.0): only a contents-ceiling Workspace takes it, and
// only as `true`, so a misspelled or misplaced opt-in fails closed instead of widening anything.
const checksRead = workspace?.checks_read;
if (checksRead !== undefined && (checksRead !== true || ceiling !== CONTENTS_CEILING)) {
fail(`workspaces[${index}].checks_read must be true and needs permission_ceiling "${CONTENTS_CEILING}" when present`);
}
return Object.freeze({
id,
github_team_id: teamId,
...(teamSlug === undefined ? {} : { github_team_slug: teamSlug }),
credential_file: credentialFile,
...(ceiling === undefined ? {} : { permission_ceiling: ceiling }),
...(checksRead === undefined ? {} : { checks_read: true }),
});
});
if (new Set(workspaces.map(({ id }) => id)).size !== workspaces.length) {
Expand Down Expand Up @@ -1174,7 +1189,7 @@ export function createGithubClient({ appId, signJwt, fetchImpl = fetch, now = ()
}

async function mintToken(policy, workspace, repositoryId, access) {
const requested = tokenPermissions(policy, access, workspace);
const requested = tokenPermissions(policy, access, workspace, repositoryId);
// The Team gate already selects the read tier there for a contents-ceiling Workspace; a gate
// that lost that rule fails closed here instead of minting such a write (see grantAccess).
if (
Expand Down
Loading
Loading