Skip to content

firstboot: Add --root-shell option and tighten up passwd/shadow handling - #16496

Merged
poettering merged 2 commits into
systemd:masterfrom
daandemeyer:firstboot-shell
Jul 23, 2020
Merged

poettering merged 2 commits into
systemd:masterfrom
daandemeyer:firstboot-shell

Conversation

@daandemeyer

Copy link
Copy Markdown
Collaborator

The first commit adds --root-shell and related options to configure the shell for the root user.

Second commit tries to tighten up the whole passwd/shadow story a bit more. There are a lot of edge cases when we're modifying both files since they generally should be modified in lockstep so I tried to reduce the number of possibles scenarios a bit by either modifying neither or modifying both but nothing inbetween that.

I also added some logic so that if we have to add the root entries to passwd and shadow ourselves and no root password is provided by the user, we lock the root account so as to not cause security issues by accident.

Tested manually and via my modified mkosi that uses systemd-firstboot. Maybe we should eventually add a firstboot test to make it a bit harder to accidentally break stuff.

Ideally this could still go in for v246 since it makes stuff a bit more strict than before (if we want this in the first place of course).

@keszybz keszybz 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.

Looks reasonable...

Comment thread src/firstboot/firstboot.c Outdated
Comment thread src/firstboot/firstboot.c Outdated
Comment thread src/firstboot/firstboot.c Outdated
Comment thread src/firstboot/firstboot.c Outdated
@keszybz keszybz added this to the v246 milestone Jul 20, 2020

@poettering poettering 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.

man page update missing

i wonder if we should make a stricter check: i.e. validate that the selected shell is actually available in the image. Or maybe it shouldn#t be a hard check, but a warning only. i.e. a chase_symlinks() check placed at an appropriate place

Comment thread src/firstboot/firstboot.c Outdated
Comment thread src/firstboot/firstboot.c Outdated
Comment thread src/firstboot/firstboot.c Outdated
Comment thread src/firstboot/firstboot.c Outdated
Comment thread src/firstboot/firstboot.c Outdated
@poettering poettering added the reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks label Jul 21, 2020
@daandemeyer
daandemeyer force-pushed the firstboot-shell branch 3 times, most recently from 8819e07 to b3dcf83 Compare July 21, 2020 21:35
@daandemeyer

Copy link
Copy Markdown
Collaborator Author

Addressed the comments and switched the order of the two commits. First comes the refactoring, then the new feature. Should be a lot more logical to follow.

@poettering

poettering commented Jul 22, 2020 •

Copy link
Copy Markdown
Member

man page update still missing, see earlier review

@poettering

Copy link
Copy Markdown
Member

(looks good codewise otherwise)

There are a lot of edge cases that the current implementation
doesn't handle, especially in cases where one of passwd/shadow
exists and the other doesn't exist. For example, if
--root-password is specified, we will write /etc/shadow but
won't add a root entry to /etc/passwd if there is none.

To fix some of these issues, we constrain systemd-firstboot to
only modify /etc/passwd and /etc/shadow if both do not exist
already (or --force) is specified. On top of that, we calculate
all necessary information for both passwd and shadow upfront so
we can take it all into account when writing the actual files.

If no root password options are given --force is specified or both
files do not exist, we lock the root account for security purposes.
@poettering
poettering merged commit 82ff544 into systemd:master Jul 23, 2020
@poettering

Copy link
Copy Markdown
Member

btw, did you see my earlier comments that we probably should at least warn if the specified shell doesn't exist in the image? i.e. a quick call to chase_symlinks() with the specified shell and an error message if it cannot be found?

@daandemeyer

Copy link
Copy Markdown
Collaborator Author

Yes I did, it was getting late yesterday so I didn't add it yet. Should I modify valid_shell to do the chase_symlinks call or will that break other stuff?

@poettering

Copy link
Copy Markdown
Member

I'd keep it separate. valid_shell should not go to disk I think. it should be a superficial check just checking if the value makes any sense at all without matching it up with reality on some system.

@yuwata yuwata removed the reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks label Jul 29, 2020
@daandemeyer
daandemeyer deleted the firstboot-shell branch August 25, 2020 19:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

4 participants