osbuild: use internal users package structs in stages

Don't pass blueprint Users and Groups options all the way down to the
osbuild stage bindings.  Instead, convert them to the internal
users.User and users.Group structs.
Ideally we would do this even higher up in the code path, before
reaching the distro, but this is the first step towards that.
This commit is contained in:
Achilleas Koutsou 2022-09-23 15:08:21 +02:00 committed by Christian Kellner
parent 5bf4b2ab98
commit 14f608de0a
10 changed files with 32 additions and 36 deletions

View file

@ -257,8 +257,8 @@ func iotInstallerImage(workload workload.Workload,
img.Platform = t.platform img.Platform = t.platform
img.ExtraBasePackages = packageSets[installerPkgsKey] img.ExtraBasePackages = packageSets[installerPkgsKey]
img.Users = customizations.GetUsers() img.Users = users.UsersFromBP(customizations.GetUsers())
img.Groups = customizations.GetGroups() img.Groups = users.GroupsFromBP(customizations.GetGroups())
img.ISOLabelTempl = d.isolabelTmpl img.ISOLabelTempl = d.isolabelTmpl
img.Product = d.product img.Product = d.product

View file

@ -8,6 +8,7 @@ import (
"github.com/osbuild/osbuild-composer/internal/distro" "github.com/osbuild/osbuild-composer/internal/distro"
"github.com/osbuild/osbuild-composer/internal/osbuild" "github.com/osbuild/osbuild-composer/internal/osbuild"
"github.com/osbuild/osbuild-composer/internal/rpmmd" "github.com/osbuild/osbuild-composer/internal/rpmmd"
"github.com/osbuild/osbuild-composer/internal/users"
) )
func buildPipeline(repos []rpmmd.RepoConfig, buildPackageSpecs []rpmmd.PackageSpec, runner string) *osbuild.Pipeline { func buildPipeline(repos []rpmmd.RepoConfig, buildPackageSpecs []rpmmd.PackageSpec, runner string) *osbuild.Pipeline {
@ -87,10 +88,10 @@ func osPipeline(t *imageType,
} }
if groups := c.GetGroups(); len(groups) > 0 { if groups := c.GetGroups(); len(groups) > 0 {
p.AddStage(osbuild.NewGroupsStage(osbuild.NewGroupsStageOptions(groups))) p.AddStage(osbuild.NewGroupsStage(osbuild.NewGroupsStageOptions(users.GroupsFromBP(groups))))
} }
if userOptions, err := osbuild.NewUsersStageOptions(c.GetUsers(), false); err != nil { if userOptions, err := osbuild.NewUsersStageOptions(users.UsersFromBP(c.GetUsers()), false); err != nil {
return nil, err return nil, err
} else if userOptions != nil { } else if userOptions != nil {
p.AddStage(osbuild.NewUsersStage(userOptions)) p.AddStage(osbuild.NewUsersStage(userOptions))

View file

@ -216,7 +216,7 @@ func edgeInstallerPipelines(t *imageType, customizations *blueprint.Customizatio
kernelVer := rpmmd.GetVerStrFromPackageSpecListPanic(installerPackages, "kernel") kernelVer := rpmmd.GetVerStrFromPackageSpecListPanic(installerPackages, "kernel")
ostreeRepoPath := "/ostree/repo" ostreeRepoPath := "/ostree/repo"
payloadStages := ostreePayloadStages(options, ostreeRepoPath) payloadStages := ostreePayloadStages(options, ostreeRepoPath)
kickstartOptions, err := osbuild.NewKickstartStageOptions(kspath, "", customizations.GetUsers(), customizations.GetGroups(), makeISORootPath(ostreeRepoPath), options.OSTree.Ref, "rhel") kickstartOptions, err := osbuild.NewKickstartStageOptions(kspath, "", users.UsersFromBP(customizations.GetUsers()), users.GroupsFromBP(customizations.GetGroups()), makeISORootPath(ostreeRepoPath), options.OSTree.Ref, "rhel")
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -255,7 +255,7 @@ func imageInstallerPipelines(t *imageType, customizations *blueprint.Customizati
tarPath := "/liveimg.tar" tarPath := "/liveimg.tar"
tarPayloadStages := []*osbuild.Stage{osbuild.NewTarStage(&osbuild.TarStageOptions{Filename: tarPath}, treePipeline.Name)} tarPayloadStages := []*osbuild.Stage{osbuild.NewTarStage(&osbuild.TarStageOptions{Filename: tarPath}, treePipeline.Name)}
kickstartOptions, err := osbuild.NewKickstartStageOptions(kspath, makeISORootPath(tarPath), customizations.GetUsers(), customizations.GetGroups(), "", "", "rhel") kickstartOptions, err := osbuild.NewKickstartStageOptions(kspath, makeISORootPath(tarPath), users.UsersFromBP(customizations.GetUsers()), users.GroupsFromBP(customizations.GetGroups()), "", "", "rhel")
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -449,17 +449,17 @@ func osPipeline(t *imageType,
// don't put users and groups in the payload of an installer // don't put users and groups in the payload of an installer
// add them via kickstart instead // add them via kickstart instead
if groups := c.GetGroups(); len(groups) > 0 { if groups := c.GetGroups(); len(groups) > 0 {
p.AddStage(osbuild.NewGroupsStage(osbuild.NewGroupsStageOptions(groups))) p.AddStage(osbuild.NewGroupsStage(osbuild.NewGroupsStageOptions(users.GroupsFromBP(groups))))
} }
if userOptions, err := osbuild.NewUsersStageOptions(c.GetUsers(), false); err != nil { if userOptions, err := osbuild.NewUsersStageOptions(users.UsersFromBP(c.GetUsers()), false); err != nil {
return nil, err return nil, err
} else if userOptions != nil { } else if userOptions != nil {
if t.rpmOstree { if t.rpmOstree {
// for ostree, writing the key during user creation is // for ostree, writing the key during user creation is
// redundant and can cause issues so create users without keys // redundant and can cause issues so create users without keys
// and write them on first boot // and write them on first boot
userOptionsSansKeys, err := osbuild.NewUsersStageOptions(c.GetUsers(), true) userOptionsSansKeys, err := osbuild.NewUsersStageOptions(users.UsersFromBP(c.GetUsers()), true)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View file

@ -211,7 +211,7 @@ func edgeInstallerPipelines(t *imageType, customizations *blueprint.Customizatio
kernelVer := rpmmd.GetVerStrFromPackageSpecListPanic(installerPackages, "kernel") kernelVer := rpmmd.GetVerStrFromPackageSpecListPanic(installerPackages, "kernel")
ostreeRepoPath := "/ostree/repo" ostreeRepoPath := "/ostree/repo"
payloadStages := ostreePayloadStages(options, ostreeRepoPath) payloadStages := ostreePayloadStages(options, ostreeRepoPath)
kickstartOptions, err := osbuild.NewKickstartStageOptions(kspath, "", customizations.GetUsers(), customizations.GetGroups(), makeISORootPath(ostreeRepoPath), options.OSTree.Ref, "rhel") kickstartOptions, err := osbuild.NewKickstartStageOptions(kspath, "", users.UsersFromBP(customizations.GetUsers()), users.GroupsFromBP(customizations.GetGroups()), makeISORootPath(ostreeRepoPath), options.OSTree.Ref, "rhel")
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -250,7 +250,7 @@ func imageInstallerPipelines(t *imageType, customizations *blueprint.Customizati
tarPath := "/liveimg.tar" tarPath := "/liveimg.tar"
tarPayloadStages := []*osbuild.Stage{osbuild.NewTarStage(&osbuild.TarStageOptions{Filename: tarPath}, treePipeline.Name)} tarPayloadStages := []*osbuild.Stage{osbuild.NewTarStage(&osbuild.TarStageOptions{Filename: tarPath}, treePipeline.Name)}
kickstartOptions, err := osbuild.NewKickstartStageOptions(kspath, makeISORootPath(tarPath), customizations.GetUsers(), customizations.GetGroups(), "", "", "rhel") kickstartOptions, err := osbuild.NewKickstartStageOptions(kspath, makeISORootPath(tarPath), users.UsersFromBP(customizations.GetUsers()), users.GroupsFromBP(customizations.GetGroups()), "", "", "rhel")
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -444,17 +444,17 @@ func osPipeline(t *imageType,
// don't put users and groups in the payload of an installer // don't put users and groups in the payload of an installer
// add them via kickstart instead // add them via kickstart instead
if groups := c.GetGroups(); len(groups) > 0 { if groups := c.GetGroups(); len(groups) > 0 {
p.AddStage(osbuild.NewGroupsStage(osbuild.NewGroupsStageOptions(groups))) p.AddStage(osbuild.NewGroupsStage(osbuild.NewGroupsStageOptions(users.GroupsFromBP(groups))))
} }
if userOptions, err := osbuild.NewUsersStageOptions(c.GetUsers(), false); err != nil { if userOptions, err := osbuild.NewUsersStageOptions(users.UsersFromBP(c.GetUsers()), false); err != nil {
return nil, err return nil, err
} else if userOptions != nil { } else if userOptions != nil {
if t.rpmOstree { if t.rpmOstree {
// for ostree, writing the key during user creation is // for ostree, writing the key during user creation is
// redundant and can cause issues so create users without keys // redundant and can cause issues so create users without keys
// and write them on first boot // and write them on first boot
userOptionsSansKeys, err := osbuild.NewUsersStageOptions(c.GetUsers(), true) userOptionsSansKeys, err := osbuild.NewUsersStageOptions(users.UsersFromBP(c.GetUsers()), true)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View file

@ -4,19 +4,19 @@ import (
"math/rand" "math/rand"
"github.com/osbuild/osbuild-composer/internal/artifact" "github.com/osbuild/osbuild-composer/internal/artifact"
"github.com/osbuild/osbuild-composer/internal/blueprint"
"github.com/osbuild/osbuild-composer/internal/manifest" "github.com/osbuild/osbuild-composer/internal/manifest"
"github.com/osbuild/osbuild-composer/internal/platform" "github.com/osbuild/osbuild-composer/internal/platform"
"github.com/osbuild/osbuild-composer/internal/rpmmd" "github.com/osbuild/osbuild-composer/internal/rpmmd"
"github.com/osbuild/osbuild-composer/internal/runner" "github.com/osbuild/osbuild-composer/internal/runner"
"github.com/osbuild/osbuild-composer/internal/users"
) )
type OSTreeInstaller struct { type OSTreeInstaller struct {
Base Base
Platform platform.Platform Platform platform.Platform
ExtraBasePackages rpmmd.PackageSet ExtraBasePackages rpmmd.PackageSet
Users []blueprint.UserCustomization Users []users.User
Groups []blueprint.GroupCustomization Groups []users.Group
ISOLabelTempl string ISOLabelTempl string
Product string Product string

View file

@ -4,9 +4,9 @@ import (
"fmt" "fmt"
"path" "path"
"github.com/osbuild/osbuild-composer/internal/blueprint"
"github.com/osbuild/osbuild-composer/internal/disk" "github.com/osbuild/osbuild-composer/internal/disk"
"github.com/osbuild/osbuild-composer/internal/osbuild" "github.com/osbuild/osbuild-composer/internal/osbuild"
"github.com/osbuild/osbuild-composer/internal/users"
) )
// An ISOTree represents a tree containing the anaconda installer, // An ISOTree represents a tree containing the anaconda installer,
@ -18,8 +18,8 @@ type ISOTree struct {
// TODO: review optional and mandatory fields and their meaning // TODO: review optional and mandatory fields and their meaning
OSName string OSName string
Release string Release string
Users []blueprint.UserCustomization Users []users.User
Groups []blueprint.GroupCustomization Groups []users.Group
PartitionTable *disk.PartitionTable PartitionTable *disk.PartitionTable

View file

@ -1,7 +1,6 @@
package osbuild package osbuild
import ( import (
"github.com/osbuild/osbuild-composer/internal/blueprint"
"github.com/osbuild/osbuild-composer/internal/users" "github.com/osbuild/osbuild-composer/internal/users"
) )
@ -22,7 +21,7 @@ func NewGroupsStage(options *GroupsStageOptions) *Stage {
} }
} }
func NewGroupsStageOptions(groups []blueprint.GroupCustomization) *GroupsStageOptions { func NewGroupsStageOptions(groups []users.Group) *GroupsStageOptions {
options := GroupsStageOptions{ options := GroupsStageOptions{
Groups: map[string]GroupsStageOptionsGroup{}, Groups: map[string]GroupsStageOptionsGroup{},
} }

View file

@ -1,8 +1,6 @@
package osbuild package osbuild
import ( import "github.com/osbuild/osbuild-composer/internal/users"
"github.com/osbuild/osbuild-composer/internal/blueprint"
)
type KickstartStageOptions struct { type KickstartStageOptions struct {
// Where to place the kickstart file // Where to place the kickstart file
@ -41,8 +39,8 @@ func NewKickstartStage(options *KickstartStageOptions) *Stage {
func NewKickstartStageOptions( func NewKickstartStageOptions(
path string, path string,
imageURL string, imageURL string,
userCustomizations []blueprint.UserCustomization, userCustomizations []users.User,
groupCustomizations []blueprint.GroupCustomization, groupCustomizations []users.Group,
ostreeURL string, ostreeURL string,
ostreeRef string, ostreeRef string,
osName string) (*KickstartStageOptions, error) { osName string) (*KickstartStageOptions, error) {

View file

@ -1,7 +1,6 @@
package osbuild package osbuild
import ( import (
"github.com/osbuild/osbuild-composer/internal/blueprint"
"github.com/osbuild/osbuild-composer/internal/crypt" "github.com/osbuild/osbuild-composer/internal/crypt"
"github.com/osbuild/osbuild-composer/internal/users" "github.com/osbuild/osbuild-composer/internal/users"
) )
@ -30,7 +29,7 @@ func NewUsersStage(options *UsersStageOptions) *Stage {
} }
} }
func NewUsersStageOptions(userCustomizations []blueprint.UserCustomization, omitKey bool) (*UsersStageOptions, error) { func NewUsersStageOptions(userCustomizations []users.User, omitKey bool) (*UsersStageOptions, error) {
if len(userCustomizations) == 0 { if len(userCustomizations) == 0 {
return nil, nil return nil, nil
} }

View file

@ -4,8 +4,7 @@ import (
"strings" "strings"
"testing" "testing"
"github.com/osbuild/osbuild-composer/internal/blueprint" "github.com/osbuild/osbuild-composer/internal/users"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@ -24,20 +23,20 @@ func TestNewUsersStageOptionsPassword(t *testing.T) {
EmptyPass := "" EmptyPass := ""
CryptPass := "$6$RWdHzrPfoM6BMuIP$gKYlBXQuJgP.G2j2twbOyxYjFDPUQw8Jp.gWe1WD/obX0RMyfgw5vt.Mn/tLLX4mQjaklSiIzoAW3HrVQRg4Q." // #nosec G101 CryptPass := "$6$RWdHzrPfoM6BMuIP$gKYlBXQuJgP.G2j2twbOyxYjFDPUQw8Jp.gWe1WD/obX0RMyfgw5vt.Mn/tLLX4mQjaklSiIzoAW3HrVQRg4Q." // #nosec G101
users := []blueprint.UserCustomization{ users := []users.User{
blueprint.UserCustomization{ {
Name: "bart", Name: "bart",
Password: &Pass, Password: &Pass,
}, },
blueprint.UserCustomization{ {
Name: "lisa", Name: "lisa",
Password: &CryptPass, Password: &CryptPass,
}, },
blueprint.UserCustomization{ {
Name: "maggie", Name: "maggie",
Password: &EmptyPass, Password: &EmptyPass,
}, },
blueprint.UserCustomization{ {
Name: "homer", Name: "homer",
}, },
} }