Skip to content

lnd: a custom macaroon baked for a normal user is readable by everyone in group users #130

Closed

Description

@ostermayer

services.lnd.macaroons.<name>.user bakes a scoped macaroon for another user, and docs/configuration.md points operators at it for any application that needs lnd access ("give it a separate macaroon with the permissions it needs via services.lnd.macaroons"). The lnd-create-macaroons script in modules/lnd.nix writes the file like this:

umask ug=r,o=
...
chown ${cfg.macaroons.${macaroon}.user}: "$tmpMacaroon"
mv -fT "$tmpMacaroon" "$RUNTIME_DIRECTORY/${macaroon}.macaroon"

So the macaroon is 0440, owned by the user and by the user's primary group, in /run/lnd, which has mode 711 (RuntimeDirectoryMode) and is traversable by everyone. Who's in that primary group decides who can read the macaroon:

  • For a system user with its own group, as charge-lnd has, only that user, which is fine.
  • For the operator, or any isNormalUser account, the primary group is users, which every normal user on the host shares. A macaroon baked for the operator is therefore readable by every login account, and the operator is exactly the user most people would name here, since the operator is the one who runs lncli and local tools. With {"entity":"offchain","action":"write"} in the permissions, that's payment authority for everyone with a shell.

Nothing needs group read on these files, because the consumer runs as the named user.

Fix: umask u=r,go= and chown "${user}:root" (or chown to the user and chmod 400), so the file is 0400 owned by the user with the group left out of it. A test can bake a macaroon for operator in the regtest scenario and assert stat -c '%a %U %G' gives 400 operator root, and that a second normal user can't read it.

I can send that PR if you want it.

Found by DeepSeek V4.1 Flash 1017 at max thinking in the review of #62's tree. GPT-6 Astra, run at xhigh reasoning as the second opinion, confirmed it and rated it medium, and I checked it against master 4452d89.

Activity

  1. added
    area: modules
    type: security
    on Oct 23, 2026
  2. seberm commented on Nov 12, 2026

    @seberm
    Contributor

    @ostermayer Yes, please send the PR. It still applies: #236 moves the script to modules/lnd-macaroons.nix with the same umask ug=r,o=, so base it on #236 or rebase it once #236 is merged.

    Assisted-by: Claude Code (Claude Opus 5.5)

  3. prusnak commented on Nov 13, 2026

    @prusnak
    Contributor

    #236 has been merged

  4. added a commit that references this issue on Nov 14, 2026
    6935b01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: modulestype: security

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions