iamops.dev Search
Argo on X RSS feed
ENEnglish

Labs Practitioner · 12 min

Developers and identity engineers who want to see why a bearer token needs a second factor on each call. Skip the setup if you only want the result.

Agent proof of possession lab: why a copied token is not enough

A local issuer and resource server: a bearer token alone was refused, a signed proof was accepted once, and replay, wrong-key and forged proofs failed.

Sequence diagram: the agent gets a token bound to its key, the resource server refuses the token sent alone, and accepts it once the agent sends a proof signed with that key.
TL;DRThe bearer token alone is refused with proof_required, so a copied…
Repeat this lab 11 steps

I wrote this lab so you can run it yourself. Each step has the commands to copy and the output I got, and you can tick it as done. Your ticks stay in this browser only.

Go to the steps

How this works

Copies a ready-made prompt for Claude Code, Cursor, Codex or any coding agent. For test environments only.

Show prompt
I want to run a hands-on lab from iamops.dev, and I would like your help to do it safely.

Lab: Agent proof of possession lab: why a copied token is not enough
Read the whole lab here (Markdown): https://iamops.dev/agent-proof-of-possession-lab.md

What the lab needs before the first step:
- Python 3, curl, jq, openssl and tr

How I want you to work:
1. Read the lab from start to finish first (each step lists its own prerequisites). Then check that the prerequisites are in place and that the tool versions match what the lab expects. Tell me what is missing before you run anything.
2. Run one step at a time. Before each command, show it to me and say in a sentence what it does.
3. Ask me before anything that costs money, creates cloud resources, touches a real tenant or account, or deletes anything. Wait for my answer.
4. Use the placeholders from the lab. Never paste real secrets, tokens or production identities into a command, a file or this chat. If a value is needed, tell me where to set it myself.
5. After each step, compare the output with the expected output in the lab. If it does not match, stop and tell me what differs. Do not carry on or invent a fix without asking me.
6. At the end, report what passed, what failed and which cleanup you did. Then offer to tick the steps off for me. The lab page keeps ticks only in my browser, so if you cannot do that, list the steps I should tick.

This lab is for test environments only. Do not run it against production, or against a tenant or account that holds real data or real users.

You may answer in my language.

A bearer token works for whoever holds it. If an agent’s token is copied, the copy works too, unless the resource server also checks something the copy does not have. This lab binds the token to a key and makes the resource server check a signed proof on every call.

The lab uses one Python file with the standard library, plus openssl, curl and jq. The issuer binds the token to the agent’s public key. The resource server checks the token, then the proof. The proof is signed with the agent’s private key and covers the method, the path and a hash of the token.

This is a generic demo. It follows the idea of proof of possession from RFC 9449, and it is not an implementation of the agent-specific spec. That spec is not published yet, so agent-specific spec details are marked to watch and are not claimed here.

Setup#

You need Python 3, curl, jq, openssl and tr. The issuer listens on 127.0.0.1 port 4901 and the resource server on port 4902. Nothing needs an account, and nothing leaves the computer after the download.

The service is one file, pop_lab.py, and the helper functions are in agent_proof.sh.

Step 1: Download the service and make two keys#

bash
mkdir -p pop-lab/run && cd pop-lab
curl -s -O https://iamops-dev.github.io/lab-files/agent-proof-of-possession-lab/pop_lab.py
curl -s -O https://iamops-dev.github.io/lab-files/agent-proof-of-possession-lab/agent_proof.sh
openssl ecparam -name prime256v1 -genkey -noout -out issuer.key.pem
openssl ec -in issuer.key.pem -pubout -out issuer.pub.pem 2>/dev/null
openssl ecparam -name prime256v1 -genkey -noout -out agent.key.pem
openssl ec -in agent.key.pem -pubout -out agent.pub.pem 2>/dev/null
chmod 600 issuer.key.pem agent.key.pem

The private keys stay in files that only you can read. The cleanup step deletes them.

Step 2: Start both services#

bash
export ISSUER=http://127.0.0.1:4901 RESOURCE=http://127.0.0.1:4902
python3 -I pop_lab.py --role issuer --port 4901 --key issuer.key.pem --log run/issuer.log > run/issuer.out 2>&1 &
echo $! >> run/pids
python3 -I pop_lab.py --role resource --port 4902 --issuer-pub issuer.pub.pem --log run/resource.log > run/resource.out 2>&1 &
echo $! >> run/pids
sleep 1
cat run/issuer.out run/resource.out
Terminal output: the two start commands in the background, then the cat of both output files showing the issuer on 4901 and the resource server on 4902 listening
Step 2. Both services listen on 127.0.0.1.

Step 3: Check the health endpoints#

