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

install-multi-user: chown bootstrap store contents #7442

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

winterqt
Copy link
Member

Before this change, the bootstrap store contents would be owned by the user who ran the script.

This is not ideal, and leads to confusing issues like zsh's compaudit being fired.

@winterqt winterqt requested review from abathur and removed request for edolstra and thufschmitt December 11, 2022 17:21
@winterqt
Copy link
Member Author

winterqt commented Dec 11, 2022

Oh, so that... removes code owner review requests when that usually isn't possible... 🙃

@abathur
Copy link
Member

abathur commented Dec 11, 2022

I don't feel like I have a handle on the high-level correctness of the change, but we can start by setting up testing as a backstop.

If you follow the steps in https://nixos.org/manual/nix/stable/contributing/hacking.html#installer-tests it'll enable the installer test job in your fork's GA workflow.

It's not a full test suite, but it at least confirms that the happy-path isn't broken. It'll also be possible to use the x86_64-darwin installer it generates outside of the workflow to confirm.

@winterqt
Copy link
Member Author

I manually tested the change before I submitted this PR, and it worked as expected.

I'll setup the tests in a few hours, though, and we can go from there.

@winterqt
Copy link
Member Author

It'll also be possible to use the x86_64-darwin installer it generates outside of the workflow to confirm.

This isn't a Darwin specific issue, I was also able to reproduce this on Linux.

@abathur
Copy link
Member

abathur commented Dec 11, 2022

Sorry--jumping to conclusions since most of my installer work is for macOS fixes. It'll generate an x86_64-linux installer as well.

@winterqt
Copy link
Member Author

Yup, was just making sure you were aware that this affects both Darwin and Linux.

I've tested that this works on aarch64-darwin (thanks to Virtualization.framework), and I'll generate an installer for aarch64-linux and test there. (Maybe we can even add this as a case for installer_test, that is, making sure the store permissions are setup correctly?)

(Side note, but we should probably enable aarch64-linux cross builds for the installer workflow... I'll test + do that in another PR :)

@winterqt
Copy link
Member Author

winterqt commented Dec 12, 2022

@abathur Installer tests succeeded: https://github.com/winterqt/nix/actions/runs/3671329069

scripts/install-multi-user.sh Outdated Show resolved Hide resolved
@@ -810,6 +810,24 @@ install_from_extracted_nix() {
_sudo "to make the new store non-writable at $NIX_ROOT/store" \
chmod -R ugo-w "$NIX_ROOT/store/"

# This is copied from create_directories, see it for why we do all this stuff just to find chown.
Copy link
Member

Choose a reason for hiding this comment

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

Instead of copying, this could be factored out into a function? Or just moved up in the script so it's done only once?

Copy link
Member Author

Choose a reason for hiding this comment

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

See #7442 (comment) for @abathur and I's previous discussion on this.

Before this change, the bootstrap store contents would be owned by the user who ran the script. This leads to inconsistencies in store path permissions, and can cause confusing issues for users (an example being zsh's compaudit being fired when attempting to use the completions from the bootstrap copy of Nix).
EOF
else
_sudo "to change ownership of Nix store files" \
"$get_chr_own" -R "root:$NIX_BUILD_GROUP_NAME" "$NIX_ROOT/store" || true
Copy link
Member Author

Choose a reason for hiding this comment

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

Should this use $NIX_ROOT/store/ like the commands above, does it really make a difference in this case? (I think we e.g. still want /nix/store to be owned by root:nixbld, so I don't think any special casing surrounding trailing versus no trailing slash should matter practically...)

@edolstra
Copy link
Member

edolstra commented Feb 3, 2023

@abathur Do you have any opinion on this?

Maybe instead of doing a chown -R on the store, we can do a chown -R on the unpacked tarball.

@abathur
Copy link
Member

abathur commented Feb 3, 2023

I said I wasn't sure about high-level correctness before, and I guess that's because I'm a little perplexed about why it's only showing up now if this has been happening on normal installs in the wild. It seems like anything running later under the installing user being able to fiddle with the bootstrapped files is probably Bad, so I'd be surprised if it went unnoticed for years and years, which makes me feel like there's an unknown variable somewhere.

I guess an explanation that would make sense is if this shifted as a result of #5150

Idiomatically, this addition mirrors the chmod to disable write permissions above it. If the rsync -> cp change above did cause ownership to shift, I guess the ownership of the unpacked files may not get preserved during the recursive copy anyways?

I can't fiddle around with the commands to test that thesis just now. Maybe this evening.

@abathur
Copy link
Member

abathur commented Feb 3, 2023

Though the ls output in #7603 (comment) does indicate root root for something that's presumably in the bootstrap.

@iFreilicht did you happen to notice the installing user owning any store files while working through #7603?

@abathur
Copy link
Member

abathur commented Feb 6, 2023

Got out a spare laptop to test. I do see this behavior on modern installers. Can verify with something like find /nix -user $USER

The first release with the rsync -> cp change from 5150 was 2.4, and the behavior is present there. I do not see the behavior on 2.3.16.

I think this is because the -p flag to rsync preserves permissions but not ownership, while the -p flag to cp preserves permissions, ownership, and more. Since it looks like the cp command should preserve the ownership, I think @edolstra is right that we should be able to chown the unpacked store before copying it over.

@iFreilicht
Copy link
Contributor

iFreilicht commented Feb 9, 2023

@iFreilicht did you happen to notice the installing user owning any store files while working through #7603?

I did not, but I didn't look particularly closely at that. The issues I fixed were not caused by an ownership issue.

find /nix -user $USER

That would be a great addition to the installer-test to prevent a regression in this matter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: 🏁 Review
Development

Successfully merging this pull request may close these issues.

4 participants