Skip to content

Commit

Permalink
openshift/v4.16: Remove GRUB password support
Browse files Browse the repository at this point in the history
  • Loading branch information
yasminvalim committed May 29, 2024
1 parent 0c9a587 commit 6f7f189
Show file tree
Hide file tree
Showing 3 changed files with 165 additions and 108 deletions.
26 changes: 1 addition & 25 deletions config/openshift/v4_16/translate.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ func (c Config) ToMachineConfig4_16Unvalidated(options common.TranslateOptions)
if r.IsFatal() {
return result.MachineConfig{}, ts, r
}
ts = translateUserGrubCfg(&cfg, &ts)

// wrap
ts = ts.PrefixPaths(path.New("yaml"), path.New("json", "spec", "config"))
Expand Down Expand Up @@ -208,7 +207,7 @@ func (c Config) ToIgn3_4(options common.TranslateOptions) (types.Config, report.
// translating, an error is returned.
func ToConfigBytes(input []byte, options common.TranslateBytesOptions) ([]byte, report.Report, error) {
if options.Raw {
return cutil.TranslateBytes(input, &Config{}, "ToIgn4", options)
return cutil.TranslateBytes(input, &Config{}, "ToIgn3_4", options)
} else {
return cutil.TranslateBytesYAML(input, &Config{}, "ToMachineConfig4_16", options)
}
Expand Down Expand Up @@ -302,26 +301,3 @@ func validateMCOSupport(mc result.MachineConfig) report.Report {
}
return r
}

// fcos config generates a user.cfg file using append; however, OpenShift config
// does not support append (since MCO does not support it). Let change the file to use contents
func translateUserGrubCfg(config *types.Config, ts *translate.TranslationSet) translate.TranslationSet {
newMappings := translate.NewTranslationSet("json", "json")
for i, file := range config.Storage.Files {
if file.Path == "/boot/grub2/user.cfg" {
if len(file.Append) != 1 {
// The number of append objects was different from expected, this file
// was created by the user and not via butane GRUB sugar
return *ts
}
fromPath := path.New("json", "storage", "files", i, "append", 0)
translatedPath := path.New("json", "storage", "files", i, "contents")
config.Storage.Files[i].FileEmbedded1.Contents = file.Append[0]
config.Storage.Files[i].FileEmbedded1.Append = nil
newMappings.AddFromCommonObject(fromPath, translatedPath, config.Storage.Files[i].FileEmbedded1.Contents)

return ts.Map(newMappings)
}
}
return *ts
}
83 changes: 0 additions & 83 deletions config/openshift/v4_16/translate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,89 +272,6 @@ func TestTranslateConfig(t *testing.T) {
{From: path.New("yaml", "openshift", "fips"), To: path.New("json", "spec", "fips")},
},
},
// Test Grub config
{
Config{
Metadata: Metadata{
Name: "z",
Labels: map[string]string{
ROLE_LABEL_KEY: "z",
},
},
Config: fcos.Config{
Grub: fcos.Grub{
Users: []fcos.GrubUser{
{
Name: "root",
PasswordHash: util.StrToPtr("grub.pbkdf2.sha512.10000.874A958E526409..."),
},
},
},
},
},
result.MachineConfig{
ApiVersion: result.MC_API_VERSION,
Kind: result.MC_KIND,
Metadata: result.Metadata{
Name: "z",
Labels: map[string]string{
ROLE_LABEL_KEY: "z",
},
},
Spec: result.Spec{
Config: types.Config{
Ignition: types.Ignition{
Version: "3.4.0",
},
Storage: types.Storage{
Filesystems: []types.Filesystem{
{
Device: "/dev/disk/by-label/boot",
Format: util.StrToPtr("ext4"),
Path: util.StrToPtr("/boot"),
},
},
Files: []types.File{
{
Node: types.Node{
Path: "/boot/grub2/user.cfg",
},
FileEmbedded1: types.FileEmbedded1{
Contents: types.Resource{
Source: util.StrToPtr("data:,%23%20Generated%20by%20Butane%0A%0Aset%20superusers%3D%22root%22%0Apassword_pbkdf2%20root%20grub.pbkdf2.sha512.10000.874A958E526409...%0A"),
Compression: util.StrToPtr(""),
},
},
},
},
},
},
},
},
[]translate.Translation{
{From: path.New("yaml", "version"), To: path.New("json", "apiVersion")},
{From: path.New("yaml", "version"), To: path.New("json", "kind")},
{From: path.New("yaml", "version"), To: path.New("json", "spec")},
{From: path.New("yaml"), To: path.New("json", "spec", "config")},
{From: path.New("yaml", "ignition"), To: path.New("json", "spec", "config", "ignition")},
{From: path.New("yaml", "version"), To: path.New("json", "spec", "config", "ignition", "version")},
{From: path.New("yaml", "grub", "users"), To: path.New("json", "spec", "config", "storage")},
{From: path.New("yaml", "grub", "users"), To: path.New("json", "spec", "config", "storage", "filesystems")},
{From: path.New("yaml", "grub", "users"), To: path.New("json", "spec", "config", "storage", "filesystems", 0)},
{From: path.New("yaml", "grub", "users"), To: path.New("json", "spec", "config", "storage", "filesystems", 0, "path")},
{From: path.New("yaml", "grub", "users"), To: path.New("json", "spec", "config", "storage", "filesystems", 0, "device")},
{From: path.New("yaml", "grub", "users"), To: path.New("json", "spec", "config", "storage", "filesystems", 0, "format")},
{From: path.New("yaml", "grub", "users"), To: path.New("json", "spec", "config", "storage", "files")},
{From: path.New("yaml", "grub", "users"), To: path.New("json", "spec", "config", "storage", "files", 0)},
{From: path.New("yaml", "grub", "users"), To: path.New("json", "spec", "config", "storage", "files", 0, "path")},
// "append" field is a remnant of translations performed in fcos config
// TODO: add a delete function to translation.TranslationSet and delete "append" translation
{From: path.New("yaml", "grub", "users"), To: path.New("json", "spec", "config", "storage", "files", 0, "append")},
{From: path.New("yaml", "grub", "users"), To: path.New("json", "spec", "config", "storage", "files", 0, "contents")},
{From: path.New("yaml", "grub", "users"), To: path.New("json", "spec", "config", "storage", "files", 0, "contents", "source")},
{From: path.New("yaml", "grub", "users"), To: path.New("json", "spec", "config", "storage", "files", 0, "contents", "compression")},
},
},
}

for i, test := range tests {
Expand Down
Loading

0 comments on commit 6f7f189

Please sign in to comment.