Skip to main content

Module github_tokens

Module github_tokens 

Source
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/gh commands 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.
MintRequest
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, on owner/repo (names as GitHub spells them; compared without case).

Enums§

TokenError
Why there is no token. Display is what the person (or the agent) reads.

Constants§

BROKER_ENV
Set in the environment of an agent whose git and gh use the broker’s tokens; the gh function agentmux-bashwrap exports 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-bashwrap knows 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_in for a spawn: every path that starts an agent process or runs a command for one comes through gh_guard::apply_gh_guard, which calls this.
apply_agent_git_in
Point an agent’s git at the broker’s tokens, or take that out again.
apply_container_git
A container agent’s exec environment with its git and gh set up like a host agent’s: the credential helper, the git and gh functions and the hooks, which agentmux-bashwrap in the image runs from CONTAINER_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 gh through AgentMux: a token source exists (the host’s gh-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: write only for an agent the person allowed to change CI.
without_agent_git
env without what apply_agent_git_in sets: for a container, which gets its own setup (apply_container_git) or none.