Secrets and lists

Secrets from 1Password

Keep a source's API key or password in 1Password, and have Legato read it with a service account when a card needs it.

On this page 9 sections

A page's sources name their credentials as secrets, such as "secret": "pihole". A secret's value can be typed into Settings → Secrets and kept in the Mac's Keychain, or it can stay in 1Password: Legato then reads it with a 1Password service account when a source needs it.

Keeping it in 1Password means there's one copy of each credential. When you rotate a key in 1Password, the cards pick up the new one on their own.

What you need

  • A 1Password account where you can create a service account.

That's all. Legato reads 1Password with a helper of its own, built with 1Password's SDK, so you don't need 1Password's op tool or Homebrew. (If the helper can't run, Legato uses op where it's installed, at /opt/homebrew/bin/op or /usr/local/bin/op. Settings → Secrets shows which it reads with.)

Set it up

  1. Make a vault for Legato. Put in it only the items your pages need, such as your Pi-hole app password or a GitHub token. A service account can only read the vaults you grant it, so a separate vault keeps what Legato can reach small.

  2. Create a service account with read access to that vault, following 1Password's guide. 1Password shows its token once; it starts with ops_.

  3. Save the token in Legato. Open Settings → Secrets and choose Set Up… beside 1Password. Paste the token into Service account and choose Save. Legato keeps it in the Keychain. Or save it from a shell, without it appearing on screen: printenv OP_SERVICE_ACCOUNT_TOKEN | /Applications/Legato.app/Contents/MacOS/Legato secret token set (see below).

  4. Copy the item's reference. In 1Password, open the item, then choose Copy Secret Reference from the field's menu. A reference looks like op://Legato/Pi-hole/password.

  5. Add the secret. Choose + under the list (or Set… on a secret a page already asks for) and fill in:

    • Name: the name the page uses, such as pihole.
    • Host: the host the secret goes to, such as pi.hole or 192.168.1.2.
    • Value from: 1Password.
    • Reference: the reference you copied.

    Choose Save. Legato reads the item once right away and says whether 1Password returned a value. A wrong reference, or a vault the service account can't read, shows here rather than on a card.

The page itself doesn't change. It names the secret exactly as it would for a Keychain secret:

json
"sources": {
  "pihole": {
    "url": "http://pi.hole",
    "secret": "pihole",
    "every": "1m"
  }
}

A secret the page needs but nobody has set yet is already in the Secrets list, marked Not set. Choose Set… on it: its name and host are filled in. Switch Value from to 1Password and paste the reference.

A secret in two fields

Some secrets come in two parts: a username and a password, or an OAuth client's ID and secret. Legato sends them as one value, first:second. A 1Password item usually keeps the two in separate fields, so give Legato a reference to each:

  • In Settings → Secrets, choose 1Password under Value from, Two under Fields, then fill in First (the username or client ID) and Second.
  • When you install a page, Sign in names the fields, such as Client ID reference and Client secret reference.
  • From the command line, give --1password twice, the first field first.

Legato reads both fields together and checks both when you save. If one can't be read, the message names it. The first field can't contain a colon, since the colon separates the two parts.

If an item keeps both parts in one field as first:second, choose One (One field on Sign in) and give that field's reference.

From the command line, or an agent

Legato secret set can link a reference when the caller supplies the same service account token saved in Legato:

bash
/Applications/Legato.app/Contents/MacOS/Legato secret set pihole --1password 'op://Legato/Pi-hole/password'

For a secret in two fields, give --1password twice: --1password 'op://Legato/Example API/client id' --1password 'op://Legato/Example API/client secret'.

Before saving anything, Legato compares your OP_SERVICE_ACCOUNT_TOKEN with its saved token, then checks the reference by reading it, with the helper (or op). It passes only that token and a small fixed environment; account, Connect-server and configuration overrides from your shell are ignored. A different token, an app sign-in or no token is refused. Use Settings → Secrets for those setups.

--host HOST sets the host (by default, the host of the page that names the secret), and --replace overwrites a secret that's already saved, with the same check. Legato secret list shows these secrets as from 1Password. Saved references use the service account token saved now.

The service account token, from the command line

bash
printenv OP_SERVICE_ACCOUNT_TOKEN | /Applications/Legato.app/Contents/MacOS/Legato secret token set

Legato secret token set saves the token read from standard input, never from an argument, so it stays out of shell history and the process list. A saved token is replaced only with --replace. Legato secret token delete removes it. Either way, Legato forgets every value it read with the old token. Legato secret list says whether a token is saved, never what it is.

Saving a token gives Legato the access that token holds. Replacing or deleting it can stop cards working if the new token cannot read the items or no token is saved. Legato's copy is in the Keychain, locked to Legato: another program asking for it is refused unless you approve a macOS prompt, so a token you saved isn't handed to agents. The same goes the other way: an item another program puts in Legato's part of the Keychain isn't used without your approval.

Which service account to give Legato

  • One of its own, for a vault of its own (recommended). Agents that don't hold that exact token ask you to link references in Settings.
  • The same token your agents use. Simpler, and agents can set up 1Password secrets themselves. Legato's vault is then only as protected as your agents' environment.

