Skip to content

Commit 546d1ff

Browse files
committed
fcos/v1_6_exp: Fail if user provides invalid file type
1 parent b50dc15 commit 546d1ff

File tree

4 files changed

+51
-0
lines changed

4 files changed

+51
-0
lines changed

config/common/errors.go

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ var (
2929
// high-level errors for fatal reports
3030
ErrInvalidSourceConfig = errors.New("source config is invalid")
3131
ErrInvalidGeneratedConfig = errors.New("config generated was invalid")
32+
ErrInvalidFileExtension = errors.New("file type provided was invalid; use .ign for local/inline instead")
3233

3334
// deprecated variant/version
3435
ErrRhcosVariantUnsupported = errors.New("rhcos variant has been removed; use openshift variant instead: https://coreos.github.io/butane/upgrading-openshift/")

config/fcos/v1_6_exp/validate.go

+13
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
const rootDevice = "/dev/disk/by-id/coreos-boot-disk"
2828

2929
var allowedMountpoints = regexp.MustCompile(`^/(etc|var)(/|$)`)
30+
var fileExt = regexp.MustCompile("^(.ign)$")
3031

3132
// We can't define a Validate function directly on Disk because that's defined in base,
3233
// so we use a Validate function on the top-level Config instead.
@@ -45,6 +46,18 @@ func (conf Config) Validate(c path.ContextPath) (r report.Report) {
4546
r.AddOnError(c.Append("storage", "filesystems", i, "path"), common.ErrMountPointForbidden)
4647
}
4748
}
49+
50+
if conf.Ignition.Config.Merge != nil {
51+
for i, conf := range conf.Ignition.Config.Merge {
52+
if conf.Inline != nil && !fileExt.MatchString(string(*conf.Inline)) {
53+
r.AddOnError(c.Append("ignition", "config", "merge", i, "inline"), common.ErrInvalidFileExtension)
54+
}
55+
56+
if conf.Local != nil && !fileExt.MatchString(string(*conf.Local)) {
57+
r.AddOnError(c.Append("ignition", "config", "merge", i, "local"), common.ErrInvalidFileExtension)
58+
}
59+
}
60+
}
4861
return
4962
}
5063

config/fcos/v1_6_exp/validate_test.go

+35
Original file line numberDiff line numberDiff line change
@@ -479,3 +479,38 @@ func TestValidateConfig(t *testing.T) {
479479
})
480480
}
481481
}
482+
483+
func TestValidateFileExtension(t *testing.T) {
484+
tests := []struct {
485+
in Config
486+
out error
487+
errPath path.ContextPath
488+
}{
489+
{
490+
in: Config{
491+
Config: base.Config{
492+
Ignition: base.Ignition{
493+
Config: base.IgnitionConfig{
494+
Merge: []base.Resource{
495+
{
496+
Inline: util.StrToPtr("config.bu"),
497+
},
498+
},
499+
},
500+
},
501+
},
502+
},
503+
out: common.ErrInvalidFileExtension,
504+
errPath: path.New("yaml", "ignition", "config", "merge", 0, "inline"),
505+
},
506+
}
507+
for i, test := range tests {
508+
t.Run(fmt.Sprintf("validate %d", i), func(t *testing.T) {
509+
actual := test.in.Validate(path.New("yaml"))
510+
baseutil.VerifyReport(t, test.in, actual)
511+
expected := report.Report{}
512+
expected.AddOnError(test.errPath, test.out)
513+
assert.Equal(t, expected, actual, "invalid report")
514+
})
515+
}
516+
}

docs/release-notes.md

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ key](https://getfedora.org/security/).
2121
openshift 4.14.0-exp)_
2222
- Require `storage.filesystems.path` to start with `/etc` or `/var` if
2323
`with_mount_unit` is true _(fcos 1.6.0-exp, openshift 4.14.0-exp)_
24+
- Require local/inline fields from Ignition.Config.Merge to have the .ign file
25+
extension _(fcos 1.6.0-exp)_
2426

2527
### Bug fixes
2628

0 commit comments

Comments
 (0)