-
-
Notifications
You must be signed in to change notification settings - Fork 14.9k
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
nixos/nsd: atomically create state directories with appropriate mode #121427
Conversation
Only |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have merge rights, but I do have a query. I thought about suggesting (umask 377 && ...)
instead of mktemp
/install
, but since you need to set owner and group I like your way better.
install -dm 0700 -o ${username} -g ${username} ${stateDir}/tmp | ||
install -dm 0700 -o ${username} -g ${username} ${stateDir}/var | ||
|
||
chown ${username}:${username} -R "${stateDir}/var" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two lines above, you create ${stateDir}/var
with the right owner and group. Is there a risk that this script is going to run against a state dir that already exists? If so, maybe it's worth adding a comment to explain this chown
?
Also, this chown
is happening before the cat
below. Does that mean ${stateDir}/don't touch anything in here
will have the wrong owner/group?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two lines above, you create ${stateDir}/var with the right owner and group. Is there a risk that this script is going to run against a state dir that already exists? If so, maybe it's worth adding a comment to explain this chown?
This chown here is applied recursively to the files inside $state/var
which might already exist. The install statement serve a different purpose, it's here to create the directory on the first run.
Also, this chown is happening before the cat below. Does that mean ${stateDir}/don't touch anything in here will have the wrong owner/group?
You're right, my bad. In the grand scheme of things, this comment is part of nixpkgs, a public git repo though. I'm not sure we can consider that as a secret.
I'll address your comments when I'll be in front of my desktop. Note: I'm not using NSD anymore, I'm not the maintainer of this module and I don't think there was a vulnerability to start with here. I'm not willing to nitpick this to death. Feel free to push to this branch or create a subsequent PR if you want to clean this service further. I don't think setting the permissions as part of |
ptal Edit: doh, somehow I managed to fail a copy paste >< I'll fix it in 1 sec. |
Related to NixOS#121293 I'm not 100% sure this is an actual vulnerability, the statedir being 700, I'm not really sure we could exploit this to extract secrets. Better be safe than sorry though. Replacing the file creation followed by chmod/chown with atomic install statements.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems fine. I have no power to merge it, though.
Hi, thanks for your changes. They do however not improve much. My feedback:
So I am for using |
@NinjaTrappeur, we can still go forward with this PR, because besides less lines there is one more thing install does. It ensures 0700 on existing I am just strictly against copying them into |
Re-reading this thread, I realize closing the PR without any comments was rude for both you and endgame who take some time to review the PR. It was not my initial intention, all my apologies about this poor communication from my end.
Actually, I was wrong, it is not. At least in gnu coreutils. See https://github.com/coreutils/coreutils/blob/master/src/install.c#L473 and https://github.com/coreutils/coreutils/blob/master/src/install.c#L670 (we're copying the file before changing the ownership attributes). This is a falsehood I've been cargo-culting for a while. Thanks for questioning this and indirectly nerd-sniping me :) As I mentioned earlier, I do not use NSD anymore and I don't see much value in this patch. I'm not really willing to invest more time into this. I'm not deleting this branch on purpose: feel free to take any part of this commit you need if you feel like it. Again, apologies for the poor communication. |
@NinjaTrappeur don’t worry, everything is fine and I am happy for your participation. PRs and Issues exist to discuss exactly this kind of stuff, so thanks for raising concerns. I will be making some changes to NSD soon, so I will likely include a few improvements from this then. Have a nice day. |
Related to #121293
I'm not 100% sure this is an actual vulnerability, the statedir being
700, I'm not really sure how we could exploit this to extract secrets.
Better be safe than sorry though. Replacing the file creation followed
by chmod/chown with atomic install statements.
Things done
sandbox
innix.conf
on non-NixOS linux)nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
./result/bin/
)nix path-info -S
before and after)@GrahamcOfBorg test nsd