bash
curl -s "$ISSUER/healthz" | jq -c .
curl -s "$RESOURCE/healthz" | jq -c .
Terminal output: two JSON health lines, one for the issuer and one for the resource server, both ok true
Step 3. Both services answer.

Step 4: Get a token bound to the agent’s key#

bash
source ./agent_proof.sh
TOKEN=$(curl -s -X POST "$ISSUER/token" -d agent=demo-agent -d scope=calendar.read --data-urlencode "public_key=$(cat agent.pub.pem)" | jq -r .access_token)
decode_part "$(printf '%s' "$TOKEN" | cut -d. -f2)" | jq -r '"sub: \(.sub)", "scope: \(.scope)", "cnf.jkt: \(.cnf.jkt)"'
Terminal output: the decoded token claims, sub demo-agent, scope calendar.read, and a cnf.jkt thumbprint of the agent's key
Step 4. The token carries the key thumbprint in cnf.jkt.

The cnf.jkt claim is the thumbprint of the agent’s public key. That is what ties the token to the key.

Step 5: A bearer token alone is refused#

bash
curl -s -o body.json -w "HTTP %{http_code}\n" -H "Authorization: Bearer $TOKEN" "$RESOURCE/v1/calendar"
jq -r 'del(.events) | to_entries[] | "\(.key): \(.value)"' body.json
Terminal output: HTTP 401, error proof_required, with the detail that the endpoint needs an Agent-Proof header signed with the bound key
Step 5. The token alone is refused.

Step 6: The agent signs the request and the call succeeds#

bash
PROOF=$(prove agent.key.pem GET /v1/calendar "$TOKEN")
curl -s -o body.json -w "HTTP %{http_code}\n" -H "Authorization: Bearer $TOKEN" -H "Agent-Proof: $PROOF" "$RESOURCE/v1/calendar"
jq -r 'del(.events) | to_entries[] | "\(.key): \(.value)"' body.json
Terminal output: HTTP 200 with ok true, the endpoint, the agent demo-agent, scope calendar.read, and proof checked
Step 6. The signed proof is accepted.

The proof covers the method, the path, a timestamp, a one-time id and a hash of the token. A proof for one request does not work for another path or token.

Step 7: The same proof cannot be used twice#

bash
curl -s -o body.json -w "HTTP %{http_code}\n" -H "Authorization: Bearer $TOKEN" -H "Agent-Proof: $PROOF" "$RESOURCE/v1/calendar"
jq -r 'del(.events) | to_entries[] | "\(.key): \(.value)"' body.json
Terminal output: HTTP 401, error replay, the proof was already used once
Step 7. The repeat is refused as a replay.

Step 8: A proof from another key is refused#

bash
openssl ecparam -name prime256v1 -genkey -noout -out attacker.key.pem
openssl ec -in attacker.key.pem -pubout -out attacker.pub.pem 2>/dev/null
ATTK=$(prove attacker.key.pem GET /v1/calendar "$TOKEN")
curl -s -o body.json -w "HTTP %{http_code}\n" -H "Authorization: Bearer $TOKEN" -H "Agent-Proof: $ATTK" "$RESOURCE/v1/calendar"
jq -r 'del(.events) | to_entries[] | "\(.key): \(.value)"' body.json
Terminal output: HTTP 401, error key_mismatch, the proof key is not the key this token is bound to
Step 8. A key the token is not bound to is refused.

Step 9: A proof that swaps in the agent’s public key fails the signature#

bash
FORGED=$(prove attacker.key.pem GET /v1/calendar "$TOKEN" agent.key.pem)
curl -s -o body.json -w "HTTP %{http_code}\n" -H "Authorization: Bearer $TOKEN" -H "Agent-Proof: $FORGED" "$RESOURCE/v1/calendar"
jq -r 'del(.events) | to_entries[] | "\(.key): \(.value)"' body.json
Terminal output: HTTP 401, error bad_signature, the proof signature does not verify
Step 9. Putting the right public key next to a wrong signature fails.

The attacker can copy the public key from the header, but cannot sign with the private key. The signature check is what stops that.

Step 10: The old endpoint still takes the bearer token alone#

bash
curl -s -o body.json -w "HTTP %{http_code}\n" -H "Authorization: Bearer $TOKEN" "$RESOURCE/v1/legacy/calendar"
jq -r 'del(.events) | to_entries[] | "\(.key): \(.value)"' body.json
Terminal output: HTTP 200 with ok true on the legacy calendar endpoint, and proof not required
Step 10. The legacy endpoint accepts the stolen-token case.

This is the lesson of the lab. Any endpoint that accepts the bearer token without the proof lets a copied token work. The fix is to require the proof everywhere the token is accepted.

Step 11: Read what the resource server logged#

bash
cat run/resource.log
Terminal output: the resource server log lines, one per request, with the status and the reason
Step 11. Each refusal has a reason in the log.

