Skip to main content

An agent in GitHub Actions with no secret

Let a workflow prove its identity with the token that GitHub gives it, and receive a LumoAuth token in exchange.

RecipeDraftView source
This page is a draft. The code exists, and not all of it has been run for this page yet. The page says what was checked.
Works with
JavaScript / TypeScriptPlain HTTPGitHub Actions

What it shows​

  1. You register an agent with the identity type workload and the provider github. The binding names one repository and one branch.
  2. A workflow job asks GitHub for its OIDC token. The audience of that token is the address of the agent.
  3. The job sends the token to the attestation endpoint of the agent, POST /agents/{agentId}/attest.
  4. LumoAuth checks the signature of GitHub, the audience, the repository and the branch. It answers with an access token of the agent that is valid for 15 minutes.
  5. The job uses that token. The repository holds no LumoAuth secret.

Before you start​

  • A repository on GitHub, and an API key with the scopes admin:agents:read and admin:agents:write for the setup script.
  • GitHub Actions is the workload provider that every plan includes.
VariableValue
LUMOAUTH_URLThe address of LumoAuth: https://app.lumoauth.dev, or https://eu.app.lumoauth.dev for the EU region.
LUMOAUTH_ORG_IDYour organization, for example acme-corp.
LUMOAUTH_API_KEYFor the setup script only: an API key with the scopes admin:agents:read and admin:agents:write. The workflow needs no API key and no secret.
GITHUB_REPOFor the setup script only: your repository on GitHub, as owner/repo.
GITHUB_BRANCH_REFFor the setup script only, and optional: the branch that may act as the agent. Default: refs/heads/main.
AGENT_IDThe agent ID (agt_…). The setup script prints it. The workflow reads it from the repository variable LUMOAUTH_AGENT_ID.

The setup script registers the agent with the identity type workload, bound to your repository and to one branch. Run it on your own computer, not in the workflow.

GITHUB_REPO=acme/release-notes node agents/github-actions/setup.mjs
setup.mjs
// Registers an agent that proves its identity with the token of a GitHub
// Actions job. The agent is bound to one repository and one branch. Run it
// again at any time, also to change the repository.
//
// GITHUB_REPO=acme/release-notes node agents/github-actions/setup.mjs
//
// The API key needs the scopes admin:agents:read and admin:agents:write.
import { call, ensure, printEnv } from '../../_lib/admin.mjs';

// Only a job of this repository, on this branch, can act as the agent.
const binding = {
workloadIdentityProvider: 'github',
workloadIdentityConfig: {
repository: process.env.GITHUB_REPO ?? 'acme/release-notes',
ref: process.env.GITHUB_BRANCH_REF ?? 'refs/heads/main',
},
};

const found = await ensure('/admin/agents', (a) => a.name === 'Release notes agent', {
name: 'Release notes agent',
description: 'Reads merged pull requests and writes the release notes.',
identityType: 'workload',
capabilities: ['pull-requests:read', 'release-notes:write'],
...binding,
});

// The update applies the binding to an agent that an earlier run registered.
const { data: agent } = await call('PATCH', `/admin/agents/${found.agentId}`, binding);

console.log(`Agent "${agent.name}" accepts the workload ${agent.workloadIdentity}.`);
console.log(`GitHub must issue the token for this audience: ${agent.workloadIdentityConfig.audience}`);
printEnv({ AGENT_ID: agent.agentId });

Then prepare the repository:

  1. On GitHub, open Settings, Secrets and variables, Actions, and the tab Variables. Add the repository variable LUMOAUTH_AGENT_ID with the agent ID that the setup script printed.
  2. In the workflow file, set LUMOAUTH_ORG_ID to your organization. For an organization in the EU region, set LUMOAUTH_URL to https://eu.app.lumoauth.dev.
  3. Copy the workflow file to .github/workflows/release-notes.yaml, and the script to the root of the repository. Push to main.

Code​

Run each command from the recipes folder of the examples repository. Set the folder up once for your language. The setup script and the refusal of a wrong token were run against an organization. The accepted exchange was not run: it needs a workflow job on GitHub. The output below follows the response format of the docs.

