Rules that every agent must meet
Refuse agents that are dormant, that proved their workload too long ago, or that call from an unknown network.
What it shows
- An access rule in the portal names the conditions that an agent must meet each time it authenticates.
- The rule of this recipe applies to one agent, "Stock counter", and allows one address range.
- The agent requests a token from an address outside the range. LumoAuth refuses with
403, and the answer names the condition. - You disable the rule, and the agent receives a token again.
A rule has four conditions, and you fill in at least one: the maximum age of the last workload attestation, the days since the agent was last used, the maximum risk level, and the address ranges. Access rules exist in the portal only: no API or CLI command creates them.
Before you start
- The permission
agents.editin the portal, to create a rule.agents.viewis enough to read the rules. - An agent to try the rule on. The setup script registers the agent "Stock counter" and prints its client ID and secret.
- The setup script needs an API key with the scopes
admin:agents:readandadmin:agents:write. Create it in the portal under Applications & developer tools, API keys.
| 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. |
AGENT_CLIENT_ID | The client ID of the agent. The setup script prints it. |
AGENT_CLIENT_SECRET | The client secret of the agent. The setup script prints it once. |
The setup script creates what the recipe needs, through the Admin API. You can run it again at any time.
node agents/access-rules/setup.mjs
setup.mjs
// Registers the agent of the recipe, "Stock counter", and prints its client
// ID and secret. Run it again at any time.
//
// node agents/access-rules/setup.mjs
//
// The API key needs the scopes admin:agents:read and admin:agents:write.
import { call, list, printEnv } from '../../_lib/admin.mjs';
const name = 'Stock counter';
let agent = (await list('/admin/agents')).find((a) => a.name === name);
let secret;
if (agent) {
// LumoAuth shows a secret once. A second run therefore makes a new secret,
// and the old one stops working.
secret = (await call('POST', `/admin/agents/${agent.agentId}/rotate-credentials`)).data.clientSecret;
} else {
agent = (
await call('POST', '/admin/agents', {
name,
description: 'Counts the stock of each warehouse.',
identityType: 'client_secret',
capabilities: ['stock:read'],
})
).data;
secret = agent.clientSecret;
}
console.log(`Agent "${name}" (${agent.agentId}) is ready.`);
printEnv({ AGENT_CLIENT_ID: agent.agentId, AGENT_CLIENT_SECRET: secret });
Create the rule in the portal
- Open AI Agents, Agent rules in the portal. The Access rules tab is selected.
- Click Create rule. The dialog Create access rule opens.
- Enter a Rule name, for example "Stock counter: office network only".
- Under Applies to, choose Selected agents only, and select "Stock counter" in the Agents list.
- Under Must connect from these IP ranges, enter
203.0.113.0/24. This range is reserved for examples, so your own address is outside it. - Click Check current agents under Preview impact. The preview names the active agents that the rule would refuse today. It leaves the address ranges out, because they depend on each request.
- Click Create rule. The rule is in the list with the status Enabled, and it applies to the next request of the agent.
These steps were followed on a LumoAuth organization.
Code
The agent requests a token with the client credentials grant.
Run each command from the recipes folder of the examples repository. Set the folder up once for your language. Every version below was run against a LumoAuth organization.
- curl
#!/bin/sh
# The agent requests a token. An access rule that the agent does not meet
# refuses the request, and the answer names the rule's condition.
#
# sh agents/access-rules/http/check.sh
set -eu
ANSWER=$(mktemp)
STATUS=$(curl --silent --show-error --output "$ANSWER" --write-out '%{http_code}' \
"$LUMOAUTH_URL/orgs/$LUMOAUTH_ORG_ID/api/v1/oauth/token" \
--user "$AGENT_CLIENT_ID:$AGENT_CLIENT_SECRET" \
--data "grant_type=client_credentials")
if [ "$STATUS" = 200 ]; then
echo "200: the agent received a token"
else
# The description ends with the reason, for example (ip_not_allowed).
echo "$STATUS: $(cat "$ANSWER")"
fi
rm -f "$ANSWER"
sh agents/access-rules/http/check.sh
Check the result
403: {"error":"access_denied","error_description":"The agent is denied by a conditional access policy (ip_not_allowed)"}
- Open the menu of the rule and click Disable. Run the script again: it prints
200: the agent received a token. - Open Audit logs in the portal and filter by the event type
agent.access_policy_denied. The refusal is there, with the agent as the actor. - To remove the rule, open its menu and click Delete.
Limits
- With no rule, nothing changes for your agents. With rules, the first condition that an agent does not meet refuses it.
- Start with Selected agents only and one test agent. A rule for All agents with a wrong address range stops every agent of the organization.
- The other conditions give other reasons:
attestation_missing,attestation_stale,agent_dormantandrisk_level_exceeded. - A call with an access token that the agent already holds gets
403with"error": "access_policy_denied"and areasonmember. The token endpoint puts the reason at the end oferror_description. - A rule does not suspend an agent. LumoAuth suspends an agent by itself when the account of its owner is blocked, switched off or deleted. The audit log then holds
agent.suspended_with_owner, and the agent needs a new owner before it can be active again.