Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hardening DAC #171

Merged
merged 13 commits into from
May 19, 2020
Merged

Hardening DAC #171

merged 13 commits into from
May 19, 2020

Conversation

nixbitcoin
Copy link
Member

This PR all-around hardens our existing discretionary access control.

All lightning modules (spark-wallet, recurring-donations, lightning-charge) now run under their own user with clightning group membership. They can interact with c-lightning via group-readable/writable socket. I didn't remove the lightning-cli option because I think it's a good idea to always run it under the clightning user (otherwise it's executed with root permissions in nodeinfo), please take a look at this.

bitcoinrpc group is removed and bitcoin group membership is reduced to a minimum. Secrets are gotten via preStart with PermissionsStartOnly.

electrs also has an improved and truly optional TLSProxy.

I wasn't able to reduce the permissions of nodeinfo, onion-chef and create-webindex from root. I couldn't find an elegant way to fulfill their functions as a less-privileged user without introducing excessive complexity.

LND was out-of-scope for this PR, because I don't run it and have no experience with it.

Closes #145
Closes #170

Copy link
Member

@jonasnick jonasnick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice cleanup 👍

@@ -111,6 +110,10 @@ in {
while [[ ! -e ${cfg.dataDir}/bitcoin/lightning-rpc ]]; do
sleep 0.1
done
# give group "search" access to allow clightning group processes to find lightning-rpc
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know who needs that? lightning-rpc is always lightning-rpc - not sure why anyone would need search permissions

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spark-wallet and lightning-charge need to be able to "look" into the directory to find lightning-rpc. Otherwise you get

Lightning client connection error { Error: connect EACCES /var/lib/clightning/bitcoin

in spark-wallet for example.

@@ -132,8 +132,6 @@ in {
services.onion-chef.enable = true;
services.onion-chef.access.operator = [ "bitcoind" "clightning" "nginx" "liquidd" "spark-wallet" "electrs" "sshd" ];

# Unfortunately c-lightning doesn't allow setting the permissions of the rpc socket
# https://github.com/ElementsProject/lightning/issues/1366
security.sudo.configFile =
(optionalString cfg.clightning.enable ''
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I'm fine with keeping the lightning-cli option with sudo. It's simpler than having to deal groups.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@erikarvstedt Re: 0e66ec47489732002ba9ab96dafd3ddd401a5ae8 I thought it would be good to keep, so lightning-cli would never be executed as root by accident. But I guess the simplicity win outweighs that. So ACK.

@jonasnick
Copy link
Member

ACK want to squash?

@nixbitcoin
Copy link
Member Author

Should I squash all into one or just the jonasnick fixups?

@jonasnick
Copy link
Member

just fixups

@nixbitcoin
Copy link
Member Author

squashed

@jonasnick
Copy link
Member

Oh I meant squashing the fixups into the corresponding original commits.

@nixbitcoin
Copy link
Member Author

Done. Didn't squash clightning module: remove config group read access because it is a separate hardening, but I moved it to a more appropriate place.

nixbitcoin added a commit to nixbitcoin/nix-bitcoin that referenced this pull request May 18, 2020
@erikarvstedt
Copy link
Collaborator

I'll review this later today, please wait before merging.

@erikarvstedt
Copy link
Collaborator

Thanks, @nixbitcoin, for these very sensible changes.

Could you, in the future, add a fixup! prefix to titles of commits that are meant to be squashed?

Also, please use separate commits for larger, orthogonal changes.
For example lightning-charge: Update pkg and run under lightning-charge user consists of these single-topic commits:

  • lightning-charge: 0.4.14 -> 0.4.19
  • lightning-charge: add dedicated user
  • clightning: allow group access to RPC socket

Here are my fixups.

@nixbitcoin
Copy link
Member Author

nixbitcoin commented May 18, 2020

Thank you for the great fixup !'s 😄 I squashed them (except 679b95f2c2abe6560c2c7d4cf9688244e499cf2a) into the appropriate commits.

This was my first try at structuring commits properly. My next PR will be more diligent in separating into single-topic commits and obeying the nix naming conventions.

I separated said commit. I didn't separate 95afba4 because the changes aren't that orthogonal and splitting wasn't that easy.

@erikarvstedt
Copy link
Collaborator

Thanks! 😺
These fixups remain.

Could you please remove the ephemeral fixup messages from the squashed messages?
The squashed messages should only contain information relevant to the committed content. Historical discussion about ultimately rejected and uncommited changes should not be part of the commit message, unless it provides an insightful rationale for the actual changes.

Example

Problematic message:

nodeinfo: Convert to module and allow alternative operator username

operatorname: make into option in secure-node.nix

@jonasnick fixup

nodeinfo module: fix whitespace & remove unused

@jonasnick fixup

fixup! rename services.operatorname -> nix-bitcoin.operatorName

operatorName is not a service

fixup! improve nodeinfo

rename services.nodeinfo -> program.nodeinfo, following NixOS naming
conventions. (nodeinfo is not a service.)

currently, nodeinfo has presets/secure-node.nix as a strict
dependency as it requires onion-chef and the 'operatorName' option.
and nix-bitcoin-webindex.nix has nodeinfo as a dependecy.

so don't add nodeinfo and webindex to modules.nix because they will fail on standalone use.

Fixed message:

nodeinfo: Convert to module and allow custom operator username

Currently, nodeinfo has presets/secure-node.nix as a strict
dependency as it requires onion-chef and the 'operatorName' option.
Also, nix-bitcoin-webindex.nix has nodeinfo as a dependecy.

So don't add nodeinfo to modules.nix (and remove webindex)
because they both fail on standalone use.

@erikarvstedt
Copy link
Collaborator

erikarvstedt commented May 18, 2020

Please rename commit clightning module: remove ... -> clightning: remove ...

If TLSProxy is disabled, bypass nginx by forwarding Tor HS traffic
directly to electrs.
nixbitcoin added 11 commits May 19, 2020 11:08
Electrs does not need to be a part of "bitcoinrpc" group because preStart
electrs.toml creation is handled by PermissionsStartOnly. "bitcoin"
group membership is only necessary when cfg.high-memory is enabled and
electrs reads blocks directly from the blocks directory.
Secrets are written to clightning config file during preStart with root
permissions because of PermissionsStartOnly.
currently, nodeinfo has presets/secure-node.nix as a strict
dependency as it requires onion-chef and the 'operatorName' option.
and nix-bitcoin-webindex.nix has nodeinfo as a dependecy.

so don't add nodeinfo and webindex to modules.nix because they will fail on standalone use.
Copy link
Member

@jonasnick jonasnick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK b8e10af

@nixbitcoin
Copy link
Member Author

nixbitcoin commented May 19, 2020

@erikarvstedt

Could you format your approvals in the future like so: ACK <top commit hash>? That way it shows up in @jonasnick's merge commits.

@jonasnick jonasnick merged commit 0ac1e49 into fort-nix:master May 19, 2020
@erikarvstedt
Copy link
Collaborator

@nixbitcoin ACK 😃

nixbitcoin added a commit to nixbitcoin/nix-bitcoin that referenced this pull request May 26, 2020
@nixbitcoin nixbitcoin deleted the hardening-DAC branch March 3, 2021 10:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Run services using clightning under different users Support having another username for "operator"
3 participants