feat(slack-relay): read-only GitHub repos for the agents (repos.*)
Merged
KH
5d ago+900+900+012345678901234567890123456789-16-16-01234567890123456789
Lets the per-thread Slack agents read GitHub repositories without ever seeing the token and without Bash.
What it does
reposvalues block (opt-in,enabled: false):token: {name, key}(Secret with a GitHub token),list(optional;owner/nameor{repo, ref}),refreshMinutes: 15,host: github.com(GHE host or base URL),apiUrl(default derived),sizeLimit,resources.repo-syncsidecar 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.listis empty, the sidecar syncs every repo the token can read. It callsGET /user/repos?affiliation=owner,collaborator,organization_memberacross all pages and lists again on every refresh. It follows onlynextlinks 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
/reposread-only. The chart appendsRead(//repos/**) Glob(//repos/**) Grep(//repos/**)toAGENT_ALLOWED_TOOLSand a short note to the persona. No TS change insrc/.
Verification
- Claude Code permission syntax: checked against the pinned
@anthropic-ai/claude-code2.1.322 in--permission-mode dontAsk, with the same allow and deny flagsclaudeTurnpasses. 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.shagainst 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 ranrepo-list.mtsagainst the live API: it paginated through 369 repos. test/repo-sync.test.ts(runs in the slack-relay workflow, which now also triggers oncharts/slack-relay/files/**) covers:- Link parsing and refusal of
nextlinks 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.shagainstfile://repos: no.git, symlinks become files,../etcis refused, unchanged/updated detection, pruning of revoked repos, a failed listing that keeps the checkouts, and no token anywhere on disk.
- Link parsing and refusal of
- Chart: added
ci/repos-values.yaml.scripts/ci/charts.shnow asserts:- The token is only in the
repo-synccontainer. - The host's
/reposmount is read-only. - The exact allowed tools.
- The
REPOS_LISTrendering. - An empty list renders an empty
REPOS_LISTand 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.
- The token is only in the
- Versions and registry: slack-relay 0.3.4, agent-relay 0.7.41 (dependency and lock). Added the
opt.slack-relay.reposregistry entry, internal_env entries and matrix rows, and re-rendereddocs/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 togithub.com/api.github.comor 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/reposwas 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](https://pr-comments-assets.blacksmith.sh/codesmith/autofix-with-codesmith-dark-3x.png)
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_ASKPASSfrom the sidecar's env; it never appears in URLs, git configs, logs, or checkouts. - Checkouts have no
.gitand 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.hostandrepos.apiUrlsupport GitHub Enterprise Server.- New tests cover listing, pagination, origin pinning, sync, pruning, timeouts, and token handling end to end.