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

nixos/users-groups: createHome: Ensure HOME permissions, fix description #106995

Conversation

andir
Copy link
Member

@andir andir commented Dec 16, 2020

I'm forwarding this patch that I received via email:

commit 8833983f261c6afa0361465f31c4dbc39c45b386
Author: Klemens Nanni <klemens@posteo.de>
Date:   Sun Nov 22 23:42:02 2020 +0100

    nixos/users-groups: createHome: Ensure HOME permissions, fix description

    configuration.nix(1) states

        users.extraUsers.<name>.createHome
            [...] If [...] the home directory already exists but is not
            owned by the user, directory owner and group will be changed to
            match the user.

    i.e. ownership would change only if the user mismatched;  the code
    however ignores the owner, it is sufficient to enable `createHome`:

        if ($u->{createHome}) {
            make_path($u->{home}, { mode => 0700 }) if ! -e $u->{home};
            chown $u->{uid}, $u->{gid}, $u->{home};
        }

    Furthermore, permissions are ignored on already existing directories and
    therefore may allow others to read private data eventually.

    Given that createHome already acts as switch to not only create but
    effectively own the home directory, manage permissions in the same
    manner to ensure the intended default and cover all primary attributes.

    Avoid yet another configuration option to have administrators make a
    clear and simple choice between securely managing home directories
    and optionally defering management to own code (taking care of custom
    location, ownership, mode, extended attributes, etc.).

    While here, simplify and thereby fix misleading documentation.

configuration.nix(1) states

    users.extraUsers.<name>.createHome
        [...] If [...] the home directory already exists but is not
        owned by the user, directory owner and group will be changed to
        match the user.

i.e. ownership would change only if the user mismatched;  the code
however ignores the owner, it is sufficient to enable `createHome`:

    if ($u->{createHome}) {
        make_path($u->{home}, { mode => 0700 }) if ! -e $u->{home};
        chown $u->{uid}, $u->{gid}, $u->{home};
    }

Furthermore, permissions are ignored on already existing directories and
therefore may allow others to read private data eventually.

Given that createHome already acts as switch to not only create but
effectively own the home directory, manage permissions in the same
manner to ensure the intended default and cover all primary attributes.

Avoid yet another configuration option to have administrators make a
clear and simple choice between securely managing home directories
and optionally defering management to own code (taking care of custom
location, ownership, mode, extended attributes, etc.).

While here, simplify and thereby fix misleading documentation.
@andir andir changed the title [PATCH] nixos/users-groups: createHome: Ensure HOME permissions, fix description nixos/users-groups: createHome: Ensure HOME permissions, fix description Dec 16, 2020
Copy link
Member

@aanderse aanderse left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution klemens. How do you intend that I have users directories remain 0750 after this is merged? It is important that I retain the ability to effectively set the mode of home directories.

@andir
Copy link
Member Author

andir commented Dec 16, 2020 via email

@aanderse
Copy link
Member

I understand that I could manually create accounts, but I'm not interested in that. I'm interested in running NixOS with users.mutableUsers = false; and choosing what permissions I want on my home directories.

To clarify - I like 0700 as a default, but I would like the option to choose (and in some cases I need the option to choose).

@andir
Copy link
Member Author

andir commented Dec 16, 2020 via email

Copy link
Member

@aanderse aanderse left a comment

Choose a reason for hiding this comment

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

After reviewing and considering this PR a bit more I have decided I'm incorrect and this change is good in my opinion 👍 This change does allow declarative, flexible, user creation when combined with tmpfiles:

users.users.foo = {
  isNormalUser = false;
  createHome = false;
};

systemd.tmpfiles.rules = [
  "d ${config.users.users.foo} 0750 foo users"
];

@andir
Copy link
Member Author

andir commented Dec 16, 2020 via email

@aanderse
Copy link
Member

Yeah, sure, tmpfiles isn't a great solution... but it is declarative, can be made relatively reproducible (under certain circumstances), and will get the job done in my scenario where I need it to.

As far as racing goes - this is not a race, there is a strict ordering here I believe: user creation, followed by tmpfiles creation.

@andir andir merged commit fa0d499 into NixOS:master Dec 17, 2020
@andir andir deleted the ml2pr/PATCH-nixos-users-groups-createHome-Ensure-HOME-permissions-fix-description branch December 17, 2020 16:23
@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/apache-2-4-47-permission-denied-access-to-denied-file-system-path-home-bavramor-data/13622/3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants