Expand description
GitHub tokens for agents.
An agent that pushes or opens a pull request does it as the AgentMux GitHub App’s bot, with
an installation token AgentMux Cloud’s broker mints (github_broker::installation_token),
never with the person’s own token and never with a token pasted in. This module is srv’s
side of that:
- which installation a repository’s owner is (the installations the account has linked);
- a token narrowed to the one repository and the permissions an agent needs;
- a cache per (agent, owner, repository, workflows), so an agent that runs many
git/ghcommands an hour asks the broker about once, refreshed when less than five minutes remain; - what the person is told when there is no token: the reason, in words, and never a fall-back to another credential.
The broker is behind Backend, so the cache and the choices are tested without a network.
Structs§
- Live
- The broker as this install reaches it: the cloud sign-in and the instance key, and the person’s brokered GitHub account for a revalidation.
- Mint
Request - What a mint asks for, owned so it can be asked twice.
- Minted
- A minted token and what to do with it.
- Tokens
- The tokens srv has minted for agents.
- Want
- A token wanted: for
agent, onowner/repo(names as GitHub spells them; compared without case).
Enums§
- Token
Error - Why there is no token.
Displayis what the person (or the agent) reads.
Constants§
- BROKER_
ENV - Set in the environment of an agent whose
gitandghuse the broker’s tokens; theghfunctionagentmux-bashwrapexports reads it. - CONTAINER_
HOOKS_ DIR - Where AgentMux’s git hooks are mounted, read-only, in a container agent’s image. Ends in the
directory’s own name, which
agentmux-bashwrapknows its hooks by. - REFRESH_
MARGIN_ SECS - A cached token is renewed when it has less than this long to live.
Traits§
- Backend
- The broker, as this module needs it.
Functions§
- apply_
agent_ git apply_agent_git_infor a spawn: every path that starts an agent process or runs a command for one comes throughgh_guard::apply_gh_guard, which calls this.- apply_
agent_ git_ in - Point an agent’s
gitat the broker’s tokens, or take that out again. - apply_
container_ git - A container agent’s exec environment with its git and
ghset up like a host agent’s: the credential helper, thegitandghfunctions and the hooks, whichagentmux-bashwrapin the image runs fromCONTAINER_HOOKS_DIR. - attach_
store - The account store, whose GitHub accounts decide whether agents use the broker.
- container_
git_ hooks - The host’s hooks directory when container agents get git and
ghthrough AgentMux: a token source exists (the host’sgh-agent, or the person’s connected GitHub account) and the hooks can be written. Without the hooks there is no setup at all, so a container never gets a token whose pushes aren’t scanned. - global
- srv’s tokens: one cache for the process.
- permissions_
for - What an agent’s token may do: push and open pull requests and issues, read repository
metadata.
workflows: writeonly for an agent the person allowed to change CI. - without_
agent_ git envwithout whatapply_agent_git_insets: for a container, which gets its own setup (apply_container_git) or none.