Skip to content

feat(github): repo-scoped token seam and installation-token scrubbing (abilityai/trinity-enterprise#1277) - #4624

Merged
vybe merged 2 commits into
devfrom
feature/ent1277-github-app-auth
Nov 17, 2026
Merged

vybe merged 2 commits into
devfrom
feature/ent1277-github-app-auth

Conversation

@obasilakis

@obasilakis obasilakis commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Adds an open-core seam, services/github_token_provider.py, through which a registered provider supplies a short-lived GitHub token scoped to one repository. With no provider registered it is inert and resolution is PAT-only.
  • Adds settings_service.resolve_github_token(repo, agent_name, owner_id, permissions) -> (token, tier, expires_at). Order: per-agent PAT, per-user PAT, provider (app), platform PAT.
  • Redacts GitHub App installation tokens (ghs_<appid>_<JWT>, about 390 characters) in all four scrubbers.

No call site uses the new resolver yet. Existing behaviour is unchanged.

Changes

  • src/backend/services/github_token_provider.py (new): register_provider, token_for_repo, RepoToken, GithubTokenUnavailable, normalize_repo.
  • src/backend/services/settings_service.py: resolve_github_token, get_stored_secret_setting. resolve_github_pat, resolve_github_pat_candidates and get_github_pat_for_agent are untouched and never consult the provider; their answers are persisted or baked into a container environment, and a provider token expires within the hour.
  • src/backend/services/secret_settings.py: github_app_credentials joins SECRET_SETTING_KEYS (encrypted at rest, refused in cleartext, covered by key rotation).
  • src/backend/utils/credential_sanitizer.py, docker/base-image/agent_server/utils/credential_sanitizer.py, src/frontend/src/utils/scrub.js, src/frontend/src/components/reports/reportSummary.js: installation-token pattern. Matched by structure with bounded quantifiers.
  • .github/workflows/enterprise-docs-guard.yml: the new seam file joins SEAM_FILES.
  • Docs: docs/memory/requirements/github.md §11.20, docs/memory/architecture/backend.md.

Behaviour worth reviewing

  • A provider failure on a repo it covers raises GithubTokenUnavailable. The platform PAT is used only when the provider answers "not covered".
  • Only owner/repo reaches the provider (trailing .git removed). A URL, a third segment or a ./.. segment skips the provider tier.
  • The old ghs_[a-zA-Z0-9]{36,} pattern is kept beside the new one.
  • The first call site of resolve_github_token must check that the caller may use that repo. The resolver itself does no per-caller authorization.

Test Plan

  • cd tests && pytest -p no:randomly unit/test_ent1277_github_token_resolver.py -v (24 tests)
  • pytest unit/test_credential_sanitizer_backend.py, unit/test_credential_sanitizer_agent.py (run separately), unit/test_ec_input_hardening_properties.py, unit/test_ent1066_secret_paste_guard.py, unit/test_ec_credential_crypto_edges.py, unit/test_ent500_assignment_provider.py
  • cd src/frontend && npx vitest run tests/unit/scrubInstallationToken.spec.js tests/unit/reportSummary.spec.js
  • Removing the new scrub.js rule turns scrubInstallationToken.spec.js red
  • Full unit suite: left to CI

The private half (the provider module) is a separate PR in abilityai/trinity-enterprise and depends on this one. No submodule pointer moves here.

Journey Impact

Journey Impact: none: inert open-core seam plus token redaction; no call site uses the resolver yet, so no journey promise changes

Fixes abilityai/trinity-enterprise#1277

🤖 Generated with Claude Code

…Abilityai/trinity-enterprise#1277)

Open-core half of GitHub App authentication.

- services/github_token_provider.py: a seam through which a registered
  provider supplies a short-lived token scoped to one repository. Inert
  with no provider registered.
- settings_service.resolve_github_token(repo, agent_name, owner_id,
  permissions): per-agent PAT, per-user PAT, provider, platform PAT.
  Returns (token, tier, expires_at). A provider failure on a covered repo
  raises GithubTokenUnavailable; the platform PAT is used only when the
  provider answers "not covered".
- resolve_github_pat, resolve_github_pat_candidates and
  get_github_pat_for_agent are unchanged and never consult the provider.
  Their answers are persisted or baked into a container environment.
- github_app_credentials joins SECRET_SETTING_KEYS: encrypted at rest,
  refused in cleartext, covered by key rotation.
  settings_service.get_stored_secret_setting reads it with no env leg.
- Installation tokens (ghs_<appid>_<JWT>, about 390 characters, with
  ".", "-", "_") are redacted whole by both credential_sanitizer copies,
  scrub.js and reportSummary.js. The pattern matches by structure with
  bounded quantifiers, so it is linear on repeated prefixes and leaves
  ordinary text such as "boroughs_population_2020-2024_final.csv" alone.
- enterprise-docs-guard: the new seam file joins SEAM_FILES.

Refs Abilityai/trinity-enterprise#1277

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@obasilakis obasilakis added the ui PR touches the frontend UI — triggers Playwright e2e tests label Nov 17, 2026
@obasilakis

Copy link
Copy Markdown
Contributor Author

Private half: abilityai/trinity-enterprise#1281 (draft until this is on dev).

… refuses non-secret keys (#4624)

Mechanical, per the merge-train note on the PR.
- resolve_github_token docstring states that it does no per-caller
  authorization and passes permissions through unvalidated.
- get_stored_secret_setting raises for a key outside SECRET_SETTING_KEYS, so
  the lazy legacy migration can never run on an ordinary setting; one test.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@vybe

vybe commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

merge-train (2026-11-17): on the train. One commit pushed to this branch and the body patched.

Validated at 4a0e0e277 with /validate-pr, /review and /cso --diff: no critical finding, and 15 mutations all turned a test red.

Pushed 1e58780fb (settings_service.py, one test):

  • resolve_github_token's docstring now states the caller contract that was only in the PR body: it does no per-caller authorization, and permissions is passed to the provider unvalidated.
  • get_stored_secret_setting raises ValueError for a key outside SECRET_SETTING_KEYS. Before, a non-secret key would have run the lazy legacy migration and moved that row to <key>_encrypted. No route reached it; the test goes red without the check.

Body: Refs → Fixes abilityai/trinity-enterprise#1277, and a Journey Impact: none line added. Say so if Fixes is wrong because the private half should keep the issue open.

Ruling at Gate 1: the key and tier names in the public seam are fine as they are (recorded on the linked issue).

For you, not blocking this merge:

  1. github_token_provider.py:157-159 → settings_service.py:1152-1155: a repo string that fails normalize_repo (a URL-form remote, say) skips the provider and resolves to the platform PAT even when the provider covers that repo. test_a_malformed_repo_never_reaches_the_provider pins it as intended, but it is the wider-credential fallback the requirement rules out on failure. Worth deciding before the first call site lands.
  2. The three strict scrubbers need the full ghs_<digits>_a.b.c shape; a truncated token or a segment over the bounds passes them and only reportSummary.js catches it, so the four now disagree.
  3. A provider that fails to register at boot looks the same as "no provider": covered repos quietly resolve to the platform PAT.
  4. The SEAM_FILES entry in enterprise-docs-guard.yml has no test; its only check is the CI job itself.

@vybe vybe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merge-train: batch validated on train/20261117-1746 (#4626)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ui PR touches the frontend UI — triggers Playwright e2e tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants