Skip to content

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

Merged
sohankunkerkar merged 5 commits into
coreos:masterfrom
sohankunkerkar:delete-user-groups
Aug 6, 2020
Merged

sohankunkerkar merged 5 commits into
coreos:masterfrom
sohankunkerkar:delete-user-groups

Conversation

@sohankunkerkar

Copy link
Copy Markdown
Contributor

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

Comment thread internal/exec/stages/files/passwd.go Resolved
Comment thread internal/exec/stages/files/passwd.go Resolved
Comment thread internal/exec/util/passwd.go Resolved
Comment thread internal/exec/util/passwd.go Resolved
@arithx

arithx commented Jul 8, 2020

Copy link
Copy Markdown
Contributor

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 <[email protected]>
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 <[email protected]>
@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
Copy Markdown
Contributor 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

@sohankunkerkar
sohankunkerkar requested review from arithx and jlebon July 15, 2020 14:49
Comment thread internal/exec/stages/files/passwd.go Resolved
arithx
arithx previously approved these changes Jul 16, 2020

@jlebon jlebon left a comment

Copy link
Copy Markdown
Member

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.

Comment thread internal/exec/util/passwd.go Resolved
@sohankunkerkar
sohankunkerkar force-pushed the delete-user-groups branch 2 times, most recently from bc0e4bc to a5735ab Compare July 20, 2020 14:13
Comment thread tests/stubs/userdel-stub/main.go Resolved
@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
Copy Markdown
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?

Comment thread internal/exec/stages/files/passwd.go Resolved
Comment thread internal/exec/stages/files/passwd.go Resolved
Comment thread internal/exec/stages/files/passwd.go Resolved
Comment thread internal/exec/util/passwd.go Resolved
Comment thread internal/exec/util/passwd.go Resolved
Comment thread internal/exec/util/passwd.go Resolved
Comment thread internal/exec/util/passwd.go Resolved
Comment thread internal/exec/util/passwd.go Resolved
Comment thread tests/positive/passwd/users.go Resolved
Comment thread tests/positive/passwd/users.go 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
@sohankunkerkar
sohankunkerkar requested a review from bgilbert July 23, 2020 12:41

@arithx arithx left a comment

Copy link
Copy Markdown
Contributor

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?

Comment thread internal/exec/stages/files/passwd.go Resolved
Comment thread internal/exec/stages/files/passwd.go Resolved
Comment thread internal/exec/util/passwd.go Resolved
Comment thread tests/positive/passwd/users.go Resolved
@sohankunkerkar

Copy link
Copy Markdown
Contributor 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 requested a review from arithx July 24, 2020 16:10
@sohankunkerkar
sohankunkerkar force-pushed the delete-user-groups branch 2 times, most recently from 8568a0e to 74cd722 Compare July 24, 2020 22:27

@arithx arithx left a comment

Copy link
Copy Markdown
Contributor

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.

@jlebon jlebon left a comment

Copy link
Copy Markdown
Member

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!

Comment thread internal/exec/stages/files/passwd.go Resolved
Comment thread internal/exec/util/passwd.go 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

miabbott commented Aug 6, 2020

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor 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