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.
What it shows
- You register an agent with the identity type
workloadand the providergithub. The binding names one repository and one branch. - A workflow job asks GitHub for its OIDC token. The audience of that token is the address of the agent.
- The job sends the token to the attestation endpoint of the agent,
POST /agents/{agentId}/attest. - 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.
- 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:readandadmin:agents:writefor the setup script. - GitHub Actions is the workload provider that every plan includes.
| Variable | Value |
|---|---|
LUMOAUTH_URL | The address of LumoAuth: https://app.lumoauth.dev, or https://eu.app.lumoauth.dev for the EU region. |
LUMOAUTH_ORG_ID | Your organization, for example acme-corp. |
LUMOAUTH_API_KEY | For 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_REPO | For the setup script only: your repository on GitHub, as owner/repo. |
GITHUB_BRANCH_REF | For the setup script only, and optional: the branch that may act as the agent. Default: refs/heads/main. |
AGENT_ID | The 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:
- On GitHub, open Settings, Secrets and variables, Actions, and the tab Variables. Add the repository variable
LUMOAUTH_AGENT_IDwith the agent ID that the setup script printed. - In the workflow file, set
LUMOAUTH_ORG_IDto your organization. For an organization in the EU region, setLUMOAUTH_URLtohttps://eu.app.lumoauth.dev. - Copy the workflow file to
.github/workflows/release-notes.yaml, and the script to the root of the repository. Push tomain.
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.
- Node.js
- curl
# 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
// 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.
# A job that runs the agent with no stored secret. Copy this file to
# .github/workflows/release-notes.yaml of your repository, and attest.sh 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
- run: sh attest.sh
#!/bin/sh
# Runs inside a GitHub Actions job: exchange the OIDC token of the job for a
# LumoAuth token of the agent, with curl. The workflow file runs it with
#
# sh attest.sh
#
# The script needs curl and jq. The runners of GitHub have both.
set -eu
API="$LUMOAUTH_URL/orgs/$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.
GITHUB_OIDC_TOKEN=$(curl --silent --show-error --fail --get "$ACTIONS_ID_TOKEN_REQUEST_URL" \
--header "Authorization: Bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" \
--data-urlencode "audience=$API/agents/$AGENT_ID" | jq -r '.value')
# 2. Send that token to the attestation endpoint of the agent. LumoAuth
# checks the signature of GitHub, the audience, the repository and the branch.
ANSWER=$(curl --silent --show-error "$API/agents/$AGENT_ID/attest" \
--header "Content-Type: application/json" \
--data "{\"attestation_token\": \"$GITHUB_OIDC_TOKEN\"}")
TOKEN=$(printf '%s\n' "$ANSWER" | jq -r '.access_token // empty')
if [ -z "$TOKEN" ]; then
# The answer never says which check failed. The audit log of the organization does.
echo "refused: $(printf '%s\n' "$ANSWER" | jq -r '.error')"
exit 1
fi
printf '%s\n' "$ANSWER" | jq -r '
"workload: \(.identity.subject)",
"token: \(.token_type), valid for \(.expires_in) seconds",
"scope: \(.scope)"'
# 3. Use the token like the token of any other agent.
curl --silent --show-error --fail "$API/agents/me" --header "Authorization: Bearer $TOKEN" |
jq -r '"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:
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 namesrefs/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. Thereasonof 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 (
environmentinworkloadIdentityConfig). - The repository name can change hands after a rename. Add
repository_idandrepository_owner_idto the binding for an agent in production. attestWorkload()of@lumoauth/agentsends noscope, so the token carries every capability of the agent. The curl version can add"scope"to the body to ask for fewer.