Managing identities
Users, tags, registered API keys, and the local profiles that hold private
keys are one workflow because a rotation touches all four. Flag forms come
first; --input-json is the escape hatch for fields the flags do not cover.
Reference
- resources:
user,user tag, andapi-keyrecords and JSON parameter shapes. - authentication: profiles and credential files.
Rules
- Register public keys only. A private key is generated where it will be used and never crosses a transcript or a command argument.
- A constrained user stays non-root. Root quorum membership is a separate organization setting; never grant it to make a denial go away.
- Preserve access until the replacement is verified: rotate by registering,
verifying with
whoami, then deleting the old key. - Deleting a local profile forgets a file path. It revokes nothing.
Instructions
Inputs: the acting root profile (admin), the target user's name or id, and
for a new key the machine that will hold it.
Create a user
Generate the credential where the user will run. On that machine, with no profile yet:
<!-- example: identities.profile-create -->tk --message-format json --organization-id ORG_UUID profile create --profile-name agentSave
data.publicKeyasPUBLIC_KEY. The file path is indata.profile.api_key_file.Create the user with its tag and key. Root.
<!-- example: identities.user-create -->tk --profile admin --message-format json user create --user-name agent --tag-name agent --public-key PUBLIC_KEY--tag-nameresolves against the organization's tags and must match exactly one; pass--tag TAG_IDwhen names are ambiguous. Add--expires-in 7dfor an expiring key and--anchor-keywhen every key the user will hold expires. Savedata.activity.result.createUsersResult.userIds[0]asUSER_ID.Verify from the new profile. On the user's machine:
<!-- example: identities.login -->tk --message-format json login --profile-name agentProceed when
data.identity.userIdequalsUSER_ID.
Rotate an API key
Generate the replacement on the user's machine, without changing the profile yet:
<!-- example: identities.generate -->tk --message-format json api-key generate --output ./next-key.jsonSave
data.publicKeyasPUBLIC_KEY. The record never contains the private key.Register it. Root.
<!-- example: identities.register -->tk --profile admin --message-format json api-key register --input-json '{"userId":"USER_ID","apiKeys":[{"apiKeyName":"agent-next","publicKey":"PUBLIC_KEY","curveType":"API_KEY_CURVE_P256"}]}'Save
data.activity.result.createApiKeysResult.apiKeyIds[0]. Apendingstatus means a policy gates credential creation; wait on the activity before switching.Switch the profile and verify. On the user's machine:
<!-- example: identities.switch -->tk --message-format json profile set --profile-name agent --api-key-file ./next-key.json tk --profile agent --message-format json whoamiprofile setreportsdata.publicKeyanddata.previousApiKeyFile, and removes the stored copy of the old key. Proceed only whenwhoamisucceeds with the expecteduserId; if it fails withunauthorized, point the profile back at the original old key file and inspect the registration activity.Revoke the old key. Root. List first to find the id of the key that is not
<!-- example: identities.revoke-key -->PUBLIC_KEY:tk --profile admin --message-format json api-key list --user-id USER_ID tk --profile admin --message-format json api-key delete --user-id USER_ID --id API_KEY_IDdata.apiKeys[].credential.publicKeyidentifies each key;expiresAtis a Unix-millisecond string ornull. After deletion the old key fails withunauthorized; the old file may be removed locally.
Revoke a user
For a compromised or retired non-root user, confirm the identity, then delete the user; key deletion alone leaves any other credential valid.
<!-- example: identities.revoke-user -->tk --profile admin --message-format json user get --id USER_ID
tk --profile admin --message-format json user delete --id USER_IDProceed only when data.user.userName and data.user.userTags match the
intended user and the user is not a root quorum member. Deletion is final.
Verified by
| Examples | Test |
|---|---|
| identities.profile-create, identities.user-create, identities.login | users::user_create_from_flags_resolves_tag_names_and_registers_anchor_and_expiring_keys |
| identities.generate, identities.register, identities.switch, identities.revoke-key, identities.revoke-user | api_keys::managing_identities_rotate_and_revoke |
Troubleshooting
loginfails: followdetails.nextStepwhen present, checking its condition first. A missing profile isnot_found. A key Turnkey does not accept isunauthorized; registerdetails.publicKeyon a user, then log in again. A missing credential file isnot_foundand a malformed oneinvalid_input; neither carriesnextStep. See cli-convention for the fulldetails.user createfails withnot_foundfor--tag-name: the tag does not exist in this organization. Create it withtk --profile admin --message-format json user tag create --name agentor pass--tag TAG_ID.user createfails withinvalid_inputnaming two tags: the name is ambiguous; pass--tag TAG_ID.user createwith only--expires-infails withapi_error400: every user needs one persistent credential. Add--anchor-key.loginfails withunauthorizedright afteruser create: the create activity is still pending or was rejected. Inspect it withtk --profile admin --message-format json activity get --id ACTIVITY_ID.api-key deletefails withunauthorizedwhen run as the user itself: a credential DENY is in force, which is intended. Run it as root, or as a revoker from revoking-agent-keys.whoamifails afterprofile set: the registration has not completed. Restore the original old key file with anotherprofile setand wait on the activity.
Related Skills
- managing-policies: scope what the new user may do; a user with no matching ALLOW can only read.
- monitoring-activities: when a create,
register, or delete returns
pending. - bootstrapping-organization: when the tags do not exist yet.