Managing secrets
Result: named, property-tagged secrets that the right agent reads at startup with one command, with approval-gated values handled by rerunning that same command after a human approves, and an acceptance test proving the export policies from the agent's own credential.
Reference
- secrets:
secretcommand records,secret envquoting, and pending-export state. - resources:
policy createflags and records. - activities:
activity approveon a pending export andpolicy evaluationsfor a denial.
Rules
- Values never enter the transcript. Import from
--from-fileor a pipe; export to--outor into the consuming process. Verify by exit code and metadata. - Every secret carries exactly one
consensusproperty,unilateralorapproval, and is named<scope>/<VAR>sosecret envcan build an environment. Properties are immutable and policy-visible; never put a secret value in one. - Export and
envare rerun, not resumed: the same credential from the same home directory picks up its own pending export. - Access is granted by policy on the property, not by name prefix. The prefix selects; the policy authorizes.
- 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), an agent identity from
provisioning-agent-identity or
provisioning-session-agent (its
profile agent and AGENT_TAG), HUMAN_APPROVER_TAG from
bootstrapping-organization, the
export column chosen from
approval-models.md, the scope prefix
(service/), and for each value its file and approval level.
Allow agents to export. Root. From policy-patterns.md create
agents-export-unilateralfor the unilateral column,agents-export-with-approvalfor the human column, or both when the organization holds both kinds of secrets. Skip a policy that already exists with the same name; the tag makes it shared by every agent.Import a value. Root, from a file the agent must not read:
<!-- example: secrets.import -->tk --profile admin --message-format json secret import --name service/API_TOKEN --property consensus=unilateral --from-file ./api-token.txt tk --profile admin --message-format json secret import --name service/DEPLOY_KEY --property consensus=approval --from-file ./deploy-key.txtEach record is
command: "secret.import"withdata.secretId,data.name, anddata.activity. Import is not idempotent; apendingimport is waited on, never repeated. Add further--propertyflags for isolation scopes the policies select.List metadata. Any identity.
<!-- example: secrets.list -->tk --profile agent --message-format json secret list --limit 100data.secrets[]carriessecretId,name,staticProperties[](key,value), andcreatedAtUnixMs;data.nextCursorpages. Values are never listed.Accept from the agent credential. With one secret of each level imported:
<!-- example: secrets.acceptance -->tk --profile agent --message-format json secret export --name service/API_TOKEN --out ./api-token tk --profile agent --message-format json secret export --name service/DEPLOY_KEY --out ./deploy-keyThe unilateral export returns
completedwithdata.out. The approval export returnspendingwithactivity.idand stays pending until a non-roothuman-approvervotes; finish it as in step 6. Any other outcome is a policy defect; do not proceed on it.Build the agent's environment. The agent's process, at startup:
<!-- shared: secret-env-startup --> <!-- example: secrets.env -->tk --profile agent --message-format json secret env --name-prefix service/ --property consensus=unilateralExit
0:data.envmaps eachVARto its value anddata.exported[]names the secrets; in human mode the same command prints dotenv lines for the process to source. The property filter excludes approval-gated secrets silently. Without the filter, any approval-gated secret in the selection makes the command exit1withcode: "approval_required"anddetails.pending[](name,secretId,activityId), and prints no values at all.Finish an approval-gated read. Submitter runs the export; a human approves; the submitter reruns the identical command:
<!-- example: secrets.export-approved -->tk --profile agent --message-format json secret export --name service/DEPLOY_KEY --out ./deploy-key tk --profile approver --message-format json activity approve --id ACTIVITY_ID tk --profile agent --message-format json secret export --name service/DEPLOY_KEY --out ./deploy-keyThe first run returns
status: "pending",activity.id, anddata.nextStep; nothing is written. The rerun returnscompletedwithdata.out.--outrefuses an existing path. Rerunning while the approval is outstanding returns the samependingactivity, not a second one.Isolate agents from each other, when more than one exists, as in policy-patterns.md, with
<!-- example: secrets.isolation -->BILLING_AGENT_TAGset to the billing agent's tag id fromuser tag create:tk --profile admin --message-format json policy create --name billing-agent-export --effect allow \ --consensus "approvers.any(user, user.tags.contains('${BILLING_AGENT_TAG}'))" \ --condition "activity.type == 'ACTIVITY_TYPE_EXPORT_SECRETS' && secret.static_properties['consensus'] == 'unilateral' && secret.static_properties['scope'] == 'billing'" tk --profile billing --message-format json secret export --name ops/TOKEN tk --profile billing --message-format json secret env --name-prefix ops/Both commands as the other agent fail with
unauthorized403.Rotate a value. Root. Secrets are immutable and names are unique, so a rotation is a delete followed by an import under the same name with the same properties. The name is unavailable between the two.
<!-- example: secrets.rotate -->tk --profile admin --message-format json secret delete --name service/API_TOKEN tk --profile admin --message-format json secret import --name service/API_TOKEN --property consensus=unilateral --from-file ./api-token-new.txtWait for a
pendingdeletion before importing. The new secret has a new id. Deleting does not revoke a value already exported; rotate the credential at its provider first when access is being reduced.Hand off. Report the export policy ids and the approval column in force, each secret's id, name, and properties, the acceptance results from step 4, the pending activity ids still awaiting approval, and the exact
secret envcommand the process runs. Stop.
Runtime examples
The process, not the agent in conversation, runs step 5 and sources its
output. Hermes Agent, for example, takes the command as secrets.command;
a systemd unit, for example, runs it in ExecStartPre and writes to an
EnvironmentFile. Approval-gated secrets stay out of startup paths that
cannot wait.
Verified by
| Examples | Test |
|---|---|
| secrets.import, secrets.list, secrets.env, secrets.rotate | secrets::managing_secrets_env_and_rotation |
| secrets.acceptance | secrets::managing_secrets_agent_export_acceptance |
| secrets.export-approved | secrets::secret_export_with_consensus_finishes_by_rerunning_the_command |
| secrets.isolation | secrets::managing_secrets_isolation_denies_cross_agent_export |
| secrets.env | secrets::secret_env_exports_matching_secrets_as_dotenv |
Troubleshooting
secret envexits1withapproval_required: anapprovalsecret is in the selection. Either add--property consensus=unilateralfor the startup path, or approve eachdetails.pending[].activityIdand rerun.secret exportfails withunauthorized403: no export policy selects this user for this secret's properties. Check the secret carries theconsensusproperty and the policy'sAGENT_TAGis the id, not the name. Inspecttk --profile admin --message-format json policy evaluations --activity-id ACTIVITY_IDwhen the error carries an activity; otherwise compare the user's tags with the policy consensus. Do not switch to root.secret exportfails withapi_erroranddetails.activity: the export was rejected or failed; local state is cleared and the next run starts a new export.secret importfails withapi_error400: the name is taken. A pending deletion holds the name until it completes.secret envfails withinvalid_input"no secrets match": the prefix or property selects nothing in this organization. Checksecret list.- The approval export returns
completedwithout a human vote: the approver is root, or the secret carriesconsensus=unilateral. Fix the property or the approver; root approval proves nothing. secret envfails withunauthorized403: the prefix selected a secret outside this agent's scope. Narrow the prefix or fix thescopeproperty.secret exportfrom a different machine or profile returns a newpending: pending state belongs to the credential and home that started it. Finish from the original.
Related Skills
- managing-policies: debug a denied export
with
policy evaluationsor adjust the export set. - monitoring-activities: approve a pending export or deletion.
- provisioning-agent-identity: the
agent user and profile that runs
secret env. - managing-identities: rotate the agent's credential later.