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
4 changes: 3 additions & 1 deletion docs/self-host/github-app.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ It uses GitHub's [manifest flow](https://docs.github.com/en/apps/sharing-github-
| Pull requests | write | Open and update pull requests; post reviews |
| Issues | write | Read assigned issues; post progress |
| Checks | write | Read CI results to fix failures; show the "CoderHelm review" check on a pull request's commit from the moment CoderHelm accepts anything on it (a push, a reply, a re-review, an edited description), saying what it is doing, until it ends, linking to the session page; a reply that is only answered leaves the commit showing the standing verdict |
| Actions | read | Read workflow runs and logs |
| Actions | write | Read workflow runs and logs; start a workflow a step needs (a deploy, an end-to-end run) with `workflow_dispatch`. Read is required; write is optional: without it CoderHelm adds the label that starts a workflow where the workflow has one, and otherwise the step waits |
| Commit statuses | read | CI that reports statuses instead of checks |
| Workflows | write | Change workflow files when a task asks for it |
| Metadata | read | Repository list and details |
Expand All @@ -51,6 +51,8 @@ An app created before security fixes keeps working without **Dependabot alerts:

With CoderHelm's hosted app (hybrid installs), each token asks only for the permissions your installation has granted: one added to the app later is left out until an owner accepts it on the installation, and a token never fails for it. Accepting it takes effect within an hour, when the next token is issued.

An app created before CoderHelm asked for **Actions: write** keeps working with **Actions: read**. Setup checks warns about it once, on the install's setup page, never on a pull request: set Actions to write on the app's Permissions and events page and accept the new permission on each installation. Until then CoderHelm starts workflows through their labels where they have one (adding a label needs only pull request write).

An app created before CoderHelm asked for **Checks: write** keeps working with **Checks: read**: reviews are posted as before, but pull requests don't show the "CoderHelm review" check. Setup checks warns about it until you set Checks to write on the app's Permissions and events page and accept the new permission on each installation.

## URLs it uses
Expand Down
13 changes: 9 additions & 4 deletions installer/lib/github-app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ export const PERMISSIONS = {
// check on a pull request while it is reviewed. Only read is required
// (REQUIRED_PERMISSIONS): reviews work without the check.
checks: "write",
// Read workflow runs and their logs (CI fixes).
actions: "read",
// Read workflow runs and their logs (CI fixes), and start a workflow a
// step needs (workflow_dispatch: a deploy, an end-to-end run that has no
// label to start it). Only read is required (REQUIRED_PERMISSIONS):
// without write, CoderHelm starts what a label starts and lists the rest.
actions: "write",
// Read commit statuses (CI that reports statuses, not checks).
statuses: "read",
// Change workflow files when a task asks for it.
Expand Down Expand Up @@ -56,6 +59,7 @@ export const OPTIONAL_WHY = {
deployments: "Without Deployments, what shipped where is worked out from workflow names instead of GitHub's deployments.",
repository_advisories: "Without Repository security advisories, security fixes don't see a repository's own advisories and private vulnerability reports.",
code_quality: "Without Code quality, reviews don't see GitHub's code quality findings on the changed files.",
actions: "Without Actions: write, CoderHelm can't start a workflow itself (a deploy, an end-to-end run): it adds the label that starts one where the workflow has one, and otherwise the step waits.",
};

/**
Expand All @@ -64,8 +68,9 @@ export const OPTIONAL_WHY = {
* (services/gateway/src/routes/setup_checks.rs REQUIRED_PERMISSIONS).
*/
export const REQUIRED_PERMISSIONS = (() => {
const out = { ...PERMISSIONS, checks: "read" };
for (const k of Object.keys(OPTIONAL_WHY)) if (k !== "checks") delete out[k];
// Checks and Actions: read is required, write is optional.
const out = { ...PERMISSIONS, checks: "read", actions: "read" };
for (const k of Object.keys(OPTIONAL_WHY)) if (k !== "checks" && k !== "actions") delete out[k];
return out;
})();

Expand Down
6 changes: 4 additions & 2 deletions installer/test/checks.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,10 @@ test("GitHub: no app, refused keys, missing permissions, wrong webhook, bad secr

// Every optional permission a new app asks for warns with what it limits.
for (const [key, why] of Object.entries(OPTIONAL_WHY)) {
const lacking = { ...APP, permissions: { ...PERMISSIONS, [key]: key === "checks" ? "read" : undefined } };
if (key !== "checks") delete lacking.permissions[key];
// Checks and Actions: read is required, only write is optional.
const readOnly = key === "checks" || key === "actions";
const lacking = { ...APP, permissions: { ...PERMISSIONS, [key]: readOnly ? "read" : undefined } };
if (!readOnly) delete lacking.permissions[key];
const r = (await C.checkGithubApp({ fetchImpl: github({ "/app": json(200, lacking) }).fetchImpl }, SECRET, "https://helm.example.org")).find((x) => x.id === "github_permissions");
assert.equal(r.status, C.WARN, key);
assert.ok(r.why.includes(why), `${key}: ${r.why}`);
Expand Down
7 changes: 5 additions & 2 deletions installer/test/installer.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import path from "node:path";
import http from "node:http";
import { main } from "../lib/cli.mjs";
import * as cmd from "../lib/commands.mjs";
import { buildManifest, convertCode, EVENTS, formPage, newAppUrl, PERMISSIONS, runManifestFlow, secretKeysFromApp } from "../lib/github-app.mjs";
import { buildManifest, convertCode, EVENTS, formPage, newAppUrl, PERMISSIONS, REQUIRED_PERMISSIONS, runManifestFlow, secretKeysFromApp } from "../lib/github-app.mjs";
import { parseSums, verifySums } from "../lib/release.mjs";
import { initialSecret, hasGithubApp } from "../lib/secrets.mjs";
import { checkPrereqs } from "../lib/prereqs.mjs";
Expand Down Expand Up @@ -213,9 +213,12 @@ test("manifest: URLs, permissions and events", () => {
assert.deepEqual(m.default_events, EVENTS);
// Security fixes: Dependabot alerts and the advisory events are asked for.
assert.equal(m.default_permissions.vulnerability_alerts, "read");
for (const k of ["deployments", "repository_advisories", "code_quality", "actions", "statuses"]) {
for (const k of ["deployments", "repository_advisories", "code_quality", "statuses"]) {
assert.equal(m.default_permissions[k], "read", k);
}
// Starting a workflow a step needs (workflow_dispatch); read stays required.
assert.equal(m.default_permissions.actions, "write");
assert.equal(REQUIRED_PERMISSIONS.actions, "read");
assert.equal(m.default_permissions.checks, "write");
assert.equal(m.default_permissions.workflows, "write");
assert.ok(m.default_events.includes("dependabot_alert"));
Expand Down
Loading
Loading