Storing and reading secrets
Problem
You have SPIKE up and running and you want to do the everyday thing: write a secret, read it back, list what is there, and clean up old ones. You also want to know what happens when you overwrite a secret (does the old value vanish?) and how to recover one you deleted by mistake.
TL;DR
Secrets are versioned key-value maps stored at a namespaced path. Use
spike secret from SPIKE Pilot:
spike secret put tenants/acme/db/creds user=acme pass=SPIKERocks
spike secret get tenants/acme/db/creds
spike secret list
spike secret delete tenants/acme/db/creds # soft delete (recoverable)
spike secret undelete tenants/acme/db/creds # bring it back
Every put to an existing path creates a new version; old versions are
retained until you explicitly delete them.
Workflow
-
Write a secret. A secret is one or more
key=valuepairs at a path:spike secret put tenants/acme/db/creds user=acme pass=SPIKERocksThis is an upsert. Writing the same path again stores a new version rather than mutating the old one.
-
Read it back. Get the whole map, a single key, or a specific version:
spike secret get tenants/acme/db/creds # all keys, current version spike secret get tenants/acme/db/creds pass # just one key spike secret get tenants/acme/db/creds -v 2 # version 2 (0 = current) spike secret get tenants/acme/db/creds -f json # plain | yaml | json -
List paths.
listshows every secret path you are allowed to see:spike secret list spike secret list -f json -
Inspect metadata without revealing the value (versions, timestamps, current version):
spike secret metadata get tenants/acme/db/creds spike secret metadata get tenants/acme/db/creds -v 2 -
Delete and undelete. Delete is a soft delete: the version is marked deleted, not destroyed, so it can be restored. Versions are given as a comma-separated list with
-v;0means the current version (the default when-vis omitted):spike secret delete tenants/acme/db/creds # current version spike secret delete tenants/acme/db/creds -v 1,2,3 # specific versions spike secret undelete tenants/acme/db/creds -v 1,2,3 # restore them
Tips
- Multiple keys per path. One path can hold a whole map
(
put .../creds user=acme pass=… host=db.internal). Group related fields under one path instead of scattering them. -vdiffers by command. Forgetandmetadata get,-v/--versiontakes a single integer. Fordeleteandundelete,-v/--versionstakes a comma-separated list.0always means the current version.- Output formats.
get,list, andmetadata getaccept-f/--formatwithplain/p,yaml/y, orjson/j. Usejsonwhen piping into scripts. - Persistence depends on the backend. In
memorymode everything is gone on restart;sqlitepersists to disk;litekeeps no secrets at all (it is encryption-only). See Choosing a backend store.
Pitfalls
- Paths are namespaces, not filesystem paths. Use
tenants/acme/db/creds, never/tenants/acme/db/creds. A leading slash is wrong, and trailing slashes are discouraged. listtakes no path argument. It lists all paths you can access; it does not filter by prefix. Filter in your shell if you need a subset.- Reading needs a policy. SPIKE Pilot authenticates with its SPIFFE ID, but
it still needs a policy granting
read/writeon the path. “I canputbut another workload can’tget” is almost always a missing policy, not a storage problem. See Writing access policies. - Overwrite does not destroy history.
putover an existing path keeps the old version. If you must scrub a value, delete the specific versions.
Cross-links
- Choosing a backend store
- Writing access policies
- Granting a workload access to secrets
- Reference: SPIKE CLI and the command reference
What’s next
Control who can read and write these secrets: Writing access policies.