Skip to content
This repository was archived by the owner on Nov 25, 2026. It is now read-only.
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
2 changes: 1 addition & 1 deletion docs/MANUAL-STEPS.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ The official Claude GitHub App requests **Workflows: read and write**, so it is
- [x] Create a GitHub App (owner: your account) named **`nullthrone-governance`**. If the slug differs, update `bot_app_slug` and `bots` in `config/governance.json`.
- Webhook: off. Installable: "Any account" (needed for several organizations).
- Repository permissions: Contents **write**, Pull requests **write**, Issues **write**, Checks read, Actions read, Administration read (audit reads rulesets), Discussions read (Ideas digest), Metadata read.
- **Workflows: no access.** Organization and account permissions: none.
- **Workflows: no access.** **Secrets: no access** (the scheduled audit skips `publish-secrets` and `token-permissions`; the owner's full audit, default mode with their own `gh` login, covers them). Organization and account permissions: none.
- [x] Generate a private key.
- [x] Install the app on all orgs and your personal account (all repositories, or at least every governed repo plus each organization's `.github` repo).
- [x] Per organization: variable `GOVERNANCE_APP_ID` and secret `GOVERNANCE_APP_PRIVATE_KEY` (organization level, visible to all repositories). Personal-account repositories need them as repository variable/secret.
Expand Down
7 changes: 6 additions & 1 deletion scripts/governance_audit.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

Modes
default all checks; remote checks use the owner's gh login. A remote check that cannot run fails.
--ci as default, but checks that need the owner's own token (app installation permissions) are skipped.
--ci as default, but checks that need the owner's own token (app installation permissions, Actions and
environment secrets) are skipped.
--local only checks on the working tree; remote checks are reported as skip.

Output: human summary on stdout, JSON report with --json. Exit code 1 if any check fails.
Expand Down Expand Up @@ -392,6 +393,10 @@ def check_labels(self) -> None:
self.add("labels", "fail" if problems else "pass", ("; ".join(problems) or "taxonomy in sync") + extra)

def check_publish_secrets(self) -> None:
# The governance app has no Secrets permission (least privilege); its token gets 403 on these endpoints.
if self.mode == "ci":
self.add("publish-secrets", "skip", "needs the owner's token (run the audit locally)")
return
names = [s["name"] for s in govlib.gh_api(f"repos/{self.repo}/actions/secrets?per_page=100", paginate=True)]
try:
names += [f"org:{s['name']}" for s in govlib.gh_api(f"repos/{self.repo}/actions/organization-secrets?per_page=100", paginate=True)]
Expand Down
33 changes: 33 additions & 0 deletions tests/test_audit_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def test_compliant_repo_passes(self):
statuses = {c["id"]: c["status"] for c in report["checks"]}
self.assertEqual(statuses["scorecard"], "info")
self.assertEqual(statuses["token-permissions"], "pass")
self.assertEqual(statuses["publish-secrets"], "pass")

def test_token_permissions_fall_back_to_the_organization(self):
# A gh OAuth login gets 403 on user/installations; the organization's list carries the same data.
Expand Down Expand Up @@ -99,6 +100,38 @@ def test_ci_mode_skips_owner_only_check(self):
statuses = {c["id"]: c["status"] for c in self.run_audit(mode="ci")["checks"]}
self.assertEqual(statuses["token-permissions"], "skip")

def run_without_secrets_access(self, mode):
# The governance app has no Secrets permission: GitHub answers 403 on the secrets endpoints.
api = fake_api()
denied = []

def app_token(path, *args, **kwargs):
if "secrets" in path or "/environments" in path:
denied.append(path)
raise govlib.GhError(f"gh api {path} failed: gh: Resource not accessible by integration (HTTP 403)")
return api(path, *args, **kwargs)

with mock.patch.object(govlib, "gh_api", side_effect=app_token), \
mock.patch.object(govlib, "gh", return_value=""), \
mock.patch.object(govlib, "gh_authenticated", return_value=True), \
mock.patch("urllib.request.urlopen", side_effect=urllib.error.URLError("offline")):
report = governance_audit.Audit(self.root, "o/demo", mode, None, None).run()
return report, {c["id"]: c for c in report["checks"]}, denied

def test_ci_mode_skips_publish_secrets_without_calling_the_api(self):
report, checks, denied = self.run_without_secrets_access("ci")
self.assertEqual(checks["publish-secrets"]["status"], "skip", checks["publish-secrets"])
self.assertEqual(checks["publish-secrets"]["message"], checks["token-permissions"]["message"])
self.assertEqual(denied, [])
self.assertEqual(failed(report), set(), report["checks"])
self.assertTrue(report["passed"])

def test_full_mode_still_reports_unreadable_secrets(self):
_, checks, denied = self.run_without_secrets_access("full")
self.assertEqual(checks["publish-secrets"]["status"], "fail")
self.assertIn("cannot verify", checks["publish-secrets"]["message"])
self.assertTrue(denied)

def test_detects_remote_drift(self):
bad_ruleset = copy.deepcopy(repo_settings.ruleset_templates()[0])
for rule in bad_ruleset["rules"]:
Expand Down