Step 12: Clean up#

bash
kill $(cat run/pids)
rm -f body.json agent.key.pem agent.pub.pem attacker.key.pem attacker.pub.pem issuer.key.pem issuer.pub.pem pop_lab.py agent_proof.sh
cd .. && rm -rf pop-lab
lsof -nP -iTCP:4901-4902 -sTCP:LISTEN || echo "no listener on 4901 or 4902"
pgrep -fl pop_lab.py || echo "no pop_lab.py process left"
Terminal output: the cleanup check, no listener on 4901 or 4902 and no pop_lab.py process left
Step 12. The services and the keys are gone.

What this does not cover#

  • The proof format is this lab’s own, not the agent-specific spec format. agent-specific spec is to watch until its spec is published.
  • The issuer and the resource server share one local trust setup and one process each. A real deployment needs key rotation, a key store and proper token lifetimes.
  • The legacy endpoint is there on purpose, to show the gap.

Repeat this lab#

You need Python 3 (no extra packages), curl, jq, openssl and tr. Everything runs on your own computer on ports 4901 and 4902, with no account and no internet access after the download. Plan for about 15 minutes. This is a generic proof-of-possession demo, not the AAuth spec, which is not published yet.

Every value in angle brackets is a placeholder for your own test environment. Nothing on this page is a real identifier or secret.

Set your variables once

bash · env.sh
export ISSUER=http://127.0.0.1:4901 RESOURCE=http://127.0.0.1:4902
Step 1Download the service and make two keys

Goal. Create a work folder, download the service and the helper functions, and make an issuer key and an agent key that only you can read.

Prerequisites

  • Python 3, curl, jq, openssl and tr
bash · setup.sh
mkdir -p pop-lab/run && cd pop-lab
curl -s -O https://iamops-dev.github.io/lab-files/agent-proof-of-possession-lab/pop_lab.py
curl -s -O https://iamops-dev.github.io/lab-files/agent-proof-of-possession-lab/agent_proof.sh
openssl ecparam -name prime256v1 -genkey -noout -out issuer.key.pem
openssl ec -in issuer.key.pem -pubout -out issuer.pub.pem 2>/dev/null
openssl ecparam -name prime256v1 -genkey -noout -out agent.key.pem
openssl ec -in agent.key.pem -pubout -out agent.pub.pem 2>/dev/null
chmod 600 issuer.key.pem agent.key.pem

Expected output

output
(no output)
Step 2Start the issuer and the resource server

Goal. Start both services on 127.0.0.1. The issuer signs the tokens, and the resource server checks the token and the proof on every call.

Prerequisites

  • The setup step has completed
  • Ports 4901 and 4902 are free
bash · start.sh
python3 -I pop_lab.py --role issuer --port 4901 --key issuer.key.pem --log run/issuer.log > run/issuer.out 2>&1 &
echo $! >> run/pids
python3 -I pop_lab.py --role resource --port 4902 --issuer-pub issuer.pub.pem --log run/resource.log > run/resource.out 2>&1 &
echo $! >> run/pids
sleep 1
cat run/issuer.out run/resource.out

Expected output

output
issuer listening on 127.0.0.1:4901
resource listening on 127.0.0.1:4902
Step 3Check both health endpoints

Goal. Confirm both services answer before you send any request.

Prerequisites

  • The start step has completed
bash · health.sh
curl -s "$ISSUER/healthz" | jq -c .
curl -s "$RESOURCE/healthz" | jq -c .

Expected output

output
{"role":"issuer","ok":true}
{"role":"resource","ok":true}
Step 4Get a token bound to the agent's key

Goal. The issuer returns a token for the agent. The token carries a confirmation claim, cnf.jkt, that is the thumbprint of the agent's public key.

Prerequisites

  • The health step has completed
bash · token.sh
source ./agent_proof.sh
TOKEN=$(curl -s -X POST "$ISSUER/token" -d agent=demo-agent -d scope=calendar.read --data-urlencode "public_key=$(cat agent.pub.pem)" | jq -r .access_token)
decode_part "$(printf '%s' "$TOKEN" | cut -d. -f2)" | jq -r '"sub: \(.sub)", "scope: \(.scope)", "cnf.jkt: \(.cnf.jkt)"'

Expected output

output
sub: demo-agent
scope: calendar.read
cnf.jkt: _AjEqWefsVfSdbOwV9dDsLuYAJia9ZPF9PrLfV2N37A
Step 5A bearer token alone is refused

Goal. Send the token with no proof. The resource server refuses it, because a copied bearer token is not enough.

Prerequisites

  • The token step has completed
bash · bearer-only.sh
curl -s -o body.json -w "HTTP %{http_code}\n" -H "Authorization: Bearer $TOKEN" "$RESOURCE/v1/calendar"
jq -r 'del(.events) | to_entries[] | "\(.key): \(.value)"' body.json

