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

passwd: Add a way to delete users/groups #1014

Merged
merged 5 commits into from
Aug 6, 2020

Conversation

sohankunkerkar
Copy link
Member

Fixes #738
We need to wait until coreos/ignition-dracut#197 gets merged. Not ready for review yet.

config/v3_2_experimental/schema/ignition.json Show resolved Hide resolved
internal/exec/stages/files/passwd.go Outdated Show resolved Hide resolved
internal/exec/util/passwd.go Show resolved Hide resolved
internal/exec/util/passwd.go Outdated Show resolved Hide resolved
@arithx
Copy link
Contributor

arithx commented Jul 8, 2020

From the CI output it looks like you need to update the translate function (here's an example of what I did in the LUKS stuff: 5e91412#diff-9f93889254bb669415809d4953fd3fbe)

@sohankunkerkar sohankunkerkar force-pushed the delete-user-groups branch 5 times, most recently from 733df71 to c7e716d Compare July 13, 2020 17:21
jlebon added a commit to jlebon/ignition that referenced this pull request Jul 14, 2020
Both `getpwnam_r(3)` and `getgrnam_r(3)` can return `ENOENT` or `ESRCH`
if the record is not found. Handle these.

The manpages also list `EBADF` and `EPERM` (and implies others via
`...`) as other possible codes, which is not great. Digging into this a
bit, I think it may be due to different conventions in different NSS
providers? Let's just handle `ENOENT` and `ESRCH` for now and leave the
less obvious ones until we actually hit something that returns it.

This fixes the error CI is hitting in coreos#1014 where it gets `ESRCH` when
looking up a non-existent group.

Tested-by: Sohan Kunkerkar <sohank2602@gmail.com>
jlebon added a commit to jlebon/ignition that referenced this pull request Jul 14, 2020
Both `getpwnam_r(3)` and `getgrnam_r(3)` can return `ENOENT` or `ESRCH`
if the record is not found. Handle these.

The manpages also list `EBADF` and `EPERM` (and implies others via
`...`) as other possible codes, which is not great. Digging into this a
bit, I think it may be due to different conventions in different NSS
providers? Let's just handle `ENOENT` and `ESRCH` for now and leave the
less obvious ones until we actually hit something that returns it.

This fixes the error CI is hitting in coreos#1014 where it gets `ESRCH` when
looking up a non-existent group.

Tested-by: Sohan Kunkerkar <sohank2602@gmail.com>
@sohankunkerkar sohankunkerkar force-pushed the delete-user-groups branch 2 times, most recently from 7b96d10 to 0178899 Compare July 14, 2020 20:55
@sohankunkerkar sohankunkerkar marked this pull request as ready for review July 15, 2020 02:59
@sohankunkerkar sohankunkerkar changed the title WIP passwd: Add a way to delete users/groups passwd: Add a way to delete users/groups Jul 15, 2020
@sohankunkerkar
Copy link
Member Author

I would like to add a test to verify this change, however, I'm a little skeptical about the testing part because there's no way I can delete the existing users/groups, at least for an FCOS base image (all users listed below are created via Ignition during first boot and not built into the image)

[core@localhost ~]$ cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
core:x:1000:1000:CoreOS Admin:/var/home/core:/bin/bash
fedora-coreos-pinger:x:981:981:Fedora CoreOS telemetry service user:/:/usr/sbin/nologin
zincati:x:980:980:Zincati user for auto-updates:/:/usr/sbin/nologin

internal/exec/stages/files/passwd.go Outdated Show resolved Hide resolved
arithx
arithx previously approved these changes Jul 16, 2020
Copy link
Member

@jlebon jlebon left a comment

Choose a reason for hiding this comment

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

I would like to add a test to verify this change, however, I'm a little skeptical about the testing part.

Hmm, I think we can expand the blackbox tests we have for this? See e.g. tests/positive/passwd/users.go.

internal/exec/util/passwd.go Show resolved Hide resolved
@sohankunkerkar sohankunkerkar force-pushed the delete-user-groups branch 2 times, most recently from bc0e4bc to a5735ab Compare July 20, 2020 14:13
@sohankunkerkar sohankunkerkar force-pushed the delete-user-groups branch 2 times, most recently from ca0cf88 to 873d405 Compare July 20, 2020 16:54
@cgwalters
Copy link
Member

I want to more strongly emphasize my feelings on this: #738 (comment)

I'm not opposed to this code as is, but it seems like it'd be a lot simpler for us to instead skip adding the core user in the first place than to have our default config add the user, then we immediately go and delete it when processing later Ignition.

Wouldn't it work to skip the useradd if shouldExist: false or so?

internal/exec/stages/files/passwd.go Outdated Show resolved Hide resolved
internal/exec/stages/files/passwd.go Outdated Show resolved Hide resolved
internal/exec/stages/files/passwd.go Outdated Show resolved Hide resolved
internal/exec/util/passwd.go Outdated Show resolved Hide resolved
internal/exec/util/passwd.go Outdated Show resolved Hide resolved
internal/exec/util/passwd.go Show resolved Hide resolved
internal/exec/util/passwd.go Outdated Show resolved Hide resolved
internal/exec/util/passwd.go Outdated Show resolved Hide resolved
tests/positive/passwd/users.go Outdated Show resolved Hide resolved
tests/positive/passwd/users.go Show resolved Hide resolved
@sohankunkerkar sohankunkerkar changed the title passwd: Add a way to delete users/groups WIP passwd: Add a way to delete users/groups Jul 22, 2020
@sohankunkerkar sohankunkerkar force-pushed the delete-user-groups branch 2 times, most recently from 67bb289 to a2f9661 Compare July 22, 2020 19:30
@sohankunkerkar sohankunkerkar changed the title WIP passwd: Add a way to delete users/groups passwd: Add a way to delete users/groups Jul 22, 2020
Copy link
Contributor

@arithx arithx left a comment

Choose a reason for hiding this comment

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

Is the current code working in FCOS to be able to not create the core user?

internal/exec/stages/files/passwd.go Outdated Show resolved Hide resolved
internal/exec/stages/files/passwd.go Outdated Show resolved Hide resolved
internal/exec/util/passwd.go Show resolved Hide resolved
tests/positive/passwd/users.go Show resolved Hide resolved
@sohankunkerkar
Copy link
Member Author

Is the current code working in FCOS to be able to not create the core user?

Yeah, it is.
I think #1014 (comment) suggestion helped to resolve the above issue.

@sohankunkerkar sohankunkerkar force-pushed the delete-user-groups branch 2 times, most recently from 8568a0e to 74cd722 Compare July 24, 2020 22:27
Copy link
Contributor

@arithx arithx left a comment

Choose a reason for hiding this comment

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

Changes LGTM; CI looks like it needs a retrigger and will let someone else take another glance at it.

Copy link
Member

@jlebon jlebon left a comment

Choose a reason for hiding this comment

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

Just some nits, LGTM as is!

internal/exec/stages/files/passwd.go Outdated Show resolved Hide resolved
internal/exec/util/passwd.go Outdated Show resolved Hide resolved
Fixes coreos#738
Some users may want to add a custom user, and remove
the `core` user injected via the default configuration.
This PR will enable users to delete the existing
users/groups in a given distro.
This variable is added to indicate if we want to delete the existing
users/groups
@miabbott
Copy link
Member

miabbott commented Aug 6, 2020

We've got 3 approvals and green CI...can we merge this?

@sohankunkerkar sohankunkerkar merged commit 2433c55 into coreos:master Aug 6, 2020
@sohankunkerkar
Copy link
Member Author

For tracking purpose: coreos/fedora-coreos-tracker#155

cgwalters added a commit to cgwalters/ignition that referenced this pull request Aug 29, 2020
This addition to the docs was missed in the original PR
coreos#1014
cgwalters added a commit to cgwalters/ignition that referenced this pull request Aug 30, 2020
This addition to the docs was missed in the original PR
coreos#1014
cgwalters added a commit to cgwalters/ignition that referenced this pull request Aug 31, 2020
This addition to the docs was missed in the original PR
coreos#1014
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.

Add a way to delete users/groups
7 participants