-
Notifications
You must be signed in to change notification settings - Fork 94
Catch invalid root user kickstart options early [HMS-9378] #1879
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
Merged
supakeen
merged 6 commits into
osbuild:main
from
achilleas-k:fix/catch-invalid-root-user-kickstart-early
Oct 9, 2025
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
37343ed
osbuild: add tests for the various kickstart constructors
achilleas-k f3482f3
osbuild: validate kickstart path option
achilleas-k 3e7e28c
manifest: test AnacondaISOTree variants with kickstart users
achilleas-k adb7ff2
manifest: fix error message for tar payload stage creation failure
achilleas-k eede93b
customizations/kickstart: test the kickstart options constructor
achilleas-k 4f76acf
customizations/kickstart: validate root user options
achilleas-k File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,159 @@ | ||
| package kickstart_test | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/osbuild/blueprint/pkg/blueprint" | ||
| "github.com/osbuild/images/internal/common" | ||
| "github.com/osbuild/images/pkg/customizations/kickstart" | ||
| "github.com/osbuild/images/pkg/customizations/users" | ||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| func TestNewKickstart(t *testing.T) { | ||
| type testCase struct { | ||
| customizations *blueprint.Customizations | ||
|
|
||
| expOptions *kickstart.Options | ||
| expErr string | ||
| } | ||
|
|
||
| testCases := map[string]testCase{ | ||
| "empty": { | ||
| expOptions: &kickstart.Options{ | ||
| Users: []users.User{}, | ||
| Groups: []users.Group{}, | ||
| }, | ||
| }, | ||
|
|
||
| "users+groups": { | ||
| // we don't need to extensively test the whole blueprint.User -> | ||
| // users.User and blueprint.Group -> users.Group conversion here, | ||
| // so just one test case is enough | ||
| customizations: &blueprint.Customizations{ | ||
| User: []blueprint.UserCustomization{ | ||
| { | ||
| Name: "alice", | ||
| Key: common.ToPtr("ssh-ed25519 iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii"), | ||
| Home: common.ToPtr("/var/home/alice"), | ||
| }, | ||
| { | ||
| Name: "bob", | ||
| Key: common.ToPtr("ssh-ed25519 eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"), | ||
| Home: common.ToPtr("/var/home/bob"), | ||
| }, | ||
| }, | ||
| Group: []blueprint.GroupCustomization{ | ||
| { | ||
| Name: "data", | ||
| GID: common.ToPtr(2010), | ||
| }, | ||
| { | ||
| Name: "datarw", | ||
| GID: common.ToPtr(2020), | ||
| }, | ||
| }, | ||
| }, | ||
|
|
||
| expOptions: &kickstart.Options{ | ||
| Users: []users.User{ | ||
| { | ||
| Name: "alice", | ||
| Key: common.ToPtr("ssh-ed25519 iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii"), | ||
| Home: common.ToPtr("/var/home/alice"), | ||
| }, | ||
| { | ||
| Name: "bob", | ||
| Key: common.ToPtr("ssh-ed25519 eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"), | ||
| Home: common.ToPtr("/var/home/bob"), | ||
| }, | ||
| }, | ||
| Groups: []users.Group{ | ||
| { | ||
| Name: "data", | ||
| GID: common.ToPtr(2010), | ||
| }, | ||
| { | ||
| Name: "datarw", | ||
| GID: common.ToPtr(2020), | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
|
|
||
| "installer-customizations-kickstart-contents": { | ||
| customizations: &blueprint.Customizations{ | ||
| Installer: &blueprint.InstallerCustomization{ | ||
| Kickstart: &blueprint.Kickstart{ | ||
| Contents: "echo 'Hello!!'", | ||
| }, | ||
| }, | ||
| }, | ||
|
|
||
| expOptions: &kickstart.Options{ | ||
| Users: []users.User{}, | ||
| Groups: []users.Group{}, | ||
| UserFile: &kickstart.File{ | ||
| Contents: "echo 'Hello!!'", | ||
| }, | ||
| }, | ||
| }, | ||
|
|
||
| "installer-customizations-unattended": { | ||
| customizations: &blueprint.Customizations{ | ||
| Installer: &blueprint.InstallerCustomization{ | ||
| Unattended: true, | ||
| }, | ||
| }, | ||
|
|
||
| expOptions: &kickstart.Options{ | ||
| Users: []users.User{}, | ||
| Groups: []users.Group{}, | ||
| Unattended: true, | ||
| }, | ||
| }, | ||
|
|
||
| "error/installer-customizations-kickstart+unattended": { | ||
| customizations: &blueprint.Customizations{ | ||
| Installer: &blueprint.InstallerCustomization{ | ||
| Kickstart: &blueprint.Kickstart{ | ||
| Contents: "echo 'Hello!!'", | ||
| }, | ||
| Unattended: true, | ||
| }, | ||
| }, | ||
|
|
||
| expErr: "installer.unattended is not supported when adding custom kickstart contents", | ||
| }, | ||
|
|
||
| "error/unsupported-root-options": { | ||
| customizations: &blueprint.Customizations{ | ||
| User: []blueprint.UserCustomization{ | ||
| { | ||
| Name: "root", | ||
| Home: common.ToPtr("/megaroot"), | ||
| Shell: common.ToPtr("/bin/zsh"), | ||
| Groups: []string{"cups"}, | ||
| }, | ||
| }, | ||
| }, | ||
|
|
||
| expErr: "unsupported kickstart options for user \"root\": groups, home, shell", | ||
| }, | ||
| } | ||
|
|
||
| for name, tc := range testCases { | ||
| t.Run(name, func(t *testing.T) { | ||
| assert := assert.New(t) | ||
|
|
||
| options, err := kickstart.New(tc.customizations) | ||
| if tc.expErr != "" { | ||
| assert.EqualError(err, tc.expErr) | ||
| return | ||
| } | ||
|
|
||
| assert.NoError(err) | ||
| assert.Equal(tc.expOptions, options) | ||
| }) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quick drive-by: can move the checks into a shared helper somehow maybe? It worries me that we have two places now that (almost) do the same thing, it will most likely cause drift if/when we add more checks to one place.
Or we could look at the root of the problem and make serialize() return an error (probably a much bigger PR though)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I mentioned as much in the PR description, but I couldn't think of an obvious way to do it nicely since they're different types.
Yes, we should get on this.