feat(slack-relay): read-only GitHub repos for the agents (repos.*)

Merged
KH
5d ago
+900-16

Lets the per-thread Slack agents read GitHub repositories without ever seeing the token and without Bash.

What it does

  • repos values block (opt-in, enabled: false): token: {name, key} (Secret with a GitHub token), list (optional; owner/name or {repo, ref}), refreshMinutes: 15, host: github.com (GHE host or base URL), apiUrl (default derived), sizeLimit, resources.
  • repo-sync sidecar in the host StatefulSet. It reuses the slack-relay image (it already has git and node), and the script comes from a ConfigMap (charts/slack-relay/files/repo-sync.sh, repo-list.mts), so it works with the currently pinned digest and needs no image rebuild. Each pass shallow-fetches each repo into a sidecar-only bare cache, then checks the commit out at /repos/<owner>/<name> and swaps it in with renames. Checkouts have no .git, and symlinks become plain files, so a repo can't point an agent outside /repos.
  • Token handling: the token is only in the sidecar's env. Git gets it through GIT_ASKPASS, with credential helpers disabled. It never goes into a URL, a remote, a git config, the checkouts, or a log line; git error lines are masked too. The host container and the agents never get it, and the pod doesn't share a process namespace.
  • Discovery: when repos.list is empty, the sidecar syncs every repo the token can read. It calls GET /user/repos?affiliation=owner,collaborator,organization_member across all pages and lists again on every refresh. It follows only next links on the same origin. With a fine-grained PAT, the token's repository selection is the list. Repos that are no longer listed are deleted from the volume, and a failed listing deletes nothing.
  • Agents: the host mounts /repos read-only. The chart appends Read(//repos/**) Glob(//repos/**) Grep(//repos/**) to AGENT_ALLOWED_TOOLS and a short note to the persona. No TS change in src/.

Verification

  • Claude Code permission syntax: checked against the pinned @anthropic-ai/claude-code 2.1.322 in --permission-mode dontAsk, with the same allow and deny flags claudeTurn passes. With the //<abs>/repos/** rules, Read, Glob and Grep on the repos dir work, including through a symlinked repo dir. Read and Grep on a sibling agent's workdir are still denied. Without the rules, reading the repos dir is denied.
  • Token handling end to end: ran repo-sync.sh against a real private GitHub repo using a token. The token never appeared in the logs or on disk, and a wrong token gave "Authentication failed". Also ran repo-list.mts against the live API: it paginated through 369 repos.
  • test/repo-sync.test.ts (runs in the slack-relay workflow, which now also triggers on charts/slack-relay/files/**) covers:
    • Link parsing and refusal of next links on another origin.
    • Pagination, de-duplication and name filtering, with the token sent only as a header.
    • The 401 path, without echoing the token.
    • The CLI against a local HTTP API.
    • repo-sync.sh against file:// repos: no .git, symlinks become files, ../etc is refused, unchanged/updated detection, pruning of revoked repos, a failed listing that keeps the checkouts, and no token anywhere on disk.
  • Chart: added ci/repos-values.yaml. scripts/ci/charts.sh now asserts:
    • The token is only in the repo-sync container.
    • The host's /repos mount is read-only.
    • The exact allowed tools.
    • The REPOS_LIST rendering.
    • An empty list renders an empty REPOS_LIST and the github.com API.
    • The GHE API base.
    • With repos off, there's no sidecar or mount (the default, http, brain and relaygate renders are byte-identical to main apart from labels).
    • Render failures for: no token, path traversal, duplicate repo, option-like ref, credentials in the host, and zero refresh.
  • Versions and registry: slack-relay 0.3.4, agent-relay 0.7.41 (dependency and lock). Added the opt.slack-relay.repos registry entry, internal_env entries and matrix rows, and re-rendered docs/self-hosted-requirements.md.
  • Docs: new "GitHub repos (optional)" section in docs/self-hosted-slack-relay.md. It covers creating a fine-grained read-only PAT (Contents: Read-only, selected repos, expiry), the Secret, the values, what agents see, where the token goes, and egress to github.com/api.github.com or the GHE host.

Not verified

  • Not deployed to a cluster. The sidecar has not run in a pod: its readOnlyRootFilesystem setup, emptyDirs and ConfigMap mount are verified by render and kubeconform only.
  • GET /user/repos was not tested with a fine-grained PAT (only a classic or OAuth token). GitHub documents that it returns the token's selected repos.
  • GHE was not tested against a real server.

šŸ¤– Generated with Claude Code


Autofix with [code]smith
Open in [code]smith Ā· Need help on this PR? Tag @codesmith-bot with what you need.


Summary by cubic

Lets the per-thread Slack agents read GitHub repositories without ever seeing the token and without Bash.

Adds an opt-in repos values block to slack-relay 0.3.4. A repo-sync sidecar in the host pod shallow-fetches repos.list (or every repo the token can read when the list is empty) into a sidecar-only cache and checks each out at /repos/<owner>/<name>, mounted read-only. The agents get only Read, Glob, and Grep on /repos/**. The persona names the listed repos, or points at Glob on /repos in discovery mode.

  • The GitHub token reaches git only through GIT_ASKPASS from the sidecar's env; it never appears in URLs, git configs, logs, or checkouts.
  • Checkouts have no .git and symlinks are plain files, so a repo can't point an agent outside /repos.
  • A failed listing keeps current checkouts; repos no longer listed are removed. Stalling fetches or listings are cut off after REPOS_TIMEOUT_SECONDS (default 600) and retried on the next pass; the swap checks each rename and restores the old tree if the new one can't be moved in. Staging and pruning handle dot-named repos (like .github) without touching selected ones.
  • repos.host and repos.apiUrl support GitHub Enterprise Server.
  • New tests cover listing, pagination, origin pinning, sync, pruning, timeouts, and token handling end to end.