How Legato reads it

  • When a source needs it, together. The first request that uses the secret reads it from 1Password. Reads asked for within a tenth of a second of each other go to 1Password as one request, and so does every secret due to be read again within the next 10 minutes, so the secrets your pages use renew together. Several cards asking for the same secret share one read.
  • Then from memory, for an hour. Legato keeps the value in memory, never on disk, and reads it again after an hour. So a rotated credential reaches the cards within the hour.
  • Again when the service refuses it. When the service turns the credential down (HTTP 401, or a refused sign-in), Legato reads it again before the next try, in case it was rotated, and never sends the refused value again. Other failures, such as an unreachable host, an HTTP 403 or a server error, don't cause a new read.
  • Failed reads wait their turn. When 1Password can't be read, Legato waits a minute before trying that item again, then twice as long each time, up to an hour, however often the cards poll. At most two requests run at once.
  • Through Legato's helper. The helper starts with the first read and signs in to 1Password once, then answers each read over a pipe, so the service account isn't signed in again for every read. Legato hands it the token on its standard input, never in its environment or on its command line, and it writes nothing anywhere else, so no secret ends up in a log. It gets nothing from your environment, so no other 1Password sign-in applies. A read that takes more than 40 seconds stops the helper; the next read starts it again. It starts again, too, when you save a different service account.
  • When 1Password can't be reached. The last value read keeps working for up to a day after it was read, unless the service had refused it. After that, cards that need it wait, and say why, until 1Password answers again. When Legato starts with no way to reach 1Password, those cards wait from the start.

Service accounts have hourly and daily request limits that depend on your 1Password plan (on Individual and Families plans, 1,000 requests a day across the account). One request reads every secret in it, from any number of items, and signing in costs none. Because Legato reads your secrets together about once an hour, that's roughly 24 requests a day however many 1Password secrets your pages use, plus a read after each refusal and the retries above. (op, where Legato falls back to it, makes a request for each secret.)

What a page can and can't do

A page names a secret and nothing else. Which 1Password item it is, and which host it's sent to, are set in Settings, or from the command line with the same service account token saved in Legato. A page can't name a 1Password item, so a page an agent wrote can't ask for another item in your vault or send one somewhere else.

Like every secret, a 1Password secret is tied to one host, and Legato sends it only there. The legato tools and MCP server never read or return secret values, so an agent working through them doesn't see them.

This protects you from pages and from agents using Legato's tools. It isn't a sandbox against a program running as you: anything that runs as your user can read what your user can, including other processes' environments, as 1Password notes.

In Settings → Secrets

A 1Password secret shows 1Password where its value comes from, and its status:

StatusMeans
ReadyRead with the service account when a source needs it.
Needs attentionNo service account is saved (choose Set Up 1Password…), or this copy of Legato has neither its helper nor op (reinstall Legato).

Replace… on a 1Password secret opens it with its reference filled in, so you can change it. A reference isn't secret; a Keychain value is never shown. Remove… removes the secret from Legato, not the item from 1Password.

Remove… in the 1Password sheet (choose Configure… beside 1Password) deletes the service account token from the Keychain, forgets every value read with it and stops any read under way. Cards that use 1Password secrets then stop until a token is saved again. Saving a different token also forgets those values; the saved references are then read with the new token.

Troubleshooting

When a read fails, the card says why. The common messages are below; anything else 1Password reports appears after "1Password:".

The card saysTry
Add a 1Password service account in Settings → SecretsIn Settings → Secrets, choose Set Up… beside 1Password and save a token.
1Password has no vault by that name that the service account can readThe vault name is wrong, or the service account can't read that vault. A service account's vaults can't be changed after it's created, so fix the reference, or create a new service account that can read that vault and save its token.
1Password has no item at that reference, or the service account can't see itCheck the item's name in the reference against Copy Secret Reference.
That 1Password item has no field by that nameThe field name is wrong; copy the reference from the field itself.
1Password refused the service account tokenThe token isn't valid any more. Create a new one for the service account and save it again.
1Password's request limit for this service account was reachedYour plan's hourly limit for this token, or the daily limit every service account on your 1Password account shares. Legato tries again later. Legato reads each secret about once an hour, so reaching it usually means something else on the account is busy; a plan with higher limits also helps.
1Password couldn't be reached, or 1Password didn't answer within 30 secondsCheck the Mac's connection. Legato tries again after a minute, then less and less often, and keeps using the last value it read for up to a day.

To check a reference outside Legato, run op read with the same token, if you have op:

bash
OP_SERVICE_ACCOUNT_TOKEN='ops_…' op read 'op://Legato/Pi-hole/password' > /dev/null && echo ok

Security notes

  • The token is kept in your Keychain, under Legato's own name, and handed only to Legato's helper, which is inside the signed app (or to op, when Legato falls back to it).
  • The helper runs 1Password's SDK, whose core runs in a WebAssembly runtime that needs one of the Hardened Runtime's exceptions (allow-unsigned-executable-memory). That exception is the helper's alone; Legato itself takes none of them.
  • When Legato falls back to op, it runs op from where Homebrew or 1Password's installer put it. Anything that can replace that file as your user could see the token, as it could if the token were in a shell profile. Keep the service account to read access on Legato's own vault.
  • To stop Legato reading 1Password at once, choose Remove in Settings → Secrets: it also forgets the values already read. Revoking the token in 1Password stops new reads, but a value Legato already holds can keep working for up to a day after it was read (it can't tell a revoked token from 1Password being unreachable), or until you quit Legato.