Skip to content

Commit

Permalink
blueprint: remove the sshkey customization
Browse files Browse the repository at this point in the history
Both the sshkey and users customizations have been around since the
beginning of time [1].  The users customization was always a superset of
the sshkey, so we have code in blueprints to convert sshkeys into users.

The blueprint code in images is not exposed directly to users.  The code
responsible for deserializing blueprint toml files lives in
osbuild-composer and is directly translated to the equivalent types in
osbuild/images.  We can simplify the code and types here to only contain
the customizations that are strictly necessary and we don't need to
maintain backwards compatibility.

The blueprint conversion code in osbuild-composer should convert all
sshkeys to users before passing them down to osbuild/images functions.

[1] 967b0e8
  • Loading branch information
achilleas-k committed Sep 16, 2024
1 parent cd83f86 commit 320f943
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 34 deletions.
18 changes: 2 additions & 16 deletions pkg/blueprint/customizations.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
type Customizations struct {
Hostname *string `json:"hostname,omitempty" toml:"hostname,omitempty"`
Kernel *KernelCustomization `json:"kernel,omitempty" toml:"kernel,omitempty"`
SSHKey []SSHKeyCustomization `json:"sshkey,omitempty" toml:"sshkey,omitempty"`
User []UserCustomization `json:"user,omitempty" toml:"user,omitempty"`
Group []GroupCustomization `json:"group,omitempty" toml:"group,omitempty"`
Timezone *TimezoneCustomization `json:"timezone,omitempty" toml:"timezone,omitempty"`
Expand Down Expand Up @@ -228,24 +227,11 @@ func (c *Customizations) GetTimezoneSettings() (*string, []string) {
}

func (c *Customizations) GetUsers() []UserCustomization {
if c == nil || (c.SSHKey == nil && c.User == nil) {
if c == nil || c.User == nil {
return nil
}

users := []UserCustomization{}

// prepend sshkey for backwards compat (overridden by users)
if len(c.SSHKey) > 0 {
for idx := range c.SSHKey {
keyc := c.SSHKey[idx]
users = append(users, UserCustomization{
Name: keyc.User,
Key: &keyc.Key,
})
}
}

users = append(users, c.User...)
users := c.User

// sanitize user home directory in blueprint: if it has a trailing slash,
// it might lead to the directory not getting the correct selinux labels
Expand Down
18 changes: 0 additions & 18 deletions pkg/blueprint/customizations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,24 +76,6 @@ func TestGetKernel(t *testing.T) {
assert.Equal(t, &expectedKernel, retKernel)
}

func TestSSHKey(t *testing.T) {
expectedSSHKeys := []SSHKeyCustomization{
{
User: "test-user",
Key: "test-key",
},
}
TestCustomizations := Customizations{
SSHKey: expectedSSHKeys,
}

retUser := TestCustomizations.GetUsers()[0].Name
retKey := *TestCustomizations.GetUsers()[0].Key

assert.Equal(t, expectedSSHKeys[0].User, retUser)
assert.Equal(t, expectedSSHKeys[0].Key, retKey)
}

func TestGetUsers(t *testing.T) {
Desc := "Test descritpion"
Pass := "testpass"
Expand Down

0 comments on commit 320f943

Please sign in to comment.