Expected output

output
HTTP 401
error: proof_required
detail: this endpoint needs an Agent-Proof header signed with the key the token is bound to
Step 6The agent signs the request and the call succeeds

Goal. Sign the method, the path and the token hash with the agent's key, and send the proof in a header next to the token.

Prerequisites

  • The token step has completed
bash · proof.sh
PROOF=$(prove agent.key.pem GET /v1/calendar "$TOKEN")
curl -s -o body.json -w "HTTP %{http_code}\n" -H "Authorization: Bearer $TOKEN" -H "Agent-Proof: $PROOF" "$RESOURCE/v1/calendar"
jq -r 'del(.events) | to_entries[] | "\(.key): \(.value)"' body.json

Expected output

output
HTTP 200
ok: true
endpoint: /v1/calendar
agent: demo-agent
scope: calendar.read
proof: checked
Step 7The same proof cannot be used twice

Goal. Send the proof from the previous step a second time. Each proof carries a one-time id, and the resource server refuses the repeat.

Prerequisites

  • The proof step has completed
bash · replay.sh
curl -s -o body.json -w "HTTP %{http_code}\n" -H "Authorization: Bearer $TOKEN" -H "Agent-Proof: $PROOF" "$RESOURCE/v1/calendar"
jq -r 'del(.events) | to_entries[] | "\(.key): \(.value)"' body.json

Expected output

output
HTTP 401
error: replay
detail: this proof was already used once
Step 8A proof from another key is refused

Goal. Make a second key, sign a proof with it, and send it with the agent's token. The token is bound to the first key, so the call fails.

Prerequisites

  • The token step has completed
bash · other-key.sh
openssl ecparam -name prime256v1 -genkey -noout -out attacker.key.pem
openssl ec -in attacker.key.pem -pubout -out attacker.pub.pem 2>/dev/null
ATTK=$(prove attacker.key.pem GET /v1/calendar "$TOKEN")
curl -s -o body.json -w "HTTP %{http_code}\n" -H "Authorization: Bearer $TOKEN" -H "Agent-Proof: $ATTK" "$RESOURCE/v1/calendar"
jq -r 'del(.events) | to_entries[] | "\(.key): \(.value)"' body.json

Expected output

output
HTTP 401
error: key_mismatch
detail: the proof key is not the key this token is bound to
Step 9A proof that swaps in the agent's public key fails the signature

Goal. Sign with the second key, but put the agent's public key in the header. The key matches the token, yet the signature does not verify.

Prerequisites

  • The other-key step has completed
bash · forged-key.sh
FORGED=$(prove attacker.key.pem GET /v1/calendar "$TOKEN" agent.key.pem)
curl -s -o body.json -w "HTTP %{http_code}\n" -H "Authorization: Bearer $TOKEN" -H "Agent-Proof: $FORGED" "$RESOURCE/v1/calendar"
jq -r 'del(.events) | to_entries[] | "\(.key): \(.value)"' body.json

Expected output

output
HTTP 401
error: bad_signature
detail: the proof signature does not verify
Step 10The old endpoint still takes the bearer token alone

Goal. Call the legacy endpoint with only the bearer token. It accepts it, which is the gap a stolen token would use.

Prerequisites

  • The token step has completed
bash · legacy.sh
curl -s -o body.json -w "HTTP %{http_code}\n" -H "Authorization: Bearer $TOKEN" "$RESOURCE/v1/legacy/calendar"
jq -r 'del(.events) | to_entries[] | "\(.key): \(.value)"' body.json

Expected output

output
HTTP 200
ok: true
endpoint: /v1/legacy/calendar
agent: demo-agent
scope: calendar.read
proof: not required
Step 11Clean up

Goal. Stop both services, delete the keys and the service files, remove the work folder, and check that nothing listens on the two ports.

Prerequisites

  • The earlier steps have completed
bash · cleanup.sh
kill $(cat run/pids)
rm -f body.json agent.key.pem agent.pub.pem attacker.key.pem attacker.pub.pem issuer.key.pem issuer.pub.pem pop_lab.py agent_proof.sh
cd .. && rm -rf pop-lab
lsof -nP -iTCP:4901-4902 -sTCP:LISTEN || echo "no listener on 4901 or 4902"
pgrep -fl pop_lab.py || echo "no pop_lab.py process left"

Expected output

output
no listener on 4901 or 4902
no pop_lab.py process left

Sources#

Discuss this on X or LinkedIn

Follow on X

New posts by email

One email a week with new posts and labs. Unsubscribe anytime.

Your address is stored with Kit, which sends the emails. Details

Related research and labs

Type to search every page. Use the arrow keys to move through the results.

    Open the full search page