Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Managing secrets

Adding a secret via CLI (imperative)

Note

All secrets must be in the same folder as sesam.yml or below it. We do not support adding secrets outside of the sesam repository. Attempts to do so will error out.

If you have a secret at path/to/secret, then having it managed by sesam is only a matter of this command:

sesam add path/to/secret --group deploy

This will:

  1. Record that this file is now managed by sesam by adding it to the audit log.
  2. Encrypt the file and place it in .sesam/objects. This is what is being pushed in the end.

If you omit the --group parameter then only the admin group will have access to the file. You can change this at any point by just re-running the add command with any groups you want to set.

Overall the workflow looks like this:

      ┌─────────────────┐   git add   ┌─────────────────┐    seal     ┌─────────────────┐
      │  git objects    │◄────────────┤  sesam objects  │◄────────────┤ revealed files  │
      │  .git/objects   ├────────────►│ .sesam/objects  ├────────────►│ in worktree     │
      └─────────────────┘   checkout  └─────────────────┘   reveal    └─────────────────┘

What this means for you:

  • The revealed files are ignored by git.
  • Commands like git log will print paths like .sesam/objects/secret.txt but not secret.txt. This is because the actual revealed file is of course not tracked.
  • If you want to run git commands explicitly on secrets, you have to run e.g. git log .sesam/objects/secret.txt not git log secret.txt therefore.

Adding a secret via config (declarative)

Adding secrets via CLI is nice for scripts. sesam also supports describing the desired state in a declarative way via sesam.yml. If you executed the above command you will notice the secret was added already to the config:

secrets:
  - path: path/to/secret
    access: [deploy]
    desc: Where it used, who owns it, Contact...

If you did not run the add command above, then you can also add the entry manually and then run:

sesam apply

This will automatically check what the state is in the repo and how it differs from the state in the config. The changes are then resolved by adding/removing secrets or adding/removing users. Either all of them are recorded or none is, so a step that cannot be carried out leaves the repository as it was.

To see the difference before applying it, use sesam config diff. It renders sesam.yml against the state the audit log describes, using whatever diff tooling your git is configured with.

Warning

sesam apply only carries out changes that are still uncommitted in your working tree. A config change that arrived with a git pull is refused - see Applying a changed config.

Adding multiple secrets

You can also add whole directories, if you need to:

tree dir/of/secrets
.
├── some_file
└── sub
    └── another_file
sesam add --nested dir/of/secrets
tree dir/of/secrets
.
├── sesam.yml
├── some_file
└── sub
    ├── another_file
    └── sesam.yml

This will create a hierarchy of sesam.yml files, each declaring the secrets of its own directory:

# dir/of/secrets/sesam.yml:
secrets:
  - path: some_file
# dir/of/secrets/sub/sesam.yml:
secrets:
  - path: another_file

There is no need to reference them from the main sesam.yml: every sesam.yml below it is picked up automatically. Only directories that hold their own .sesam (a separate sesam repository) are skipped. Without --nested, a secret is added to the nearest existing sesam.yml above it.

Once done you can also add descriptions to the files in the config or do more fine-tuning with the available config keys.

Note

If you ever create new files in the sub directories they do not automatically get added. Instead you need to run sesam add again. In that sense, it works a bit like git add. Secrets whose files you deleted stay tracked; remove them with sesam rm.

Modifying secrets

Running sesam add will work here too, similar to git add. By default this will also re-seal the secrets, except if you pass --no-seal.

If you want to change the access groups of a user, then just pass a different set of --group / -g flags. Note that this will overwrite the existing groups. If you would rather like to append, then use --group-add / -G.

Getting an overview

If you need to see which files were modified but not yet sealed you can use sesam status:

# with --all you will only see the modified files,
# without it only those that changed in some way.
sesam status --all
.
├─ M README.md (admin)
├─ ✓ bg.png (admin)
╰─ services/
   ├─ ✓ gateway.env (admin)
   ╰─ ✓ registry.env (admin)
  1 modified · 3 in sync

This will show you files you edited directly without calling sesam add on them.

The letter says what happened to a secret since its plaintext and its sealed object were last written together. sesam works that out from the object versions git holds, so nothing has to be remembered on your machine:

  • M modified: you edited the plaintext. sesam seal takes it.
  • S stale: the object moved on (a pull, checkout or merge) and the plaintext is the old version. sesam reveal takes it; sesam seal leaves it alone unless named (sesam seal <path>) or --force-stale is given.
  • ! diverged: both at once, seen during a merge or by the hooks. Pick a side with sesam reveal --force-diverged or sesam seal --force-diverged, or per secret with sesam reveal <path> / sesam seal <path>.
  • R recipients changed: the content agrees, but who may read it changed. sesam seal re-encrypts it.
  • U conflicted: a merge left conflict markers in the plaintext.

Running a command with secrets

Use sesam run to give a command access to selected secrets without revealing them in your worktree:

