Skip to content

Add trust policies, token exchange and agent tokens - #30

Merged
lnsp merged 2 commits into
masterfrom
rfc0005-ci-and-agent-tokens
Nov 21, 2026
Merged

lnsp merged 2 commits into
masterfrom
rfc0005-ci-and-agent-tokens

Conversation

@lnsp

@lnsp lnsp commented Nov 21, 2026 •

Copy link
Copy Markdown
Member

The client side of RFC-0005 release 5 (deploys from CI) and release 7 (agent tokens), plus service url on the inspect route.

Commands

  • valar trust add|list|remove (aliases create, delete) for /v2/projects/{p}/trust-policies.
    • add --service <name or prefix*> with either --github-repo owner/repo and one of --branch, --environment or --pull-requests, or --subject and --claim k=v by hand. --issuer defaults to GitHub Actions' issuer.
    • --github-repo reads the repository's and owner's IDs and /actions/oidc/customization/sub from GitHub (GH_TOKEN/GITHUB_TOKEN for private repositories). It writes the subject as GitHub issues it: sub_claim_prefix (immutable IDs where the repository uses them), and custom include_claim_keys where it knows every key's value. It pins repository_id and repository_owner_id, and for branch and environment policies also event_name (--event, default push) and workflow_ref (--workflow, required).
    • When the subject template leaves out the context (for example ["repo"]), the policy pins the branch's ref or the environment as a claim, so it still admits only that branch or environment.
    • Refused: a preview prefix without --pull-requests, --pull-requests without one, and subject keys it can't know.
    • Refused unless --force: --event or --claim event_name= of pull_request_target, workflow_run or issue_comment, and a hand-written subject with a pull_request segment for a service rather than a preview prefix. A hand-written GitHub policy without repository_id (in a claim or an immutable or custom subject) gets a warning.
  • valar auth exchange [--service] [--project] [--id-token-file path|-] [--audience] [--export] calls token-exchange with no Authorization header.
    • The identity token comes from --id-token-file, from ACTIONS_ID_TOKEN_REQUEST_URL/_TOKEN (audience: the endpoint's origin unless --audience), or from stdin. There is no flag that takes the token itself, so it stays out of ps and shell history.
    • It accepts only an answer matching ^valar_ut_[0-9a-f]{64}$; anything else fails before it is printed, masked or exported, so a malformed value cannot add lines to $GITHUB_ENV.
    • It prints the token on stdout. In GitHub Actions it also writes ::add-mask::, and with --export it appends VALAR_TOKEN to $GITHUB_ENV instead of printing.
    • On a 403, the error lists the identity token's claims that policies match (sub, ref, IDs, event_name, workflow_ref), read unverified from the JWT.
  • valar token create --agent sends kind: agent with scopes: [read] and needs --project. --ttl is checked against 30 days and defaults to the server's 7.
    • After minting, it prints the /mcp URL and how to configure clients without writing the token into a config file: an mcp add --transport http ... --header 'Authorization: Bearer ${VALAR_AGENT_TOKEN}' command and a generic mcpServers entry. It also warns against agents that can read ~/.valar (RFC-0011).
    • --json adds mcpUrl.
  • valar service url reads GET .../inspect (urls), so service-bound tokens work, and falls back to the listing when the server answers an unknown-route 404.

The API client now omits Authorization when it has no token. The README and the agent skill document the new commands.

Server dependencies

  • Trust policies and the exchange need platform#519 and [API.OIDC] on the installation. Until then the commands report "the server has no trust policies or token exchange".
  • Agent tokens need /v2/tokens with kind: agent (#487, merged) and api.mcp.enabled, which arrives with #523. Until then the server refuses the token with its own reason.
  • service url uses inspect (#467, merged).

Test steps

  • go vet ./... && go test -race ./...
  • Against a platform with #519 and an [API.OIDC] test issuer:
    • valar trust add --service web --github-repo <owner/repo> --branch main --workflow deploy.yml, then valar trust list.
    • Exchange a test issuer token: valar auth exchange --service web --id-token-file token.jwt.
    • valar trust add --service web --subject repo:<owner/repo>:pull_request is refused; with --service 'webpr*' it is accepted.
    • With the printed token as VALAR_TOKEN, run valar build push --wait, then valar service url.
    • Run valar trust remove <id>. The token then fails with "revoked".
  • With #523 and api.mcp.enabled: valar token create agent --agent --project <p>. Add the printed configuration to an MCP client and list tools.
  • valar service url with a token bound to one service prints its URLs.

The client side of RFC-0005 releases 5 (deploys from CI) and 7 (agent
tokens):

- valar trust add|list|remove (aliases create and delete) manage a
  project's trust policies. --github-repo with --branch, --environment
  or --pull-requests builds a GitHub Actions policy: it reads the
  repository's and owner's IDs and the OIDC subject format from GitHub,
  writes the subject as GitHub issues it (immutable IDs, custom claim
  keys), and pins repository_id, repository_owner_id and, for branches
  and environments, event_name and workflow_ref. --subject and --claim
  set a policy by hand.
- valar auth exchange trades a CI identity token for a one-hour token
  bound to one service. It reads the identity token from --id-token,
  --id-token-file, the GitHub Actions request variables (audience: the
  endpoint's origin, or --audience) or stdin, sends no Authorization
  header, masks the token in GitHub Actions and with --export writes it
  to GITHUB_ENV. A refusal shows the claims a policy matches.
- valar token create --agent mints a read-only agent token bound to a
  project (7 days by default, 30 at most) and prints how to configure
  MCP clients with the /mcp URL and the token in an environment variable.
- valar service url reads the inspect route, which service-bound tokens
  may read, and falls back to the listing on older platforms.
- A --github-repo policy pins the branch's ref or the environment as a
  claim when the repository's subject template leaves out its context,
  so a template such as ["repo"] no longer admits every branch and
  environment.
- trust add refuses, unless --force, policies for pull_request_target,
  workflow_run and issue_comment jobs and hand-written pull_request
  subjects for a service rather than a preview prefix, and warns when a
  hand-written GitHub policy pins no repository ID.
- auth exchange prints, masks or exports only a value matching
  ^valar_ut_[0-9a-f]{64}$, so a malformed answer cannot write further
  variables into GITHUB_ENV.
- auth exchange drops --id-token, which put the identity token on the
  command line; --id-token-file (- for stdin) and the GitHub Actions
  request remain.
- The docs no longer claim that forks never get identity tokens: private
  repositories can send them.
@lnsp
lnsp marked this pull request as ready for review November 21, 2026 22:44
@lnsp
lnsp merged commit 858113e into master Nov 21, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant