Skip to content

Credential helpers

A password reference in a target file can name a program that gives the password. lemano does not know what is behind the reference: it keeps it as written, runs the program when a login or sudo needs the password, and reads the answer. Any program that follows the protocol on this page can be a helper. lemano-ansible is one: it answers the ansible:// references that lemano ansible import writes.

The reference

spec:
  connector:
    password: vault://kv/web-01?field=login
    sudoPassword: vault://kv/web-01?field=sudo

A reference is SCHEME:// followed by anything on one line. The scheme is one to 32 lowercase letters and digits, and is not env, file, secret or prompt, which lemano reads itself. lemano checks only that the reference has this form, is not longer than 4096 characters and has no control character. What follows the scheme is the helper’s: lemano never splits it, resolves it or looks inside it.

A helper is found by its scheme: lemano-SCHEME, in the same folder as the running lemano (symbolic links resolved), and nowhere else. It is never looked for on PATH, because a program there would run with your rights whoever put it in place. If the program is missing, the error names the folder.

The protocol

lemano runs lemano-SCHEME credential get, with the environment of the lemano process, writes one JSON object on its standard input, and reads one JSON object from its standard output. It runs the helper once for each target and pass, with every password of that target that names the same reference, before the connection’s time limits start.

Request:

{
  "reference": "vault://kv/web-01?field=login",
  "target": "web-01",
  "purposes": ["login", "sudo"],
  "directory": "/etc/lemano/targets"
}
FieldMeaning
referenceThe whole reference, scheme included.
targetThe name of the target the password is for.
purposesThe passwords asked for: login (the SSH login password) and sudo (the password sudo asks for), at least one.
directoryThe folder of the target file that holds the reference, for the relative paths in it. Left out when the target did not come from a file.

Answer:

{
  "passwords": {"login": "…", "sudo": "…"},
  "errors": {"sudo": "the host sets no sudo password"}
}
FieldMeaning
passwordsThe password of each purpose that could be given.
errorsFor each purpose that could not be given, why, in words of the helper’s own. It must not hold a password.

A purpose with neither a password nor an error is an error. Fields that a reader does not know are ignored, in both directions.

Failure and limits

  • A non-zero exit status is an error for every purpose. Standard error is the diagnostic: it is cut to 1024 bytes, control characters become spaces, and any password that the helper also printed on standard output is replaced by (secret). A helper must not print a password on standard error.
  • The helper has one minute. When the time is up it is stopped.
  • Standard output is read up to 1 MiB; more is an error.
  • An answer that is not a JSON object is an error. Standard output is never shown or logged.
  • A password lives in memory only, for the length of one connection. Nothing is written to the store, a log or the command line of any process. The helper receives the reference on standard input, never in its arguments.

What lemano trusts

The helper runs as you, with your environment. It is the one place the password can leak from, so install only helpers you trust, in the folder that holds lemano, with the permissions you give lemano itself.

Writing a helper

A helper is a program that reads a request and prints an answer. In shell:

#!/bin/sh
# lemano-demo: gives every password the same value.
[ "$1 $2" = "credential get" ] || exit 2
cat >/dev/null
printf '{"passwords":{"login":"hunter2","sudo":"hunter2"}}\n'

Put it in the folder of lemano, make it executable, and write password: demo://anything in a target file.