sesam run \
  --secret TLS_CERT=certs/client.pem \
  --env-file deploy/production.env \
  -- ./deploy
  • --secret TLS_CERT=certs/client.pem gives the command a read-only file and sets TLS_CERT to its descriptor path, such as /dev/fd/3. Your program reads the secret from that path.
  • --env-file deploy/production.env adds the variables declared in that dotenv file to the command's environment. Sesam parses the file without shell expansion. Duplicate assignments within or across dotenv files produce a warning; the last value wins. Cross-file warnings name both files without printing values.

Dotenv files support NAME=value and export NAME=value assignments, blank lines, and comments starting with #. They are parsed as data, not executed as shell scripts. Shell commands such as set -euo pipefail and malformed assignments cause an error rather than being silently skipped.

Both options select managed files and can be repeated. Sesam verifies the secrets and your access before starting the command. It rejects variable collisions with file-secret variables or the inherited environment, and releases the repository lock before the command starts.

Sesam starts the command directly, passing file secrets as open files and dotenv entries as environment variables. Sesam starts the command directly, passing file secrets as open files and dotenv entries as environment variables.

Sesam starts the command as a direct child, forwards SIGHUP and SIGTERM, and waits for it. SIGINT and SIGQUIT are not forwarded: the terminal delivers them to the command directly, so sesam only keeps waiting. It returns the command's exit code, or 128 + signal if a signal terminates it. If sesam is killed with SIGKILL or crashes, the command may keep running and retain access to its inherited secret descriptors.

On Linux, each secret lives in an anonymous memory file (memfd) that never touches a filesystem and is sealed read-only before the command starts. On macOS, sesam removes each temporary file's name before writing secret bytes. Either way the open file works through /dev/fd, and the OS releases it when the last reference closes.

Automatic selection and names

Without an explicit variable name, sesam recognizes paths ending in .env as dotenv files. Other files get a SESAM_ variable derived from their sesam-relative path: ASCII letters are uppercased and characters other than ASCII letters and digits become underscores. The variable still contains a descriptor path, not the file's contents:

sesam run --secret postgres/backup/password.txt -- ./my-service
# SESAM_POSTGRES_BACKUP_PASSWORD_TXT=/dev/fd/3

sesam run --secret deploy/production.env -- ./my-service
# Variables declared in deploy/production.env are injected directly.

Use --all to select every managed secret accessible to your current identity. Automatically selected paths are processed in sorted order. Additional dotenv filename regexes can be supplied with repeatable --env-pattern flags or the SESAM_RUN_ENV_PATTERN environment variable. Regexes match sesam-relative paths with / separators; the .env suffix is always recognized.

Dotenv files selected with --secret (including automatic --all selections) are processed first. Explicit --env-file files follow in flag order, so their values override earlier dotenv assignments with the same name.

sesam run --all --env-pattern '(^|/)\.env\.' -- ./my-service

Explicit selectors take precedence over --all. For example, --secret CONFIG=production.env forces file-descriptor delivery even for a dotenv filename. --env-file forces literal dotenv parsing regardless of the filename. Generated names that collide with each other, dotenv variables, or the inherited environment are rejected rather than overwritten. File secrets are streamed into their descriptors; dotenv values remain subject to the operating system's process-environment limits.

Removing secrets

To stop managing secrets and delete their plaintext:

sesam rm files/ dir/

rm refuses plaintext with changes that were never sealed, since it is the only copy of them. Seal first to keep them in history, or pass --force to delete them anyway. To keep the content outside sesam, copy it with sesam show path > elsewhere before removing.

Warning

Please do not delete secrets just with rm. This will just remove the revealed file, but the sealed file in .sesam/ will still exist. On the next sesam open it will suddenly be back.

Moving secrets

Probably not very surprising by now, but we have a mv command as well:

sesam mv old_name new_name

Warning

The same warning as with sesam rm applies: Please do not just move the file with mv. This will just move the revealed file to a new name, but the sealed file in .sesam/ will still exist. On the next sesam open it will suddenly be back with the old path.

Listing secrets

sesam ls
╭───────────────────────────────────────────────────────────────╮
│                            Secrets                            │
├─────────────────────────────────┬───────────────┬─────────────┤
│ Path                            │ Access Groups │ Description │
├─────────────────────────────────┼───────────────┼─────────────┤
│ README.md                       │ admin         │ —           │
├─────────────────────────────────┼───────────────┼─────────────┤
│ dir/of/secrets/some_file        │ admin         │ —           │
├─────────────────────────────────┼───────────────┼─────────────┤
│ dir/of/secrets/sub/another_file │ admin         │ —           │
├─────────────────────────────────┼───────────────┼─────────────┤
│                                 │               │ 3 secrets   │
╰─────────────────────────────────┴───────────────┴─────────────╯

You can also use the --json switch to print it in a more scriptable way.

Built 2026-11-16 22:19:31 • commit: d477bef