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

user/group assertion to not exceed the 32/16 character limit #36556

Merged
merged 1 commit into from Mar 30, 2018

Conversation

qknight
Copy link
Member

@qknight qknight commented Mar 8, 2018

Motivation for this change

With the previous implementation one can add a user or group which is created by Nix but then fails to execute programs from systemd.

man useradd says: Usernames may only be up to 32 characters long.

The actual implementation says it is only 31 chars: https://github.com/systemd/systemd/blob/586fb20fd192d9f9cd2a850f50f67ccd797b6931/src/basic/user-util.c#L624

man groupadd says: Groupnames may only be up to 16 characters long.

So this simple apply check makes the user aware of this!

See also: nixcloud/nixcloud-webservices#15

@qknight qknight force-pushed the user_group_length_assertion branch from 2808301 to 03ba77a Compare March 8, 2018 20:58
@qknight qknight changed the title user/group assertion to not exceed the 32 character limit user/group assertion to not exceed the 32/16 character limit Mar 8, 2018
@qknight qknight force-pushed the user_group_length_assertion branch from 03ba77a to 15d1d9d Compare March 8, 2018 23:31
@dtzWill
Copy link
Member

dtzWill commented Mar 11, 2018

👍

@qknight
Copy link
Member Author

qknight commented Mar 12, 2018

Maybe it should be rather a warning then an abort because PPL might already be using it and for some reason it works for them.

@fpletz fpletz added this to the 18.03 milestone Mar 12, 2018
Copy link
Member

@fpletz fpletz left a comment

Choose a reason for hiding this comment

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

abort seems reasonable in this case.

cc @vcunat

Copy link
Member

@infinisil infinisil left a comment

Choose a reason for hiding this comment

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

+1 to this, but builtins. is unnecessary, the stringLength function from builtins gets reexported with lib, so it's in scope already.

@globin globin merged commit 1b0cb04 into NixOS:master Mar 30, 2018
vcunat pushed a commit that referenced this pull request Mar 31, 2018
@vcunat
Copy link
Member

vcunat commented Mar 31, 2018

Picked to 18.03, too.

@aszlig
Copy link
Member

aszlig commented Apr 5, 2018

@vcunat, @fpletz, @qknight: IMHO there is no reason to go below the systemd limit for group names, as the maximum group length is a configure option and available since 2009.

Besides, I checked the limit on other distros and they all use a limit of either 31 or 32 characters:

So I think we should change this to 31 or even 32 characters to be in par with the maximum user name length.

@qknight
Copy link
Member Author

qknight commented Apr 6, 2018

@aszlig sounds great, do you want to implement that change?

@Ralith
Copy link
Contributor

Ralith commented Apr 7, 2018

This broke a module I maintain that uses a 21-character group name, which worked fine previously.

aszlig added a commit that referenced this pull request Apr 8, 2018
With #36556, a check was introduced to make sure the user and group
names do not exceed their respective maximum length. This is in part
because systemd also enforces that length, but only at runtime.

So in general it's a good idea to catch as much as we can during
evaluation time, however the maximum length of the group name was set to
16 characters according groupadd(8).

The maximum length of the group names however is a compile-time option
and even systemd allows more than 16 characters. In the mentioned pull
request (#36556) there was already a report that this has broken
evaluation for people out there.

I have also checked what other distributions are doing and they set the
length to either 31 characters or 32 characters, the latter being more
common.

Unfortunately there is a difference between the maximum length enforced
by the shadow package and systemd, both for user name lengths and group
name lengths. However, systemd enforces both length to have a maximum of
31 characters and I'm not sure if this is intended or just a off-by-one
error in systemd.

Nevertheless, I choose 32 characters simply to bring it in par with the
maximum user name length.

For the NixOS assertion however, I use a maximum length of 31 to make
sure that nobody accidentally creates services that contain group names
that systemd considers invalid because of a length of 32 characters.

Signed-off-by: aszlig <aszlig@nix.build>
Closes: #38548
Cc: @vcunat, @fpletz, @qknight
aszlig added a commit that referenced this pull request Apr 8, 2018
With #36556, a check was introduced to make sure the user and group
names do not exceed their respective maximum length. This is in part
because systemd also enforces that length, but only at runtime.

So in general it's a good idea to catch as much as we can during
evaluation time, however the maximum length of the group name was set to
16 characters according groupadd(8).

The maximum length of the group names however is a compile-time option
and even systemd allows more than 16 characters. In the mentioned pull
request (#36556) there was already a report that this has broken
evaluation for people out there.

I have also checked what other distributions are doing and they set the
length to either 31 characters or 32 characters, the latter being more
common.

Unfortunately there is a difference between the maximum length enforced
by the shadow package and systemd, both for user name lengths and group
name lengths. However, systemd enforces both length to have a maximum of
31 characters and I'm not sure if this is intended or just a off-by-one
error in systemd.

Nevertheless, I choose 32 characters simply to bring it in par with the
maximum user name length.

For the NixOS assertion however, I use a maximum length of 31 to make
sure that nobody accidentally creates services that contain group names
that systemd considers invalid because of a length of 32 characters.

Signed-off-by: aszlig <aszlig@nix.build>
Closes: #38548
Cc: @vcunat, @fpletz, @qknight
(cherry picked from commit 99ba1cb)
globin pushed a commit to mayflower/nixpkgs that referenced this pull request May 1, 2018
With NixOS#36556, a check was introduced to make sure the user and group
names do not exceed their respective maximum length. This is in part
because systemd also enforces that length, but only at runtime.

So in general it's a good idea to catch as much as we can during
evaluation time, however the maximum length of the group name was set to
16 characters according groupadd(8).

The maximum length of the group names however is a compile-time option
and even systemd allows more than 16 characters. In the mentioned pull
request (NixOS#36556) there was already a report that this has broken
evaluation for people out there.

I have also checked what other distributions are doing and they set the
length to either 31 characters or 32 characters, the latter being more
common.

Unfortunately there is a difference between the maximum length enforced
by the shadow package and systemd, both for user name lengths and group
name lengths. However, systemd enforces both length to have a maximum of
31 characters and I'm not sure if this is intended or just a off-by-one
error in systemd.

Nevertheless, I choose 32 characters simply to bring it in par with the
maximum user name length.

For the NixOS assertion however, I use a maximum length of 31 to make
sure that nobody accidentally creates services that contain group names
that systemd considers invalid because of a length of 32 characters.

Signed-off-by: aszlig <aszlig@nix.build>
Closes: NixOS#38548
Cc: @vcunat, @fpletz, @qknight
(cherry picked from commit 99ba1cb)
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

9 participants