agents/github-actions/js/workflow.yaml
# A job that runs the agent with no stored secret. Copy this file to
# .github/workflows/release-notes.yaml of your repository, and attest.mjs to
# the root of the repository.
name: Release notes agent

on:
push:
branches: [main]

permissions:
id-token: write # lets the job ask GitHub for its OIDC token
contents: read

jobs:
agent:
runs-on: ubuntu-latest
env:
LUMOAUTH_URL: https://app.lumoauth.dev
LUMOAUTH_ORG_ID: acme-corp
# The agent ID is not a secret. It is a variable of the repository.
AGENT_ID: ${{ vars.LUMOAUTH_AGENT_ID }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
- run: npm install @lumoauth/agent
- run: node attest.mjs
agents/github-actions/js/attest.mjs
// Runs inside a GitHub Actions job: exchange the OIDC token of the job for a
// LumoAuth token of the agent. The workflow file runs it with
//
// node attest.mjs
import { attestWorkload } from '@lumoauth/agent';

const agentId = process.env.AGENT_ID;
const api = `${process.env.LUMOAUTH_URL}/orgs/${process.env.LUMOAUTH_ORG_ID}/api/v1`;

// 1. Ask GitHub for the OIDC token of this job. The audience is the address
// of the agent, so the token is of no use for another agent or service.
// GitHub sets the two ACTIONS_ variables when the job has id-token: write.
const request = new URL(process.env.ACTIONS_ID_TOKEN_REQUEST_URL);
request.searchParams.set('audience', `${api}/agents/${agentId}`);
const answer = await fetch(request, {
headers: { Authorization: `Bearer ${process.env.ACTIONS_ID_TOKEN_REQUEST_TOKEN}` },
});
const { value: githubToken } = await answer.json();

// 2. Send that token to the attestation endpoint of the agent. LumoAuth
// checks the signature of GitHub, the audience, the repository and the branch.
let token;
try {
token = await attestWorkload({ agentId, attestationToken: githubToken });
} catch (error) {
// The answer never says which check failed. The audit log of the organization does.
console.log(`refused: ${error.code}`);
process.exit(1);
}
console.log(`workload: ${token.identity.subject}`);
console.log(`token: ${token.tokenType}, valid for ${token.expiresIn} seconds`);
console.log(`scope: ${token.scope}`);

// 3. Use the token like the token of any other agent.
const me = await fetch(`${api}/agents/me`, { headers: { Authorization: `Bearer ${token.accessToken}` } });
const { identity } = await me.json();
console.log(`agent: ${identity.agent_id} (${identity.status})`);

Compiles. Not run against an organization. The script ran against an organization with a token from an unknown issuer, and LumoAuth refused it with attestation_rejected. The accepted exchange needs a job on GitHub Actions.

Check the result​

The log of the job shows these lines:

Output
workload: github:acme/release-notes:refs/heads/main
token: Bearer, valid for 900 seconds
scope: pull-requests:read release-notes:write
agent: agt_971841c8f97061c5 (active)
  • Run the same workflow on another branch. The job prints refused: attestation_rejected, because the binding names refs/heads/main.
  • The answer never says which check failed. In the portal, open Audit logs under Security and filter for the event agent.attestation.rejected. The reason of the entry names the check.
  • Search the repository settings: there is no LumoAuth secret. The agent ID is a variable, and it is of no use without a job of this repository.

Limits​

  • LumoAuth accepts each GitHub token once. The script asks GitHub for a new token before each exchange.
  • The access token is valid for 15 minutes. A job that runs longer asks for a new GitHub token and attests again.
  • A binding without a branch accepts every branch, tag and pull request of the repository, also a pull request from a fork. Bind the agent to a branch or to an environment (environment in workloadIdentityConfig).
  • The repository name can change hands after a rename. Add repository_id and repository_owner_id to the binding for an agent in production.
  • attestWorkload() of @lumoauth/agent sends no scope, so the token carries every capability of the agent. The curl version can add "scope" to the body to ask for fewer.