Provisioning an agent identity
Result: a tagged non-root user whose single API key never expires, whose private half exists only on the agent host, and which cannot change its own credentials. The identity grants no capability: exports, signing, and SSH access are each added by their own workflow. Acceptance is proven from the agent's credential, never root's.
Reference
- resources:
user tag,user create,api-keyrecords, andpolicy createflags. - authentication:
profile create,login, andwhoamirecords and the credential file location. - activities:
activity waiton a pending user creation.
Rules
- Principal separation: root creates the tag, the user, and the DENY and then stops. The agent never runs as root, and root never runs the agent's workload.
- The private key is generated on the agent host by
profile create. Onlydata.publicKeytravels to root; a key generated on root's machine and copied over is not this route. agents-no-credentialsis mandatory. Self-targeted credential changes default-allow, so without the DENY the agent can register itself another permanent key.- Policies select the tag, not names or ids. Adding an agent is one tagged
user create; the DENY already covers it. - Every acceptance check runs with
--profile agent. A root success proves nothing, because a satisfied root quorum bypasses policies.
Instructions
Inputs: the root profile (admin) and the host the agent runs on. There is
no minting row here: the one key never expires.
Ensure the agent tag. Root. List the tags and create
<!-- example: agent-identity.tag -->agentonly when no tag carries that name:tk --profile admin --message-format json user tag list tk --profile admin --message-format json user tag create --name agentSet
AGENT_TAGto the id of the tag namedagent, from the list or fromdata.activity.result.createUserTagResult.userTagId. bootstrapping-organization creates the same tag; never create a second one.Generate the credential on the agent host. On that host, with no profile yet:
<!-- example: agent-identity.profile-create -->tk --message-format json --organization-id ORG_UUID profile create --profile-name agentSave
data.publicKeyasPUBLIC_KEY. The record shape and the file it writes are described in managing-identities.Create the tagged user. Root, with the public key from step 2 and no
<!-- example: agent-identity.user-create -->--expires-in:tk --profile admin --message-format json user create --user-name agent --tag-name agent --public-key PUBLIC_KEYSet
AGENT_USER_IDtodata.activity.result.createUsersResult.userIds[0].pendingmeans a policy gates user creation; wait on the activity before step 4.Deny credential changes. Root, once per organization; the tag makes it shared by every agent:
<!-- shared: agents-no-credentials --> <!-- example: agent-identity.no-credentials -->tk --profile admin --message-format json policy create --name agents-no-credentials --effect deny \ --consensus "approvers.any(user, user.tags.contains('${AGENT_TAG}'))" \ --condition "activity.resource == 'CREDENTIAL'"The record is
command: "policy.create"withdata.activity.result.createPolicyResult.policyId. Skip it when a policy with this name already exists.Log in and verify on the agent host.
<!-- example: agent-identity.login -->tk --message-format json login --profile-name agent tk --profile agent --message-format json whoamiProceed when
whoamireturnsdata.userIdequal toAGENT_USER_ID.Acceptance test from the agent credential.
<!-- example: agent-identity.acceptance -->tk --profile agent --message-format json api-key register --input-json '{"userId":"AGENT_USER_ID","apiKeys":[{"apiKeyName":"escape","publicKey":"PUBLIC_KEY","curveType":"API_KEY_CURVE_P256"}]}' tk --profile agent --message-format json api-key list --user-id AGENT_USER_IDExpected, in order:
Command Expect self-registration code: "unauthorized"andhttpStatus: 403key list exactly one key, its credential.publicKeyequal toPUBLIC_KEYandexpiresAtnullAny other outcome is a policy defect; do not proceed on it.
Hand off. Report
AGENT_USER_ID,AGENT_TAG, the profile name and host, the DENY's policy id, and the acceptance results from step 6. Stop.
Verified by
| Examples | Test |
|---|---|
| agent-identity.tag, agent-identity.profile-create, agent-identity.user-create, agent-identity.no-credentials, agent-identity.login, agent-identity.acceptance | api_keys::provisioning_agent_identity_long_lived_route |
Troubleshooting
user tag createfails withapi_errorand a 400: a tag namedagentalready exists. Read its id from the list in step 1.user createfails withnot_foundfor--tag-name agent: step 1 did not run in this organization. Create the tag first; do not substitute--tagwith a guessed id.loginfails withunauthorized401 or 403: the create activity is pending or rejected, orPUBLIC_KEYwas mistyped. Comparetk --profile admin --message-format json api-key list --user-id AGENT_USER_IDwith the error'sdetails.publicKey.- The self-registration in step 6 returns
completedorpending: the DENY is missing or names the wrong tag, such as the''an unsetAGENT_TAGleaves. First createagents-no-credentialsand verify it by rerunning the self-registration. Only then list the agent's keys withtk --profile admin --message-format json api-key list --user-id AGENT_USER_ID, delete every unauthorized key withapi-key deleteas root, and rotate the runtime credential. Deleting first leaves a window to register another key.
Related Skills
- managing-identities: rotate or revoke the agent's key later.
- managing-secrets: grant this agent exports and give its process a startup environment.
- signing-git-commits: grant this agent a scoped signing key for its commits.
- using-ssh: grant this agent an SSH key in Turnkey's secure enclaves.
- provisioning-session-agent: the expiring-key alternative when a permanent credential is not acceptable.