Skip to content

Commit 15ef46c

Browse files
committed
base/v0_6_exp: Validate merged/replaced Ingition Configs
1 parent 546d1ff commit 15ef46c

File tree

18 files changed

+1092
-52
lines changed

18 files changed

+1092
-52
lines changed

base/v0_6_exp/validate.go

+17-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package v0_6_exp
1717
import (
1818
baseutil "github.com/coreos/butane/base/util"
1919
"github.com/coreos/butane/config/common"
20+
exp "github.com/coreos/ignition/v2/config/v3_5_experimental"
2021

2122
"github.com/coreos/ignition/v2/config/util"
2223
"github.com/coreos/vcontext/path"
@@ -29,10 +30,24 @@ func (rs Resource) Validate(c path.ContextPath) (r report.Report) {
2930
if rs.Local != nil {
3031
sources++
3132
field = "local"
33+
config := *rs.Local
34+
_, report, err := exp.Parse([]byte(config))
35+
if err != nil {
36+
r.Merge(report)
37+
} else {
38+
r.AddOnError(c.Append("ignition", "config", "merge", "local"), common.ErrEmptyReport)
39+
}
3240
}
3341
if rs.Inline != nil {
3442
sources++
3543
field = "inline"
44+
config := *rs.Inline
45+
_, report, err := exp.Parse([]byte(config))
46+
if err != nil {
47+
r.Merge(report)
48+
} else {
49+
r.AddOnError(c.Append("ignition", "config", "merge", "local"), common.ErrEmptyReport)
50+
}
3651
}
3752
if rs.Source != nil {
3853
sources++
@@ -41,7 +56,8 @@ func (rs Resource) Validate(c path.ContextPath) (r report.Report) {
4156
if sources > 1 {
4257
r.AddOnError(c.Append(field), common.ErrTooManyResourceSources)
4358
}
44-
return
59+
60+
return r
4561
}
4662

4763
func (fs Filesystem) Validate(c path.ContextPath) (r report.Report) {

config/common/errors.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ 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")
3332

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

3736
// resources and trees
37+
ErrEmptyReport = errors.New("error merging report, report empty")
3838
ErrTooManyResourceSources = errors.New("only one of the following can be set: inline, local, source")
3939
ErrFilesDirEscape = errors.New("local file path traverses outside the files directory")
4040
ErrFileType = errors.New("trees may only contain files, directories, and symlinks")

config/fcos/v1_6_exp/validate.go

-13
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ 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)$")
3130

3231
// We can't define a Validate function directly on Disk because that's defined in base,
3332
// so we use a Validate function on the top-level Config instead.
@@ -46,18 +45,6 @@ func (conf Config) Validate(c path.ContextPath) (r report.Report) {
4645
r.AddOnError(c.Append("storage", "filesystems", i, "path"), common.ErrMountPointForbidden)
4746
}
4847
}
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-
}
6148
return
6249
}
6350

config/fcos/v1_6_exp/validate_test.go

-35
Original file line numberDiff line numberDiff line change
@@ -479,38 +479,3 @@ 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

+1-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ 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)_
24+
- Validate merged/replaced ignition configs if they are local/inline _(fcos 1.6.0-exp)_
2625

2726
### Bug fixes
2827

vendor/github.com/coreos/ignition/v2/config/translate/translate.go

+187
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/coreos/ignition/v2/config/v3_0/config.go

+73
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)