In breve
- Il bearer token da solo viene rifiutato con proof_required, quindi una copia del token non basta da sola.
- La prova firmata viene accettata, e la stessa prova viene rifiutata la seconda volta.
- Una prova con un'altra chiave e una prova con la firma falsa falliscono al controllo della chiave e al controllo della firma.
- L'endpoint legacy accetta ancora il solo bearer token. È la falla che userebbe un token rubato.
- Questa è una demo generica basata sulle idee di Request for Comments (RFC) 9449 sulla dimostrazione del possesso (DPoP). La specifica per agenti non è ancora pubblicata, quindi quelle parti restano da tenere d'occhio.
Ripeti questo lab
Ho scritto questo lab perché tu possa rifarlo per conto tuo. Ogni passo ha i comandi da copiare e l'output che ho ottenuto io, e puoi segnarlo come fatto. Le spunte restano solo nel tuo browser.
Copia un prompt già pronto per Claude Code, Cursor, Codex o un altro agente di codice. Solo per ambienti di test.
Mostra il prompt
I want to run a hands-on lab from iamops.dev, and I would like your help to do it safely. Lab: Lab di proof of possession per agenti: perché un token copiato non basta Read the whole lab here (Markdown): https://iamops.dev/it/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.
Un bearer token funziona per chiunque lo possieda. Se il token di un agente viene copiato, anche la copia funziona, a meno che il server di risorse non controlli qualcosa che la copia non ha. Questo lab lega il token a una chiave e fa controllare al server di risorse una prova firmata a ogni chiamata.
Il lab usa un solo file Python con la libreria standard, più openssl, curl e jq. L’emittente lega il token alla chiave pubblica dell’agente. Il server di risorse controlla il token, poi la prova. La prova è firmata con la chiave privata dell’agente e copre il metodo, il percorso e un hash del token.
Questa è una demo generica. Segue l’idea di proof of possession della RFC 9449 e non è un’implementazione della specifica per agenti. Quella specifica non è ancora pubblicata, quindi i dettagli specifici per agenti sono segnati come da tenere d’occhio e non li presento come acquisiti.
Preparazione#
Servono Python 3, curl, jq, openssl e tr. L’emittente ascolta su 127.0.0.1 alla porta 4901 e il server di risorse alla porta 4902. Non serve nessun account e, dopo il download, nulla lascia il computer.
Il servizio è un solo file, pop_lab.py, e le funzioni di supporto sono in agent_proof.sh.
Passo 1: Scarica il servizio e crea due chiavi#
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.pemLe chiavi private restano in file che solo tu puoi leggere. Il passo di pulizia le elimina.
Passo 2: Avvia i due servizi#
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
Passo 3: Controlla gli endpoint di stato#
curl -s "$ISSUER/healthz" | jq -c .
curl -s "$RESOURCE/healthz" | jq -c .
Passo 4: Ottieni un token legato alla chiave dell’agente#
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)"'
Il claim cnf.jkt è l’impronta della chiave pubblica dell’agente. È quello che lega il token alla chiave.
Passo 5: Un bearer token da solo viene rifiutato#
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
Passo 6: L’agente firma la richiesta e la chiamata riesce#
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
La prova copre il metodo, il percorso, un timestamp, un identificativo usa-e-getta e un hash del token. Una prova per una richiesta non funziona per un altro percorso o un altro token.
Passo 7: La stessa prova non può essere usata due volte#
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
Passo 8: Una prova con un’altra chiave viene rifiutata#
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
Passo 9: Una prova che sostituisce la chiave pubblica dell’agente fallisce la firma#
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
L’attaccante può copiare la chiave pubblica dall’header, ma non può firmare con la chiave privata. Il controllo della firma è quello che lo ferma.
Passo 10: Il vecchio endpoint accetta ancora il solo bearer token#
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
Questa è la lezione del lab. Ogni endpoint che accetta il bearer token senza la prova fa funzionare un token copiato. La soluzione è richiedere la prova in ogni punto in cui il token viene accettato.
Passo 11: Leggi che cosa ha registrato il server di risorse#
cat run/resource.log
Passo 12: Pulizia#
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"
Che cosa non copre questo lab#
- Il formato della prova è quello di questo lab, non il formato della specifica per agenti. La specifica per agenti resta da tenere d’occhio finché non sarà pubblicata.
- Emittente e server di risorse condividono una sola configurazione di fiducia locale e girano ciascuno in un processo. Un’installazione reale richiede rotazione delle chiavi, un archivio delle chiavi e durate dei token adeguate.
- L’endpoint legacy c’è apposta, per mostrare la falla.
Ripeti questo lab#
Servono Python 3 (senza pacchetti extra), curl, jq, openssl e tr. Tutto gira sul tuo computer, sulle porte 4901 e 4902, senza account e senza accesso a internet dopo il download. Calcola circa 15 minuti. Questa è una demo generica di proof of possession, non la specifica AAuth, che non è ancora pubblicata.
Ogni valore tra parentesi angolari è un segnaposto per il tuo ambiente di test. Nulla in questa pagina è un identificativo o un segreto reale.
Imposta le variabili una sola volta
export ISSUER=http://127.0.0.1:4901 RESOURCE=http://127.0.0.1:4902 0 di 11 passi fatti
Passo 1Scarica il servizio e crea due chiavi
Obiettivo. Crea una cartella di lavoro, scarica il servizio e le funzioni di supporto, e crea una chiave dell'emittente e una chiave dell'agente che solo tu puoi leggere.
Prerequisiti
- Python 3, curl, jq, openssl e tr
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 Output atteso
(no output) Passo 2Avvia l'emittente e il server di risorse
Obiettivo. Avvia entrambi i servizi su 127.0.0.1. L'emittente firma i token, e il server di risorse controlla il token e la prova a ogni chiamata.
Prerequisiti
- Il passo di preparazione è completato
- Le porte 4901 e 4902 sono libere
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 Output atteso
issuer listening on 127.0.0.1:4901
resource listening on 127.0.0.1:4902 Passo 3Controlla entrambi gli endpoint di stato
Obiettivo. Verifica che entrambi i servizi rispondano prima di inviare qualsiasi richiesta.
Prerequisiti
- Il passo di avvio è completato
curl -s "$ISSUER/healthz" | jq -c .
curl -s "$RESOURCE/healthz" | jq -c . Output atteso
{"role":"issuer","ok":true}
{"role":"resource","ok":true} Passo 4Ottieni un token legato alla chiave dell'agente
Obiettivo. L'emittente restituisce un token per l'agente. Il token porta un claim di conferma, cnf.jkt, che è l'impronta della chiave pubblica dell'agente.
Prerequisiti
- Il passo di controllo è completato
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)"' Output atteso
sub: demo-agent
scope: calendar.read
cnf.jkt: _AjEqWefsVfSdbOwV9dDsLuYAJia9ZPF9PrLfV2N37A Passo 5Un bearer token da solo viene rifiutato
Obiettivo. Invia il token senza prova. Il server di risorse lo rifiuta, perché un bearer token copiato non basta.
Prerequisiti
- Il passo del token è completato
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 Output atteso
HTTP 401
error: proof_required
detail: this endpoint needs an Agent-Proof header signed with the key the token is bound to Passo 6L'agente firma la richiesta e la chiamata riesce
Obiettivo. Firma il metodo, il percorso e l'hash del token con la chiave dell'agente, e invia la prova in un header insieme al token.
Prerequisiti
- Il passo del token è completato
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 Output atteso
HTTP 200
ok: true
endpoint: /v1/calendar
agent: demo-agent
scope: calendar.read
proof: checked Passo 7La stessa prova non può essere usata due volte
Obiettivo. Invia una seconda volta la prova del passo precedente. Ogni prova porta un identificativo usa-e-getta, e il server di risorse rifiuta la ripetizione.
Prerequisiti
- Il passo della prova è completato
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 Output atteso
HTTP 401
error: replay
detail: this proof was already used once Passo 8Una prova con un'altra chiave viene rifiutata
Obiettivo. Crea una seconda chiave, firma una prova con essa e inviala insieme al token dell'agente. Il token è legato alla prima chiave, quindi la chiamata fallisce.
Prerequisiti
- Il passo del token è completato
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 Output atteso
HTTP 401
error: key_mismatch
detail: the proof key is not the key this token is bound to Passo 9Una prova che sostituisce la chiave pubblica dell'agente fallisce la firma
Obiettivo. Firma con la seconda chiave, ma metti nell'header la chiave pubblica dell'agente. La chiave corrisponde al token, ma la firma non si verifica.
Prerequisiti
- Il passo con un'altra chiave è completato
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 Output atteso
HTTP 401
error: bad_signature
detail: the proof signature does not verify Passo 10Il vecchio endpoint accetta ancora il solo bearer token
Obiettivo. Chiama l'endpoint legacy con il solo bearer token. Lo accetta, ed è la falla che userebbe un token rubato.
Prerequisiti
- Il passo del token è completato
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 Output atteso
HTTP 200
ok: true
endpoint: /v1/legacy/calendar
agent: demo-agent
scope: calendar.read
proof: not required Passo 11Pulizia
Obiettivo. Ferma entrambi i servizi, elimina le chiavi e i file del servizio, rimuovi la cartella di lavoro e verifica che nessuno ascolti sulle due porte.
Prerequisiti
- I passi precedenti sono completati
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" Output atteso
no listener on 4901 or 4902
no pop_lab.py process left Fonti#
Questo articolo in formato Markdown · RSS · JSON feed
Nuovi articoli via email
Una email a settimana con nuovi articoli e lab. Disiscrizione in qualsiasi momento.
Il tuo indirizzo è salvato su Kit, il servizio che invia le email. Dettagli